BAOLH
2026-11-10 4d730af0447c686133130d0116a0fa3dd82c2dca
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
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.contractNumber" clearable placeholder="合同编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.contractName" clearable placeholder="合同名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.firstId" filterable clearable placeholder="所属甲方" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in customerFirst"
            :key="item.firstId"
            :label="item.firstName"
            :value="item.firstId"
          >
            <span style="float: left">{{ item.firstName }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.firstPerson }}-{{ item.firstPhone }}</span>
          </el-option>
        </el-select>
        <el-select v-model="query.secondId" filterable clearable placeholder="所属乙方" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in customerSecond"
            :key="item.secondId"
            :label="item.secondName"
            :value="item.secondId"
          >
            <span style="float: left">{{ item.secondName }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.secondPerson }}-{{ item.secondPhone }}</span>
          </el-option>
        </el-select>
        <el-select v-model="query.contractType" filterable clearable placeholder="合同类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[contractType]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.contractPaymentState" filterable clearable placeholder="合同费付款状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[paymentState]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.servicePaymentState" filterable clearable placeholder="服务费付款状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[paymentState]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.contractStatus" filterable clearable placeholder="合同状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[contractStatus]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.provincial" filterable clearable placeholder="省级" style="width: 185px;" class="filter-item" @change="queryProvincialChange" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in areaOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.city" filterable clearable placeholder="市级" style="width: 185px;" class="filter-item" @change="queryCityChange" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in queryCityList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.region" filterable clearable placeholder="区级" style="width: 185px;" class="filter-item" @change="queryRegionChange" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in queryRegionList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="query.acceptStatus" filterable clearable placeholder="验收状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict[acceptStatus]"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <date-range-picker v-model="query.signDate" clearable placeholder="签订日期" style="width: 185px;" class="date-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          v-permission="permission.edit"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-upload"
          @click="uploadDialogOpen"
        >
          导入
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.download"
          class="filter-item"
          size="mini"
          type="warning"
          icon="el-icon-download"
          :loading="downloadTableLoading"
          style="margin-left: 4px !important;"
          @click="toDownloadTable()"
        >
          表格导出
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.divide"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-share"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 4px !important;"
          @click="toDivide(crud.selections[0])"
        >
          分配
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.seeDivide"
          class="filter-item"
          size="mini"
          type="primary"
          icon="el-icon-share"
          :disabled="crud.selections.length !== 1"
          style="margin-left: 4px !important;"
          @click="toSeeDivide(crud.selections[0])"
        >
          查看分配
        </el-button>
        <el-button
          slot="right"
          v-permission="permission.edit"
          class="filter-item"
          size="mini"
          type="success"
          icon="el-icon-edit"
          :loading="addWarningStatusLoading"
          :disabled="crud.selections.length === 0"
          style="margin-left: 4px !important;"
          @click="addWarningStatus(crud.selections)"
        >预警</el-button>
      </crudOperation>
      <el-row :gutter="40" style="color: red; font-weight: bolder;">
        <el-col :xs="12" :sm="12" :lg="6">
          合同费总金额:{{ crud.toMoney(contractTotalMoney) }}
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6">
          合同费延期数:{{ contractDelayTotalAmount }}
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6">
          合同费延期金额:{{ crud.toMoney(contractDelayTotalMoney) }}
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6">
          预收款总金额:{{ crud.toMoney(advancePaymentTotalMoney) }}
        </el-col>
      </el-row>
      <el-row :gutter="40" style="color: red; font-weight: bolder;">
        <el-col :xs="12" :sm="12" :lg="6">
          运维服务总金额:{{ crud.toMoney(serviceTotalMoney) }}
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6">
          运维服务延期数:{{ serviceDelayTotalAmount }}
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6">
          运维服务延期金额:{{ crud.toMoney(serviceDelayTotalMoney) }}
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6">
          应收款总金额:{{ crud.toMoney(receivePaymentTotalMoney) }}
        </el-col>
      </el-row>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="750px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="140px">
          <el-form-item label="合同名称" prop="contractName">
            <el-input v-model="form.contractName" style="width: 555px;" />
          </el-form-item>
          <el-form-item label="所属甲方" prop="firstId">
            <el-select v-model="form.firstId" filterable clearable placeholder="请选择" style="width: 555px;">
              <el-option
                v-for="item in customerFirst"
                :key="item.firstId"
                :label="item.firstName"
                :value="item.firstId"
              >
                <span style="float: left">{{ item.firstName }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.firstPerson }}-{{ item.firstPhone }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属乙方" prop="secondId">
            <el-select v-model="form.secondId" filterable clearable placeholder="请选择" style="width: 555px;">
              <el-option
                v-for="item in customerSecond"
                :key="item.secondId"
                :label="item.secondName"
                :value="item.secondId"
              >
                <span style="float: left">{{ item.secondName }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ item.secondPerson }}-{{ item.secondPhone }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="签订日期" prop="signDate">
            <el-date-picker v-model="form.signDate" type="date" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="业绩日期" prop="performanceDate">
            <el-date-picker v-model="form.performanceDate" type="month" value-format="yyyy-MM-dd HH:mm:ss" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="所属地区" prop="contractArea">
            <el-cascader
              v-model="selectedAreaOptions"
              size="small"
              :options="areaOptions"
              style="width: 555px;"
              @change="areaChange"
            />
          </el-form-item>
          <el-form-item label="起始日期" prop="startDate">
            <el-date-picker v-model="form.startDate" type="date" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="截止日期" prop="endDate">
            <el-date-picker v-model="form.endDate" type="date" style="width: 200px;" />
          </el-form-item>
          <el-form-item label="合同类型(一级)" prop="contractType">
            <el-select v-model="form.contractType" filterable placeholder="请选择" style="width: 200px;" @change="contractTypeChange">
              <el-option
                v-for="item in dict[contractType]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="合同类型(二级)" prop="contractSecondType">
            <el-select v-model="form.contractSecondType" filterable allow-create placeholder="请选择" style="width: 200px;" @change="contractSecondTypeChange">
              <template v-if="form.contractType == contractTechnology">
                <el-option
                  v-for="item in dict[technologySecondType]"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </template>
              <template v-if="form.contractType == contractConsultation">
                <el-option
                  v-for="item in dict[consultationSecondType]"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </template>
              <template v-if="form.contractType == contractWeakCurrent">
                <el-option
                  v-for="item in dict[weakCurrentSecondType]"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </template>
              <template v-if="form.contractType == contractIp">
                <el-option
                  v-for="item in dict[ipSecondType]"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </template>
            </el-select>
          </el-form-item>
          <el-form-item label="合同内容" prop="contractContent">
            <el-input v-model="form.contractContent" style="width: 200px;" />
          </el-form-item>
          <span v-if="form.contractSecondType != contractService && form.contractSecondType != null && form.contractSecondType != ''">
            <el-divider>合同费用数据</el-divider>
            <el-form-item label="合同费金额" prop="contractAmount">
              <money-input :key="random" v-model="form.contractAmount" show-ch :width="555" />
            </el-form-item>
            <el-form-item label="预计付款日期" prop="contractPaymentDate">
              <el-date-picker v-model="form.contractPaymentDate" type="date" style="width: 200px;" />
            </el-form-item>
            <el-form-item label="付款状态" prop="contractPaymentState">
              <el-select v-model="form.contractPaymentState" filterable placeholder="请选择" style="width: 200px;">
                <el-option
                  v-for="item in dict[paymentState]"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </span>
          <span v-if="form.contractSecondType == contractService || form.contractSecondType == contractDevelopService">
            <el-divider>运维服务费用数据</el-divider>
            <el-form-item v-if="form.contractSecondType == contractDevelopService" label="服务开始日期" prop="serviceStartsDate">
              <el-date-picker v-model="form.serviceStartsDate" type="date" style="width: 555px;" />
            </el-form-item>
            <el-form-item label="运维服务费金额" prop="serviceAmount">
              <money-input :key="random" v-model="form.serviceAmount" show-ch :width="555" />
            </el-form-item>
            <el-form-item label="预计付款日期" prop="servicePaymentDate">
              <el-date-picker v-model="form.servicePaymentDate" type="date" style="width: 200px;" />
            </el-form-item>
            <el-form-item label="付款状态" prop="servicePaymentState">
              <el-select v-model="form.servicePaymentState" filterable placeholder="请选择" style="width: 200px;">
                <el-option
                  v-for="item in dict[paymentState]"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </span>
          <el-form-item label="合同初版文件" prop="relatedDocumentsFirst">
            <file-upload :key="random" ref="fileFirstUpload" :file-url="form.relatedDocumentsFirst == null || form.relatedDocumentsFirst === '' ? null : form.relatedDocumentsFirst" :limit="5" style="width: 555px;" @fileInfo="getFirstFileInfo" />
          </el-form-item>
          <el-form-item label="合同终版文件" prop="relatedDocumentsFinal">
            <file-upload :key="random" ref="fileFinalUpload" :file-url="form.relatedDocumentsFinal == null || form.relatedDocumentsFinal === '' ? null : form.relatedDocumentsFinal" :limit="5" style="width: 555px;" @fileInfo="getFinalFileInfo" />
          </el-form-item>
          <el-form-item label="合同附件" prop="relatedDocumentsAttachment">
            <file-upload :key="random" ref="fileAttachmentUpload" :file-url="form.relatedDocumentsAttachment == null || form.relatedDocumentsAttachment === '' ? null : form.relatedDocumentsAttachment" :limit="5" style="width: 555px;" @fileInfo="getAttachmentFileInfo" />
          </el-form-item>
          <el-form-item label="合同状态" prop="contractStatus">
            <el-select v-model="form.contractStatus" filterable placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in dict[contractStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
              <el-popover slot="prefix" placement="top-start" width="500" trigger="hover">
                <div>
                  <div>【未签订】= 有业务/进行中业务,未拟定合同</div>
                  <div>【签订中】= 电子版已发送/合同已盖章邮寄/出差带走等收回</div>
                  <div>【已签订】= 合同已收回,甲乙双方均盖章生效</div>
                  <div>【不签订】= 业务有实际收入,但与甲方核实不签订合同,直接付款</div>
                </div>
                <i slot="reference" class="el-icon-info" />
              </el-popover>
            </el-select>
          </el-form-item>
          <el-form-item label="验收状态" prop="acceptStatus">
            <el-select v-model="form.acceptStatus" filterable placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in dict[acceptStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
              <el-popover slot="prefix" placement="top-start" width="500" trigger="hover">
                <div>
                  <div>【待制作】= 计划需要验收,项目正在进行,等结束时需要验收</div>
                  <div>【验收中】= 电子版已发送/合同已盖章邮寄/出差带走等收回</div>
                  <div>【部分验收】= 项目内容包含多项,需要先付款一部分,已完成部分已收回验收单,还有一部分未进行验收</div>
                  <div>【已验收】= 验收单已收回,甲乙双方均盖章生效</div>
                  <div>【不验收】= 无需验收</div>
                </div>
                <i slot="reference" class="el-icon-info" />
              </el-popover>
            </el-select>
          </el-form-item>
          <el-form-item label="钱款缴纳状态" prop="recoveryStatus">
            <el-select v-model="form.recoveryStatus" filterable placeholder="请选择" style="width: 200px;">
              <el-option
                v-for="item in dict[recoveryStatus]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注信息" prop="remarks">
            <el-input v-model="form.remarks" :rows="3" type="textarea" style="width: 555px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" stripe size="small" style="width: 100%;" :row-class-name="warningRowClassName" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="40" />
        <el-table-column fixed="left" type="expand">
          <template slot-scope="props">
            <el-form label-position="left" class="my-demo-table-expand" style="margin-left: 264px;">
              <template v-if="props.row.contractSecondType != contractService">
                <el-form-item label="合同费">
                  <span>{{ crud.toMoney(props.row.contractPaymentAmount) }} / {{ crud.toMoney(props.row.contractAmount) }}</span>
                </el-form-item>
              </template>
              <template v-if="props.row.contractSecondType == contractService || props.row.contractSecondType == contractDevelopService">
                <el-form-item
                  v-for="item in (parseInt(crud.toDate(new Date()).substring(0,4)) - parseInt(crud.toDate(props.row.serviceStartsDate).substring(0,4)) + 1)"
                  :key="item"
                  :label="
                    (parseInt(crud.toDate(props.row.serviceStartsDate).substring(0,4)) + (item - 1)) +
                      crud.toDate(props.row.serviceStartsDate).substring(4,10) +
                      ' ~ ' +
                      (
                        crud.toDate(new Date(props.row.serviceStartsDate).getTime() - 24 * 60 * 60 * 1000).substring(4,10) == '-12-31' ?
                          (parseInt(crud.toDate(props.row.serviceStartsDate).substring(0,4)) + (item - 1)) +
                          crud.toDate(new Date(props.row.serviceStartsDate).getTime() - 24 * 60 * 60 * 1000).substring(4,10) :
                          (parseInt(crud.toDate(props.row.serviceStartsDate).substring(0,4)) + item) +
                          crud.toDate(new Date(props.row.serviceStartsDate).getTime() - 24 * 60 * 60 * 1000).substring(4,10)
                      ) +
                      ' 运维服务费'"
                >
                  <span>{{ crud.toMoney(props.row.servicePaymentAmount.split('、')[item - 1]) }} / {{ crud.toMoney(props.row.serviceAmount) }}</span>
                </el-form-item>
              </template>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column fixed="left" :show-overflow-tooltip="true" prop="contractNumber" label="合同编号" width="160" />
        <el-table-column fixed="left" :show-overflow-tooltip="true" prop="contractName" label="合同名称" width="100" />
        <el-table-column :show-overflow-tooltip="true" prop="firstName" label="所属甲方" width="100" />
        <el-table-column :show-overflow-tooltip="true" prop="secondName" label="所属乙方" width="100" />
        <el-table-column :show-overflow-tooltip="true" prop="signDate" label="签订日期" width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.signDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="performanceDate" label="业绩日期" width="100">
          <template slot-scope="scope">
            {{ crud.toMonth(scope.row.performanceDate) }}
          </template>
        </el-table-column>
        <el-table-column label="发票详情">
          <template slot-scope="scope">
            <el-link type="info" @click="goContractInvoice(scope.row.contractId)">点击查看</el-link>
          </template>
        </el-table-column>
        <el-table-column label="付款详情">
          <template slot-scope="scope">
            <el-link type="info" @click="goContractPayment(scope.row.contractId)">点击查看</el-link>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="billingTotalAmount" label="开票总金额" width="100">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.billingTotalAmount) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="paymentTotalAmount" label="付款总金额" width="100">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.paymentTotalAmount) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="paymentIncomeAmount" label="付款收入金额" width="100">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.paymentIncomeAmount) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="paymentExpendAmount" label="付款支出金额" width="100">
          <template slot-scope="scope">
            {{ crud.toMoney(scope.row.paymentExpendAmount) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="advancePayment" label="预收款金额" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.advancePayment != null && scope.row.advancePayment != 0" style="color: red;">
              {{ crud.toMoney(scope.row.advancePayment) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="receivePayment" label="应收款金额" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.receivePayment != null && scope.row.receivePayment != 0" style="color: red;">
              {{ crud.toMoney(scope.row.receivePayment) }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="合同费数据">
          <el-table-column :show-overflow-tooltip="true" prop="contractAmount" label="合同费金额" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.contractAmount != null && scope.row.contractAmount != 0">
                {{ crud.toMoney(scope.row.contractAmount) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="contractPaymentDate" label="预计付款日期" width="100">
            <template slot-scope="scope">
              {{ crud.toDate(scope.row.contractPaymentDate) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="contractPaymentState" label="付款状态" width="100">
            <template slot-scope="scope">
              {{ dict.label[paymentState][scope.row.contractPaymentState] }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="contractPostponement" label="延期情况" width="100">
            <template slot-scope="scope">
              <span style="color: red;">{{ scope.row.contractPostponement }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="运维服务费数据">
          <el-table-column :show-overflow-tooltip="true" prop="serviceStartsDate" label="服务开始日期" width="100">
            <template slot-scope="scope">
              {{ crud.toDate(scope.row.serviceStartsDate) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="serviceAmount" label="运维服务费金额" width="110">
            <template slot-scope="scope">
              <span v-if="scope.row.serviceAmount != null && scope.row.serviceAmount != 0">
                {{ crud.toMoney(scope.row.serviceAmount) }}
              </span>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="servicePaymentDate" label="预计付款日期" width="100">
            <template slot-scope="scope">
              {{ crud.toMonthDay(scope.row.servicePaymentDate) }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="servicePaymentState" label="付款状态" width="100">
            <template slot-scope="scope">
              {{ dict.label[paymentState][scope.row.servicePaymentState] }}
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="servicePostponement" label="延期情况" width="100">
            <template slot-scope="scope">
              <span style="color: red;">{{ scope.row.servicePostponement }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="startDate" label="起始日期" width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.startDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="endDate" label="截止日期" width="100">
          <template slot-scope="scope">
            {{ crud.toDate(scope.row.endDate) }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="contractArea" label="所属地区" width="100" />
        <el-table-column :show-overflow-tooltip="true" prop="contractType" label="合同类型" width="100">
          <template slot-scope="scope">
            {{ dict.label[contractType][scope.row.contractType] }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="contractSecondType" label="合同类型(二级)" width="100" />
        <el-table-column :show-overflow-tooltip="true" prop="contractContent" label="合同内容" width="100" />
        <el-table-column label="合同费项目数据">
          <el-table-column :show-overflow-tooltip="true" prop="fundContractNum" label="分配项目数" width="100" />
          <el-table-column :show-overflow-tooltip="true" prop="fundContractAmount" label="分配总金额" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.fundContractAmount != null && scope.row.fundContractAmount != 0">
                {{ crud.toMoney(scope.row.fundContractAmount) }}
              </span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="服务费项目数据">
          <el-table-column :show-overflow-tooltip="true" prop="fundServiceNum" label="分配项目数" width="100" />
          <el-table-column :show-overflow-tooltip="true" prop="fundServiceAmount" label="分配总金额" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.fundServiceAmount != null && scope.row.fundServiceAmount != 0">
                {{ crud.toMoney(scope.row.fundServiceAmount) }}
              </span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="合同附件" width="100" align="center">
          <template slot-scope="scope">
            <el-link v-if="scope.row.relatedDocumentsAttachment != null" type="primary" :disabled="downloadAttachmentLoading" @click="toDownloadContractAttachments(scope.row.contractId)">下载</el-link>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注信息" width="100" />
        <el-table-column :show-overflow-tooltip="true" prop="acceptStatus" label="验收状态" width="100">
          <template slot-scope="scope">
            {{ dict.label[acceptStatus][scope.row.acceptStatus] }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" :show-overflow-tooltip="true" prop="contractStatus" label="合同状态" width="100">
          <template slot-scope="scope">
            {{ dict.label[contractStatus][scope.row.contractStatus] }}
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','contract:edit','contract:del','contract:divide'])" fixed="right" label="操作" width="180px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            >
              <el-button
                slot="left"
                v-permission="permission.divide"
                size="mini"
                type="primary"
                icon="el-icon-share"
                @click="toDivide(scope.row)"
              />
            </udOperation>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <!--表单组件(分配)-->
      <el-dialog :close-on-click-modal="false" :before-close="divideClose" :visible.sync="divideStatus" title="项目分配" width="500px">
        <el-form ref="divideForm" :model="divideForm" :rules="divideRules" size="small" label-width="80px">
          <el-form-item label="所属合同" prop="contractName">
            {{ divideForm.contractName }}
          </el-form-item>
          <el-form-item label="所属项目" prop="projectId">
            <el-select v-model="divideForm.projectId" filterable clearable placeholder="请选择" style="width: 370px;">
              <el-option
                v-for="item in projects"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="款项类型" prop="fundType">
            <el-select v-model="divideForm.fundType" filterable placeholder="请选择" style="width: 370px;">
              <el-option
                v-for="item in dict[fundType]"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="分配金额" prop="allocatedAmount">
            <money-input :key="random" v-model="divideForm.allocatedAmount" show-ch :width="370" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="divideClose">取消</el-button>
          <el-button :loading="divideLoading" type="primary" @click="divideSubmit">确认</el-button>
        </div>
      </el-dialog>
      <!--表单组件(导入)-->
      <el-dialog :close-on-click-modal="false" :before-close="uploadDialogClose" :visible.sync="uploadDialog.visible" title="导入" width="500px">
        <el-form ref="uploadForm" :model="uploadDialog.form" :rules="uploadDialog.rules" size="small" label-width="80px">
          <el-form-item label="文件" prop="file">
            <el-upload
              ref="contractUpload"
              :auto-upload="false"
              :action="baseApi + '/api/contract/upload'"
              accept=".xlsx, .xls"
              :limit="1"
              drag
              :headers="headers"
              :before-upload="beforeUpload"
              :on-success="handleSuccess"
              :on-error="handleError"
              :on-change="handleChange"
              :on-remove="handleRemove"
              class="upload-demo"
            >
              <i class="el-icon-upload" />
              <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
              <div slot="tip" class="el-upload__tip">只能上传xls/xlsx文件,且不超过50M</div>
            </el-upload>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="uploadDialogClose">取消</el-button>
          <el-button :loading="uploadDialog.loading" type="primary" @click="uploadDialogSubmit">确认</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
 
<script>
import crudContract from '@/api/contract/contract'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudContractFirst from '@/api/contract/contractFirst'
import crudContractSecond from '@/api/contract/contractSecond'
import crudProject from '@/api/project/project'
import crudContractProject from '@/api/contract/contractProject'
import { regionData, CodeToText } from '@/utils/elementChinaAreaData'
import moneyInput from '@/views/assembly/moneyInput/index.vue'
import fileUpload from '@/views/assembly/fileUpload/index.vue'
import DateRangePicker from '@/components/DateRangePicker'
import constant from '@/utils/constant'
import { contractTotalMoney, contractDelayTotalAmount, contractDelayTotalMoney, advancePaymentTotalMoney } from '@/api/contract/contract'
import { serviceTotalMoney, serviceDelayTotalAmount, serviceDelayTotalMoney, receivePaymentTotalMoney } from '@/api/contract/contract'
import { addWarningStatus, downloadContractAttachments, downloadTable } from '@/api/contract/contract'
import Dict from '@/components/Dict/Dict'
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import { downloadFile } from '@/utils/index'
 
const defaultForm = { contractId: null, contractNumber: null, contractName: null, firstId: null, secondId: null, signDate: null, performanceDate: null, startDate: null, endDate: null, contractAreaCode: null, contractArea: null, contractType: null, contractSecondType: null, contractContent: null, contractAmount: null, contractPaymentDate: null, contractPaymentState: null, serviceStartsDate: null, serviceAmount: null, servicePaymentDate: null, servicePaymentState: null, relatedDocumentsFirst: null, relatedDocumentsFinal: null, relatedDocumentsAttachment: null, contractStatus: null, recoveryStatus: null, remarks: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'InServiceContract',
  components: { pagination, crudOperation, rrOperation, udOperation, moneyInput, fileUpload, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: [constant.CONTRACT_TYPE, constant.PAYMENT_STATE, constant.CONTRACT_STATUS, constant.FUND_TYPE, constant.TECHNOLOGY_SECOND_TYPE, constant.CONSULTATION_SECOND_TYPE, constant.WEAK_CURRENT_SECOND_TYPE, constant.IP_SECOND_TYPE, constant.ACCEPT_STATUS, constant.RECOVERY_STATUS],
  cruds() {
    return CRUD({ title: '合同详情', url: 'api/contract', idField: 'contractId', sort: 'contractId,desc', crudMethod: { ...crudContract }})
  },
  data() {
    // 合同费金额校验规则
    var validateContractAmount = (rule, value, callback) => {
      if (value !== null) {
        if (isNaN(Number(value))) {
          callback(new Error('请输入数字值'))
        } else {
          if (value < 0 || value > 1000000000) {
            callback(new Error('合同费金额不能超过10亿'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('合同费金额不能为空'))
      }
    }
    // 服务费金额校验规则
    var validateServiceAmount = (rule, value, callback) => {
      if (value !== null) {
        if (isNaN(Number(value))) {
          callback(new Error('请输入数字值'))
        } else {
          if (value < 0 || value > 1000000000) {
            callback(new Error('服务费金额不能超过10亿'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('服务费金额不能为空'))
      }
    }
    // 分配金额校验规则
    var validateAllocatedAmount = (rule, value, callback) => {
      if (value !== null) {
        if (isNaN(Number(value))) {
          callback(new Error('请输入数字值'))
        } else {
          if (value < 0 || value > 1000000000) {
            callback(new Error('分配金额不能超过10亿'))
          } else {
            callback()
          }
        }
      } else {
        callback(new Error('分配金额不能为空'))
      }
    }
    return {
      permission: {
        add: ['admin', 'contract:add'],
        edit: ['admin', 'contract:edit'],
        del: ['admin', 'contract:del'],
        download: ['admin', 'contract:download'],
        divide: ['admin', 'contract:divide'],
        seeDivide: ['admin', 'contract:seeDivide']
      },
      rules: {
        contractName: [
          { required: true, message: '请输入合同名称', trigger: 'blur' },
          { min: 2, max: 100, message: '长度在 2 到 100 个字符', trigger: 'blur' }
        ],
        firstId: [
          { required: true, message: '请选择所属甲方', trigger: 'change' }
        ],
        secondId: [
          { required: true, message: '请选择所属乙方', trigger: 'change' }
        ],
        signDate: [
          { required: true, message: '请选择签订日期', trigger: 'change' }
        ],
        performanceDate: [
          { required: true, message: '请选择业绩日期', trigger: 'change' }
        ],
        startDate: [
          { required: true, message: '请选择起始日期', trigger: 'change' }
        ],
        endDate: [
          { required: true, message: '请选择截止日期', trigger: 'change' }
        ],
        contractArea: [
          { required: true, message: '请选择所属地区', trigger: 'change' }
        ],
        contractType: [
          { required: true, message: '请选择合同类型(一级)', trigger: 'change' }
        ],
        contractSecondType: [
          { required: true, message: '请选择合同类型(二级)', trigger: 'change' }
        ],
        contractContent: [
          { min: 2, message: '最少输入两个字符', trigger: 'blur' }
        ],
        contractAmount: [
          { required: true, validator: validateContractAmount, trigger: 'blur' }
        ],
        contractPaymentDate: [
          { required: true, message: '请选择预计付款日期', trigger: 'change' }
        ],
        contractPaymentState: [
          { required: true, message: '请选择付款状态', trigger: 'change' }
        ],
        serviceStartsDate: [
          { required: true, message: '请选择服务开始日期', trigger: 'change' }
        ],
        serviceAmount: [
          { required: true, validator: validateServiceAmount, trigger: 'blur' }
        ],
        servicePaymentDate: [
          { required: true, message: '请选择预计付款日期', trigger: 'change' }
        ],
        servicePaymentState: [
          { required: true, message: '请选择付款状态', trigger: 'change' }
        ],
        contractStatus: [
          { required: true, message: '请选择合同状态', trigger: 'change' }
        ],
        acceptStatus: [
          { required: true, message: '请选择验收状态', trigger: 'change' }
        ],
        recoveryStatus: [
          { required: true, message: '请选择钱款缴纳状态', trigger: 'change' }
        ]
      },
      queryTypeOptions: [
        { key: 'contractNumber', display_name: '合同编号' },
        { key: 'contractName', display_name: '合同名称' },
        { key: 'firstId', display_name: '所属甲方' },
        { key: 'secondId', display_name: '所属乙方' },
        { key: 'signDate', display_name: '签订日期' },
        { key: 'contractType', display_name: '合同类型' },
        { key: 'contractPaymentState', display_name: '付款状态' },
        { key: 'servicePaymentState', display_name: '付款状态' },
        { key: 'contractStatus', display_name: '合同状态' },
        { key: 'contractAreaCode', display_name: '所属地区' },
        { key: 'provincial', display_name: '省级' },
        { key: 'city', display_name: '市级' },
        { key: 'region', display_name: '区级' }
      ],
      // 字典:合同类型(一级)
      contractType: constant.CONTRACT_TYPE,
      // 字典:合同类型(科技二级)
      technologySecondType: constant.TECHNOLOGY_SECOND_TYPE,
      // 字典:合同类型(咨询二级)
      consultationSecondType: constant.CONSULTATION_SECOND_TYPE,
      // 字典:合同类型(弱电二级)
      weakCurrentSecondType: constant.WEAK_CURRENT_SECOND_TYPE,
      // 字典:合同类型(知识产权二级)
      ipSecondType: constant.IP_SECOND_TYPE,
      // 字典:合同类型-服务合同(年)
      contractService: constant.CONTRACT_SERVICE,
      // 字典:合同类型-开发服务合同
      contractDevelopService: constant.CONTRACT_DEVELOP_SERVICE,
      // 字典:合同类型(一级)-科技
      contractTechnology: constant.CONTRACT_TECHNOLOGY,
      // 字典:合同类型(一级)-咨询
      contractConsultation: constant.CONTRACT_CONSULTATION,
      // 字典:合同类型(一级)-弱电
      contractWeakCurrent: constant.CONTRACT_WEAK_CURRENT,
      // 字典:合同类型(一级)-知识产权
      contractIp: constant.CONTRACT_IP,
      // 字典:付款状态
      paymentState: constant.PAYMENT_STATE,
      // 字典:合同状态
      contractStatus: constant.CONTRACT_STATUS,
      // 字典:验收状态
      acceptStatus: constant.ACCEPT_STATUS,
      // 字典:款项类型
      fundType: constant.FUND_TYPE,
      // 字典:钱款缴纳状态
      recoveryStatus: constant.RECOVERY_STATUS,
      // 甲方数据
      customerFirst: [],
      // 乙方数据
      customerSecond: [],
      // 项目列表
      projects: [],
      // 所属地区数据
      areaOptions: regionData,
      // 选中地区数据
      selectedAreaOptions: [],
      // 随机数
      random: 0,
      // 提交触发次数
      triggerCount: 0,
      // 搜索选择市级列表
      queryCityList: [],
      // 搜索选择区级列表
      queryRegionList: [],
      // 合同款总金额
      contractTotalMoney: 0,
      // 合同款延期数
      contractDelayTotalAmount: 0,
      // 合同款延期金额
      contractDelayTotalMoney: 0,
      // 预收款总金额
      advancePaymentTotalMoney: 0,
      // 运维服务总金额
      serviceTotalMoney: 0,
      // 运维服务延期数
      serviceDelayTotalAmount: 0,
      // 运维服务延期金额
      serviceDelayTotalMoney: 0,
      // 应收款总金额
      receivePaymentTotalMoney: 0,
      // 分配表单状态
      divideStatus: false,
      // 分配表单加载
      divideLoading: false,
      // 分配表单加载
      addWarningStatusLoading: false,
      // 分配表单加载
      downloadAttachmentLoading: false,
      // 分配表单数据
      divideForm: { contractId: null, contractName: null, projectId: null, fundType: null, allocatedAmount: null },
      // 分配表单验证
      divideRules: {
        projectId: [
          { required: true, message: '所属项目不能为空', trigger: 'change' }
        ],
        fundType: [
          { required: true, message: '款项类型不能为空', trigger: 'change' }
        ],
        allocatedAmount: [
          { required: true, validator: validateAllocatedAmount, trigger: 'blur' }
        ]
      },
      // 请求头
      headers: { 'Authorization': getToken() },
      uploadDialog: {
        visible: false,
        loading: false,
        form: { file: [] },
        rules: { file: [{ required: true, message: '请选择文件', trigger: 'blur' }] }
      },
      // 下载表格加载
      downloadTableLoading: false
    }
  },
  computed: {
    ...mapGetters(['baseApi'])
  },
  watch: {
    'crud.query.contractAreaCode'(val) {
      // 判断是否为空
      if (val == null) {
        // 搜索选择市级列表
        this.queryCityList = []
        // 搜索选择区级列表
        this.queryRegionList = []
      }
    }
  },
  methods: {
    // 钩子:在获取表格数据之前执行,false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      // 获取甲方数据
      this.getCustomerFirst()
      // 获取乙方数据
      this.getCustomerSecond()
      // 获取项目列表
      this.getProjects()
      // 获取合同款总金额
      this.getContractTotalMoney()
      // 获取合同款延期数
      this.getContractDelayTotalAmount()
      // 获取合同款延期金额
      this.getContractDelayTotalMoney()
      // 获取预收款总金额
      this.getAdvancePaymentTotalMoney()
      // 获取运维服务总金额
      this.getServiceTotalMoney()
      // 获取运维服务延期数
      this.getServiceDelayTotalAmount()
      // 获取运维服务延期金额
      this.getServiceDelayTotalMoney()
      // 获取应收款总金额
      this.getReceivePaymentTotalMoney()
      return true
    },
    // 钩子:开始 "新建/编辑" - 之前
    [CRUD.HOOK.beforeToCU]() {
      const that = this
      // 选中地区数据置空
      that.selectedAreaOptions = []
      // 判断所属地区编码是否为空
      if (that.crud.form.contractAreaCode !== null && that.crud.form.contractAreaCode !== '') {
        // 选中地区数据赋值
        that.selectedAreaOptions = that.crud.form.contractAreaCode.split('/')
      }
      // 随机数
      that.random = Math.random()
    },
    // 钩子:提交 "新建/编辑" - 之后
    [CRUD.HOOK.afterSubmit]() {
      const that = this
      // 刷新字典
      that.refreshDicts()
    },
    // 获取甲方数据
    getCustomerFirst() {
      const that = this
      // 获取甲方数据
      crudContractFirst.getAll().then(res => {
        // 获取甲方数据
        that.customerFirst = res
      })
    },
    // 获取乙方数据
    getCustomerSecond() {
      const that = this
      // 获取乙方数据
      crudContractSecond.getAll().then(res => {
        // 获取乙方数据
        that.customerSecond = res
      })
    },
    // 获取项目列表
    getProjects() {
      // 获取项目列表
      crudProject.getAll().then(res => {
        // 项目列表
        this.projects = res
      })
    },
    // 地区选择触发
    areaChange(arr) {
      const that = this
      // 所属地区编码赋值
      that.crud.form.contractAreaCode = arr.join('/')
      // 所属地区赋值
      that.crud.form.contractArea = arr.map(item => CodeToText[item]).join('/')
    },
    // 合同类型(一级)变更
    contractTypeChange() {
      const that = this
      // 重置合同类型(二级)
      that.form.contractSecondType = null
      // 随机数
      that.random = Math.random()
    },
    // 合同类型(二级)变更
    contractSecondTypeChange() {
      const that = this
      // 随机数
      that.random = Math.random()
    },
    // 表单提交
    submitCU() {
      const that = this
      // 提交触发次数
      that.triggerCount = 0
      // 通过“that.$refs.fileFirstUpload”找到子页面,“submit”是子页面的方法。
      that.$refs.fileFirstUpload.submit()
      // 通过“that.$refs.fileFinalUpload”找到子页面,“submit”是子页面的方法。
      that.$refs.fileFinalUpload.submit()
      // 通过“that.$refs.fileAttachmentUpload”找到子页面,“submit”是子页面的方法。
      that.$refs.fileAttachmentUpload.submit()
    },
    // 获取文件信息
    getFirstFileInfo(info) {
      const that = this
      // 判断返回数据
      if (info.length === 0) {
        // 表单文件路径赋值
        that.crud.form.relatedDocumentsFirst = null
        // 表单提交
        that.referSubmitCU()
        // 终止
        return
      }
      // 循环返回数据
      for (let i = 0; i < info.length; i++) {
        // 判断循环下标
        if (i === 0) {
          // 表单文件路径赋值
          that.crud.form.relatedDocumentsFirst = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName
        } else {
          // 表单文件路径赋值
          that.crud.form.relatedDocumentsFirst += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName
        }
        // 判断循环是否结束
        if (i === info.length - 1) {
          // 表单提交
          that.referSubmitCU()
        }
      }
    },
    // 获取文件信息
    getFinalFileInfo(info) {
      const that = this
      // 判断返回数据
      if (info.length === 0) {
        // 表单文件路径赋值
        that.crud.form.relatedDocumentsFinal = null
        // 表单提交
        that.referSubmitCU()
        // 终止
        return
      }
      // 循环返回数据
      for (let i = 0; i < info.length; i++) {
        // 判断循环下标
        if (i === 0) {
          // 表单文件路径赋值
          that.crud.form.relatedDocumentsFinal = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName
        } else {
          // 表单文件路径赋值
          that.crud.form.relatedDocumentsFinal += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName
        }
        // 判断循环是否结束
        if (i === info.length - 1) {
          // 表单提交
          that.referSubmitCU()
        }
      }
    },
    // 获取文件信息
    getAttachmentFileInfo(info) {
      const that = this
      // 判断返回数据
      if (info.length === 0) {
        // 表单文件路径赋值
        that.crud.form.relatedDocumentsAttachment = null
        // 表单提交
        that.referSubmitCU()
        // 终止
        return
      }
      // 循环返回数据
      for (let i = 0; i < info.length; i++) {
        // 判断循环下标
        if (i === 0) {
          // 表单文件路径赋值
          that.crud.form.relatedDocumentsAttachment = info[i].response == null || info[i].response === '' ? info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : '/file/' + info[i].response.type + '/' + info[i].response.realName
        } else {
          // 表单文件路径赋值
          that.crud.form.relatedDocumentsAttachment += info[i].response == null || info[i].response === '' ? ',' + info[i].url.substring(info[i].url.indexOf('/file/'), info[i].url.length) : ',/file/' + info[i].response.type + '/' + info[i].response.realName
        }
        // 判断循环是否结束
        if (i === info.length - 1) {
          // 表单提交
          that.referSubmitCU()
        }
      }
    },
    // 表单提交
    referSubmitCU() {
      const that = this
      // 提交触发次数自增
      that.triggerCount++
      // 判断提交触发次数
      if (that.triggerCount === 3) {
        // 表单提交
        that.crud.submitCU()
      }
    },
    // 跳转合同发票详情
    goContractInvoice(contractId) {
      const that = this
      // 跳转合同发票详情页面
      that.$router.push({ path: '/contract/contractInvoice', query: { contractId: contractId }})
    },
    // 跳转合同付款详情
    goContractPayment(contractId) {
      const that = this
      // 跳转合同付款详情页面
      that.$router.push({ path: '/contract/contractPayment', query: { contractId: contractId }})
    },
    // 搜索省级变更
    queryProvincialChange(event) {
      const that = this
      // 搜索选择省级
      that.$set(that.crud.query, 'provincial', event)
      // 搜索选择市级
      that.$set(that.crud.query, 'city', null)
      // 搜索选择区级
      that.$set(that.crud.query, 'region', null)
      // 搜索选择市级列表
      that.queryCityList = []
      // 搜索选择区级列表
      that.queryRegionList = []
      // 所属地区编码赋值
      that.$set(that.crud.query, 'contractAreaCode', that.crud.query.provincial)
      // 循环所属地区数据
      that.areaOptions.forEach(function(item) {
        // 判断是否为选中市级
        if (item.value === that.crud.query.provincial) {
          // 搜索选择市级列表
          that.queryCityList = item.children
        }
      })
    },
    // 搜索市级变更
    queryCityChange(event) {
      const that = this
      // 搜索选择市级
      that.$set(that.crud.query, 'city', event)
      // 搜索选择区级
      that.$set(that.crud.query, 'region', null)
      // 搜索选择区级列表
      that.queryRegionList = []
      // 所属地区编码赋值
      that.$set(that.crud.query, 'contractAreaCode', that.crud.query.provincial + '/' + that.crud.query.city)
      // 搜索选择市级列表
      that.queryCityList.forEach(function(item) {
        // 判断是否为选中市级
        if (item.value === that.crud.query.city) {
          // 搜索选择区级列表
          that.queryRegionList = item.children
        }
      })
    },
    // 搜索区级变更
    queryRegionChange(event) {
      const that = this
      // 搜索选择区级
      that.$set(that.crud.query, 'region', event)
      // 所属地区编码赋值
      that.$set(that.crud.query, 'contractAreaCode', that.crud.query.provincial + '/' + that.crud.query.city + '/' + that.crud.query.region)
    },
    // 获取合同款总金额
    getContractTotalMoney() {
      // 获取合同款总金额
      contractTotalMoney({ ...this.crud.query }).then(res => {
        // 合同款总金额
        this.contractTotalMoney = res
      })
    },
    // 获取合同款延期数
    getContractDelayTotalAmount() {
      // 获取合同款延期数
      contractDelayTotalAmount({ ...this.crud.query }).then(res => {
        // 合同款延期数
        this.contractDelayTotalAmount = res
      })
    },
    // 获取合同款延期金额
    getContractDelayTotalMoney() {
      // 获取合同款延期金额
      contractDelayTotalMoney({ ...this.crud.query }).then(res => {
        // 合同款延期金额
        this.contractDelayTotalMoney = res
      })
    },
    // 获取预收款总金额
    getAdvancePaymentTotalMoney() {
      // 获取预收款总金额
      advancePaymentTotalMoney({ ...this.crud.query }).then(res => {
        // 预收款总金额
        this.advancePaymentTotalMoney = res
      })
    },
    // 获取运维服务总金额
    getServiceTotalMoney() {
      // 获取运维服务总金额
      serviceTotalMoney({ ...this.crud.query }).then(res => {
        // 运维服务总金额
        this.serviceTotalMoney = res
      })
    },
    // 获取运维服务延期数
    getServiceDelayTotalAmount() {
      // 获取运维服务延期数
      serviceDelayTotalAmount({ ...this.crud.query }).then(res => {
        // 运维服务延期数
        this.serviceDelayTotalAmount = res
      })
    },
    // 获取运维服务延期金额
    getServiceDelayTotalMoney() {
      // 获取运维服务延期金额
      serviceDelayTotalMoney({ ...this.crud.query }).then(res => {
        // 运维服务延期金额
        this.serviceDelayTotalMoney = res
      })
    },
    // 获取应收款总金额
    getReceivePaymentTotalMoney() {
      // 获取应收款总金额
      receivePaymentTotalMoney({ ...this.crud.query }).then(res => {
        // 应收款总金额
        this.receivePaymentTotalMoney = res
      })
    },
    // 任务分配
    toDivide(data) {
      // 分配表单数据
      this.divideForm.contractId = data.contractId
      this.divideForm.contractName = data.contractName
      // 分配表单状态
      this.divideStatus = true
    },
    // 查看分配
    toSeeDivide(data) {
      // 跳转页面
      this.$router.push({
        name: 'ContractProject',
        params: {
          contractId: data.contractId
        }
      })
    },
    // 分配表单关闭
    divideClose() {
      // 分配表单状态
      this.divideStatus = false
      // 分配表单加载
      this.divideLoading = false
      // 随机数
      this.random = Math.random()
      // 分配表单数据
      this.divideForm = { contractId: null, contractName: null, projectId: null, fundType: null, allocatedAmount: null }
      // 清除表单验证
      this.$nextTick(() => {
        this.$refs['divideForm'].clearValidate()
      })
    },
    // 分配表单提交
    divideSubmit() {
      // 分配表单加载
      this.divideLoading = true
      // 表单验证
      this.$refs['divideForm'].validate((valid) => {
        if (valid) {
          // 分配项目
          crudContractProject.add(this.divideForm).then(res => {
            // 分配表单关闭
            this.divideClose()
            // 消息提示
            this.crud.notify('项目分配成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
            // 刷新页面
            this.crud.refresh()
          }).catch(() => {
            // 分配表单加载
            this.divideLoading = false
            return false
          })
        } else {
          // 分配表单加载
          this.divideLoading = false
          return false
        }
      })
    },
    // 重新获取字典信息
    refreshDicts() {
      const that = this
      if (that.$options.dicts instanceof Array) {
        new Dict(this.dict).init(that.$options.dicts, () => {
          this.$nextTick(() => {
            this.$emit('dictReady')
          })
        })
      }
    },
    // 开启导入弹窗
    uploadDialogOpen() {
      const that = this
      that.uploadDialog.visible = true
    },
    // 关闭导入弹窗
    uploadDialogClose() {
      const that = this
      that.$refs.contractUpload.clearFiles()
      that.$refs.uploadForm.clearValidate()
      that.uploadDialog.visible = false
      that.uploadDialog.loading = false
      that.uploadDialog.form = { file: [] }
    },
    // 提交导入信息
    uploadDialogSubmit() {
      const that = this
      that.uploadDialog.loading = true
      that.$refs.uploadForm.validate(valid => {
        if (valid) {
          that.$refs.contractUpload.submit()
        } else {
          that.uploadDialog.loading = false
        }
      })
    },
    // 文件校验
    beforeUpload(file) {
      const that = this
      let isLt2M = true
      isLt2M = file.size / 1024 / 1024 < 50
      if (!isLt2M) {
        that.$message.error('上传文件大小不能超过 50MB!')
      }
      return isLt2M
    },
    // 监听文件变更
    handleChange(_, fileList) {
      const that = this
      that.uploadDialog.form.file = fileList
      that.$refs.uploadForm.validateField('file')
    },
    // 监听文件移除
    handleRemove(_, fileList) {
      const that = this
      that.uploadDialog.form.file = fileList
      that.$refs.uploadForm.validateField('file')
    },
    // 监听导入成功
    handleSuccess(res, file, fileList) {
      const that = this
 
      if (res.errCode === 0) {
        that.$notify({
          title: '导入成功',
          type: 'success',
          duration: 3000
        })
        that.uploadDialogClose()
        that.crud.toQuery()
      } else {
        that.$notify({
          title: '导入失败',
          type: 'error',
          message: res.errMsg,
          duration: 5000,
          dangerouslyUseHTMLString: true
        })
        that.uploadDialog.loading = false
        that.$refs.contractUpload.clearFiles()
      }
    },
    // 监听导入失败
    handleError(e, file, fileList) {
      const that = this
      const msg = JSON.parse(e.message)
      that.$notify({
        title: msg.message || '上传失败',
        type: 'error',
        duration: 2500
      })
      that.uploadDialog.loading = false
    },
    // 预警
    addWarningStatus(data) {
      this.addWarningStatusLoading = true
      const ids = []
      if (data instanceof Array) {
        data.forEach(val => {
          ids.push(val['contractId'])
        })
      } else {
        ids.push(data['contractId'])
      }
      // 添加预警
      addWarningStatus(ids).then(() => {
        this.addWarningStatusLoading = false
        // 消息提示
        this.crud.notify('添加预警成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
        // 刷新页面
        this.crud.refresh()
      }).catch(() => {
        this.addWarningStatusLoading = false
      })
    },
    // 预警
    warningRowClassName({ row, rowIndex }) {
      if (row.warningStatus === 1) {
        return 'warning-row'
      } else {
        return ''
      }
    },
    toDownloadContractAttachments(id) {
      this.downloadAttachmentLoading = true
      // 添加预警
      downloadContractAttachments({ 'id': id }).then(result => {
        downloadFile(result, '合同附件', 'zip')
        this.downloadAttachmentLoading = false
      }).catch(() => {
        this.downloadAttachmentLoading = false
      })
    },
    toDownloadTable() {
      const that = this
      that.downloadTableLoading = true
      // 添加预警
      downloadTable({ ...that.crud.query }).then(res => {
        downloadFile(res, '合同信息', 'xlsx')
        that.downloadTableLoading = false
      }).catch(() => {
        that.downloadTableLoading = false
      })
    }
  }
}
</script>
 
<style>
  .warning-row td {
    background-color: #F9D7BC !important;
  }
</style>