tanghaolin
2022-07-27 fd4d1d9296ba620de15b47bd1d58383d46ecb626
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
var app = getApp();
var dateTimePicker = require('../../utils/dateTimePicker.js'); //日期控件
var utils = require('../../utils/util.js')
var Constant = require('../../utils/constant.js')
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    historyProductRecordList: [], //按产品查询记录列表
    historyEmployeeRecordList: [], //按员工查询记录列表
    tabBarList: [{
      tabBarName: "按日期",
      icon: 'time'
    }, {
      tabBarName: "按产品",
      icon: 'goods'
    }, {
      tabBarName: "按员工",
      icon: 'people'
    }], //底部菜单
    monthWeeksList: ['日', '一', '二', '三', '四', '五', '六'],
    tabBarIndex: 0, //底部tabBar的默认下标
    floatMenu: { //悬浮菜单
      animation: '',
      bindtaps: "expand_floatMenu"
    },
    employeeNowDay: "", //员工界面--当前时间 年月日
    employeeHistoryDay: "", //员工界面--历史时间 年月日
    employeeDateEnd: "", //员工 界面--时间选择器的最大限制时间
    nowYear: "", //当前年份
    nowDate: '', //当前年月
    nowMonth: '', //当前月份
    nowDay: '', //当前日期
    nowMonthFirstDay: '', //当前月份的第一天
    nowMonthLastDay: '', //当前月份的最后一天
    nowMonthAllDateArr: [], //当前月份所有的日期
    dateSize: 0,
    monthMarginLeft: '', //当月天数前面对应的空格数
    productTypeFilterList: {
      typeFilerList: [{
          name: '全部'
        },
        {
          name: '流量计'
        }, {
          name: '压力机'
        }, {
          name: '水质仪'
        }, {
          name: '消防栓'
        }, {
          name: '泵'
        },
      ],
      typeFilterIndex: 0
    },
    productTypeFilterShowStatus: false, //产品类型筛选列表显示状态
    isDateNextDayAble: true, //日期界面控制是否可以点击下一天的状态值
    isEmployeeNextDayAble: true, //员工控制是否可以点击下一天的状态值
    istoexamine: true, //浮动菜单的显示状态
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var systemInfo = wx.getSystemInfoSync();
    this.setData({
      dateSize: systemInfo.screenWidth / 7, //根据屏幕宽度变化自动设置宽度
    });
    this.getDateTime() //获取年月
    this.getDateInfo() //获取日期信息
    this.getOneMonthDate() //获取当月的天数
    this.getMonthWorryStatus(this.data.nowYear, this.data.nowMonth)
  },
  //获取当前月份对应日期的巡检状态及隐患条数
  getMonthWorryStatus: function (Year, Month) {
    var that = this
    let nowMonthAllDateArr = that.data.nowMonthAllDateArr
    wx.showLoading({
      title: '数据获取中...',
    })
    wx.request({
      method: 'GET',
      cache: false,
      url: Constant.BASE_SERVER_URL + 'Repair/Mobile/InspectRecord/GetDayEmployeeCountByMonth',
      data: {
        Year: Year,
        Month: Month,
        CorpID: Constant.CorpID
      },
      success: res => {
        wx.hideLoading({
          complete: com => { //获取隐藏loading框的状态
            // console.log(com)
          }
        })
        // console.log(res, '128')
        let result = res.data
        if (result.Code != 0) {
          wx.showModal({
            title: '提示',
            content: '数据获取失败',
          })
          return;
        }
        let recordMonthAllDateArr = result.Data
        for (let i = 0; i < recordMonthAllDateArr.length; i++) {
          if (nowMonthAllDateArr[i].Day == recordMonthAllDateArr[i].Day) {
            if (recordMonthAllDateArr[i].Count != 0) {
              nowMonthAllDateArr[i].selectStatus = true
              nowMonthAllDateArr[i].Count = recordMonthAllDateArr[i].Count
            } else {
              nowMonthAllDateArr[i].selectStatus = false
              nowMonthAllDateArr[i].Count = recordMonthAllDateArr[i].Count
            }
          }
        }
        that.setData({
          nowMonthAllDateArr: nowMonthAllDateArr
        })
        // console.log(nowMonthAllDateArr, 'nowMonthAllDateArr')
      },
      fail: err => {
        // console.log(err)
      }
    })
  },
  //获取所有的产品列表
  getPageListByProduct: function () {
    var that = this
    wx.showLoading({
      title: '数据获取中...',
    })
    wx.request({
      method: 'GET',
      cache: false,
      url: Constant.BASE_SERVER_URL + 'repair/Mobile/InspectRecord/GetAllInspectProduct',
      data: {
        CorpID: Constant.CorpID,
      },
      success: res => {
        wx.hideLoading()
        // console.log(res, '188')
        let result = res.data
        if (result.Code != 0) {
          wx.showModal({
            title: '提示',
            content: '数据获取失败',
          })
          return;
        }
        this.setData({
          historyProductRecordList: result.Data
        })
      },
      fail: err => {
        console.log(err)
      }
    })
  },
  //获取所有巡检员的列表
  getAllInspectEmployee: function () {
    var that = this
    wx.showLoading({
      title: '数据获取中...',
    })
    wx.request({
      method: 'GET',
      cache: false,
      url: Constant.BASE_SERVER_URL + 'repair/Mobile/InspectRecord/GetAllInspectEmployee',
      data: {
        CorpID: Constant.CorpID,
      },
      success: res => {
        wx.hideLoading()
        // console.log(res, '188')
        let result = res.data
        if (result.Code != 0) {
          wx.showModal({
            title: '提示',
            content: result.Message,
          })
          return;
        }
        this.setData({
          historyEmployeeRecordList: result.Data
        })
      },
      fail: err => {
        console.log(err)
      }
    })
  },
  //底部tabBar切换事件
  tabBarSwitch: function (e) {
    var that = this
    let tabBarIndex = that.data.tabBarIndex
    let index = e.currentTarget.dataset.index
    if (index == 0) {
      this.getMonthWorryStatus(this.data.nowYear, this.data.nowMonth)
    }
    if (index == 1) {
      that.getPageListByProduct()
    }
    if (index == 2) {
      that.getAllInspectEmployee()
    }
    that.setData({
      tabBarIndex: index
    })
  },
  //产品界面和员工界面获取日期
  getDateTime: function () {
    var that = this;
    let productNowDay = utils.formatDay(new Date())
    // console.log(productNowDay)
    that.setData({
      productNowDay: productNowDay,
      productDateEnd: productNowDay,
      productHistoryDay: productNowDay,
      employeeNowDay: productNowDay,
      employeeDateEnd: productNowDay,
      employeeHistoryDay: productNowDay,
    });
  },
  //获取日历相关参数
  //获取当月日期
  getDateInfo: function () {
    var mydate = new Date();
    let year = mydate.getFullYear(); //当前年份
    let month = mydate.getMonth() + 1; //当前的月份
    let day = mydate.getDate(); //当前日期
    let firstDay = new Date(year, month - 1, 1).getDay(); //第一天星期几
    let lastDay = new Date(year, month, 0).getDate(); //当前月份的最后一天
    this.setData({
      nowYear: year,
      nowMonth: month,
      nowDate: year + '-' + '0' + month,
      nowMonthfirstDay: firstDay,
      nowMonthLastDay: lastDay,
      monthMarginLeft: firstDay * this.data.dateSize
    })
    // console.log("今天:" + this.data.nowDate + ',' + firstDay + '----' + lastDay, this.data.monthMarginLeft);
  },
  //选择月份
  nowMonthSelect: function (e) {
    console.log(e.detail.value)
    let date = e.detail.value
    let nowYear = parseInt(date.slice(0, 4))
    let nowMonth = parseInt(date.slice(5, 7))
    // console.log(nowYear + '-' + nowMonth)
    let nowMonthFirstDay = new Date(nowYear, nowMonth - 1, 1);
    this.data.nowMonthFirstDay = nowMonthFirstDay.getDay();
    let nowMonthLastDay = new Date(nowYear, nowMonth, 0);
    this.data.nowMonthLastDay = nowMonthLastDay.getDate();
 
    this.setData({
      nowMonth: nowMonth,
      nowYear: nowYear,
      monthMarginLeft: this.data.nowMonthFirstDay * this.data.dateSize,
      nowMonthFirstDay: this.data.nowMonthFirstDay,
      nowMonthLastDay: this.data.nowMonthLastDay,
      isDateNextDayAble: false
    })
    // console.log(nowYear + '-' + nowMonth)
    this.getOneMonthDate()
  },
  // 获取当前月份的天数
  getOneMonthDate: function () {
    let nowMonthAllDateArr = []
    for (var i = 1; i < this.data.nowMonthLastDay + 1; i++) {
      nowMonthAllDateArr.push({
        Day: i
      });
    }
    this.setData({
      nowMonthAllDateArr: nowMonthAllDateArr,
    })
    // console.log(this.data.nowMonthAllDateArr, '204')
  },
  //按日期查询界面--上一月
  prevDateMonth: function () {
    let nowMonth = "";
    let nowYear = "";
    if (this.data.nowMonth == 1) {
      nowYear = this.data.nowYear - 1
      this.data.nowMonth = 12;
      nowMonth = this.data.nowMonth;
    } else {
      nowYear = this.data.nowYear;
      nowMonth = this.data.nowMonth - 1;
    }
 
    let nowMonthFirstDay = new Date(nowYear, nowMonth - 1, 1);
    this.data.nowMonthFirstDay = nowMonthFirstDay.getDay();
    let nowMonthLastDay = new Date(nowYear, nowMonth, 0);
    this.data.nowMonthLastDay = nowMonthLastDay.getDate();
 
    this.setData({
      nowMonth: nowMonth,
      nowYear: nowYear,
      monthMarginLeft: this.data.nowMonthFirstDay * this.data.dateSize,
      nowMonthFirstDay: this.data.nowMonthFirstDay,
      nowMonthLastDay: this.data.nowMonthLastDay,
      isDateNextDayAble: false
    })
    // console.log(nowYear + '-' + nowMonth)
    this.getOneMonthDate()
    this.getMonthWorryStatus(this.data.nowYear, this.data.nowMonth)
  },
  //按日期查询界面--下一月
  nextDateMonth: function () {
    let nowMonth = "";
    let nowYear = "";
    let historyDate = this.data.nowDate
    if (this.data.nowMonth == 12) {
      this.data.nowMonth = 0;
      nowMonth = this.data.nowMonth;
      nowYear = this.data.nowYear + 1;
    } else {
      nowMonth = this.data.nowMonth + 1;
      nowYear = this.data.nowYear;
    }
    nowMonth = this.data.nowMonth + 1;
    // console.log(nowMonth, 290)
    let nowMonthFirstDay = new Date(nowYear, nowMonth - 1, 1);
    this.data.nowMonthFirstDay = nowMonthFirstDay.getDay();
    let nowMonthLastDay = new Date(nowYear, nowMonth, 0);
    this.data.nowMonthLastDay = nowMonthLastDay.getDate();
 
    let nowDate = nowYear + '-' + (nowMonth < 10 ? '0' + nowMonth : nowMonth)
    // console.log(nowDate, historyDate)
    let isDateNextDayAble = false
    if (nowDate == historyDate) {
      isDateNextDayAble = true
    }
    this.setData({
      nowMonth: nowMonth,
      nowYear: nowYear,
      monthMarginLeft: this.data.nowMonthFirstDay * this.data.dateSize,
      nowMonthFirstDay: this.data.nowMonthFirstDay,
      nowMonthLastDay: this.data.nowMonthLastDay,
      isDateNextDayAble: isDateNextDayAble
    })
    // console.log(nowYear + '-' + nowMonth)
    this.getOneMonthDate()
    this.getMonthWorryStatus(this.data.nowYear, this.data.nowMonth)
  },
  //跳转到某日期的巡检记录
  jumpMonthDetail: function (e) {
    console.log(e.currentTarget.dataset.detialDate)
    let detialDate = e.currentTarget.dataset.detialDate
    wx.navigateTo({
      url: '../historyByMonthDetail/index?detialDate=' + detialDate,
    })
  },
  //跳转到某一产品的巡检记录
  jumpProductDetailPage: function (e) {
    // console.log(e)
    let Day = e.currentTarget.dataset.day
    let mainTabActiveIndex = e.currentTarget.dataset.mainTabIndex
    let ProductID = e.currentTarget.dataset.productId
    let ProductName = e.currentTarget.dataset.productName
    wx.navigateTo({
      url: '../../product/detail/newPumpDetail/index?id=' + ProductID + '&Name=' + ProductName + '&mainTabActiveIndex=' + mainTabActiveIndex + '&Day=' + Day,
    })
  },
  //跳转到某员工的巡检记录
  jumpEmployeeDetailPage: function (e) {
    let EmployeeID = e.currentTarget.dataset.employeeId
    wx.navigateTo({
      url: '../historyByEmployeeDetial/index?EmployeeID=' + EmployeeID,
    })
  },
  //按员工查询界面 -- 上一天
  employeeLastDayClick: function () {
    this.setData({
      employeeNowDay: utils.formatDay(utils.GetNextDate(this.data.employeeNowDay, -1)),
      isEmployeeNextDayAble: false,
    });
  },
  //按员工查询界面 -- 下一天
  employeeNextDayClick: function () {
    var day = utils.formatDay(utils.GetNextDate(this.data.employeeNowDay, 1));
 
    let isEmployeeNextDayAble = false;
    if (day == this.data.employeeHistoryDay) {
      isEmployeeNextDayAble = true;
    }
    this.setData({
      employeeNowDay: day,
      isEmployeeNextDayAble: isEmployeeNextDayAble
    });
  },
  //按产品查询界面 -- 选择日期
  employeeSelectDate: function (e) {
    var that = this
    console.log(e.detail.value)
    let selectDay = utils.formatDay(utils.GetNextDate(e.detail.value, 0));
    var isEmployeeNextDayAble = false;
    if (selectDay == this.data.employeeHistoryDay) {
      isEmployeeNextDayAble = true;
    }
    that.setData({
      employeeNowDay: selectDay,
      isEmployeeNextDayAble: isEmployeeNextDayAble
    })
  },
  //产品类型列表过滤显示
  productTypeFilter: function () {
    this.data.productTypeFilterShowStatus = !this.data.productTypeFilterShowStatus
    this.setData({
      productTypeFilterShowStatus: this.data.productTypeFilterShowStatus
    })
  },
  //产品类型列表选项
  productTypeOptionsChoice: function (e) {
    this.setData({
      "productTypeFilterList.typeFilterIndex": e.currentTarget.dataset.index,
      productTypeFilterShowStatus: false,
    })
  },
  // 手部触摸开始
  ListTouchStart(e) {
    this.setData({
      ListTouchStart: e.touches[0].pageX,
    })
    // console.log(this.data.changeClick)
  },
 
  // 手指滑动过程计算方向
  ListTouchMove(e) {
    this.setData({
      tapTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > -50 ? 'right' : 'left',
    })
    // console.log(this.data.changeClick)
  },
 
  // 手指滑动结束计算滚动
  ListTouchEnd(e) {
    if (this.data.tapTouchDirection == 'left') {
      this.setData({
        modalName: e.currentTarget.dataset.target,
      })
      // console.log(this.data.changeClick)
    } else {
      this.setData({
        modalName: null
      })
    }
    this.setData({
      tapTouchDirection: null,
    })
  },
  //浮动菜单旋转方法
  expand_floatMenu: function () {
    this.setData({
      floatMenu: {
        animation: 'animation',
        bindtaps: "unExpand_floatMenu"
      }
    })
  },
  unExpand_floatMenu: function () {
    this.setData({
      floatMenu: {
        animation: 'animations',
        bindtaps: "expand_floatMenu"
      }
    })
  },
  //悬浮菜单列表收缩方法
  tapExpandList() {
    if (this.data.isExpandList == false) {
      this.setData({
        isExpandList: true
      })
      var historyRecord = this.data.historyRecord
      for (let i = 0; i < historyRecord.length; i++) {
        historyRecord[i].isStatus = true
      }
    } else {
      this.setData({
        isExpandList: false
      })
      var historyRecord = this.data.historyRecord
      for (let i = 0; i < historyRecord.length; i++) {
        historyRecord[i].isStatus = false
      }
    }
    this.setData({
      historyRecord: historyRecord
    })
  },
  toTop() { //悬浮菜单回到顶部方法
    this.setData({
      scrolltop: 0
    })
  },
  //悬浮菜单刷新方法
  tapRefreshBtn() {},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.hideLoading()
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // console.log('到底了');
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return Constant.Share
  },
})