tanghaolin
2022-11-08 c8c3f384040bad0044dcabf72e162e35b5786afa
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
var Constant = require('../../utils/constant.js');
var app = getApp();
import Request  from "../../utils/api"
Page({
  data: {
    scrollHeight: wx.getSystemInfoSync().windowHeight,
    //列表下部菜单
    isShowFloatMenu: false, //是否显示
    animationFloatMenu: '', //显示动画
 
    //列表中区域组的显示的状态
    listGrpDispStatus: null,
    //页面切换
    tabIndex: 1,
    //列表数据
    allStationList: null,
    allRegionList: null,
    allMeterList: null, //设备列表
    isExpandList: false, //列表展开状态 默认true不展开
    isInitialMap: false,
    currentCorpID: 1,
    currentUserID: 1, //当前用户ID
    stationID: '', //泵站id
    modalName: '', //模态框抓状态
    isLoadingMeter:false
 
  },
  onLoad: function (options) {
    var that = this;
    var userInfo = app.globalData.userInfo;
    // console.log(userInfo.CorpID,"corpID")
    if (userInfo) {
      this.setData({
        currentCorpID: userInfo.CorpID,
        currentUserID: userInfo.EmployeeID
      });
    } else {
      wx.navigateTo({
        url: '/login/login/index',
      });
      return;
    }
    // console.log(userInfo)
 
    //初始化泵站列表 
    this.initialStationTree();
    return;
  },
  onShow(){
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
  },
  onShareAppMessage: function () {
    return Constant.Share;
  },
  //泵站列表显示隐藏
  tapListGrpView(e) {
    var index = e.currentTarget.dataset.menu_index;
    var listGrpDispStatus = this.data.listGrpDispStatus;
    if (listGrpDispStatus[index]) {
      listGrpDispStatus[index] = false;
    } else {
      listGrpDispStatus[index] = true;
    }
    this.setData({
      listGrpDispStatus: listGrpDispStatus
    })
  },
  //仪表列表
  tapMeterListGrpView: function (e) {
    var index = e.currentTarget.dataset.menu_index;
    var allMeterList = this.data.allMeterList;
    allMeterList[index].isShow = !allMeterList[index].isShow
    this.setData({
      allMeterList: allMeterList
    })
  },
  //切换页面
  tabFun(e) {
    var y_index = e.currentTarget.dataset.index;
    this.setData({
      tabIndex: y_index
    })
    if (y_index == 1) {
      //初始化泵站列表 
      //this.initialStationTree();
      //  return;
    } else if (y_index == 2) {
      if(this.data.isLoadingMeter == true){
        return
      }
      this.initAllMeter()
    }
  },
 
  onClickData: function (e) {
    console.log(e.currentTarget.dataset)
  },
 
  //当前页面列表回到顶部
  goTop() {
    let tabIndex = this.data.tabIndex
    if (tabIndex == 1) {
      this.setData({
        stationScrollTop: 0
      })
    } else if (tabIndex == 2) {
      this.setData({
        meterScrollTop: 0
      })
    }
  },
  //弹出更多菜单菜单
  moreMeun: function (e) {
    var that = this
    var id = e.currentTarget.dataset.stationid;
    this.setData({
      stationID: id,
      modalName: e.currentTarget.dataset.target
    })
    // console.log(id)
    wx.showActionSheet({
      alertTitle: '更多',
      itemList: ['视频监控', '供水月报表'],
      itemColor: '#16b5cb',
      success(res) {
        // console.log(res.tapIndex)
        if (res.tapIndex == 0) {
          wx.navigateTo({
            url: '/video/station/index?stationID=' + id,
          })
        } else if (res.tapIndex == 1) {
          var stationList = that.data.allRegionList;
          for (var i = 0; i < stationList.length; i++) {
            stationList[i].Items.forEach(ele => {
              if (ele.ID == id) {
                wx.navigateTo({
                  url: '../../test/reportTable/index?id=' + id + "&name=" + ele.Name,
                });
                return;
              }
            });
          }
        }
      },
      fail(res) {
        // console.log(res.errMsg)
      }
    })
  },
  //回到滑动容器顶部
  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'
      })
    }
  },
  //初始化设备列表
  initAllMeter: function () {
    var that = this
    wx.showLoading({
      title: '加载中...',
    })
    Request({
      url: Constant.BASE_SERVER_URL + "Product/Meter/Mobile/GetByCorpID@V1.0",
      data: {
        CorpID: that.data.currentCorpID
      },
      success: res => {
        wx.hideLoading();
          //  console.log(res.data)
          that.setData({
            isLoadingMeter:true
          })
        let allMeterList = that.data.allMeterList
        var result = res.data;
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.Message,
          });
          return;
        }
        if (result.Data == null) {
          wx.showModal({
            title: '',
            content: "暂未添加仪表",
          });
          return;
        }
        wx.showToast({
          title: '加载成功',
          icon: "success",
          duration: 2000
        });
        // console.log(res, '134')
        allMeterList = [{
          MeterName: '流量计',
          imgPath: '../../images/icons/liuliangji.svg',
          isShow: true,
          MeterList: []
        }, {
          MeterName: '压力计',
          imgPath: '../../images/icons/yaliji.svg',
          isShow: true,
          MeterList: []
        }, {
          MeterName: '水质仪',
          imgPath: '../../images/icons/shuizhiyi.svg',
          isShow: true,
          MeterList: []
        }]
        allMeterList.forEach((meterNode)=>{
          result.Data.forEach(ele=>{
            // if(ele.Specification == null){
            //   ele.Specification = ""
            // }
            if(ele.Catalog == meterNode.MeterName){
              meterNode.MeterList.push(ele)
            }
          })
        })
        //  console.log(allMeterList,201)
        that.setData({
          allMeterList: allMeterList
        })
        // console.log(that.data.allMeterList)
      },
      fail: err => {
        console.log(err)
      }
    })
  },
  //跳转仪表列表设备详情记录
  jumpGeneralByList: function (e) {
    // console.log(e, 214)
    let pointid = e.currentTarget.dataset.meter_node_id
    if (pointid == 0) {
       return
    }
    this.openMeterMonitorPage(pointid)
 
    // wx.navigateTo({
    //   url: '../../monitor/singlePoint/index?id=' + pointid + "&name=" + e.currentTarget.dataset.meterName,
    // });
 
  },
 
  //  刷新泵站列表
  tapRefreshTree() {
    let index = this.data.tabIndex
    if (index == 1) {
      this.refreshStationTree(); //刷新泵站列表
    } else if (index == 2) {
      this.initAllMeter(); //刷新仪表列表
    }
 
  },
  //伸缩泵站列表
  tapExpandList() {
    let that = this;
    let isExpandList = that.data.isExpandList;
    let tabIndex = that.data.tabIndex
    if (isExpandList == true) {
      that.setData({
        isExpandList: false
      })
      if (tabIndex == 1) {
        var allRegionList = this.data.allRegionList;
        var listGrpDispStatus = [];
        for (var i = 0; i < allRegionList.length; i++) {
          listGrpDispStatus.push(true)
        }
        that.setData({
          listGrpDispStatus: listGrpDispStatus
        });
      } else if (tabIndex == 2) {
        let allMeterList = that.data.allMeterList
        for (let m = 0; m < allMeterList.length; m++) {
          allMeterList[m].isShow = false
        }
        that.setData({
          allMeterList: allMeterList
        });
      }
    } else {
      that.setData({
        isExpandList: true
      })
      if (tabIndex == 1) {
        var allRegionList = this.data.allRegionList;
        var listGrpDispStatus = [];
        for (var i = 0; i < allRegionList.length; i++) {
          listGrpDispStatus.push(false)
        }
        that.setData({
          listGrpDispStatus: listGrpDispStatus
        });
      } else if (tabIndex == 2) {
        let allMeterList = this.data.allMeterList
        for (let m = 0; m < allMeterList.length; m++) {
          allMeterList[m].isShow = true
        }
        that.setData({
          allMeterList: allMeterList
        });
      }
    }
  },
 
  //初始化泵站列表 
  initialStationTree: function () {
    var that = this;
 
    var allRegionList = null;
    var allStationList = this.data.allStationList;
    if (allStationList != null && allStationList.length > 0)
      return;
    var cacheName = "StationRegionTree.Corp." + this.data.currentCorpID;
    var stationRegionComp = wx.getStorageSync(cacheName); //读取缓存   
    //  console.log('泵站列表及其他信息', stationRegionComp);
    if (stationRegionComp != null && stationRegionComp != "") {
      allRegionList = stationRegionComp.RegionList;
      // console.log(allRegionList, "RegionList")
      //
      var timestamp = Date.parse(new Date());
      var cache_length = timestamp / 1000 - stationRegionComp.T;
      // console.log("read cache from station_cache_length:"+cache_length)
      if (cache_length < 60 * 60 * 2) { //缓存2个小时
        var listGrpDispStatus = [];
        for (var i = 0; i < allRegionList.length; i++) {
          if (allRegionList.length == 1) { //判断当数据只有一条的时候默认展开列表
            listGrpDispStatus.push(false)
            that.setData({
              allRegionList: allRegionList,
              listGrpDispStatus: listGrpDispStatus
            });
            break;
          }
          listGrpDispStatus.push(true)
        }
        //console.log(allRegionList)
        //console.log(allStationList)
        that.setData({
          allRegionList: allRegionList,
          listGrpDispStatus: listGrpDispStatus
        });
        //console.log('打印allRegionList',that.data.allRegionList);
        // console.log('打印listGrpDispStatus', that.data.listGrpDispStatus);
 
        return;
      }
    }
 
    this.refreshStationTree();
  },
  //刷新泵站的列表
  refreshStationTree: function () {
    var that = this;
    wx.showLoading({
      title: '加载中...'
    });
 
    Request({
      url: Constant.BASE_SERVER_URL + "Main/Station/Mobile/GetAttentionList@V1.0",
      method: 'GET',
      data: {
        CorpID: this.data.currentCorpID
      },
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) {
        console.log(err)
        wx.hideLoading();
        wx.showModal({
          title: '',
          content: '通讯失败',
        })
      }, //请求失败
      success: function (res) {
         console.log(res,363)
        wx.hideLoading();
        //console.log(res.data)
        var result = res.data;
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.Message,
          });
          return;
        }
        wx.showToast({
          title: '加载成功',
          icon: "success",
          duration: 2000
        });
        //
        // var allStationList = result.Data;
        var allRegionList = [{Name:"演示用",Items:[]}]
        let Items= []
        result.Data.forEach((ele=>{
          let node = {
            ID:ele.ID,
            Name:ele.Name,
            Description:ele.Description,
            CorpID:ele.CorpID,
            Address:ele.Address
          }
          Items.push(node)
        }))
        allRegionList[0].Items = Items
          // console.log(allRegionList);
        var listGrpDispStatus = [];
        for (var i = 0; i < allRegionList.length; i++) {
          if (allRegionList.length == 1) { //判断当数据只有一条的时候默认展开列表
            listGrpDispStatus.push(false)
            that.setData({
              listGrpDispStatus: listGrpDispStatus
            })
            break;
          }
          listGrpDispStatus.push(true)
        }
        //存入缓存
        var cacheName = "StationRegionTree.Corp." + that.data.currentCorpID;
        wx.setStorageSync(cacheName, {
          T: Date.parse(new Date()) / 1000,
          // StationList: allStationList,
          RegionList: allRegionList
        });
        that.setData({
          allRegionList: allRegionList,
          // allStationList: allStationList,
          listGrpDispStatus: listGrpDispStatus
        });
      }
    });
  },
 
  //隐藏对话框
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(300).step()
    this.setData({
      animationMapTip: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationMapTip: animation.export(),
        isShowMapBottomTip: false
      })
    }.bind(this), 200)
  },
 
 
  //键盘输入时实时调用搜索方法
  inputKeyWrd(e) {
    this.searchStationByKeyWrd(e.detail.value)
  },
  //点击完成按钮时触发
  confirmSearch(e) {
    this.searchStationByKeyWrd(e.detail.value)
  },
  searchStationByKeyWrd(key) {
    var that = this;
 
    if (key == '') { //用户没有输入时全部为空
      that.setData({
        searchMarkList: [],
        isShowsearchMarkList: false
      })
      return;
    }
    let markers = that.data.markers;
    var arr = []; //临时数组,用于存放匹配到的数组
    for (let i in markers) {
      var mark = markers[i];
      //markers[i].show = false; //所有数据隐藏
      if (mark.title.indexOf(key) >= 0) {
        //markers[i].show = true; //让匹配到的数据显示
        arr.push(mark)
      } else if (mark.content.indexOf(key) >= 0) {
        //markers[i].show = true; //让匹配到的数据显示
        arr.push(mark)
      }
    }
 
    if (arr.length == 0) {
      that.setData({
        searchMarkList: [{
          show: true,
          name: '没有相关数据!'
        }],
        isShowsearchMarkList: true
      })
    } else {
      that.setData({
        searchMarkList: arr,
        isShowsearchMarkList: true
      })
    }
  },
 
  //打开泵站监控页面
  tapOpenStationMonitorPageInList: function (e) {
    var id = e.currentTarget.dataset.stationid;
    let corpID = e.currentTarget.dataset.corpid;
    //console.log(e.currentTarget);
    this.openStationMonitorPage(id,corpID);
  },
  openStationMonitorPage: function (id,corpID) {
     console.log(corpID,505)
    if (id == undefined) {
      wx.navigateTo({
        url: '../../monitor/station/index?id=1',
      });
      return;
    }
    var stationList = this.data.allRegionList;
    for (var i = 0; i < stationList.length; i++) {
        for (var j = 0; j < stationList[i].Items.length; j++) {
          let items = stationList[i].Items[j]
          if(items.ID == id){
            wx.navigateTo({
              url: '../../monitor/station/index?id=' + id + "&name=" + items.Name + '&corpID=' + corpID,
            });
            return;
          }
        }
    }
  },
  openMeterMonitorPage: function (id,corpID) {
     console.log(id,505)
    if (id == undefined) {
      return;
    }
    var allmeterList = this.data.allMeterList;
    // console.log(meterList,513)
    for (var i = 0; i < allmeterList.length; i++) {
        for (var j = 0; j < allmeterList[i].MeterList.length; j++) {
          let items = allmeterList[i].MeterList[j]
          if(items.ID == id){
            wx.navigateTo({
              url: '../../monitor/meter/index?id=' + id + "&name=" + items.Name + '&corpID=' + corpID,
            });
            return;
          }
        }
    }
  },
  //打开泵站BIM页面
  tapOpenStationBimPageInList: function (e) {
    var id = e.currentTarget.dataset.stationid;
    let corpID = e.currentTarget.dataset.corpid;
    //console.log(e.currentTarget);
    this.openStationBimPage(id,corpID);
  },
  openStationBimPage: function (id,corpID) {
    if (id == undefined) {
      wx.navigateTo({
        url: '../../bim/station/index?id=1',
      });
      return;
    }
    var regionList = this.data.allRegionList;
    for (var i = 0; i < regionList.length; i++) {
      for(var j = 0; j < regionList[i].Items.length; j++){
      // console.log(stationList[i].ID);
      if (regionList[i].Items[j].ID == id) {
        wx.navigateTo({
          url: '../../bim/station/index?id=' + regionList[i].Items[j].ID + "&name=" + regionList[i].Items[j].Name + '&corpID=' + corpID,
        });
        return;
      }
    }
    }
  },
  //资产
  tapOpenProductInStationPageInList: function (e) {
    var id = e.currentTarget.dataset.stationid;
    let corpID = e.currentTarget.dataset.corpid
    console.log(id,corpID,555)
    if (id == undefined) {
      return;
    }
 
    var regionList = this.data.allRegionList;
    for (var i = 0; i < regionList.length; i++) {
      for(var j = 0; j < regionList[i].Items.length; j++) {
      // console.log(stationList[i].ID);
      let items = regionList[i].Items[j]
      if (items.ID == id) {
        wx.navigateTo({
          url: '../../product/listInStation/index?id=' + items.ID + '&name=' + items.Name + '&corpID=' + corpID,
        });
        return;
      }
    }
    }
  },
 
 
  //查询
  tapSearchIcon: function () {
    var that = this;
    that.setData({
      animationSearchBar: "animation"
    })
    return;
  },
  //点击搜索的ITEM,定位内容位置
  tapMapSearchItem(e) {
    var that = this;
    var value = e.currentTarget.dataset;
    that.setData({
      mapCenterLatitude: value.latitude,
      mapCenterLongitude: value.longitude,
      scale: 13,
      animationSearchBar: '',
      searchKeyWrd: ''
    });
    // console.log(value);
    that.showMapTipInBottomPanel(value.id, "search");
    //that.search(that.data.searchKeyWrd);
    return;
  },
 
  //跳转到报表界面
  tapOpenReportForm(e) {
    let id = e.currentTarget.dataset.stationid;
    var stationList = this.data.allStationList;
    for (var i = 0; i < stationList.length; i++) {
      // console.log(stationList[i].ID);
      if (stationList[i].ID == id) {
        wx.navigateTo({
          url: '../../reportForm/index/index?id=' + id + "&name=" + stationList[i].Name,
        });
        return;
      }
    }
  },
})