forked from gzzfw/frontEnd/gzDyh

liuwh
2024-09-07 d7ca134342a0a2004d9c15fab49fd0a41557e29c
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
// pages/register/index.js
const $$ = require('../../utils/util');
const app = getApp();
import Toast from '../../components/vant/toast/toast';
 
// 获取个人信息
function getUserInfoApi() {
  return $$.request({
    url: 'paUser/getUserInfo',
    type: 'get',
    service: 'cust'
  });
}
 
function caseRegisterSaveApi(submitData) {
  return $$.request({
    url: 'caseInfo/caseRegister',
    type: 'post',
    submitData,
    service: 'mediate'
  });
}
 
Page({
  /**
   * 页面的初始数据
   */
  userInfo: {},
  location: [], // 省市区等地理资源
  select: {}, // 下拉框数据
  goToMaterialSave: false, // 避免跳转到材料上传页面重复保存草稿
  agreementMsg: '', // 服务协议
  data: {
    stepText: 5, //用户须知倒计时5秒
    timer: null, // 用于存储定时器的引用
    popupVisibleText: false, //是否滚动到底部
    imgUrl: $$.url.img,
    steps: [{
        title: '填写人员',
        number: '1',
        activeIcon: 'steps-register-1-active.png'
      },
      {
        title: '描述纠纷',
        number: '2',
        activeIcon: 'steps-register-2-active.png'
      },
      {
        title: '提交申请',
        number: '3',
        activeIcon: 'steps-register-3-active.png'
      },
    ],
    saveStatus: false, //未提交,已提交
    oneList: [],
    titleShow: {
      '09_01001-1': ['自然人', '姓名', '真实姓名'],
      '09_01001-2': ['法人', '企业名称', '企业全名', '法定代表人姓名'],
      '09_01001-3': ['机构代表人', '机构名称', '机构全名', '机构代表人姓名'],
    }, // 用于判断显示的输入框标题
    stepsActive: 0, // 步骤条当前下标
    submitData: {
      occurTime: new Date().getTime(),
      occurTimeName: $$.moment(new Date().getTime()).format('YYYY-MM-DD'),
      caseType: '',
      caseTypeName: '',
      addr: '',
      lat: '',
      lng: '',
      peopleNum: '',
      amount: '',
      caseDes: '',
      caseClaim: '',
      plaintiffList: [],
      defendantList: [],
    }, // 表单数据
    addPersonData: {}, //添加的当事人
    materialNum: 0, // 纠纷材料总数量
    userInfoVisible: false, // 是否采用个人信息更新申请人信息
    timePicker: false, //时间选择展示
    maxDate: new Date().getTime(),
    popup: {
      formtype: '', // 控制在纠纷信息 or 申请人信息 or 被申请人添加数据
      index: 0, // 如为申请人信息 or 被申请人确认下拉选择此参数为下标
    }, // 下拉弹出框数据
    changeVisible: false, // 是否是修改
    recordingVisible: false, // 录音界面是否显示
    popupMsg: {
      show: false,
      title: '',
      type: 1,
      editType: 'add',
      buttonText: ''
    }, // 弹窗, type: 1'恢复草稿',2'申请人',3'被申请人', editType: 'add'新增,'edit'修改
    tipData: {
      caseList: [].join("\n"),
      guideList: [],
    },
    caseText: '',
    caseTitle: '',
    similarity: '',
    showCase: false,
    popupSelect: {
      show: false,
      data: [],
      activeIndex: null
    }, // 选择人员
    threeAvtice: '1',
    caseDesNum: 0, //事项概况字数
    caseClaimNum: 0, //事项申请字数
  },
 
  // 获取服务协议
  async getAgreement() {
    var that = this;
    const res = await $$.commonRequest({
      url: `${$$.url.txt}agree.txt`,
      type: 'get'
    });
    if (res) {
      that.data.popupVisible = true;
      that.setData({
        popupVisible: true,
      });
      this.startCountdown(); // 启动倒计时
    }
  },
 
  //须知弹窗倒计时
  startCountdown: function () {
    let that = this;
    that.setData({
      timer: setInterval(function () {
        if (that.data.stepText > 0) {
          that.data.stepText--;
          that.setData({
            stepText: that.data.stepText
          });
        } else {
          clearInterval(that.data.timer); // 倒计时结束,清除定时器
          // 在这里执行销毁操作,比如隐藏或删除倒计时组件
        }
      }, 1000)
    })
  },
 
 
 
  // 表单修改
  handleChange(e) {
    let key = e.currentTarget.dataset.key,
      value = e.detail;
    this.data.submitData[key] = value;
    this.setData({
      submitData: this.data.submitData
    });
    if (key === 'caseDes' || key === 'caseClaim') {
      this.setData({
        [key + 'Num']: value.length
      });
    }
  },
 
  threeTagChange(e) {
    value = e.detail;
    this.setData({
      threeAvtice: value
    });
  },
  // 下拉框选择确认
  handleConfirmPicker({
    detail
  }) {
    let type = this.data.popup.type,
      value = detail.detail.value,
      arr = [];
    this.data.popup.visible = false;
    if (type === 'caseCause') {
      arr = ['caseType', 'caseTypeName'];
      arr.forEach((x, t) => {
        this.data.submitData[x] = value[0][t === 0 ? 'value' : 'label'];
      });
    } else if (type === 'location') {
      arr = [
        ['city', 'cityName'],
        ['area', 'areaName'],
        ['road', 'roadName']
      ];
      arr.forEach((x, t) => {
        this.data.submitData[x[0]] = value[t]?.value || '';
        this.data.submitData[x[1]] = value[t]?.label || '';
      });
    }
    this.setData({
      popup: this.data.popup,
      submitData: this.data.submitData
    });
  },
 
 
  // 下拉框选择开启
  handleShowPopup(e) {
    let type = e.currentTarget.dataset.type;
    let selectData = [];
    if (type === 'location') {
      if (this.location.length === 0) {
        return false;
      }
      let selectOption = JSON.parse(JSON.stringify(this.location));
      let arr = $$.getLocationIndex(this.location, this.data.submitData); // 计算默认的市区县下标
      selectData = [{
          values: selectOption,
          defaultIndex: arr[0]
        },
        {
          values: selectOption[arr[0]].children,
          defaultIndex: arr[1]
        },
        {
          values: selectOption[arr[0]].children[arr[1]].children || [],
          defaultIndex: arr[2]
        },
      ];
      selectData.forEach((x) => {
        x.values.forEach((y) => {
          delete y.children;
        });
      });
    } else if (type === 'occurTime') {
      this.setData({
        timePicker: true
      })
      return;
    } else {
      let selectOption = this.select[type];
      selectData = [{
        values: selectOption,
        defaultIndex: 0
      }];
    }
    this.setData({
      popup: {
        formtype: e.currentTarget.dataset.formtype,
        index: e.currentTarget.dataset.index,
        visible: true,
        title: e.currentTarget.dataset.title,
        type: type,
        selectData: selectData,
      },
    });
  },
  // 关闭下拉框选择
  handleClosePopup() {
    this.data.popup.visible = false;
    this.setData({
      popup: this.data.popup
    });
  },
 
 
 
  // 滚动到底部事件
  handlescrolltolower() {
    this.setData({
      popupVisibleText: true
    })
  },
 
  // 用户须知
  handleAgree(e) {
    let type = e.currentTarget.dataset.type;
    if (!this.data.popupVisibleText) {
      Toast('请阅读完整的用户须知');
      return;
    }
    if (type === 'agree') {
      // 同意协议之后退出登录后不重复弹出
      wx.setStorage({
        key: 'agreement',
        data: 1
      });
    }
    this.setData({
      popupVisible: false
    });
  },
 
  // 下一步 or 上一步
  handleNext(e) {
    let type = e.currentTarget.dataset.type;
    if (type === 'next' && this.data.stepsActive === 0) {
      this.setData({
        stepsActive: 1
      });
      return;
    }
    if (type === 'back' && this.data.stepsActive === 1) {
      this.setData({
        stepsActive: 0
      });
      return;
    }
    if (type === 'next' && this.data.stepsActive === 1) {
      this.setData({
        stepsActive: 2
      });
      return;
    }
 
    if (type === 'back' && this.data.stepsActive === 2) {
      this.setData({
        stepsActive: 1
      });
      return;
    }
    // 申请提交
    if (type === 'next' && this.data.stepsActive === 2) {
      let data = this.data.submitData;
      let list = this.data.oneList;
      let personList = []; //"15_020008-1" 申请方当事人 ,"15_020008-2" 被申请方当事人
      let agentList = []; //"24_00006-1" 申请方代理人 ,"24_00006-2" 被申请方代理人
      personList = list.filter(item => item.perType === '15_020008-1' || item.perType === '15_020008-2');
      agentList = list.filter(item => item.perType === '24_00006-1' || item.perType === '24_00006-2');
      this.caseRegisterSave({
        ...data,
        personList,
        agentList
      });
    }
  },
 
  async caseRegisterSave(params) {
    $$.showLoading();
    const res = await caseRegisterSaveApi(params);
    $$.hideLoading();
    if (res.type) {
      Toast('提交成功');
    }
  },
 
  //选择纠纷类型 、跳转事项概况语音描述,跳转事项申请语音描述
  caseTypeGoPage(e) {
    let url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    });
  },
 
  //选择地址
  openmap: function (e) {
    var that = this;
    console.log('latitude')
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success: function (res) {
        wx.chooseLocation({
          success: function (res) {
            that.setData({
              submitData: {
                ...that.data.submitData,
                addr: res.address,
                lng: res.longitude,
                lat: res.latitude,
              }
            })
          },
          fail: function (res) {
 
          },
 
        })
      }
    })
  },
 
  delAddress() {
    this.setData({
      submitData: {
        ...this.data.submitData,
        addr: '',
        lng: '',
        lat: ''
      }
    })
  },
 
  // 获取省市区等地理资源
  async getLocationData() {
    $$.showLoading();
    const res = await $$.commonRequest({
      url: `${$$.url.assets}locationSelect.json`,
      type: 'get'
    });
    $$.hideLoading();
    if (res) {
      let location = [];
      $$.province.forEach((x) => {
        location.push(res[x][0]);
      });
      this.location = location;
    }
  },
 
  // 请求下拉框资源
  async getSelectOptionData() {
    const res = await $$.commonRequest({
      url: `${$$.url.assets}selectOption.json`,
      type: 'get'
    });
    if (res) {
      this.select.cardType = res.data.cardType || [];
      this.select.caseCause = this.data.caseCause || [];
      this.select.personClass = res.data.personClass || [];
    }
  },
 
 
  // 获取个人信息
  async getUserInfo() {
    $$.showLoading();
    const res = await getUserInfoApi();
    $$.hideLoading();
    if (res.type) {
      let data = res.data || {}
      this.setData({
        oneList: [{
          ...data,
          perType: '15_020008-1',
          perTypeName: '申请方当事人',
          perClass: '09_01001-1',
          perClassName: '自然人',
          certiNo: data.idcard || ''
        }]
      })
    };
  },
 
  // 自动添加申请人提醒
  oneAddMe(e) {
    let formtype = e.currentTarget.dataset.formtype;
    if (formtype === 'yes') {
      this.getUserInfo()
    }
    this.setData({
      addMePlaintiff: false
    })
  },
 
  // 填写人员
  oneDelPerson(e) {
    console.log('e', e);
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
 
    $$.showModal({
      title: '删除人员确认',
      content: '确定删除当事人' + item.trueName + '吗?',
      cancelText: '我再想想',
      confirmText: '确定删除',
      success: (res) => {
        if (res.confirm) {
          this.setData({
            oneList: this.data.oneList.filter((i, idx) => idx !== index)
          })
        }
      },
    });
  },
 
  // 添加当事人
  oneAddPerson(e) {
    let perType = e.currentTarget.dataset.pertype;
    let perTypeName = e.currentTarget.dataset.pertypename;
    if (!perType) {
      this.setData({
        addPerson: true
      })
    } else {
      this.setData({
        addPerson: false
      })
      wx.navigateTo({
        url: `../../pages/addPerson/index?perType=${perType}&perTypeName=${perTypeName}`,
      });
    }
  },
 
  // 修改当事人
  oneEditPerson(e) {
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: `../../pages/addPerson/index?data=${JSON.stringify(item)}&index=${index}`,
    });
  },
 
  // 关闭自定义弹窗
  addClosePopup(e) {
    let key = e.currentTarget.dataset.key;
    this.setData({
      [key]: false
    })
  },
 
  // 选择发生事件确定
  onInput(e) {
    let key = e.currentTarget.dataset.key;
    let value = e.detail;
    this.setData({
      [key]: false,
      submitData: {
        ...this.data.submitData,
        occurTime: value,
        occurTimeName: $$.moment(value).format('YYYY-MM-DD'),
      }
    })
  },
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getLocationData();
    let agreement = wx.getStorageSync('agreement');
    if (!agreement) {
      this.getAgreement();
    } else {
      if (this.data.oneList?.length === 0) {
        this.setData({
          addMePlaintiff: true
        })
      }
    }
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.oneData?.trueName) {
      let list = this.data.oneList;
      console.log('list', list);
      console.log('this.data.editIndex', this.data.editIndex);
      console.log('this.data.oneData', this.data.oneData);
      if (this.data.editIndex) {
        list[this.data.editIndex] = this.data.oneData;
      } else {
        list = list.concat(this.data.oneData)
      }
      this.setData({
        oneList: list,
        oneData: {},
        editIndex: false,
      })
    }
 
    if (this.data.twoData?.title) {
      this.setData({
        submitData: {
          ...this.data.submitData,
          caseType: this.data.twoData.value,
          caseTypeName: this.data.twoData.title,
        },
        twoData: {}
      })
    }
    if (this.data.twoValue) {
      console.log('this.data.twoValue', this.data.twoValue);
      console.log('this.data.twoKey', this.data.twoKey);
      this.setData({
        submitData: {
          ...this.data.submitData,
          [this.data.twoKey]: this.data.twoValue
        },
        twoValue: '',
        twoKey: ''
      })
    }
  },
 
  onHide: function () {
    // this.handleCheckSave();
  },
 
  onUnload: function () {
    // this.handleCheckSave();
  },
});