riku
2022-08-26 9f78f3f014a3423ea3fcab8f9f1056c57cd47fc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// pages/learn/learn.js
const lawservice = require("../../../service/lawservice")
const moment = require('../../../utils/moment.min')
const beLearn = require('../behaviors/beLearn')
const app = getApp()
 
Page({
  behaviors: [beLearn],
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    tabList: [{
        "name": "VOCs排放"
      },
      {
        "name": "台账"
      },
      {
        "name": "治理设施设备"
      },
      {
        "name": "在线监测设备"
      }
    ],
    pageList: [
 
    ],
    banners: [
      {
        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) {
    let that = this;
    let query = wx.createSelectorQuery(); //必须要先创建一个查询
    query.select(element).boundingClientRect(function (rect) {
      that.setData({
        pageheight: rect.height + 'px'
      });
    }).exec();
  },
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        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); //查询哪一个元素
    }
  },
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current,
      navScrollLeft: e.detail.current >= 4 ? ((e.detail.current) * 60) : 0 //判断当前选中的个数是否是第5个
    });
    // that.tabsHeight('.page'+e.target.dataset.current);    //查询哪一个元素
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 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)
  },
 
  openFile(e) {
    var index = e.currentTarget.dataset.index
    let f = this.data.resources[index]
    this.behaviorOpenFile(f)
  },
  goto: function (e) {
    var url = ""
    var index = e.currentTarget.dataset.index
    switch (index) {
      case '0':
        url = '/pages'
        break;
      case '1':
        url = ""
        break;
    }
    if (url != "") {
      wx.navigateTo({
        url: url,
      })
    }
  }
})