riku
2022-08-23 8fbd6b8d09e70494d920cc0b77812e9643be3196
pages/learn/learn.js
@@ -1,4 +1,8 @@
// pages/learn/learn.js
const lawservice = require("../../service/lawservice")
const moment = require('../../utils/moment.min')
const app = getApp()
Page({
  /**
@@ -20,244 +24,45 @@
      }
    ],
    pageList: [
    ],
    banners: [
      {
        banners: [
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
        ],
        text1: [{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年4月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年3月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        }],
        text2: [{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        }]
      },{
        banners: [
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
        ],
        text1: [{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年4月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年3月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        }],
        text2: [{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        }]
      },{
        banners: [
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
        ],
        text1: [{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年4月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年3月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        }],
        text2: [{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        }]
      },{
        banners: [
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
          '/res/icons/btn_bg_1.png',
          '/res/icons/btn_bg_2.png',
        ],
        text1: [{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年4月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年3月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        },{
          title: "企业营业执照、食品经营许可证丢失该如何补领",
          time: "2022年2月5日",
          views: 2012,
          pic: "/res/icons/temp_pic_1.png"
        }],
        text2: [{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        },{
          title: "因违章建筑导致执法",
          content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
          tags: ['违法搭建', '依法拆除'],
          views: 123,
          time: '2021年3月2日',
          likes: 233
        }]
      }
    ]
        pic: '',
        url: '',
        fileType: ''
      },
    ],
    resources: [],
    text2: [{
      title: "因违章建筑导致执法",
      content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
      tags: ['违法搭建', '依法拆除'],
      views: 123,
      time: '2021年3月2日',
      likes: 233
    }, {
      title: "因违章建筑导致执法",
      content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
      tags: ['违法搭建', '依法拆除'],
      views: 123,
      time: '2021年3月2日',
      likes: 233
    }, {
      title: "因违章建筑导致执法",
      content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
      tags: ['违法搭建', '依法拆除'],
      views: 123,
      time: '2021年3月2日',
      likes: 233
    }, {
      title: "因违章建筑导致执法",
      content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一",
      tags: ['违法搭建', '依法拆除'],
      views: 123,
      time: '2021年3月2日',
      likes: 233
    }]
  },
  //计算swiper高度方法(在切换的时候调用)
  tabsHeight(element) {
@@ -278,7 +83,7 @@
        currentTab: e.target.dataset.current,
        navScrollLeft: e.target.dataset.current >= 4 ? ((e.target.dataset.current) * 60) : 0 //判断当前选中的个数是否是第5个
      })
      that.tabsHeight('.page'+e.target.dataset.current);   //查询哪一个元素
      that.tabsHeight('.page' + e.target.dataset.current); //查询哪一个元素
    }
  },
  bindChange: function (e) {
@@ -294,38 +99,120 @@
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.tabsHeight('.page0');
    // this.tabsHeight('.page0');
    this.getResources()
  },
  onReachBottom () {
    console.log('onReachBottom');
    if (this.cPage && this.tPage) {
      if (this.cPage < this.tPage) {
        this.getResources(this.cPage + 1)
      }
    }
  },
  getBanner() {
    let banners = []
    for (let i = 0; i < 6; i++) {
      const d = this.data.resources[i]
      banners.push({
        pic: d.lrPicurl,
        url: d.lrBodyurl,
        fileType: d.lrResourcefiletype,
      })
    }
    this.setData({
      banners
    })
  },
  getResources(cPage = 1) {
    var that = this
    let user = app.globalData.userInfo
    lawservice.getLawRegulations(user.guid, cPage, {sceneTypeId: user.extension2}, {
      onHead(header) {
        that.cPage = parseInt(header.currentPage)
        that.tPage = parseInt(header.totalPage)
        console.log(`cPage:${that.cPage}, tPage:${that.tPage}`);
      },
      success(data) {
        let resources = that.data.resources
        data.forEach(d => {
          d.views = parseInt(Math.random() * 1000 + 10)
          d.lrPublishdate = moment(d.lrPublishdate).format('YYYY年MM月DD日')
        });
        resources = resources.concat(data)
        that.setData({
          resources
        })
        if (that.cPage == 1) {
          that.getBanner()
        }
      }
    }, 10)
  },
  gotoBanner(e) {
    var index = e.currentTarget.dataset.index
    let f = this.data.resources[index]
    this.goto(f)
  },
  gotoResource(e) {
    var index = e.currentTarget.dataset.index
    let f = this.data.resources[index]
    this.goto(f)
  },
  /**
   * 页面跳转
   */
  goto: function (e) {
  goto: function (f) {
    var url = ""
    var index = e.currentTarget.dataset.index
    switch (index) {
      case "0":
        url = ""
        break;
    switch (f.lrResourcefiletype) {
      //文档
      case "1":
        let bodyUrl = f.lrBodyurl
        wx.showLoading({
          title: ' 文件下载中',
          mask: true,
        })
        wx.downloadFile({
          url: bodyUrl,
          success: function (res) {
            wx.hideLoading()
            const filePath = res.tempFilePath
            wx.openDocument({
              filePath: filePath,
              success: function (res) {
                console.log('打开文档成功')
              },
              fail(error) {
                console.log(error);
              }
            })
          }
        })
        break;
      //链接
      case 2:
        url = ""
        break;
      case "2":
        url = ""
        return;
      case "3":
      //图片
      case 3:
        url = ""
        break;
      case "4":
        //环保守法
        url = "/pages/text/text"
        break;
      case "5":
      //视频
      case 4:
        url = "/pages/module_common/pagevideo/pagevideo"
        break;
    }
    if (url != "") {
      wx.navigateTo({
        url: url
        url: url,
        success: (res) => {
          // 通过 eventChannel 向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', f)
        },
      })
    }
  }