yangyin
2023-12-26 ebd9f0bd44a76a0fba4f82f799b349cdab2b21ca
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// reportForm/index/index.js
var dateTimePickerCtrl = require('../../utils/dateTimePicker.js'); //日期控件
var Constant = require('../../utils/constant.js');
var util = require('../../utils/util.js');
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    width: '',
    height: '',
    colHeight: '',
    colWidth: '',
    scrollTop: 0,
    VerticalNavTop: 0,
    stationName: '', //泵站名称
    stationID: '', //泵站id
    requestData: {
      stationID: "",
      year: '',
      month: '',
    },
    dateStart: "",
    dateEnd: "",
    startDate: "",
    endDate: "",
    selectDate: '', //日期选择后的日期
    isShowFilter: false, //是否显示日期筛选
    isLeftScroll: false, //判断左边的scroll-view 的方法是否调用
    isRightScroll: false, //判断右边的scroll-view 的方法是否调用
    tabDateList: [], //存储日期的数组
    tabHeadList: [], //存储表头内容的数组
    timeList: [], //存储开关机时间、用电量、供水量的数组,
    list: [], //存储表格内容元素宽高的数组
    load: true,
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options, 328)
    let that = this;
    wx.getSystemInfo({ //获取设备的宽度和高度
      success: (res) => {
        console.log(res.windowWidth, res.windowHeight, '设备物理宽高')
        that.setData({
          width: res.windowWidth,
          height: res.windowHeight
        })
      },
      fail: (err) => {
        console.log(err)
      }
    })
    that.initialDateTimePicker();
    var requestData = that.data.requestData
    requestData.stationID = options.id
    that.setData({
      stationID: options.id,
      requestData: requestData,
      stationName: options.name
    })
    that.initData();
  },
  //初始化数据
  initData: function () {
    wx.showLoading({
      title: '数据加载中...',
    })
    var that = this
    var requestData = that.data.requestData
    wx.request({
      url: Constant.BASE_SERVER_URL + 'Main/Web/PumpRunParas/GetMonthDetailSumDataByStationID',
      method: "GET",
      data: {
        StationID: requestData.stationID,
        Year: requestData.year,
        Month: requestData.month
      },
      success: res => {
        console.log(res,83)
        wx.hideLoading()
        var tabDateList = that.data.tabDateList; //表格左侧日期列表
        var tabHeadList = that.data.tabHeadList; //表头
        var list = []; //表格内容-各个机组的时间
 
        // console.log(res.data.Data, 291)
        // console.log(timeList, 292)
        var result = res.data.Data
        if (res.data.Code != 0) {
          wx.showToast({
            title: '数据加载失败',
            icon: 'none',
            duration: 2000
          })
          return;
        }
        //构造表格需要的数据格式
        var temp = result[0];
        var recordArr = result;
 
        var temp1 = 0
        var arrtest = []
        for (var i = 0; i < recordArr.length - 1; i++) {
          var test = {}
          if (recordArr[i].SumDay != recordArr[i + 1].SumDay) {
            // console.log(temp1, i)
            for (var j = temp1; j < i + 1; j++) {
              test['kaiji' + j + 1] = recordArr[j].RunHours;
              test['kaiji' + j + 2] = recordArr[j].D;
              test['kaiji' + j + 3] = recordArr[j].Q;
            }
            temp = recordArr[i + 1]
            temp1 = i + 1
            arrtest.push(test)
          }
          if (i == recordArr.length - 2) {
            for (var j = temp1; j < recordArr.length; j++) {
              test['kaiji' + j + 1] = recordArr[j].RunHours;
              test['kaiji' + j + 2] = recordArr[j].D;
              test['kaiji' + j + 3] = recordArr[j].Q;
            }
            arrtest.push(test)
          }
        }
        // console.log(arrtest, '列表主体数据')
 
        for (let i = 0; i < result.length; i++) {
          var info = result[i]
          tabDateList.push(info.SumDay) //获取日期
          var tabHead = { //临时存储表头信息
            PumpId: info.PumpId,
            PumpName: info.PumpName,
            child: ['开机时间(h)', '用电量', '供水量']
          }
          tabHeadList.push(tabHead)
        }
 
        //作用于表格左右滚动组件的适配
        for (let k = 0; k < util.unique(tabDateList).length; k++) {
          list.push({
            id: k
          })
        }
        that.setData({
          tabDateList: util.unique(tabDateList),
          tabHeadList: util.uniqueArr(tabHeadList),
          timeList: arrtest,
          list: list,
        })
      },
 
      fail: err => {
        wx.hideLoading();
        if (err.errMsg == "request:fail ")
          wx.showToast({
            title: '网络请求失败',
            icon: 'none',
            duration: 2000
          })
        // console.log(err)
      }
    })
  },
  //监听左侧滚动事件
  leftScroll: function (e) {
    // this.setData({
    //   isLeftScroll: true,
    //   isRightScroll: false,
    //   leftScrollTop: e.detail.scrollTop
    // })
  },
  VerticalMain(e) {
    let that = this;
    let list = that.data.list;
    let listbak = that.data.list;
    let tabHeight = 0;
    if (this.data.load) {
      list = listbak
      for (let i = 0; i < list.length; i++) {
        let view = wx.createSelectorQuery().select("#main-" + list[i].id);
        view.fields({
          size: true
        }, data => {
          // console.log(data)
          list[i].top = tabHeight;
          tabHeight = tabHeight + data.height;
          list[i].bottom = tabHeight;
        }).exec();
      }
      console.log(list, 111111);
      that.setData({
        load: false,
        list: list
      })
    }
    let scrollTop = e.detail.scrollTop;
    // console.log(e.detail.scrollTop)
    that.setData({
      // VerticalNavTop: (list[i].id) * 26,
      VerticalNavTop: scrollTop
    })
    // console.log(that.data.VerticalNavTop)
  },
  //监听右侧滚动事件
  rightScroll: function (e) {
    // console.log(e.detail.scrollTop)
    this.setData({
      isLeftScroll: true,
      rightScrollTop: e.detail.scrollTop,
    })
  },
  //开关机总表明细
  toDetial: function (e) {
    console.log(e.currentTarget.dataset.id, 284)
    var selectDate = this.data.selectDate
    var year = this.data.requestData.year
    var month = this.data.requestData.month
    wx.navigateTo({
      url: '../Detail/index?id=' + e.currentTarget.dataset.id + '&year=' + year + '&month=' + month + '&name=' + e.currentTarget.dataset.pumpName + '&selectDate=' + selectDate,
    })
  },
  //显示隐藏日期筛选查询
  filterClick: function () {
    var isShowFilter = this.data.isShowFilter
    if (isShowFilter) {
      isShowFilter = false
    } else {
      isShowFilter = true
    }
    this.setData({
      isShowFilter: isShowFilter
    })
  },
  //获取日期
  initialDateTimePicker: function () {
    var that = this;
    var requestData = that.data.requestData;
    var setDateStart = dateTimePickerCtrl.getDate(1);
    var setDateEnd = dateTimePickerCtrl.getDate();
    console.log('当前日期', setDateEnd)
    requestData.year = setDateEnd.substring(0, 4)
    requestData.month = setDateEnd.substring(5, 7)
    that.setData({
      requestData: requestData,
      dateStart: setDateStart,
      dateEnd: setDateEnd.substring(0, 7),
      endDate: setDateEnd,
      selectDate: setDateEnd.substring(0, 7)
    });
  },
  //点击选择年、月份的事件
  changeDateStart(e) {
    console.log(e.detail.value)
    var requestData = this.data.requestData
    var year = e.detail.value.substring(0, 4);
    var month = e.detail.value.substring(5, 7);
    requestData.year = year
    requestData.month = month
    this.setData({
      tabDateList: [],
      requestData: requestData,
      dateEnd: e.detail.value,
      isShowFilter: false,
      selectDate: e.detail.value
    });
    console.log(e.detail.value, year, month)
    this.initData();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //获取开机时间、用电量、供水量表格的宽高
    let that = this
    // 获取元素宽高进行表格适配
    setTimeout(function () {
      let query = wx.createSelectorQuery();
      query.selectAll('.med_body > .body_item').boundingClientRect();
      query.exec(function (rect) {
        // console.log(rect, 163)
        // console.log(rect[0][0].height)
        // console.log(rect[0][0].width)
        if (rect[0].length == 0) {
          wx.showModal({
            title: '提示',
            content: '表格图像加载错误\n请检查您的网络重新进入该页面',
            showCancel: false,
            success: res => {
              if (res.confirm) {
                console.log('用户点击确定')
                return;
              }
            }
          })
        }
        that.setData({
          colHeight: rect[0][0].height + 'px',
          colWidth: rect[0][0].width + 'px'
        })
      })
    }, 500)
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return Constant.Share;
  },
})