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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
import * as echarts from '../../components/ec-canvas/echarts';
import constant from '../../utils/constant.js';
var util = require('../../utils/util.js');
var Constant = require('../../utils/constant.js');
import Request  from "../../utils/api"
//获取引用实例
var app = getApp();
var RefreshTime = 120;
var barec = null; //动态配置图表数据的变量
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabBar: [{
        index: 0,
        iconPath: "icon-shebeijiance-dianji",
        selectedIconPath: "icon-shebeijiance-dianji blue",
        text: "监测"
      },
      {
        index: 2,
        iconPath: "icon-guzhang",
        selectedIconPath: "icon-guzhang blue",
        text: "警报"
      }
    ],
 
 
 
    machineList: [], //泵组详情名称
 
    startAlarmDate: util.formatDay(util.GetBeforeDate(7)),
    endAlarmDate: util.formatDay(new Date()),
    today: util.formatDay(new Date()),
    meterID: 0,
    currentTabIndex: 0,
    lastRefreshTime: RefreshTime, //秒
    loadingHidden: false,
    loadingInfo: "加载中,请稍等...",
    intervalRefreshTime: null,
    allProductPoints: [],
    allPointId: [],
    alarmListInfo: [],
 
    isInitialAlarmData: false, //是否初始化警报记录
    hasAlarmData: false,
    hasPointData: true,
 
    IsDefault: true,
    kpiParas: { //顶部状态
      status: '正常',
      runNnumber: 4,
      alarmNumber: "无"
    },
 
    scrollHeight: wx.getSystemInfoSync().windowHeight,
    isShowFloatMenu: false, //是否显示
    animationFloatMenu: '', //显示动画
 
    //echart 所有变量定义
    ec: {
      onInit: function (canvas, width, height, dpr) {
        //初始化echarts元素,绑定到全局变量,方便更改数据
        barec = echarts.init(canvas, null, {
          width: width,
          height: height,
          devicePixelRatio: dpr
        });
        canvas.setChart(barec);
        return barec;
      },
    },
    //当前时间
    yestday: util.formatDay(util.GetNextDate(new Date(), 0)),
    historyDate: util.formatDay(util.GetNextDate(new Date(), 0)),
    isNextDayAble: false, //是否可以点击下一天
    PageIndex: 1, //初始化页数
    PageSize: 20, //初始化条数
    message: '未发生报警',
    bottomStatus: false,
    isExpandList: false, //列表展开状态 默认true不展开
    isShowFloatMenu: false, //是否显示
    animationFloatMenu: '', //显示动画
    scrollHeight: wx.getSystemInfoSync().windowHeight,
    scrollTop: 0,
  },
  //监测列表伸缩
  tapExpandList() {
    var allProductPoints = this.data.allProductPoints
    if (this.data.isExpandList) {
      for (let i = 0; i < allProductPoints.length; i++) {
        allProductPoints[i].IsExpand = false
      }
      this.setData({
        isExpandList: false,
        allProductPoints: allProductPoints
      })
    } else if (this.data.isExpandList == false) {
      for (let i = 0; i < allProductPoints.length; i++) {
        allProductPoints[i].IsExpand = true
      }
      this.setData({
        isExpandList: true,
        allProductPoints: allProductPoints
      })
    }
  },
  //上一天点击事件
  yesterDay: function () {
    this.setData({
      historyDate: util.formatDay(util.GetNextDate(this.data.historyDate, -1)),
      isNextDayAble: true,
    });
    this.getWorkTime()
  },
  //下一天点击事件
  tomorrow: function () {
    var day = util.formatDay(util.GetNextDate(this.data.historyDate, 1));
    // console.log(day);
    // console.log(this.data.yestday);
 
    var isNextDayAble = true;
    if (day == this.data.yestday) {
      isNextDayAble = false;
    }
    this.setData({
      historyDate: day,
      isNextDayAble: isNextDayAble
    });
    this.getWorkTime()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //  console.log(options)
    wx.setNavigationBarTitle({
      title: "设备监控" + options.name
    })
    var getNewDateArry = util.getNewDateArry.getNewDateArry();
    var that = this;
    var meterID = options.id;
    // console.log('打印meterID', meterID);
    if (meterID == null) {
      meterID = 462;
    }
    //console.log(meterID);
    // wx.showToast({
    //   title: '获取中....',
    //   icon: "loading",
    //   duration: 3000
    // }) 
    this.setData({
      meterID: meterID,
      getNewDateArry: getNewDateArry.ymdhm
    });
    var userInfo = app.globalData.userInfo;
    if (userInfo == null) {
      return;
    }
 
    Request({
      url: Constant.BASE_SERVER_URL + "Monitor/MonitorPoint/Mobile/GetByMeterID@V1.0",
      method: 'GET',
      data: {
        CorpID: userInfo.CorpID,
        MeterID: meterID,
      },
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) {
        that.setData({
          loadingHidden: true
        });
      }, //请求失败
      success: function (res) {
        that.setData({
          loadingHidden: true
        });
 
        var result = res.data;
          console.log('获取的仪器信息', result);
 
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.Message,
          });
          return;
        }
        //  console.log(result);
        var dict = result.Data;
        // var dict = result.Data.PointList;
        // console.log('dict',dict);
        var allMeterPoints = dict;
        if (allMeterPoints.length == 0) {
          return;
        }
         console.log('allMeterPoints', allMeterPoints);
 
 
        var machineList = []
        for (var i = 0; i < allMeterPoints.length; i++) {
          var node = allMeterPoints[i];
          machineList.push({
            ID: node.ID,
            TitleName: node.Name,
            MachineName: node.Name,
            WorkTime: 0
          });
        }
         var allMeterPointIds = [];
          var dis_num = 0;
          for (var n = 0; n < allMeterPoints.length; n++) {
            var record = allMeterPoints[n];
            record.SignalList[0].SignalValue = ""
            record.SignalList[0].RecordTime= ""
            record.isDisp = false;
            if (record.length <= 2) {
              record.isDisp = true;
              dis_num++;
              allMeterPointIds.push(record.ID);
            }
          }
          if (dis_num < 2) { //没有就显示前两个
            for (var n = 0; n < allMeterPoints.length; n++) {
              var record = allMeterPoints[n];
              if (dis_num <= 2) {
                record.isDisp = true;
                dis_num++;
                allMeterPointIds.push(record.ID);
              }
            }
          }
        
        // console.log(allMeterPointIds)
 
        //定时刷新
        var intervalRefreshTime = setInterval(function () {
          var getNewDateArry = util.getNewDateArry.getNewDateArry()
          var miao = that.data.lastRefreshTime;
          miao = miao - 1;
          if (miao <= 0) {
            that.setData({
              lastRefreshTime: RefreshTime,
              getNewDateArry: getNewDateArry.ymdhm
            });
            that.refreshRecordValue();
          } else {
            that.setData({
              lastRefreshTime: miao
            });
          }
        }, 1000);
 
        // console.log('289行',allProductPoints)
        //更新数据
        that.setData({
          allPointId: allMeterPointIds,
          hasPointData: true,
          allProductPoints: allMeterPoints,
          intervalRefreshTime: intervalRefreshTime,
          machineList: machineList
        });
        console.log('machineList', that.data.machineList);
 
        that.refreshRecordValue(); //刷新一下
      }
    });
  },
  onReady: function () {
    // this.getPoint(); //更新图表配置
  },
  //底部tab切换栏
  tapTab: function (e) {
    var selIndex = e.currentTarget.dataset.index;
    var that = this;
    this.setData({
      currentTabIndex: selIndex
    });
    if (selIndex == 1) { //当选中的下标为1的时候修改图表配置
      setTimeout(function () {
        that.getWorkTime()
      }, 500)
    }
    if (selIndex == 2 && !this.data.isInitialAlarmData) {
 
      this.setData({
        loadingHidden: false,
        isInitialAlarmData: true
      })
      that.getAlarmData(); //调用警报
    }
 
  },
 
  tapProductItem: function (e) {
    // console.log(e.currentTarget.dataset.id)
 
    // wx.navigateTo({
    //  url: '../product/index?id=' + e.currentTarget.dataset.id,
    //})
  },
  refreshRecordValue: function (e) {
    var that = this;
    var allPointId = this.data.allPointId;
    //console.log(allPointId,565)
    var userInfo = app.globalData.userInfo;
    if (allPointId == null || allPointId.length == 0)
      return;
    that.setData({
      loadingHidden: false,
      loadingInfo: "刷新中,请稍等..."
    });
 
     console.log(allPointId.join(','))
 
     Request({
      url: Constant.BASE_SERVER_URL + "Run/MonitorRecord/Mobile/GetLastRecordByMonitorPointIds@V1.0",
      method: 'GET',
      data: {
        CorpID: userInfo.CorpID,
        MonitorPointIds : allPointId.join(',')
      },
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) {
        that.setData({
          loadingHidden: true
        });
        wx.showModal({
          title: '',
          content: '通讯失败',
        })
      }, //请求失败
      complete: function () {}, //请求完成后执行的函数
      success: function (res) {
           console.log('打印刷新后的数据',res);
        that.setData({
          loadingHidden: true
        });
 
        var result = res.data;
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.Message,
          });
          return;
        }
 
        // 
        var newRecordList = result.Data;
        //console.log(result);
        if (newRecordList == null)
          return;
 
        var allProductPoints = that.data.allProductPoints;
          for (var i = 0; i < allProductPoints.length; i++) {
            var r_ds = allProductPoints[i];;
            for (var j = 0; j < newRecordList.length; j++) {
              if (r_ds.ID == newRecordList[j].MonitorPointID) {
                console.log(r_ds.ID,newRecordList[j].MonitorPointID,"ddd")
                r_ds.SignalList[0].SignalValue =  newRecordList[j].DataValue;
                r_ds.SignalList[0].RecordTime = newRecordList[j].DataTime;
                if (r_ds.SignalList[0].ValueType == 2 && r_ds.SignalList[0].ValueSettings != null) {
                  r_ds.SignalList[0].SignalValue = r_ds.SignalList[0].ValueSettings[r_ds.SignalList[0].SignalValue];
                }
                break;
              }
            }
          }
        
 
 
        //更新数据
        that.setData({
          allProductPoints: allProductPoints
        });
 
      }
 
    });
 
  },
  tapeMonitorPoint: function (e) {
    // console.log(e,653)
    var pointid = e.currentTarget.dataset.pointid;
    let cronType = e.currentTarget.dataset.crontype;
    let pointName = e.currentTarget.dataset.pointname;
    let pointUnit = e.currentTarget.dataset.pointunit;
    console.log(pointid);
if(cronType != 0){
  wx.showModal({
    title:"提示",
    content:"不是实时测点,暂无配置",
    showCancel:false,
  })
  return
}
    wx.navigateTo({
      url: '../singlePoint/index?id=' + pointid + '&name=' + pointName + "&unit=" + pointUnit,
    });
  },
  //刷新警报数据
  tapRefreshAlarm: function () {
    this.setData({ //初始化设置
      bottomStatus: false,
      PageIndex: 1,
      alarmListInfo: []
    })
    this.getAlarmData();
  },
  //警报
  getAlarmData: function () {
    var that = this;
    var alarmListInfo = that.data.alarmListInfo
    var userInfo = app.globalData.userInfo;
    wx.showLoading({
      title: '加载中...',
    })
 
    Request({
      url: Constant.BASE_SERVER_URL + "Run/MonitorAlarmRecord/Mobile/GetPageListByMonitorPointID@V1.0",
      method: 'GET',
      data: {
        CorpID:userInfo.CorpID,
        MonitorPointID : that.data.meterID,
        StartTime: that.data.startAlarmDate,
        EndTime: that.data.endAlarmDate,
        PageIndex: that.data.PageIndex,
        PageSize: that.data.PageSize
      },
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) {
        wx.showModal({
          title: '',
          content: '通讯失败',
        })
      }, //请求失败
      complete: function () {
        that.setData({
          loadingHidden: true
        });
      }, //请求完成后执行的函数
      success: function (res) {
        // console.log('打印警报信息', res.data)
        wx.hideLoading();
        if (res.data.Code != 0) {
          wx.showToast({
            title: '获取数据失败',
          });
          that.setData({
            hasAlarmData: false
          });
          return;
        }
        let result = res.data.Data
        if (result.List.length == 0) {
          wx.showToast({
            title: '当前无报警数据',
          });
          that.setData({
            hasAlarmData: false
          });
          return;
        }
        if (result.Total == 0) {
          that.setData({
            hasAlarmData: false,
            message: '暂无报警数据'
          });
          return;
        }
        if (result == null) {
          that.setData({
            bottomStatus: true,
            message: '暂无报警数据'
          });
          return;
        }
        // console.log(that.data.PageIndex, that.data.PageSize)
        // console.log(that.data.PageIndex * that.data.PageSize)
 
        if (that.data.PageIndex * that.data.PageSize > res.data.Data.Total) {
          let list = res.data.Data
          that.setData({
            bottomStatus: true,
            hasAlarmData: true,
            alarmListInfo: alarmListInfo.concat(list)
          })
          return;
        }
        var ListInfo = res.data.Data
        var pageIndex = that.data.PageIndex
        //更新数据
        that.setData({
          hasAlarmData: true,
          alarmListInfo: alarmListInfo.concat(ListInfo),
          PageIndex: ++pageIndex
        });
        // console.log(that.data.alarmListInfo);
      }
    });
  },
  //回到scroll组件顶部
  goTop() {
    this.setData({
      scrollTop: 0
    })
  },
  //scroll组件高度监听
  scrollListView(e) {
    let scrollTop = e.detail.scrollTop
    // 如果超过半屏
    if (scrollTop > this.data.scrollHeight / 2) {
      this.setData({
        isShowFloatMenu: true,
        animationFloatMenu: 'fadeIn'
      })
    } else {
      this.setData({
        isShowFloatMenu: false,
        animationFloatMenu: 'fadeOut'
      })
      // setTimeout(() => {this.setData({visual: false})}, 1000)
    }
  },
  //警报 -- 开始时间选择器
  bindStartAlarmDateChange: function (e) {
    this.setData({
      startAlarmDate: e.detail.value
    })
  },
  //警报 -- 结束时间选择器
  bindEndAlarmDateChange: function (e) {
    this.setData({
      endAlarmDate: e.detail.value
    })
  },
  //展开与收缩
  tapProductName: function (e) {
    var list = this.data.allProductPoints;
    var pid = e.currentTarget.dataset.productid;
    // console.log(pid,801)
    for (var i = 0; i < list.length; i++) {
      if (list[i].ID == pid) {
        list[i].IsExpand = !list[i].IsExpand
      }
    }
    this.setData({
      allProductPoints: list
    });
    // console.log(list,364)
  },
  //列表展示更多
  tapMoreMonitor(e) {
    var that = this;
    var allProductPoints = that.data.allProductPoints;
    //var id = e.currentTarget.dataset.id;
    var index = e.currentTarget.dataset.index;
    var product = allProductPoints[index];
    product.isExpandAll = true;
    // console.log(RecordList)
    //allProductPoints[index].RecordList = JSON.parse(JSON.stringify(RecordList).replace(/false/g, "true"));
    //allProductPoints[index].StateMore = "是否展示更多";
 
    var pointids = this.data.allPointId;
    // console.log(pointids,product,825)
    for (var n = 0; n < product.Items.length; n++) {
      var record = product.Items[n];
      if (!record.isDisp) {
        record.isDisp = true;
        pointids.push(record.PointID);
      }
    }
    //console.log(allProductPoints)
    //更新数据
    that.setData({
      allProductPoints: allProductPoints,
      allPointId: pointids
    });
 
    that.refreshRecordValue();
  },
  //警报列表 -- 到底部时加载数据
  lowRefresh: function () {
    var that = this
    if (that.data.bottomStatus == true) {
      return;
    }
    that.getAlarmData()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if (this.data.intervalRefreshTime != null)
      clearInterval(this.data.intervalRefreshTime);
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
  /** 时间选择器状态 **/
  tapChangeWorkTime(e) {
    var isNextDayAble = true;
    if (e.detail.value == this.data.yestday) {
      isNextDayAble = false;
    }
    this.setData({
      historyDate: e.detail.value,
      isNextDayAble: isNextDayAble
    })
    this.getWorkTime();
  },
  /**返回顶部 */
  goTop() {
    this.setData({
      scrollTop: 0
    })
  },
  scrollListView(e) {
    var that = this;
    let scrollTop = e.detail.scrollTop
    // 如果超过半屏
    if (scrollTop > that.data.scrollHeight / 3.5) {
      that.setData({
        isShowFloatMenu: true,
        animationFloatMenu: 'fadeIn'
      })
    } else {
      that.setData({
        isShowFloatMenu: false,
        animationFloatMenu: 'fadeOut'
      })
      // setTimeout(() => {that.setData({visual: false})}, 1000)
    }
  },
  /**
   * 
   * 屏幕旋转事件
   */
  onResize(res) {
    res.size.windowWidth // 新的显示区域宽度
    res.size.windowHeight // 新的显示区域高度
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return Constant.Share;
  },
})