forked from gzzfw/frontEnd/gzDyh

dminyi
2024-08-09 a2a5220469a3e1f8bc216f47c887ca4c941920b0
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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
// 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 getCaseDetailApi(submitData) {
  return $$.request({
    url: 'paCaseInfo/getCaseInfo?id=' + submitData,
    type: 'get',
    service: 'mediate'
  });
}
 
// 获取保存的草稿案件
function getDraftCaseApi(type) {
  return $$.request({
    url: 'paCaseInfo/listByInputUserAndStatus?inputStatus=' + type,
    type: 'get',
    service: 'mediate'
  });
}
 
// 保存草稿 or 保存案件
function submitCaseApi(submitData) {
  return $$.request({
    url: 'paCaseInfo/applyCase',
    type: 'post',
    submitData,
    service: 'mediate'
  });
}
 
// 检查请求中的风险
function checkCaseClaimRiskApi(submitData) {
  return $$.request({
    url: 'guide/checkCaseClaimRisk',
    type: 'post',
    submitData,
    v1: true,
    service: 'mediate'
  });
}
 
// 获取历史填写过的人员数据
function getPersonHistoryApi() {
  return $$.request({
    url: 'paCaseInfo/pickUser',
    type: 'get',
    service: 'mediate'
  });
}
 
//类案推荐缓存
function getCaseApi(submitData) {
  return $$.request({
    url: 'guide/cacheLatjCaseGuide',
    submitData,
    type: 'get',
    v1: true,
    service: 'mediate'
  });
}
 
//案件特征
function getFeatureApi(submitData) {
    return $$.request({
      url: 'guide/cacheCaseFeature',
      submitData,
      type: 'get',
      v1: true,
      service: 'mediate'
    });
  }
 
//调解策略及争议焦点
function getCacheOpenAiCaseGuideList(submitData) {
  return $$.request({
    url: 'guide/cacheOpenAiCaseGuideList',
    submitData,
    type: 'get',
    v1: true,
    service: 'mediate'
  });
}
 
