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
//获取应用实例
var Constant = require('../../utils/constant.js');
var utils = require('../../utils/util.js')
var app = getApp();
var CorpID = Constant.CorpID; //当前公司id
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null, //用户信息
    isRotateRefreshIcon: false, //刷新图标的选择状态
    addressInfo: "正在获取定位...", //巡检地址
    userLocAddress: "", //定位的巡检地址(可能不是报修地址)
    longitude: 0, //精度
    latitude: 0, //纬度
    tapTouchDirection: "", //手指滑动列表中的子项时计算的滑动距离
 
    ToDay: utils.formatDay(new Date()), //显示的时间
    allProductList: [], //存放巡检产品的列表 
    dispProductList: [], //存放巡检产品的列表 
    searchResult: false,
    //
    distanceText: "距离",
    distanceFilter: { //距离筛选列表
      distanceFilterOptions: [{ //距离筛选选项
          value: "0",
          text: "不限距离"
        },
        {
          value: "100",
          text: "100米"
        }, {
          value: "300",
          text: "300米"
        }, {
          value: "500",
          text: "500米"
        }, {
          value: "800",
          text: "800米"
        }, {
          value: "1000",
          text: "1000米"
        }
      ],
      distanceOptionsIndex: 0 //当前选择的距离选项下标
    },
    distanceFilterShowStatus: false, //距离筛选下拉框是否显示
    distanceShowColorStatus: false, //距离筛选列表选项被选中后的颜色展示状态
    isSelectDistance: true, //是否能点击距离筛选
    bodyStyleName: "", //样式
 
    inspectStatusText: "巡检状态",
    inspectStatusFilter: { //巡检状态筛选列表
      inspectStatusOptions: ["全部", "已巡检", "未巡检", "巡检中"], //巡检状态筛选选项
      inspectStatusOptionsIndex: 0 //选择的巡检状态的下标
    },
    inspectStatusFilterShow: false, //巡检状态下拉框是否显示
    inspectStatusShowColor: false, //巡检状态被选中后改变文字颜色
 
    // type: 0,
    productTypeShowColorStatus: false, //产品类型被选中后改变颜色状态
    productTypeText: "类型",
    productTypeShowStatus: false, //产品类型下拉框是否显示
    productTypeIndex: 0, //产品类型被选择的下标
    productTypeFilter: [{ //产品类型筛选列表及筛选选项
        name: '全部类型',
        value: '全部类型',
        subType: 0
      },
      {
        name: '流量计',
        value: '流量计',
        subType: 7501
      },
      {
        name: '压力计',
        value: '压力计',
        subType: 7502
      },
      {
        name: '水质仪',
        value: '水质仪',
        subType: 7504
      },
      {
        name: '其他',
        value: '其他',
        subType: 7000
      },
    ],
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    // console.log(options)
    var userInfo = app.globalData.userInfo
    if (userInfo == null) {
      wx.redirectTo({
        url: '/login/login/index',
      })
      return;
    }
    that.setData({
      userInfo: userInfo
    });
    //console.log(userInfo)
    wx.getSetting({ //判断用户有没有打开定位设置
      success(res) {
        // console.log(res.authSetting, '115')
        if (res.authSetting["scope.userLocation"] != true) {
          wx.showModal({
            title: '提示',
            content: '请您打开系统定位',
          })
        }
      }
    })
    this.getCurrentLocation()
  },
  //初始化产品列表
  initProductListData: function () {
    var that = this
 
    let userInfo = that.data.userInfo
    let corpID = userInfo.CorpID //公司id
    let employeeID = userInfo.EmployeeID //员工id
    let PosiX = that.data.longitude //精度
    let PosiY = that.data.latitude //纬度
    wx.showLoading({
      title: '数据加载中,请稍后...',
    })
    //console.log(corpID)
    wx.request({
      method: 'GET',
      url: Constant.BASE_SERVER_URL + 'Repair/Mobile/InspectRecord/GetProductScheduleByToDay4Input',
      data: {
        CorpID: corpID,
        EmployeeID: employeeID,
        PosiX: PosiX,
        PosiY: PosiY
      },
      success: res => {
        wx.hideLoading()
        // 
        let result = res.data
        if (result.Code != 0) {
          wx.showModal({
            title: '提示',
            content: '数据请求失败',
          })
          return;
        }
        wx.showToast({
          title: '获取数据成功',
          icon: 'success',
          duration: 2000
        })
        //console.log(result, '产品列表')
 
        let allProductList = []
        for (let i = 0; i < result.Data.length; i++) {
          let product = result.Data[i];
          // console.log(product)
          allProductList.push(product)
        }
        that.setData({
          dispProductList: allProductList,
          allProductList: allProductList
        });
 
      },
      fail: err => {
        wx.hideLoading({})
        console.log(err)
      }
    })
  },
  //赋值选择位置进行 选择当前位置
  tapChooseLocation() {
    let that = this;
    wx.chooseLocation({
      success: function (res) {
        //console.log("chooseLocation", res)
        that.setData({
          addressInfo: res.address.substring(3, res.address.length),
          latitude: res.latitude,
          longitude: res.longitude,
        })
        that.initProductListData()
      }
    });
  },
 
  //加载定位
  getCurrentLocation: function () {
    var that = this;
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
      success(resLoc) {
        //console.log("getCurrentLocation", resLoc);
        if (resLoc.longitude == 0 || resLoc.latitude == 0) { //当前位置信号较弱,请换个位置尝试
          wx.showModal({
            title: '提示',
            content: '当前信号较弱请换个位置尝试',
            success(res) {
              if (res.confirm) {
                return;
              } else if (res.cancel) {
                return;
              }
            }
          })
        }
        //
        that.setData({
          longitude: resLoc.longitude,
          latitude: resLoc.latitude,
        })
 
        //获取经纬度后,初始化产品列表
        that.initProductListData()
 
        //发送请求通过经纬度反查地址信息  
        var getAddressUrl = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + resLoc.latitude + "," + resLoc.longitude + "&key=GFDBZ-D3NKX-LNL4Z-TSWGU-RYCE3-4HB3I";
        wx.request({
          url: getAddressUrl,
          success: function (result) {
            //console.log("getAddressUrl", result);
            that.setData({
              addressInfo: result.data.result.address,
              userLocAddress: result.data.result.address
            })
          },
          fail: err => {
            wx.showModal({
              title: '提示',
              content: '获取位置失败请打开定位'
            })
            console.log(err)
          }
        });
      },
      fail: err => {
        wx.showModal({
          title: '提示',
          content: '获取位置失败请打开定位,或者手动选择位置',
          success(res) {
            if (res.confirm) {
              that.setData({
                latitude: 0,
                longitude: 0
              })
              that.initProductListData()
 
              setTimeout(() => { //五秒之后调用位置接口
                that.getCurrentLocation()
              }, 5000);
            } else if (res.cancel) {
              console.log('用户点击取消')
              return;
            }
          }
        })
        console.log(err)
      }
 
    });
  },
 
 
  //巡检距离筛选部分
  distanceFilterShow: function () { //距离下拉
    if (this.data.distanceFilterShowStatus) {
      this.setData({
        distanceFilterShowStatus: !this.data.distanceFilterShowStatus,
        productTypeShowStatus: false,
        inspectStatusFilterShow: false
      })
    } else {
      this.setData({
        distanceFilterShowStatus: !this.data.distanceFilterShowStatus,
        productTypeShowStatus: false,
        inspectStatusFilterShow: false
      })
    }
  },
 
  distanceOptionsChoice: function (e) { //距离下拉选择子项//
    // console.log(e)
    this.setData({
      distanceText: e.currentTarget.dataset.item,
      "distanceFilter.distanceOptionsIndex": e.currentTarget.dataset.index,
      distanceFilterShowStatus: false,
      distanceShowColorStatus: true,
      distance: e.currentTarget.dataset.distance
    })
  },
  inspectionStatusFilterShow: function () { //巡检状态筛选下拉
    if (this.data.inspectStatusFilterShow) {
      this.setData({
        inspectStatusFilterShow: !this.data.inspectStatusFilterShow,
        productTypeShowStatus: false,
        distanceFilterShowStatus: false
      })
    } else {
      this.setData({
        inspectStatusFilterShow: !this.data.inspectStatusFilterShow,
        productTypeShowStatus: false,
        distanceFilterShowStatus: false
      })
    }
  },
  inspectionStatusOptionsChoice: function (e) { //巡检状态下拉选择子项
    // console.log(e)
    this.setData({
      inspectStatusText: e.currentTarget.dataset.item,
      "inspectStatusFilter.inspectStatusOptionsIndex": e.currentTarget.dataset.index,
      inspectStatusFilterShow: false,
      inspectStatusShowColor: true
    })
  },
 
  productTypeFilterShow: function () { //类型下拉
    if (this.data.productTypeShowStatus) {
      this.setData({
        productTypeShowStatus: !this.data.productTypeShowStatus,
        inspectStatusFilterShow: false,
        distanceFilterShowStatus: false,
      })
    } else {
      this.setData({
        productTypeShowStatus: !this.data.productTypeShowStatus,
        inspectStatusFilterShow: false,
        distanceFilterShowStatus: false,
 
      })
    }
  },
  productTypeOptionsChoice: function (e) { //类型下拉选项
    this.setData({
      subType: e.currentTarget.dataset.subType,
      productTypeIndex: e.currentTarget.dataset.index,
      productTypeText: e.currentTarget.dataset.typeName,
      productTypeShowStatus: false,
      productTypeShowColorStatus: true
    })
  },
 
  handletouchtart: function (event) { //点击透明背景隐藏下拉
    this.setData({
      inspectStatusFilterShow: false,
      distanceFilterShowStatus: false,
      productTypeShowStatus: false
    })
  },
 
  // 手部触摸开始
  onTouchStart(e) {
    this.setData({
      ListTouchStart: e.touches[0].pageX,
    })
    // console.log(this.data.changeClick)
  },
 
  // 手指滑动过程计算方向
  onTouchMove(e) {
    this.setData({
      tapTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > -50 ? 'right' : 'left',
    })
    // console.log(this.data.changeClick)
  },
 
  // 手指滑动结束计算滚动
  onTouchEnd(e) {
    if (this.data.tapTouchDirection == 'left') {
      this.setData({
        bodyStyleName: e.currentTarget.dataset.target,
      })
      // console.log(this.data.changeClick)
    } else {
      this.setData({
        bodyStyleName: ""
      })
    }
    this.setData({
      tapTouchDirection: null,
    })
  },
  //跳转到巡检明细
  gotoDetailPage: function (e) {
    //
    let productId = e.currentTarget.dataset.productId;
    var product = this.getProductById(productId)
    if (product == null)
      return;
 
    wx.navigateTo({
      url: '../todayDetail/index?productId=' + productId + '&productName=' + product.ProductName + '&belongId=' + product.BelongID + '&belongType=' + product.BelongType,
    })
  },
  //刷新对应id的泵的信息
  getProductById: function (id) {
    let allProductList = this.data.allProductList;
    //console.log(id,allProductList);
    for (let i = 0; i < allProductList.length; i++) {
      const product = allProductList[i]
      if (product.ProductID == id) {
        return product;
      }
    }
    return null;
  },
  //进入报修界面
  tapOpenRepairReport: function (e) {
    //console.log(e.target.dataset.productId);
    var productId = e.target.dataset.productId;
    wx.navigateTo({
      url: "../../repair/addReport/index?ProductId=" + productId
    })
  },
  //根据巡检内容页面传过来的值刷新产品列表的数据
  refreshReordData: function (record) {
    var that = this;
    if (record == null)
      return;
    // console.log(record)
    // console.log(that.data.allProductList)
    let allProductList = that.data.allProductList
    for (let i = 0; i < allProductList.length; i++) {
      const product = allProductList[i]
      if (product.RecordID == record.ID || product.ProductID == record.ProductID) {
        product.RecordID == record.ID;
        product.ProgressInfo = record.ProgressInfo;
        product.WorryCount = record.WorryCount;
        product.CompleteStatus = record.CompleteStatus;
      }
    }
 
    let dispProductList = that.data.dispProductList
    for (let i = 0; i < dispProductList.length; i++) {
      const product = dispProductList[i]
      if (product.RecordID == record.ID || product.ProductID == record.ProductID) {
        product.RecordID == record.ID;
        product.ProgressInfo = record.ProgressInfo;
        product.WorryCount = record.WorryCount;
        product.CompleteStatus = record.CompleteStatus;
      }
    }
    // console.log(allProductList, dispProductList)
 
    that.setData({
      allProductList: allProductList,
      dispProductList: dispProductList
    })
  },
  //刷新设备列表
  refreshProductList: function () {
    var that = this
    that.setData({
      isRotateRefreshIcon: true
    })
    that.initProductListData()
    setTimeout(function () {
      that.setData({
        isRotateRefreshIcon: false
      })
    }, 1000)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return Constant.Share;
  }
})