hailu
2023-12-07 1a0abf4788e8b1ee17d5a3a9834385bbc6b8f14b
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
690
691
692
693
694
// pages/problemReport/proRep.js
import { GetManagementClass, GetCompany } from '../../utils/network'
var util = require('../../utils/network');
const DatePickerUtil = require('../../utils/DatePicker')
const app = getApp()
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    imageUrl: [],
    form: {
      deviceId: undefined,
      address: '',//地址
      appointmentTime: '',//预约时间
      remark: '',//备注
      erectoId: -1,//安装工
      userName: '', //用户信息,联系人
      userPhone: '',//用户信息联系电话
      erectoName: '未指派',
      state: 0
    },
    deviceIndex: 0,
    erectoIndex: 0,
    erectoList1: [],
    erectoList2: [],
    deviceList1: [],
    deviceList2: [],
    imgUrl: '/images/img.png',
 
    time: '选择预约时间',
    multiArray: [],//piker的item项
    multiIndex: [],//当前选择列的下标
    year: '',//选择的年
    month: '',//选择的月
    day: '',//选择的日
    hour: '',//选择的时
    minute: '',//选择的分
    showDate: false,
    selectDate: '',
    paramsInfo: {},
    showJD: false,
    view:false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
    if (options && options.info) {
      let info = JSON.parse(options.info)
      console.log(info);
      this.setData({
        showJD: true,
        paramsInfo: info,
        form: info,
        time: info.appointmentTime,
        deviceIndex: 0,
        deviceList2: [info.device.deviceName],
        // erectoIndex: 0,
        // erectoList2: [info.erectoName],
        view:info.imgUrl?true:false
 
      })
      wx.setNavigationBarTitle({
        title:'ID'+this.data.form.id+' | '+this.data.form.device.deviceName
      })
    }
    this.getErectoList()
    this.getDeviceList()
  },
  changeUserName(e) {
    this.data.form.userName = e.detail.value
  },
  changePhone(e) {
    this.data.form.userPhone = e.detail.value
  },
  changeaddress(e) {
    this.data.form.address = e.detail.value
  },
  changeRemark(e) {
    this.data.form.remark = e.detail.value
  },
  Cancel() {
    wx.navigateBack()
  },
  Yes() {
    console.log(this.data.form);
    // return false
    if (this.data.form.state == 3) {
      if (!this.data.form.imgUrl) {
        wx.showToast({
          title: '请上传图片',
          icon: 'none'
        });
        return
      }
      this.data.form.orderType='2'
      if (this.data.form.appointmentTime) {
        this.data.form.appointmentTime += ':00'
      }
      console.log(this.data.form);
      wx.request({
        url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder`,
        method: "put",
        header: {
          "Access-Control-Allow-Headers": 'token',
          Authorization: `Bearer ${wx.getStorageSync('token')}`
        },
        data: this.data.form,
        success: (res, header) => {
          if (res.data.code != 200) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            });
          } else {
            wx.navigateBack()
          }
        }
      })
    } else if (Object.keys(this.data.paramsInfo).length > 0 && this.data.form.state != 3) {
      console.log(this.data.form);
      let phoneReg = /^1[3456789]\d{9}$/;
      if (!this.data.form.userName) {
        wx.showToast({
          title: '请输入用户名',
          icon: 'none'
        })
        return
      } else if (!phoneReg.test(this.data.form.userPhone)) {
        wx.showToast({
          title: '请输入正确手机号',
          icon: 'none'
        })
        return
      } else if (!this.data.form.address) {
        wx.showToast({
          title: '请输入安装地址',
          icon: 'none'
        })
        return
      }
      this.data.form.orderType='2'
      if (this.data.form.appointmentTime) {
        this.data.form.appointmentTime += ':00'
      }
      console.log(this.data.form);
 
      wx.request({
        url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder`,
        method: "put",
        header: {
          "Access-Control-Allow-Headers": 'token',
          Authorization: `Bearer ${wx.getStorageSync('token')}`
        },
        data: this.data.form,
        success: (res, header) => {
          if (res.data.code != 200) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            });
          } else {
            wx.navigateBack()
          }
        }
      })
    } else {
      console.log(this.data.form);
      let phoneReg = /^1[3456789]\d{9}$/;
      if (!this.data.form.userName) {
        wx.showToast({
          title: '请输入用户名',
          icon: 'none'
        })
        return
      } else if (!phoneReg.test(this.data.form.userPhone)) {
        wx.showToast({
          title: '请输入正确手机号',
          icon: 'none'
        })
        return
      } else if (!this.data.form.address) {
        wx.showToast({
          title: '请输入安装地址',
          icon: 'none'
        })
        return
      }
      if (this.data.form.appointmentTime) {
        this.data.form.appointmentTime += ':00'
      }
      this.data.form.orderType='2'
      this.data.form.repairFlag=1,
      console.log(this.data.form);
      wx.request({
        url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder`,
        method: "post",
        header: {
          "Access-Control-Allow-Headers": 'token',
          Authorization: `Bearer ${wx.getStorageSync('token')}`
        },
        data: this.data.form,
        success: (res, header) => {
          console.log(res);
          if (res.data.code != 200) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            });
          } else {
            wx.navigateTo({
              url: '/pages/problemListwx/problemListwx',
            })
          }
        }
      })
    }
  },
  chooseimage() {
    var that = this; // 将当前页面的上下文赋值给 that 变量
    // 在某个事件处理函数中调用以下代码
    wx.chooseImage({
      count: 1, // 最多可以选择的图片数量,这里设为1
      sourceType: ['album'], // 从相册选择
      success: function (res) {
        // 选择成功后,res.tempFilePaths 是选定的图片的本地文件路径列表
        const tempFilePath = res.tempFilePaths;
        wx.compressImage({
          src: tempFilePath[0],
          quality: 80, // 设置压缩质量,范围为 0-100
          success: function (res) {
            const compressedFilePath = res.tempFilePath;
            console.log(compressedFilePath, 'compressedFilePath');
            // 压缩后的图片路径进行的后续操作
            try {
              let data = compressedFilePath
              wx.uploadFile({
                // 上传接口路径
                url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder/profile/avatar`,
                filePath: data,
                name: 'avatarfile', // 上传文件对应的 key 名称
                method: 'post',
                header: {
                  'content-type': 'application/form-data',
                  "Access-Control-Allow-Headers": 'token',
                  Authorization: `Bearer ${wx.getStorageSync('token')}`
                },
                // data: data
                success: function (res) {
                  console.log(res.data);
                  // 上传成功后的处理逻辑
                  that.setData({
                    imgUrl: 'https://puyue.yhupai.com/prod-api' + JSON.parse(res.data).imgUrl // 将选择的图片路径设置为页面数据的某个属性
                  });
                  console.log(that.data.imgUrl);
                  that.data.form.imgUrl = that.data.imgUrl
                },
                fail: function (res) {
                  // 上传失败后的处理逻辑
                  console.log(res, '上传失败后的处理逻辑');
                }
              })
            } catch (e) { }
 
          },
          fail: function (err) {
            // 压缩失败的处理
            console.error(err);
          }
        });
      }
    });
  },
  getDeviceList() {
    let data = {
      repairFlag: 0
    }
    wx.request({
      url: 'https://puyue.yhupai.com/prod-api/iot/device/shortList',
      method: "GET",
      header: {
        "Access-Control-Allow-Headers": 'token',
        Authorization: `Bearer ${wx.getStorageSync('token')}`
      },
      data: data,
      success: (res, header) => {
        if (res.data.code != 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        } else {
          let data = []
          for (let i = 0; i < res.data.rows.length; i++) {
            data.push(res.data.rows[i].deviceName)
          }
          this.setData({
            deviceList1: res.data.rows,
            deviceList2: data
          })
          this.data.form.deviceId = res.data.rows[0].deviceId
          this.data.form.deviceName = res.data.rows[0].deviceName
        }
      }
    })
  },
  getErectoList() {
    let data = {
      pageNum: 1,
      pageSize: 10000,
      deptId: wx.getStorageSync('deptId'),
      isAuthentication: 1
    }
    wx.request({
      url: 'https://puyue.yhupai.com/prod-api/system/user/list',
      method: "GET",
      header: {
        "Access-Control-Allow-Headers": 'token',
        Authorization: `Bearer ${wx.getStorageSync('token')}`
      },
      data: data,
      success: (res, header) => {
        if (res.data.code != 200) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        } else {
          console.log(res);
          
          res.data.rows.unshift({
            nickName:'未指派',
            erectoId:-1
          })
          let data1 = []
          for (let i = 0; i < res.data.rows.length; i++) {
            data1.push(res.data.rows[i].nickName)
          }
          this.setData({
            erectoList1: res.data.rows,
            erectoList2: data1
          })
          
          if (this.data.showJD) {
            console.log(11111111111);
            for (let i = 0; i < this.data.erectoList1.length; i++) {
              if (this.data.erectoList1[i].userId == this.data.paramsInfo.erectoId) {
                console.log(i);
                this.setData({
                  erectoIndex: i,
                })
              }
            }
          } else {
            this.data.form.erectoId = -1
            this.data.form.erectoName = '未指派'
          }
        }
      }
    })
  },
  bindPicker(e) {
    console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      deviceIndex: e.detail.value
    })
    this.data.form.deviceId = this.data.deviceList1[e.detail.value].deviceId
    this.data.form.deviceName = this.data.deviceList1[e.detail.value].deviceName
    console.log(this.data.form, this.data.deviceList1);
  },
  bindPicker2(e) {
    this.setData({
      erectoIndex: e.detail.value
    })
    if (this.data.erectoIndex == 0) {
      let item = JSON.parse(JSON.stringify(this.data.form))
      item.state = 0
      this.setData({
        form: item
      })
      // this.data.form.state = 0
      this.data.form.erectoId = -1
      this.data.form.erectoName = '未指派'
    } else {
      let item = JSON.parse(JSON.stringify(this.data.form))
      item.state = 1
      this.setData({
        form: item
      })
      this.data.form.erectoId = this.data.erectoList1[Number(e.detail.value)].userId
      this.data.form.erectoName = this.data.erectoList1[Number(e.detail.value)].nickName
    }
 
  },
  openShowDate() {
    this.setData({
      showDate: true
    })
  },
  bindMultiPickerChange: function (e) { //时间日期picker选择改变后,点击确定 
    // console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      multiIndex: e.detail.value
    })
    const index = this.data.multiIndex; // 当前选择列的下标
    const year = this.data.multiArray[0][index[0]];
    const month = this.data.multiArray[1][index[1]];
    const day = this.data.multiArray[2][index[2]];
    const hour = this.data.multiArray[3][index[3]];
    const minute = this.data.multiArray[4][index[4]];
    // console.log(`${year}-${month}-${day} ${hour}:${minute}`); 
 
    this.setData({
      time: (year + month + day + ' ' + hour.replace('时', '') + ':' + minute.replace('分', '')).replace('年', '-').replace('月', '-').replace('日', ''),
      year: year, //记录选择的年
      month: month, //记录选择的月
      day: day, //记录选择的日
      hour: hour, //记录选择的时
      minute: minute, //记录选择的分 
    })
    this.data.form.appointmentTime = this.data.time
  },
  bindMultiPickerColumnChange: function (e) { //监听picker的滚动事件
 
    // console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
 
    let getCurrentDate = DatePickerUtil.getCurrentDate();//获取现在时间  
    let currentYear = parseInt(getCurrentDate.substring(0, 4));
    let currentMonth = parseInt(getCurrentDate.substring(5, 7));
    let currentDay = parseInt(getCurrentDate.substring(8, 10));
    let currentHour = parseInt(getCurrentDate.substring(11, 13));
    let currentMinute = parseInt(getCurrentDate.substring(14, 16));
 
    if (e.detail.column == 0) {//修改年份列 
 
      let yearSelected = parseInt(this.data.multiArray[e.detail.column][e.detail.value]);//当前选择的年份
 
      this.setData({
        multiIndex: [0, 0, 0, 0, 0],//设置pickerIndex
        year: yearSelected //当前选择的年份
      });
 
      if (yearSelected == currentYear) {//当前选择的年份==当前年份  
        var loadPickerData = DatePickerUtil.loadPickerData();
 
        this.setData({
          multiArray: loadPickerData,//picker数组赋值
          multiIndex: [0, 0, 0, 0, 0] //设置pickerIndex
        });
 
      } else {  // 选择的年份!=当前年份 
 
        // 处理月份
        let monthArr = DatePickerUtil.loadMonths(1, 12)
        // 处理日期
        let dayArr = DatePickerUtil.loadDays(currentYear, currentMonth, 1)
        // 处理hour
        let hourArr = DatePickerUtil.loadHours(0, 24);
        // 处理minute
        let minuteArr = DatePickerUtil.loadMinutes(0, 60)
 
        // 给每列赋值回去
        this.setData({
          ['multiArray[1]']: monthArr,
          ['multiArray[2]']: dayArr,
          ['multiArray[3]']: hourArr,
          ['multiArray[4]']: minuteArr
        });
      }
    }
    if (e.detail.column == 1) {//修改月份列
      let mon = parseInt(this.data.multiArray[e.detail.column][e.detail.value]); //当前选择的月份
      this.setData({
        month: mon  // 记录当前列
      })
 
      if (mon == currentMonth) {//选择的月份==当前月份 
        if (this.data.year == currentYear) {
 
          // 处理日期
          let dayArr = DatePickerUtil.loadDays(currentYear, mon, currentDay)
          // 处理hour
          let hourArr = DatePickerUtil.loadHours(currentHour, 24);
          // 处理minute
          let minuteArr = DatePickerUtil.loadMinutes(currentMinute, 60)
 
          this.setData({
            ['multiArray[2]']: dayArr,
            ['multiArray[3]']: hourArr,
            ['multiArray[4]']: minuteArr
          })
        } else {
          // 处理日期
          let dayArr = DatePickerUtil.loadDays(currentYear, mon, 1)
          // 处理hour
          let hourArr = DatePickerUtil.loadHours(0, 24);
          // 处理minute
          let minuteArr = DatePickerUtil.loadMinutes(0, 60)
 
          this.setData({
            ['multiArray[2]']: dayArr,
            ['multiArray[3]']: hourArr,
            ['multiArray[4]']: minuteArr
          });
        }
      } else {  // 选择的月份!=当前月份 
        // 处理日期
        let dayArr = DatePickerUtil.loadDays(currentYear, mon, 1) // 传入当前年份,当前选择的月份去计算日
        // 处理hour
        let hourArr = DatePickerUtil.loadHours(0, 24);
        // 处理minute
        let minuteArr = DatePickerUtil.loadMinutes(0, 60)
 
        this.setData({
          ['multiArray[2]']: dayArr,
          ['multiArray[3]']: hourArr,
          ['multiArray[4]']: minuteArr
        });
      }
    }
    if (e.detail.column == 2) {//修改日
      let dd = parseInt(this.data.multiArray[e.detail.column][e.detail.value]);//当前选择的日
      this.setData({
        day: dd
      })
      if (dd == currentDay) {//选择的日==当前日
        if (this.data.year == currentYear && this.data.month == currentMonth) {//选择的是今天 
 
          // 处理hour
          let hourArr = DatePickerUtil.loadHours(currentHour, 24);
          // 处理minute
          let minuteArr = DatePickerUtil.loadMinutes(currentMinute, 60)
 
          this.setData({
            ['multiArray[3]']: hourArr,
            ['multiArray[4]']: minuteArr
          });
 
        } else { //选择的不是今天 
          // 处理hour
          let hourArr = DatePickerUtil.loadHours(0, 24);
          // 处理minute
          let minuteArr = DatePickerUtil.loadMinutes(0, 60)
 
          this.setData({
            ['multiArray[3]']: hourArr,
            ['multiArray[4]']: minuteArr
          });
        }
      } else {  // 选择的日!=当前日 
        // 处理hour
        let hourArr = DatePickerUtil.loadHours(0, 24);
        // 处理minute
        let minuteArr = DatePickerUtil.loadMinutes(0, 60)
 
        this.setData({
          ['multiArray[3]']: hourArr,
          ['multiArray[4]']: minuteArr
        });
      }
    }
    if (e.detail.column == 3) {//修改时
      let hh = parseInt(this.data.multiArray[e.detail.column][e.detail.value]); //当前选择的时
      this.setData({
        hour: hh
      })
      if (hh == currentHour) {//选择的时==当前时 
        if (this.data.year == currentYear && this.data.month == currentMonth && this.data.month == currentMonth) {   // 选择的是今天
 
          // 处理minute
          let minuteArr = DatePickerUtil.loadMinutes(currentMinute, 60)
          this.setData({
            ['multiArray[4]']: minuteArr
          });
        } else { // 选择的不是今天
 
          // 处理minute
          let minuteArr = DatePickerUtil.loadMinutes(0, 60)
          this.setData({
            ['multiArray[4]']: minuteArr
          });
        }
      } else {//选择的时!=当前时 
        // 处理minute
        let minuteArr = DatePickerUtil.loadMinutes(0, 60)
        this.setData({
          ['multiArray[4]']: minuteArr
        });
      }
    }
    var data = {
      multiArray: this.data.multiArray,
      multiIndex: this.data.multiIndex
    };
 
    // console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
    data.multiIndex[e.detail.column] = e.detail.value; //将值赋回去
 
    this.setData(data);  //将值赋回去
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
 
    if (this.data.form && this.data.form.appointmentTime) {
      var loadPickerData = DatePickerUtil.loadPickerData()
      // var getCurrentDate = DatePickerUtil.getCurrentDate()
      var GetMultiIndex = DatePickerUtil.GetMultiIndex()
      //这里写的是为了记录当前时间
      let year = parseInt(this.data.form.appointmentTime.substring(0, 4));
      let month = parseInt(this.data.form.appointmentTime.substring(5, 7));
      let day = parseInt(this.data.form.appointmentTime.substring(8, 10));
      let hour = parseInt(this.data.form.appointmentTime.substring(11, 13));
      let minute = parseInt(this.data.form.appointmentTime.substring(14, 16));
      this.setData({
        multiArray: loadPickerData,//picker数组赋值,格式 [years, months, days, hours, minutes]
        multiIndex: GetMultiIndex,//设置pickerIndex,[0,0,0,0,0]
        time: year + '-' + month + '-' + day + ' ' + hour + ':' + minute, //设置当前时间 ,currentYears+'-'+mm+'-'+dd+' '+hh+':'+min
        year: year,//记录选择的年
        month: month,//记录选择的月
        day: day,//记录选择的日
        hour: hour,//记录选择的时
        minute: minute,//记录选择的分 
      });
    } else {
      var loadPickerData = DatePickerUtil.loadPickerData()
      var getCurrentDate = DatePickerUtil.getCurrentDate()
      var GetMultiIndex = DatePickerUtil.GetMultiIndex()
      //这里写的是为了记录当前时间
      let year = parseInt(getCurrentDate.substring(0, 4));
      let month = parseInt(getCurrentDate.substring(5, 7));
      let day = parseInt(getCurrentDate.substring(8, 10));
      let hour = parseInt(getCurrentDate.substring(11, 13));
      let minute = parseInt(getCurrentDate.substring(14, 16));
      this.setData({
        multiArray: loadPickerData,//picker数组赋值,格式 [years, months, days, hours, minutes]
        multiIndex: GetMultiIndex,//设置pickerIndex,[0,0,0,0,0]
        time: getCurrentDate.replace('年', '-').replace('月', '-').replace('日', ' '), //设置当前时间 ,currentYears+'-'+mm+'-'+dd+' '+hh+':'+min
        year: year,//记录选择的年
        month: month,//记录选择的月
        day: day,//记录选择的日
        hour: hour,//记录选择的时
        minute: minute,//记录选择的分 
      });
    }
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})