Page({
  /**
   * 页面的初始数据
   */
  userInfo: {},
  location: [], // 省市区等地理资源
  select: {}, // 下拉框数据
  goToMaterialSave: false, // 避免跳转到材料上传页面重复保存草稿
  data: {
    imgUrl: $$.url.img,
    steps: [{
        title: '填写申请',
        icon: '',
        activeIcon: 'steps-register-1-active.png'
      },
      {
        title: '预览申请',
        icon: 'steps-register-2.png',
        activeIcon: 'steps-register-2-active.png'
      },
      {
        title: '提交申请',
        icon: 'steps-register-3.png',
        activeIcon: 'steps-register-3-active.png'
      },
    ],
    titleShow: {
      '09_01001-1': ['自然人', '姓名', '真实姓名'],
      '09_01001-2': ['法人', '企业名称', '企业全名', '法定代表人姓名'],
      '09_01001-3': ['机构代表人', '机构名称', '机构全名', '机构代表人姓名'],
    }, // 用于判断显示的输入框标题
    stepsActive: 0, // 步骤条当前下标
    submitData: {
      caseDes: '',
      caseType: '',
      caseTypeName: '',
      caseClaim: '',
      prov: '',
      provName: '',
      city: '',
      cityName: '',
      area: '',
      areaName: '',
      road: '',
      roadName: '',
      village: '',
      villageName: '',
      addr: '',
      wantUserId: '',
      wantUserName: '',
      wantUnitId: '',
      wantUnitName: '',
      plaintiffList: [],
      defendantList: [],
    }, // 表单数据
    materialNum: 0, // 纠纷材料总数量
    userInfoVisible: false, // 是否采用个人信息更新申请人信息
    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
    }, // 选择人员
    caseCause: [{
        value: '22_00039-0005',
        label: '家庭婚姻纠纷',
      },
      {
        value: '22_00039-0004',
        label: '邻里纠纷',
      },
      {
        value: '22_00039-0019',
        label: '房屋宅基地纠纷',
      },
      {
        value: '22_00039-0002',
        label: '合同纠纷',
      },
      {
        value: '22_00039-0020',
        label: '生产经营纠纷',
      },
      {
        value: '22_00039-0013',
        label: '损害赔偿纠纷',
      },
      {
        value: '22_00039-0015',
        label: '山林土地纠纷',
      },
      {
        value: '22_00039-0016',
        label: '征地纠纷',
      },
      {
        value: '22_00039-0021',
        label: '环境污染纠纷',
      },
      {
        value: '22_00039-0001',
        label: '劳动争议纠纷',
      },
      {
        value: '22_00039-0006',
        label: '道路交通事故纠纷',
      },
      {
        value: '22_00039-0007',
        label: '医疗纠纷',
      },
      {
        value: '22_00039-0022',
        label: '物业管理纠纷',
      },
      {
        value: '22_00039-0018',
        label: '消费纠纷',
      },
      {
        value: '22_00039-0023',
        label: '旅游纠纷',
      },
      {
        value: '22_00039-0008',
        label: '知识产权纠纷',
      },
      {
        value: '22_00039-0024',
        label: '互联网纠纷',
      },
      {
        value: '22_00039-0003',
        label: '借贷纠纷',
      },
      {
        value: '22_00039-0009',
        label: '所有权纠纷',
      },
      {
        value: '22_00039-0010',
        label: '继承纠纷',
      },
      {
        value: '22_00039-0011',
        label: '人格权纠纷',
      },
      {
        value: '22_00039-0012',
        label: '股权转让纠纷',
      },
      {
        value: '22_00039-0014',
        label: '建设用地使用权纠纷',
      },
      {
        value: '22_00039-0017',
        label: '其他纠纷',
      },
    ],
  },
 
  //类案推荐展开隐藏
  _case() {
    this.setData({
      showDetail: !this.data.showDetail,
    })
  },
 
 
 
 
  // 身份证ocr
  handleOCR(e) {
    let that = this;
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success(res2) {
        const tempFiles = res2.tempFiles[0];
        $$.showLoading();
        wx.uploadFile({
          url: `${$$.baseUrl}${$$.url.sys}/api/v1/fileInfo/wecatRecognition`,
          filePath: tempFiles.tempFilePath,
          name: 'file',
          header: {
            Authorization: app.globalData.token
          },
          complete(res3) {
            $$.hideLoading();
            if (res3.errMsg === 'uploadFile:ok') {
              let {
                code,
                data
              } = JSON.parse(res3.data);
              if (code == -1) {
                $$.errorModal({
                  content: '识别失败'
                });
                return;
              }
              let item = that.data.popupMsg.data;
              that.data.popupMsg.data.certiNo = data?.ocrResult.certificateNumber;
              that.data.popupMsg.data[item.perClass === '09_01001-1' ? 'trueName' : 'deputy'] = data?.ocrResult.trueName;
              that.setData({
                popupMsg: that.data.popupMsg
              });
            }
          },
        });
      },
    });
  },
 
  // 表单修改
  handleChange(e) {
    let formtype = e.currentTarget.dataset.formtype,
      key = e.currentTarget.dataset.key,
      value = e.detail;
    if (formtype === 'popupMsg') {
      // 修改申请人and被申请人的form
      this.data.popupMsg.data[key] = value;
    } else {
      this.data.submitData[key] = value;
    }
    this.setData({
      submitData: this.data.submitData
    });
  },
 
  // 删除意向调解信息
  handleDeleteWant() {
    let that = this;
    $$.showModal({
      content: '确定删除意向调解信息吗?',
      success: (res) => {
        if (res.confirm) {
          let obj = {
            wantUserId: '',
            wantUserName: '',
            wantUnitId: '',
            wantUnitName: '',
          };
          that.setData({
            submitData: {
              ...that.data.submitData,
              ...obj
            }
          });
        }
      },
    });
  },
 
  // 下拉框选择确认
  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 = [
        ['prov', 'provName'],
        ['city', 'cityName'],
        ['area', 'areaName'],
        ['road', 'roadName'],
        ['village', 'villageName'],
      ];
      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
    });
  },
 
  // 多行下拉选择时,省市区选择
  handleChangeColumns(e) {
    if (this.data.popup.type === 'location') {
      let selectData = $$.changeLocation(e, this.location, this.data.popup.selectData);
      this.setData({
        popup: {
          ...this.data.popup,
          selectData
        }
      });
    }
  },
 
  // 下拉框选择开启
  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]
        },
        {
          values: selectOption[arr[0]].children[arr[1]].children[arr[2]].children || [],
          defaultIndex: arr[3]
        },
      ];
      selectData.forEach((x) => {
        x.values.forEach((y) => {
          delete y.children;
        });
      });
    } 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
    });
  },
 
  // 调解请求输入时额外的需求操作
  handlecaseClaimFocus() {
    if (!this.data.submitData.caseClaim) {
      this.data.submitData.caseClaim = '请求1:';
      this.setData({
        submitData: this.data.submitData
      });
    }
  },
 
  // 点击新增 or 删除 or 修改 申请人或被申请人
  handleEditParty(e) {
    let that = this;
    let formtype = e.currentTarget.dataset.formtype,
      index = e.currentTarget.dataset.index,
      edittype = e.currentTarget.dataset.edittype,
      agent = e.currentTarget.dataset.agent;
    let type = formtype === 'plaintiffList' ? 2 : 3;
    if (edittype === 'delete') {
      // 点击删除
      $$.showModal({
        content: '确定删除当前人员信息吗?',
        success: (res) => {
          if (res.confirm) {
            let formtype_ = that.data.popupMsg.type === 2 ? 'plaintiffList' : 'defendantList';
            let partyIndex = that.data.popupMsg.partyIndex;
            if (this.data.popupMsg.partyTabActive === '2') {
              that.data.submitData[formtype_][partyIndex].agent = null;
            } else {
              that.data.submitData[formtype_].splice(partyIndex, 1);
            }
            that.setData({
              submitData: that.data.submitData,
              popupMsg: {
                show: false
              }
            });
          }
        },
      });
    } else if (edittype === 'edit') {
      // 点击修改
      let data = this.data.submitData[formtype][index];
      this.setData({
        popupMsg: {
          show: true,
          title: formtype === 'plaintiffList' ? '修改申请人' : '修改被申请人',
          type: type,
          editType: 'edit',
          buttonText: '保存信息',
          partyArr: this.select['personClass'],
          partyTabActive: agent ? '2' : '1',
          partyIndex: index,
          perClassIndex: agent ? 0 : data.perClass === '09_01001-1' ? 0 : data.perClass === '09_01001-2' ? 1 : 2,
          data: agent ? data.agent : data,
        },
      });
    } else {
      // 点击增加
      this.setData({
        popupMsg: {
          show: true,
          title: formtype === 'plaintiffList' ? '增加申请人' : '增加被申请人',
          type: type,
          editType: 'add',
          buttonText: '保存信息',
          partyArr: this.select['personClass'],
          partyTabActive: '1', // 当事人代理人tab下标
          perClassIndex: 0, // 当事人类型下标
          data: {
            id: $$.getBusinessId(),
            perClass: '09_01001-1',
            perClassName: '自然人',
            trueName: '',
            deputy: '',
            mobile: '',
            certiNo: '',
          },
        },
      });
    }
  },
 
  // 切换增加弹窗的'1'当事人,'2'代理人
  handleChangeTab(e) {
    if (this.data.popupMsg.editType === 'edit') {
      Toast.fail('不支持修改类型');
      return false;
    }
    this.setData({
      popupMsg: {
        ...this.data.popupMsg,
        partyTabActive: e.detail.name,
        perClassIndex: 0,
        partyIndex: 0,
        data: {
          ...this.data.popupMsg.data,
          perClass: '09_01001-1',
          perClassName: '自然人',
          trueName: '',
          deputy: '',
          mobile: '',
          certiNo: '',
        },
      },
    });
  },
 
  // 切换增加弹窗的人员类型
  handleChangePerClass(e) {
    if (this.data.popupMsg.editType === 'edit') {
      Toast.fail('不支持修改类型');
      return false;
    }
    let value = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    let arr = ['perClass', 'perClassName'];
    arr.forEach((x, t) => {
      this.data.popupMsg.data[x] = value[t === 0 ? 'value' : 'label'];
    });
    this.data.popupMsg.data.trueName = '';
    this.data.popupMsg.data.deputy = '';
    this.data.popupMsg.perClassIndex = index;
    this.setData({
      popupMsg: this.data.popupMsg
    });
  },
 
  // 选择代理人
  handleSelectAgent(e) {
    this.setData({
      popupMsg: {
        ...this.data.popupMsg,
        partyIndex: e.currentTarget.dataset.index,
      },
    });
  },
 
  // 底部弹窗操作,恢复草稿
  handleClickPopupMsg() {
    if (this.data.popupMsg.type === 1) {
      // 恢复草稿
      this.setData({
        materialNum: this.data.popupMsg.submitData.fileSize,
        userInfoVisible: false,
        submitData: {
          ...this.data.submitData,
          ...this.data.popupMsg.submitData,
          ...this.data.popupMsg.intentionObj
        },
        popupMsg: {
          show: false
        },
      });
    } else {
      // 当事人保存
      let popupMsg = this.data.popupMsg;
      let data = this.data.popupMsg.data;
 
      // 信息校验
      let msg = null;
      let arr = this.data.submitData[popupMsg.type === 2 ? 'defendantList' : 'plaintiffList'];
      let arr2 = this.data.submitData[popupMsg.type === 2 ? 'plaintiffList' : 'defendantList'];
 
      console.log('arr2', arr2);
      console.log('arr', arr);
      console.log('data', data);
      console.log('popupMsg', popupMsg);
      forEach: for (let t = 0; t < arr.length; t++) {
        if (arr[t].certiNo === data.certiNo && !!$$.verifyEmpty(data.certiNo)) {
          msg = '申请人与被申请人不能相同';
          break forEach;
        }
      }
      forEach: for (let t = 0; t < arr2.length; t++) {
        if (arr2[t].certiNo === data.certiNo && !!$$.verifyEmpty(data.certiNo) && arr2[t].perClass === data.perClass && t !== popupMsg.partyIndex) {
          msg = `与${popupMsg.type === 3 ? '被' : ''}申请人不能重复`;
          break forEach;
        }
      }
      // 被申请人可不需要手机号码,申请人和代理人需要
      if (
        (data.mobile && !$$.mobileRegExp(data.mobile) && popupMsg.type === 3) ||
        (!$$.mobileRegExp(data.mobile) && popupMsg.type === 2) ||
        (!$$.mobileRegExp(data.mobile) && popupMsg.partyTabActive === '2')
      ) {
        msg = '请输入正确的手机号码';
      }
      if (!$$.verifyEmpty(data.trueName) || (data.perClass !== '09_01001-1' && !$$.verifyEmpty(data.deputy))) {
        msg = '请补充' + (popupMsg.type === 3 ? '被' : '') + '申请人方的' + (popupMsg.partyTabActive === '1' ? '当事人' : '代理人') + '信息';
      }
      if (popupMsg.partyTabActive === '1') {
 
      }
      // 增加申请人的信息
      // if (!arr2[popupMsg.partyIndex]?.trueName || !arr2[popupMsg.partyIndex]?.mobile) {
      //   msg = '请补充申请人方的当事人信息';
      // }
      if (msg) {
        Toast.fail(msg);
        return;
      }
      if (popupMsg.partyTabActive === '2' && typeof popupMsg.partyIndex !== 'number') {
        Toast.fail('请选择代理对象');
        return;
      }
      if (popupMsg.partyTabActive === '2' && arr2[popupMsg.partyIndex]?.certiNo === data.certiNo) {
        Toast.fail('代理人与当事人不能相同');
        return;
      }
 
      let type = popupMsg.type === 2 ? 'plaintiffList' : 'defendantList';
      if (popupMsg.partyTabActive === '2') {
        this.data.submitData[type][popupMsg.partyIndex] = {
          ...this.data.submitData[type][popupMsg.partyIndex]
        };
        this.data.submitData[type][popupMsg.partyIndex].agent = {
          ...this.data.submitData[type][popupMsg.partyIndex].agent,
          ...data
        };
      } else {
        if (popupMsg.editType === 'add') {
          this.data.submitData[type] = [...this.data.submitData[type], data];
        } else {
          this.data.submitData[type][popupMsg.partyIndex] = {
            ...this.data.submitData[type][popupMsg.partyIndex],
            ...data
          };
        }
      }
      this.setData({
        submitData: this.data.submitData,
        popupMsg: {
          show: false
        }
      });
    }
  },
 
  // 关闭底部弹窗
  handleClosePopupMsg() {
    if (this.data.popupMsg.type === 1) {
      this.getUserInfo(this.data.popupMsg.intentionObj);
    } else {
      this.setData({
        popupMsg: {
          show: false
        }
      });
    }
  },
 
  // 关闭选择人员
  handleVisiblePopupSelect(e) {
    let type = e.currentTarget.dataset.type;
    if (type === 'open') {
      this.getPersonHistory();
    } else {
      this.setData({
        popupSelect: {
          show: false
        }
      });
    }
  },
 
  // 选择人员
  handleSelectPerson(e) {
    this.setData({
      popupSelect: {
        ...this.data.popupSelect,
        activeIndex: e.currentTarget.dataset.index
      }
    });
  },
 
  // 确定历史人员数据填充
  handleConfirmPerson() {
    if (typeof this.data.popupSelect.activeIndex !== 'number') {
      Toast.fail('请选择人员');
      return;
    }
    let data = this.data.popupSelect.data[this.data.popupSelect.activeIndex] || {};
    this.data.popupMsg.perClassIndex =
      this.data.popupMsg.partyTabActive === '2' ? 0 : data.perClass === '09_01001-1' ? 0 : data.perClass === '09_01001-2' ? 1 : 2;
    this.data.popupMsg.data = {
      ...this.data.popupMsg.data,
      perClass: data.perClass,
      perClassName: data.perClassName,
      trueName: data.trueName,
      deputy: data.deputy,
      mobile: data.mobile,
      certiNo: data.certiNo,
    };
    this.setData({
      popupSelect: {
        show: false
      },
      popupMsg: this.data.popupMsg
    });
  },
 
  // 跳转至材料上传页面
  handleGoToMaterial() {
    // 先保存
    if (this.data.submitData.inputStatus !== '2') {
      this.goToMaterialSave = true;
      this.saveCase();
    }
    // 获取人员数据保存至全局变量中,方便附件上传页面获取有多少人员
    let person = [];
    let arr = ['plaintiffList', 'defendantList'];
    arr.forEach((y) => {
      this.data.submitData[y].forEach((x) => {
        if (x.trueName) {
          person.push({
            id: x.id,
            perClass: x.perClass,
            perClassName: x.perClassName,
            trueName: x.trueName,
          });
        }
        if (x.agent && x.agent.trueName) {
          person.push({
            agent: true,
            id: x.agent.id,
            perClass: x.agent.perClass,
            perClassName: x.agent.perClassName,
            trueName: x.agent.trueName,
          });
        }
      });
    });
    app.globalData.material.person = person;
    wx.navigateTo({
      url: '../../pages/materialShow/index?caseId=' + this.data.submitData.id + '&editVisible=true',
    });
  },
 
  // 下一步 or 上一步
  handleNext(e) {
    let type = e.currentTarget.dataset.type;
    let content = this.data.tipData.guideList.length === 0 ?
      '请再次仔细核对您的申请信息,确定提交调解申请吗?' :
      `根据人工智能大数据分析,您的请求可调整为:【${this.data.tipData.guideList}】(以上建议仅供参考),确定提交调解申请吗?`
    if (type === 'next' && this.data.stepsActive === 0) {
      // this.checkCaseDetail();
      this.fengxian();
    } else if (type === 'next' && this.data.stepsActive === 1) {
      let that = this;
      $$.showModal({
        title: '申请提交确认',
        content: content,
        success: (res) => {
          if (res.confirm) {
            that.submitCase();
          }
        },
      });
    } else if (type === 'back' && this.data.stepsActive === 1) {
      this.setData({
        stepsActive: 0
      });
    }
  },
 
  // 校验提交信息的必填项并下一步
  checkCaseDetail() {
    let msg = '';
    let submitData = this.data.submitData;
    let arr1 = [{
        key: 'area',
        title: '纠纷发生地'
      },
      {
        key: 'caseDes',
        title: '纠纷描述'
      },
      {
        key: 'caseClaim',
        title: '调解请求'
      },
    ];
    forEach: for (let i = 0; i < arr1.length; i++) {
      if (!$$.verifyEmpty(submitData[arr1[i].key])) {
        msg = arr1[i].title;
        break forEach;
      }
    }
    if (msg) {
      Toast.fail(msg + '未填写');
      return false;
    }
    if (submitData.plaintiffList.length === 0) {
      Toast.fail('至少添加一名申请人');
      return false;
    }
    if (submitData.plaintiffList?.length > 0) {
      if (!submitData.plaintiffList[0].trueName) {
        Toast.fail('至少添加一名申请人');
        return false;
      }
    }
    if (submitData.defendantList.length === 0) {
      Toast.fail('至少添加一名被申请人');
      return false;
    }
    if (submitData.defendantList?.length > 0) {
      if (!submitData.defendantList[0].trueName) {
        Toast.fail('至少添加一名申请人');
        return false;
      }
    }
    if (msg) {
      Toast.fail(msg);
      return false;
    }
    // this.fengxian();
    this.setData({
      stepsActive: 1
    });
  },
 
  // 返回首页
  handleGoHomepage() {
    if (this.data.changeVisible) {
      wx.navigateBack({
        delta: 1,
      });
      return false;
    }
    wx.reLaunch({
      url: '../../pages/homePage/index',
    });
  },
 
  // 录音组件开启 and 关闭触发
  handleVisibleRecording(e) {
    this.setData({
      recordingVisible: !this.data.recordingVisible
    });
  },
 
  // 获取录音转写的文字
  handleGetWords(e) {
    let key = e.currentTarget.dataset.type;
    let value = e.detail;
    if (key === 'caseDes') {
      this.data.submitData[key] = this.data.submitData[key] + value;
      this.setData({
        submitData: this.data.submitData,
        recordingVisible: !this.data.recordingVisible
      });
    } else {
      if (!this.data.submitData.caseClaim) {
        this.data.submitData[key] = '请求1:' + value;
      } else {
        this.data.submitData[key] = this.data.submitData[key] + value;
      }
      this.setData({
        submitData: this.data.submitData,
        recordingVisible: !this.data.recordingVisible
      });
    }
  },
 
  // 退出页面保存草稿前判断,如果地址没有更改则不需要保存。
  handleCheckSave() {
    if (this.data.popupMsg.type === 1 && this.data.popupMsg.show) {
      // 恢复草稿弹窗时退出不保存
      return;
    }
    if (this.goToMaterialSave || this.data.stepsActive !== 0 || this.data.submitData.inputStatus === '2') {
      // 跳转纠纷材料 || 不在第一步骤 || 修改时则不保存
      this.goToMaterialSave = false;
      return;
    }
    // 地址变动后保存草稿
    let save = false;
    if (['prov', 'city', 'area', 'road', 'village'].map((x) => this.data.submitData[x]).join('') !== this.userInfo.address) save = true;
    let arr = ['caseDes', 'caseType', 'caseTypeName', 'caseClaim', 'addr', 'wantUserId', 'wantUserName', 'wantUnitId', 'wantUnitName'];
    arr.forEach((x) => {
      if ($$.verifyEmpty(this.data.submitData[x])) save = true;
    });
    if (this.data.submitData['plaintiffList'].length > 1 || this.data.submitData['defendantList'].length > 0) {
      save = true;
    }
    if (save) {
      this.saveCase();
    }
  },
 
  async fengxian() {
    let that = this;
    $$.showLoading();
    let submitData = this.data.submitData;
    const res = await checkCaseClaimRiskApi({
      caseDes: submitData.caseDes,
      caseClaim: submitData.caseClaim,
      caseTypeName: submitData.caseTypeName,
    });
    $$.hideLoading();
    if (res.type) {
      if (res.data?.case_risk_claims || res.data?.guide_risk_claims) {
        if (res.data?.case_risk_claims.length && res.data?.guide_risk_claims.length) {
          let caseList = res.data?.case_risk_claims;
          let guideList = res.data?.guide_risk_claims;
          let caseText = res.data?.caseText;
          let caseTitle = res.data?.caseTitle;
          let similarity = res.data?.similarity;
          if (!this.data.tipData.guideList || JSON.stringify(this.data.tipData.guideList) !== JSON.stringify(guideList)) {
            this.setData({
              'tipData.guideList': guideList,
              'tipData.caseList': caseList,
              caseText: caseText,
              caseTitle: caseTitle,
              similarity: similarity,
              showCase: true,
            });
          } else {
            this.checkCaseDetail();
          }
          that.setData({
            tipData: {
              caseList,
              guideList
            }
          })
        } else {
          this.setData({
            'tipData.guideList': [],
            'tipData.caseList': [],
          });
          this.checkCaseDetail();
        }
      }
    }
  },
 
  // 上传案件
  async submitCase() {
    $$.showLoading();
    let submitData = this.data.submitData;
    submitData.inputStatus = '2';
    submitData.process = null;
    const res = await submitCaseApi(submitData);
    $$.hideLoading();
    if (res.type) {
      if (this.data.changeVisible) {
        // 用于当“我的调解”页面等其他页面进入修改时,修改后返回更新数据凭证
        app.globalData.caseMsg.handleVisible = true;
      }
      this.setData({
        stepsActive: 2
      });
      let caseId = res.data;
      // 在这里调用接口
    //   getCaseApi({
    //     caseId,
    //     start_page_num: '0',
    //     end_page_num: '100'
    //   });
    //   getFeatureApi({
    //     caseId,
    //   })
    //   getCacheOpenAiCaseGuideList({
    //     caseId,
    //     guideTypes: '5,6'
    //   })
    }
  },
 
  // 保存草稿
  async saveCase() {
    let submitData = this.data.submitData;
    submitData.inputStatus = '1';
    const res = await submitCaseApi(submitData);
    if (res.type) {
      console.log('保存成功');
    }
  },
 
  // 修改案件 时 获取案件信息
  async getCaseData(caseId, changeVisible) {
    $$.showLoading();
    const res = await getCaseDetailApi(caseId);
    $$.hideLoading();
    if (res.type) {
      this.setData({
        materialNum: res.data.fileSize,
        userInfoVisible: false,
        submitData: res.data,
        changeVisible: changeVisible,
      });
    }
  },
 
  // 获取当前页面是否存在草稿
  async getDraftCase(options) {
    let intentionObj = {};
    if (options.type) {
      // 找他调页面跳转进入赋值意向调解信息
      let arr = [];
      if (options.type === '1') {
        arr = ['wantUserId', 'wantUserName'];
      } else {
        arr = ['wantUnitId', 'wantUnitName'];
      }
      intentionObj[arr[0]] = options.id;
      intentionObj[arr[1]] = options.name;
    }
    $$.showLoading();
    const res = await getDraftCaseApi('1');
    if (res.type) {
      if (res.data?.id) {
        $$.hideLoading();
        this.userInfo = {
          address: ['prov', 'city', 'area', 'road', 'village'].map((x) => res.data[x]).join('')
        };
        this.setData({
          popupMsg: {
            show: true,
            title: '恢复草稿',
            buttonText: '恢复草稿',
            type: 1,
            intentionObj,
            submitData: res.data
          }
        });
      } else {
        this.getUserInfo(intentionObj);
      }
    } else {
      this.getUserInfo(intentionObj);
    }
  },
 
  // 获取个人信息,填充个人信息材料至第一个申请人处,如有草稿则不执行
  async getUserInfo(intentionObj) {
    let obj = {},
      locationObj = {};
    const res = await getUserInfoApi();
    $$.hideLoading();
    if (res.type) {
      this.data.userInfoVisible = true;
      obj = {
        trueName: res.data.trueName || '',
        certiNo: res.data.idcard || '',
        mobile: res.data.mobile || '',
        address: ['prov', 'city', 'area', 'road', 'village'].map((x) => res.data[x]).join(''),
      };
      ['prov', 'provName', 'city', 'cityName', 'area', 'areaName', 'road', 'roadName', 'village', 'villageName'].forEach((x) => {
        locationObj[x] = res.data[x] || '';
      });
    }
    this.data.submitData.plaintiffList[0] = {
      perClass: '09_01001-1',
      perClassName: '自然人',
      id: $$.getBusinessId(),
      ...obj
    };
    this.userInfo = obj;
    this.setData({
      userInfoVisible: this.data.userInfoVisible,
      submitData: {
        ...this.data.submitData,
        ...intentionObj,
        ...locationObj,
        id: $$.getBusinessId()
      },
      popupMsg: {
        show: false
      },
    });
  },
 
  // 获取选择人员
  async getPersonHistory() {
    $$.showLoading();
    const res = await getPersonHistoryApi();
    $$.hideLoading();
    if (res.type) {
      this.setData({
        popupSelect: {
          show: true,
          data: res.data || []
        }
      });
    }
  },
 
  // 请求下拉框资源
  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 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;
    }
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getLocationData();
    this.getSelectOptionData();
    if (options.change) {
      this.getCaseData(options.caseId, true);
    } else {
      this.getDraftCase(options);
    }
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.material.data.length !== 0) {
      // 计算附件数量
      let num = 0;
      app.globalData.material.data.forEach((x) => {
        num = num + x.num;
      });
      app.globalData.material.data = [];
      this.setData({
        materialNum: num
      });
    }
  },
 
  onHide: function () {
    this.handleCheckSave();
  },
 
  onUnload: function () {
    this.handleCheckSave();
  },
});