AccountModal.vue
92.1 KB
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
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit" width="1000px" @cancel="handleCancel" :confirmLoading="submitLoading">
<template v-if="accountType === 'production'">
<BasicForm @register="productionFormRegister" />
</template>
<template v-else>
<!-- 员工档案表单 -->
<div class="employee-file-form">
<!-- 使用标签页组件 -->
<a-tabs v-model:activeKey="activeTabKey" class="tab-container" @change="handleTabChange">
<a-tab-pane key="basic" tab="基本信息">
<a-form ref="employeeFormRef" :model="formState" layout="inline" class="form-section" :rules="rules">
<a-row :gutter="[16, 16]" style="width: 100%">
<!-- 第一行:姓名、昵称、性别、入职时间 -->
<a-col :span="6">
<a-form-item label="姓名" name="chineseName">
<a-input v-model:value="formState.chineseName" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="昵称(英文名)" name="nickName">
<a-input v-model:value="formState.nickName" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="性别" name="gender">
<a-select v-model:value="formState.gender" placeholder="选择">
<a-select-option value="男">男</a-select-option>
<a-select-option value="女">女</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="入职时间">
<a-date-picker v-model:value="formState.userBasicDetailVO.entryTime" style="width: 100%" />
</a-form-item>
</a-col>
<!-- 第二行:公司、部门、岗位 -->
<a-col :span="8">
<a-form-item label="公司" name="companyId">
<a-select v-model:value="formState.companyId" placeholder="选择">
<a-select-option v-for="company in companyOptions" :key="company.id" :value="company.id">
{{ company.name }}
</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="部门" name="deptId">
<a-select v-model:value="formState.deptId" placeholder="选择">
<a-select-option v-for="dept in deptOptions" :key="dept.id" :value="dept.id">
{{ dept.name }}
</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="岗位" name="roleId">
<a-select
v-model:value="formState.roleId"
placeholder="选择"
:disabled="isUpdate && isFieldLocked('roleId')"
>
<a-select-option v-for="role in roleOptions" :key="role.id" :value="role.id">
{{ role.description }}
</a-select-option>
</a-select>
</a-form-item>
</a-col>
<!-- 第三行:身份证号、年龄、考勤组 -->
<a-col :span="8">
<a-form-item label="身份证号" name="idCard" :rules="idCardRules">
<a-input
v-model:value="formState.userBasicDetailVO.idCard"
placeholder="输入身份证号"
@blur="handleIdCardChange"
@input="handleIdCardInput"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="年龄">
<a-input
v-model:value="formState.userBasicDetailVO.age"
placeholder="自动计算"
style="background-color: #f5f5f5;"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="考勤组">
<a-select
v-model:value="formState.userBasicDetailVO.selectedAttendanceType"
placeholder="选择考勤组"
@change="handleAttendanceTypeChange"
:style="{ width: '100%' }"
:disabled="isUpdate && isFieldLocked('monthlyAttendanceName')"
>
<!-- 如果有monthlyAttendanceName但没有匹配的selectedAttendanceType,添加一个特殊选项 -->
<a-select-option v-if="formState.userBasicDetailVO.monthlyAttendanceName && !hasMatchingAttendanceOption"
:value="'custom'" key="custom">
{{ formState.userBasicDetailVO.monthlyAttendanceName }}
</a-select-option>
<template v-if="attendanceOptions.length === 0">
<a-select-option value="" disabled>没有配置</a-select-option>
</template>
<template v-else>
<a-select-opt-group v-for="yearGroup in yearGroups" :key="yearGroup.year" :label="`${yearGroup.year}年`">
<a-select-option v-for="option in yearGroup.options" :key="option.value" :value="option.value">
{{ option.label }}
</a-select-option>
</a-select-opt-group>
</template>
</a-select>
<!-- 调试信息 -->
<div v-if="isDebug" style="color: #999; font-size: 12px;">
选项数量: {{ attendanceOptions.length }}
</div>
</a-form-item>
</a-col>
<!-- 第四行:出生年月、民族、户籍地址 -->
<a-col :span="8">
<a-form-item label="出生年月">
<a-date-picker
v-model:value="formState.userBasicDetailVO.dateBirth"
style="width: 100%; background-color: #f5f5f5;"
placeholder="自动计算"
/>
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="民族">
<a-input v-model:value="formState.userBasicDetailVO.nationality" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="10">
<a-form-item label="户籍地址">
<a-input v-model:value="formState.userBasicDetailVO.registeredAddress" placeholder="输入" />
</a-form-item>
</a-col>
<!-- 第五行:婚姻状况、政治面貌、现居地址 -->
<a-col :span="6">
<a-form-item label="婚姻状况">
<a-select v-model:value="formState.userBasicDetailVO.maritalStatus" placeholder="选择">
<a-select-option value="未婚">未婚</a-select-option>
<a-select-option value="已婚">已婚</a-select-option>
<a-select-option value="离婚">离婚</a-select-option>
<a-select-option value="丧偶">丧偶</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="政治面貌">
<a-select v-model:value="formState.userBasicDetailVO.politicalStatus" placeholder="选择">
<a-select-option value="党员">党员</a-select-option>
<a-select-option value="团员">团员</a-select-option>
<a-select-option value="群众">群众</a-select-option>
<a-select-option value="其他">其他</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="现居地址">
<a-input v-model:value="formState.userBasicDetailVO.address" placeholder="输入" />
</a-form-item>
</a-col>
<!-- 第六行:手机号码、微信、电子邮箱 -->
<a-col :span="8">
<a-form-item label="手机号码" name="phone">
<a-input v-model:value="formState.phone" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="微信">
<a-input v-model:value="formState.userBasicDetailVO.wechat" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="电子邮箱" name="email">
<a-input v-model:value="formState.email" placeholder="输入" />
</a-form-item>
</a-col>
<!-- 第七行:紧急联系人、关系、紧急联系人手机号码 -->
<a-col :span="8">
<a-form-item label="紧急联系人">
<a-input v-model:value="formState.userBasicDetailVO.emergencyContact" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="关系">
<a-input v-model:value="formState.userBasicDetailVO.relationShip" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="紧急联系人电话">
<a-input v-model:value="formState.userBasicDetailVO.emergencyContactPhone" placeholder="输入" />
</a-form-item>
</a-col>
<!-- 第八行:银行卡号、开户行、社保关系 -->
<a-col :span="8">
<a-form-item label="银行卡号">
<a-input v-model:value="formState.userBasicDetailVO.card" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="开户行">
<a-input v-model:value="formState.userBasicDetailVO.openingBank" placeholder="输入" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="社保关系">
<a-input v-model:value="formState.userBasicDetailVO.socialSecurity" placeholder="输入" />
</a-form-item>
</a-col>
<!-- 第九行:试用期开始时间、试用期结束时间、员工状态 -->
<a-col :span="8">
<a-form-item label="试用期开始时间">
<a-date-picker
v-model:value="formState.userBasicDetailVO.periodStartTime"
style="width: 100%"
:disabled="isUpdate && isFieldLocked('periodStartTime')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="试用期结束时间">
<a-date-picker
v-model:value="formState.userBasicDetailVO.periodEndTime"
style="width: 100%"
:disabled="isUpdate && isFieldLocked('periodEndTime')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="员工状态">
<a-select v-model:value="formState.status" disabled placeholder="选择">
<a-select-option :value="10">在职</a-select-option>
<a-select-option :value="20">离职</a-select-option>
</a-select>
</a-form-item>
</a-col>
<!-- 第十行:劳务合同签署时间、劳务合同结束时间、合同期限 -->
<a-col :span="8">
<a-form-item label="合同签署时间">
<a-date-picker
v-model:value="formState.userBasicDetailVO.contractStartTime"
style="width: 100%"
:disabled="isUpdate && isFieldLocked('contractStartTime')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="合同结束时间">
<a-date-picker
v-model:value="formState.userBasicDetailVO.contractEndTime"
style="width: 100%"
:disabled="isUpdate && isFieldLocked('contractEndTime')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="合同期限">
<a-input :value="calculateContractDuration" disabled style="width: 100%" />
</a-form-item>
</a-col>
</a-row>
</a-form>
<!-- 备注信息 -->
<div class="section-header">备注信息</div>
<a-form layout="inline" class="form-section" :model="formState">
<a-row :gutter="[16, 16]" style="width: 100%">
<a-col :span="24">
<a-form-item label="备注">
<a-textarea v-model:value="formState.remark" placeholder="输入备注信息" :rows="3" />
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-tab-pane>
<a-tab-pane key="salary" tab="工资配置">
<div class="tab-content-container">
<a-form layout="inline" class="form-section" :model="formState">
<a-row :gutter="[16, 16]" style="width: 100%">
<a-col :span="8">
<a-form-item label="基本工资">
<a-input-number
v-model:value="formState.userWagesVO.basicWages"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('basicWages')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="岗位津贴">
<a-input-number
v-model:value="formState.userWagesVO.postAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('postAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="管理岗位津贴">
<a-input-number
v-model:value="formState.userWagesVO.managementAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('managementAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="话费补贴">
<a-input-number
v-model:value="formState.userWagesVO.phoneAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('phoneAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="餐补">
<a-input-number
v-model:value="formState.userWagesVO.mealAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('mealAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="交通补贴">
<a-input-number
v-model:value="formState.userWagesVO.transportationAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('transportationAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="全勤奖">
<a-input-number
v-model:value="formState.userWagesVO.attendanceAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('attendanceAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="绩效部分">
<a-input-number
v-model:value="formState.userWagesVO.performanceAllowance"
placeholder="输入"
style="width: 100%"
:precision="2"
:min="0"
:disabled="isUpdate && isFieldLocked('performanceAllowance')"
/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="社保待遇">
<a-select
v-model:value="formState.userWagesVO.socialSetting"
placeholder="选择"
@change="handleSocialSettingChange"
:disabled="isUpdate && isFieldLocked('socialSetting')"
>
<template v-if="socialSettingOptions.length === 0">
<a-select-option value="" disabled>没有配置</a-select-option>
</template>
<template v-else>
<a-select-opt-group v-for="yearGroup in socialSettingYearGroups" :key="yearGroup.year" :label="`${yearGroup.year}年`">
<a-select-option v-for="option in yearGroup.options" :key="option.value" :value="option.value">
{{ option.label }}
</a-select-option>
</a-select-opt-group>
</template>
</a-select>
<!-- 调试信息 -->
<div v-if="isDebug" style="color: #999; font-size: 12px;">
选项数量: {{ socialSettingOptions.length }}
<button @click.prevent="parseTestData()" style="margin-left: 8px;">测试解析</button>
</div>
</a-form-item>
</a-col>
<!-- 社保信息部分 - 个人部分 -->
<a-col :span="24">
<div class="section-header">社保信息 - 个人部分</div>
</a-col>
<a-col :span="8">
<a-form-item label="养老保险(个人)">
<a-input-number
v-model:value="formState.userWagesVO.personalPensionInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="医疗保险(个人)">
<a-input-number
v-model:value="formState.userWagesVO.personalPensionMedicalInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="失业保险(个人)">
<a-input-number
v-model:value="formState.userWagesVO.personalPensionUnemploymentInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="大额医疗(个人)">
<a-input-number
v-model:value="formState.userWagesVO.personalPensionLargeScaleMedicalInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="住房公积金(个人)">
<a-input-number
v-model:value="formState.userWagesVO.personalPensionProvidentFundInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<!-- 社保信息部分 - 企业部分 -->
<a-col :span="24">
<div class="section-header">社保信息 - 企业部分</div>
</a-col>
<a-col :span="8">
<a-form-item label="养老保险(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="医疗保险(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyMedicalInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="失业保险(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyUnemploymentInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="工伤保险(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyEmploymentInjuryInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="生育保险(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyMaternityInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="大额医疗(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyLargeScaleMedicalInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item label="住房公积金(企业)">
<a-input-number
v-model:value="formState.userWagesVO.companyProvidentFundInsurance"
placeholder="系统生成"
style="width: 100%"
:precision="2"
:min="0"
:disabled="true" />
</a-form-item>
</a-col>
<!-- 社保信息部分 - 个人部分 -->
<a-col :span="24">
<div style="height: 20px;"></div>
</a-col>
</a-row>
</a-form>
</div>
</a-tab-pane>
</a-tabs>
</div>
</template>
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, computed, unref, toRaw, reactive, onMounted, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
// 分别从不同文件导入
import { accountFormSchema } from './account.data';
import { productionAccountFormSchema } from './productionForm.data';
import { getCompanyList, getDeptList, getRoleList } from '/@/api/project/account';
import { defHttp } from '/@/utils/http/axios';
import type { FormInstance } from 'ant-design-vue';
import dayjs from 'dayjs'; // 引入dayjs用于日期处理
export default defineComponent({
name: 'AccountModal',
components: { BasicModal, BasicForm },
emits: ['success', 'register'],
setup(_, { emit }) {
const isUpdate = ref(true);
const rowId = ref('');
const accountType = ref('employee'); // 默认为员工账号
const activeTabKey = ref('basic'); // 默认显示基本信息标签
const employeeFormRef = ref<FormInstance | null>(null); // 添加表单ref类型
const isDebug = ref(true); // 调试模式
const submitLoading = ref(false); // 添加提交状态变量
// 添加字段锁定状态管理
const fieldLockStatus = ref<Record<string, boolean>>({
// 基本信息字段
roleId: false, // 岗位
monthlyAttendanceName: false, // 考勤组
periodStartTime: false, // 试用期开始时间
periodEndTime: false, // 试用期结束时间
contractStartTime: false, // 合同签署时间
contractEndTime: false, // 合同结束时间
// 工资配置字段
basicWages: false, // 基本工资
postAllowance: false, // 岗位津贴
managementAllowance: false, // 管理岗位津贴
phoneAllowance: false, // 话费补贴
mealAllowance: false, // 餐补
transportationAllowance: false, // 交通补贴
attendanceAllowance: false, // 全勤奖
performanceAllowance: false, // 绩效部分
socialSetting: false // 社保待遇
});
// 检查字段是否被锁定的函数
const isFieldLocked = (fieldName: string): boolean => {
return fieldLockStatus.value[fieldName] || false;
};
// 处理字段锁定状态的函数
const processFieldLockStatus = (userWagesFieldLockApplyVO: any) => {
if (!userWagesFieldLockApplyVO) {
return;
}
// 字段映射关系
const fieldMapping = {
// userWagesFieldLockApplyVO字段名 -> 本地字段名
'roleName': 'roleId', // 岗位
'monthlyAttendanceName': 'monthlyAttendanceName', // 考勤组
'periodStartTime': 'periodStartTime', // 试用期开始时间
'periodEndTime': 'periodEndTime', // 试用期结束时间
'contractStartTime': 'contractStartTime', // 合同签署时间
'contractEndTime': 'contractEndTime', // 合同结束时间
'basicWages': 'basicWages', // 基本工资
'postAllowance': 'postAllowance', // 岗位津贴
'managementAllowance': 'managementAllowance', // 管理岗位津贴
'phoneAllowance': 'phoneAllowance', // 话费补贴
'mealAllowance': 'mealAllowance', // 餐补
'transportationAllowance': 'transportationAllowance', // 交通补贴
'attendanceAllowance': 'attendanceAllowance', // 全勤奖
'performanceAllowance': 'performanceAllowance', // 绩效部分
'socialSettingName': 'socialSetting' // 社保待遇
};
// 重置所有字段为可编辑状态
Object.keys(fieldLockStatus.value).forEach(key => {
fieldLockStatus.value[key] = false;
});
// 根据返回的锁定状态设置字段
Object.entries(fieldMapping).forEach(([apiField, localField]) => {
const apiValue = userWagesFieldLockApplyVO[apiField];
if (apiValue !== undefined && apiValue !== null) {
const isLocked = apiValue === 'LOCKED';
fieldLockStatus.value[localField] = isLocked;
} else {
console.log(`字段 ${apiField} 在API数据中不存在或为空`);
}
});
console.log('最终字段锁定状态:', fieldLockStatus.value);
};
// 定义表单验证规则
const rules = {
chineseName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
nickName: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
gender: [{ required: true, message: '请选择性别', trigger: 'change' }],
companyId: [{ required: true, message: '请选择公司', trigger: 'change' }],
deptId: [{ required: true, message: '请选择部门', trigger: 'change' }],
roleId: [{ required: true, message: '请选择岗位', trigger: 'change' }],
phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
email: [{ required: true, message: '请输入电子邮箱', trigger: 'blur' }]
// 工资字段不设置必填规则,用户没有填写就不发送字段属性
};
// 身份证号校验规则
const idCardRules = [
{
validator: (rule: any, value: string) => {
if (!value) {
return Promise.resolve(); // 非必填,允许为空
}
// 身份证号格式校验
if (!validateIdCard(value)) {
return Promise.reject(new Error('请输入正确的身份证号码'));
}
return Promise.resolve();
},
trigger: 'blur'
}
];
// 身份证号校验函数
function validateIdCard(idCard: string): boolean {
if (!idCard) return false;
// 去除空格
idCard = idCard.replace(/\s/g, '');
// 18位身份证号正则表达式
const reg18 = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
// 15位身份证号正则表达式
const reg15 = /^[1-9]\d{5}\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}$/;
if (idCard.length === 18) {
if (!reg18.test(idCard)) return false;
// 校验18位身份证号的校验码
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
let sum = 0;
for (let i = 0; i < 17; i++) {
sum += parseInt(idCard[i]) * weights[i];
}
const checkCode = checkCodes[sum % 11];
return idCard[17].toUpperCase() === checkCode;
} else if (idCard.length === 15) {
return reg15.test(idCard);
}
return false;
}
// 从身份证号提取出生日期
function extractBirthFromIdCard(idCard: string): dayjs.Dayjs | null {
if (!idCard || !validateIdCard(idCard)) return null;
idCard = idCard.replace(/\s/g, '');
let birthStr = '';
if (idCard.length === 18) {
birthStr = idCard.substring(6, 14); // YYYYMMDD
} else if (idCard.length === 15) {
birthStr = '19' + idCard.substring(6, 12); // YYMMDD -> 19YYMMDD
}
if (birthStr.length === 8) {
const year = parseInt(birthStr.substring(0, 4));
const month = parseInt(birthStr.substring(4, 6));
const day = parseInt(birthStr.substring(6, 8));
// 验证日期有效性
const birthDate = dayjs(`${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`);
if (birthDate.isValid()) {
return birthDate;
}
}
return null;
}
// 计算年龄
function calculateAge(birthDate: dayjs.Dayjs): number {
const today = dayjs();
let age = today.year() - birthDate.year();
// 如果今年的生日还没到,年龄减1
if (today.month() < birthDate.month() ||
(today.month() === birthDate.month() && today.date() < birthDate.date())) {
age--;
}
return age;
}
// 身份证号输入处理
function handleIdCardInput(e: Event) {
const target = e.target as HTMLInputElement;
let value = target.value;
// 限制输入长度和字符
value = value.replace(/[^\dXx]/g, ''); // 只允许数字和X
if (value.length > 18) {
value = value.substring(0, 18);
}
formState.userBasicDetailVO.idCard = value;
}
// 身份证号失焦处理
function handleIdCardChange() {
const idCard = formState.userBasicDetailVO.idCard;
if (!idCard) {
// 清空相关字段
formState.userBasicDetailVO.age = undefined;
formState.userBasicDetailVO.dateBirth = null;
return;
}
if (validateIdCard(idCard)) {
// 提取出生日期
const birthDate = extractBirthFromIdCard(idCard);
if (birthDate) {
formState.userBasicDetailVO.dateBirth = birthDate;
formState.userBasicDetailVO.age = calculateAge(birthDate).toString();
console.log('身份证号校验通过,自动填充出生日期和年龄');
}
} else {
// 身份证号格式错误,清空相关字段
formState.userBasicDetailVO.age = undefined;
formState.userBasicDetailVO.dateBirth = null;
}
}
// 用于表单数据的响应式对象
const formState = reactive({
id: '',
chineseName: '',
nickName: '',
gender: '',
phone: '',
companyId: undefined,
roleId: undefined,
deptId: undefined,
email: '',
remark: undefined,
status: undefined,
baseSalary: undefined,
positionAllowance: undefined,
managementAllowance: undefined,
pensionInsurance: 'basic',
medicalInsurance: 'basic',
unemploymentInsurance: 'basic',
// 用户基本详情VO对象,包含更多员工详细信息
userBasicDetailVO: {
idCard: undefined,
entryTime: null,
age: undefined,
monthlyAttendanceIds: [] as number[], // 修改为数组,存储同一类型的多个ID,并指定类型
selectedAttendanceType: undefined as string | undefined, // 新增字段,存储用户选择的考勤组选项值,格式为"type:value"
monthlyAttendanceName: undefined as string | undefined, // 新增字段,存储用户选择的考勤组名称
dateBirth: null,
nationality: undefined,
registeredAddress: undefined,
maritalStatus: undefined,
politicalStatus: undefined,
address: undefined,
wechat: undefined,
emergencyContact: undefined,
relationShip: undefined,
emergencyContactPhone: undefined,
card: undefined,
openingBank: undefined,
socialSecurity: undefined,
periodStartTime: null,
periodEndTime: null,
contractStartTime: null,
contractEndTime: null
},
// 用户工资配置VO对象,包含工资相关字段
userWagesVO: {
basicWages: undefined, // 基本工资
postAllowance: undefined, // 岗位津贴
managementAllowance: undefined, // 管理岗位津贴
phoneAllowance: undefined, // 话费补贴
mealAllowance: undefined, // 餐补
transportationAllowance: undefined, // 交通补贴
attendanceAllowance: undefined, // 全勤奖
performanceAllowance: undefined, // 绩效部分
socialSetting: undefined, // 社保待遇
socialSettingName: undefined, // 新增字段,存储用户选择的社保待遇名称
socialSettingId: undefined, // 新增字段,存储用户选择的社保待遇ID
// 新增社保相关字段
personalPensionInsurance: undefined, // 养老保险(个人)
personalPensionMedicalInsurance: undefined, // 医疗保险(个人)
personalPensionUnemploymentInsurance: undefined, // 失业保险(个人)
personalPensionLargeScaleMedicalInsurance: undefined, // 大额医疗(个人)
personalPensionProvidentFundInsurance: undefined, // 住房公积金(个人)
companyInsurance: undefined, // 养老保险(企业)
companyMedicalInsurance: undefined, // 医疗保险(企业)
companyUnemploymentInsurance: undefined, // 失业保险(企业)
companyEmploymentInjuryInsurance: undefined, // 工伤保险(企业)
companyMaternityInsurance: undefined, // 生育保险(企业)
companyLargeScaleMedicalInsurance: undefined, // 大额医疗(企业)
companyProvidentFundInsurance: undefined // 住房公积金(企业)
}
});
// 下拉选项数据
const companyOptions = ref<any[]>([]);
const deptOptions = ref<any[]>([]);
const roleOptions = ref<any[]>([]);
// 考勤组数据,按类型和年份双重分组存储
const attendanceGroups = ref<Record<number, Record<string, any[]>>>({
61: {},
62: {},
63: {},
64: {}
});
// 考勤组类型+年份组合的选项
const attendanceOptions = ref<{value: string, label: string, ids: number[]}[]>([]);
// 社保待遇选项
const socialSettingOptions = ref<{value: string, label: string, id: number}[]>([]);
// 按年份分组的社保待遇选项
const socialSettingYearGroups = computed(() => {
// 按年份归类
const groupedByYear: Record<string, Record<number, any>> = {};
// 遍历所有选项,提取年份信息并按年份分组
socialSettingOptions.value.forEach(option => {
// 获取年份信息 (假设格式是 "year:type" - 与考勤组不同)
const valueArr = option.value.split(':');
if (valueArr.length === 2) {
const year = valueArr[0];
if (!groupedByYear[year]) {
groupedByYear[year] = {};
}
// 由于标签可能已经包含年份信息,这里不需要移除
groupedByYear[year][option.id] = option;
} else {
// 如果没有年份信息,放入"其他"分组
if (!groupedByYear['其他']) {
groupedByYear['其他'] = {};
}
groupedByYear['其他'][option.id] = option;
}
});
// 将分组转换为数组并按年份降序排序(新的年份在前)
return Object.entries(groupedByYear)
.map(([year, typeItems]) => ({
year,
options: Object.values(typeItems).sort((a, b) => {
// 按社保类型排序
const typeA = parseInt(a.value.split(':')[1]);
const typeB = parseInt(b.value.split(':')[1]);
return typeA - typeB;
})
}))
.sort((a, b) => b.year.localeCompare(a.year));
});
// 社保待遇变更处理
function handleSocialSettingChange(value: string) {
if (value) {
const selectedOption = socialSettingOptions.value.find(option => option.value === value);
if (selectedOption) {
// 设置社保待遇显示值、ID和名称
const displayValue = value; // 保留显示值(year:type)格式,用于UI显示
formState.userWagesVO.socialSetting = displayValue;
// 保存社保待遇ID和名称
formState.userWagesVO.socialSettingId = selectedOption.id;
formState.userWagesVO.socialSettingName = selectedOption.label;
// 直接使用query_list API获取系统设置数据
defHttp.post<any>({
url: '/order/erp/system_setting/query_list',
params: {
setting_type: [70, 71, 72,73]
}
}).then(settingList => {
if (Array.isArray(settingList)) {
const targetSetting = settingList.find(item => item.id === selectedOption.id);
if (targetSetting && targetSetting.relationValue) {
tryParseAndFillInsurance(targetSetting.relationValue);
} else {
parseTestData(selectedOption.id);
}
}
}).catch(error => {
console.error('获取社保配置数据失败,使用测试数据:', error);
parseTestData(selectedOption.id);
});
} else {
console.warn(`未找到选项 ${value} 对应的配置`);
}
} else {
formState.userWagesVO.socialSetting = undefined;
formState.userWagesVO.socialSettingName = undefined;
formState.userWagesVO.socialSettingId = undefined;
// 清空保险字段值
formState.userWagesVO.personalPensionInsurance = undefined;
formState.userWagesVO.personalPensionMedicalInsurance = undefined;
formState.userWagesVO.personalPensionUnemploymentInsurance = undefined;
formState.userWagesVO.personalPensionLargeScaleMedicalInsurance = undefined;
formState.userWagesVO.personalPensionProvidentFundInsurance = undefined;
formState.userWagesVO.companyInsurance = undefined;
formState.userWagesVO.companyMedicalInsurance = undefined;
formState.userWagesVO.companyUnemploymentInsurance = undefined;
formState.userWagesVO.companyEmploymentInjuryInsurance = undefined;
formState.userWagesVO.companyMaternityInsurance = undefined;
formState.userWagesVO.companyLargeScaleMedicalInsurance = undefined;
formState.userWagesVO.companyProvidentFundInsurance = undefined;
}
}
// 尝试解析测试数据,用于调试
function parseTestData(id?: number) {
// 使用用户提供的示例数据
const testRelationValue = "{\"companyEmploymentInjuryInsurance\":1.0,\"companyInsurance\":800.0,\"companyLargeScaleMedicalInsurance\":1100.0,\"companyMaternityInsurance\":1.0,\"companyMedicalInsurance\":900.0,\"companyProvidentFundInsurance\":1200.0,\"companyUnemploymentInsurance\":1000.0,\"personalPensionInsurance\":10.0,\"personalPensionLargeScaleMedicalInsurance\":10.0,\"personalPensionMedicalInsurance\":10.0,\"personalPensionProvidentFundInsurance\":10.0}";
tryParseAndFillInsurance(testRelationValue);
}
// 尝试解析并填充保险数据
function tryParseAndFillInsurance(relationValue: any) {
try {
let insuranceValues;
if (typeof relationValue === 'string') {
insuranceValues = JSON.parse(relationValue);
} else {
insuranceValues = relationValue;
}
// 填充保险字段值
formState.userWagesVO.personalPensionInsurance = insuranceValues.personalPensionInsurance;
formState.userWagesVO.personalPensionMedicalInsurance = insuranceValues.personalPensionMedicalInsurance;
formState.userWagesVO.personalPensionUnemploymentInsurance = insuranceValues.personalPensionUnemploymentInsurance;
formState.userWagesVO.personalPensionLargeScaleMedicalInsurance = insuranceValues.personalPensionLargeScaleMedicalInsurance;
formState.userWagesVO.personalPensionProvidentFundInsurance = insuranceValues.personalPensionProvidentFundInsurance;
formState.userWagesVO.companyInsurance = insuranceValues.companyInsurance;
formState.userWagesVO.companyMedicalInsurance = insuranceValues.companyMedicalInsurance;
formState.userWagesVO.companyUnemploymentInsurance = insuranceValues.companyUnemploymentInsurance;
formState.userWagesVO.companyEmploymentInjuryInsurance = insuranceValues.companyEmploymentInjuryInsurance;
formState.userWagesVO.companyMaternityInsurance = insuranceValues.companyMaternityInsurance;
formState.userWagesVO.companyLargeScaleMedicalInsurance = insuranceValues.companyLargeScaleMedicalInsurance;
formState.userWagesVO.companyProvidentFundInsurance = insuranceValues.companyProvidentFundInsurance;
} catch (error) {
console.error('解析或填充数据失败:', error);
}
}
// 考勤组类型变更处理
function handleAttendanceTypeChange(value: string) {
// 特殊处理自定义选项
if (value === 'custom') {
// 保留monthlyAttendanceName不变,但不设置IDs
return;
}
// 根据选择的类型,获取对应的ID数组
const selectedOption = attendanceOptions.value.find(opt => opt.value === value);
if (selectedOption) {
formState.userBasicDetailVO.monthlyAttendanceIds = selectedOption.ids;
formState.userBasicDetailVO.monthlyAttendanceName = selectedOption.label;
} else {
formState.userBasicDetailVO.monthlyAttendanceIds = [];
formState.userBasicDetailVO.monthlyAttendanceName = undefined;
}
}
// 获取考勤组标签
function getAttendanceLabel(type: number) {
switch (type) {
case 61:
return '9小时双休';
case 62:
return '9小时大小周';
case 63:
return '8小时双休';
case 64:
return '8.5小时大小周';
default:
return '未知考勤组';
}
}
// 获取下拉选项数据
const fetchOptions = async () => {
try {
const [companies, depts, roles] = await Promise.all([
getCompanyList({}),
getDeptList({}),
getRoleList({})
]);
companyOptions.value = companies || [];
deptOptions.value = depts || [];
// 过滤掉ID为6的生产科角色
roleOptions.value = (roles || []).filter(role => role.id !== 6);
} catch (error) {
console.error('获取选项数据失败:', error);
}
};
// 获取考勤组数据
async function getAttendanceOptions() {
try {
const res = await defHttp.post<any>({
url: '/order/erp/system_setting/query_list',
params: {
setting_type: [61, 62, 63, 64]
}
});
if (Array.isArray(res)) {
// 重置分组数据
attendanceGroups.value = {
61: {},
62: {},
63: {},
64: {}
};
// 清空选项
attendanceOptions.value = [];
// 按settingType和settingValue双重分组
res.forEach(item => {
const type = item.settingType;
const value = item.settingValue;
if (type >= 61 && type <= 64 && value) {
if (!attendanceGroups.value[type][value]) {
attendanceGroups.value[type][value] = [];
}
attendanceGroups.value[type][value].push(item);
}
});
// 为每个分组创建选项
Object.entries(attendanceGroups.value).forEach(([typeStr, valueGroups]) => {
const type = parseInt(typeStr);
const baseLabel = getAttendanceLabel(type);
Object.entries(valueGroups).forEach(([value, items]) => {
if (items.length > 0) {
const ids = items.map(item => item.id);
// 创建类型+年份的选项,值格式为 "type:value"
attendanceOptions.value.push({
value: `${type}:${value}`,
label: `${baseLabel}(${value})`,
ids: ids
});
}
});
});
// 按考勤类型排序,相同类型的按年份降序排序
attendanceOptions.value.sort((a, b) => {
const typeA = parseInt(a.value.split(':')[0]);
const typeB = parseInt(b.value.split(':')[0]);
if (typeA !== typeB) {
return typeA - typeB;
}
// 相同类型,按年份降序
const yearA = a.value.split(':')[1];
const yearB = b.value.split(':')[1];
return yearB.localeCompare(yearA);
});
}
} catch (error) {
console.error('获取考勤组数据失败:', error);
}
}
// 获取社保待遇数据
async function getSocialSettingOptions() {
try {
const res = await defHttp.post<any>({
url: '/order/erp/system_setting/query_list',
params: {
setting_type: [70, 71, 72,73]
}
});
if (Array.isArray(res)) {
// 清空选项
socialSettingOptions.value = [];
// 按settingValue(年份)和settingType(配置类型)分组
const groupedData: Record<string, Record<number, any>> = {};
res.forEach(item => {
const year = item.settingValue;
const type = item.settingType;
if (year && type) {
if (!groupedData[year]) {
groupedData[year] = {};
}
groupedData[year][type] = item;
}
});
// 为每个分组创建选项
Object.entries(groupedData).forEach(([year, typeItems]) => {
Object.entries(typeItems).forEach(([typeStr, item]) => {
const type = parseInt(typeStr);
let label = '';
// 根据类型设置具体的标签名称
switch (type) {
case 70:
label = '五险一金-特殊';
break;
case 71:
label = '五险一金-普通';
break;
case 72:
label = '五险一金-无社保';
break;
case 73:
label = '五险一金-个体';
break;
default:
label = `社保配置${type}`;
}
// 创建社保选项,值格式为 "year:type"
socialSettingOptions.value.push({
value: `${year}:${type}`,
label: `${label}(${year})`,
id: item.id
});
});
});
// 按年份降序排序,相同年份按类型升序
socialSettingOptions.value.sort((a, b) => {
const yearA = a.value.split(':')[0];
const yearB = b.value.split(':')[0];
if (yearA !== yearB) {
return yearB.localeCompare(yearA);
}
// 相同年份,按类型升序
const typeA = parseInt(a.value.split(':')[1]);
const typeB = parseInt(b.value.split(':')[1]);
return typeA - typeB;
});
}
} catch (error) {
console.error('获取社保待遇数据失败:', error);
}
}
onMounted(() => {
fetchOptions();
});
// 员工账号表单
const [employeeFormRegister, { resetFields: resetEmployeeForm, setFieldsValue: setEmployeeFormValues }] = useForm({
labelWidth: 100,
baseColProps: { span: 24 },
schemas: accountFormSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 },
});
// 生产科账号表单
const [productionFormRegister, { resetFields: resetProductionForm, validate: validateProductionForm, setFieldsValue: setProductionFormValues }] = useForm({
labelWidth: 100,
baseColProps: { span: 24 },
schemas: productionAccountFormSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 },
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
// 重置表单
resetEmployeeForm();
resetProductionForm();
// 重置提交状态
submitLoading.value = false;
setModalProps({ confirmLoading: false });
// 每次打开模态框时都重新获取最新的选项数据
await Promise.all([
fetchOptions(), // 重新获取公司、部门、岗位数据
getAttendanceOptions(), //获取考勤组数据社
getSocialSettingOptions() //获取保待遇数据
]);
// 重置表单数据
Object.keys(formState).forEach(key => {
if (key !== 'userBasicDetailVO' && key !== 'userWagesVO') {
// 必填字段重置为空字符串,非必填字段重置为undefined
const requiredFields = ['chineseName', 'nickName', 'gender', 'phone', 'email'];
if (requiredFields.includes(key)) {
formState[key] = '';
} else {
formState[key] = undefined;
}
}
});
// companyId, deptId, roleId特殊处理为undefined
formState.companyId = undefined;
formState.deptId = undefined;
formState.roleId = undefined;
// 重置用户基本详情VO
Object.keys(formState.userBasicDetailVO).forEach(key => {
// 日期类型字段设为null,其他字段设为undefined
if (['entryTime', 'dateBirth', 'periodStartTime', 'periodEndTime', 'contractStartTime', 'contractEndTime'].includes(key)) {
formState.userBasicDetailVO[key] = null;
} else if (key === 'monthlyAttendanceIds') {
formState.userBasicDetailVO[key] = []; // 数组类型重置为空数组
} else if (key === 'monthlyAttendanceName') {
formState.userBasicDetailVO[key] = undefined; // 名称字段重置为undefined
} else {
formState.userBasicDetailVO[key] = undefined;
}
});
// 重置用户工资配置VO
Object.keys(formState.userWagesVO).forEach(key => {
formState.userWagesVO[key] = undefined;
});
// 设置默认值
formState.pensionInsurance = 'basic';
formState.medicalInsurance = 'basic';
formState.unemploymentInsurance = 'basic';
// 明确设置isUpdate的值
if (data?.isUpdate === true) {
isUpdate.value = true;
} else {
isUpdate.value = false;
}
// 设置账号类型
if (data?.type) {
accountType.value = data.type;
} else if (isUpdate.value && data?.record?.isAdmin) {
// 如果是编辑,根据record中的isAdmin判断账号类型
accountType.value = data.record.isAdmin === '1' ? 'employee' : 'production';
}
if (isUpdate.value) {
rowId.value = data.record.id;
// 使用nextTick确保表单已渲染
await nextTick();
try {
// 根据不同账号类型设置表单值
if (accountType.value === 'production') {
// 确保record中包含公司ID
const recordWithCompanyId = {
...toRaw(data.record),
// 如果没有companyId但有companyId字段,使用它
companyId: data.record.companyId || data.record.company_id,
};
// 设置表单值
setProductionFormValues(recordWithCompanyId);
} else {
// 确保record中包含公司ID
const recordWithCompanyId = {
...toRaw(data.record),
// 如果没有companyId但有companyId字段,使用它
companyId: data.record.companyId || data.record.company_id,
};
// 处理字段锁定状态
processFieldLockStatus(recordWithCompanyId.userWagesFieldLockApplyVO);
// 设置自定义表单数据
Object.entries(formState).forEach(([key, value]) => {
if (key !== 'userBasicDetailVO' && key !== 'userWagesVO' && recordWithCompanyId[key] !== undefined) {
formState[key] = recordWithCompanyId[key];
}
});
// 处理userBasicDetailVO数据
if (recordWithCompanyId.userBasicDetailResultVO) {
// 直接从返回的数据中提取字段并映射到formState
const basicDetail = recordWithCompanyId.userBasicDetailResultVO;
// 按照字段名称一一映射
// 日期字段需要特殊处理
const dateFields = ['entryTime', 'dateBirth', 'periodStartTime', 'periodEndTime', 'contractStartTime', 'contractEndTime'];
// 遍历所有字段进行处理
Object.keys(basicDetail).forEach(key => {
// 如果返回的字段在表单中存在
if (formState.userBasicDetailVO.hasOwnProperty(key)) {
// 日期字段需要特殊处理
if (dateFields.includes(key) && basicDetail[key]) {
try {
// 使用dayjs处理日期,而不是原生Date对象
// 如果日期字段有值且是有效日期,使用dayjs转换
const dateValue = basicDetail[key];
if (dateValue && dayjs(dateValue).isValid()) {
formState.userBasicDetailVO[key] = dayjs(dateValue);
} else {
// 如果日期无效,设置为null
formState.userBasicDetailVO[key] = null;
console.warn(`日期字段 ${key} 值无效: ${dateValue},已设置为null`);
}
} catch (error) {
console.error(`处理日期字段 ${key} 出错:`, error);
formState.userBasicDetailVO[key] = null;
}
} else {
// 非日期字段直接赋值
formState.userBasicDetailVO[key] = basicDetail[key];
}
}
});
// 处理考勤组信息 - 优先使用后端返回的monthlyAttendanceName
if (basicDetail.monthlyAttendanceName) {
// 直接使用后端返回的考勤组名称
formState.userBasicDetailVO.monthlyAttendanceName = basicDetail.monthlyAttendanceName;
// 尝试查找匹配的选项
let foundMatch = false;
if (Array.isArray(basicDetail.monthlyAttendanceIds) && basicDetail.monthlyAttendanceIds.length > 0) {
const firstId = basicDetail.monthlyAttendanceIds[0];
for (const option of attendanceOptions.value) {
if (option.ids.includes(firstId)) {
formState.userBasicDetailVO.selectedAttendanceType = option.value;
foundMatch = true;
break;
}
}
} else {
// 如果没有ID,尝试通过名称匹配
for (const option of attendanceOptions.value) {
if (option.label === basicDetail.monthlyAttendanceName) {
formState.userBasicDetailVO.selectedAttendanceType = option.value;
foundMatch = true;
break;
}
}
}
// 如果没有匹配项,使用自定义选项
if (!foundMatch) {
formState.userBasicDetailVO.selectedAttendanceType = 'custom';
}
}
// 处理考勤组ID数组
if (Array.isArray(basicDetail.monthlyAttendanceIds) && basicDetail.monthlyAttendanceIds.length > 0) {
formState.userBasicDetailVO.monthlyAttendanceIds = basicDetail.monthlyAttendanceIds;
// 如果没有monthlyAttendanceName但有ID,尝试根据ID查找考勤组选项
if (!basicDetail.monthlyAttendanceName) {
const firstId = basicDetail.monthlyAttendanceIds[0];
let foundMatch = false;
// 遍历所有考勤选项
for (const option of attendanceOptions.value) {
if (option.ids.includes(firstId)) {
formState.userBasicDetailVO.selectedAttendanceType = option.value;
formState.userBasicDetailVO.monthlyAttendanceName = option.label;
foundMatch = true;
break;
}
}
// 如果没找到匹配项但有考勤选项,设置第一个考勤选项
if (!foundMatch && attendanceOptions.value.length > 0) {
formState.userBasicDetailVO.selectedAttendanceType = attendanceOptions.value[0].value;
formState.userBasicDetailVO.monthlyAttendanceName = attendanceOptions.value[0].label;
}
}
}
}
// 修改原有的备选逻辑,添加对monthlyAttendanceName的处理
else if (recordWithCompanyId.userBasicDetailVO) {
// 创建一个新对象来处理转换后的数据
const processedBasicDetail = { ...recordWithCompanyId.userBasicDetailVO };
// 处理考勤组数据
// 如果有userID11字段,根据其值查找对应的考勤组类型
if (processedBasicDetail.userID11 !== undefined) {
// 查找userID11对应的考勤组类型和值
let foundMatch = false;
// 遍历所有考勤选项
for (const option of attendanceOptions.value) {
if (option.ids.includes(parseInt(processedBasicDetail.userID11))) {
// 设置选择的考勤组选项
formState.userBasicDetailVO.selectedAttendanceType = option.value;
// 设置ID数组
formState.userBasicDetailVO.monthlyAttendanceIds = option.ids;
// 设置考勤组名称
formState.userBasicDetailVO.monthlyAttendanceName = option.label;
foundMatch = true;
break;
}
}
// 如果没找到匹配项,但有已有的考勤组名称,使用自定义选项
if (!foundMatch) {
if (processedBasicDetail.monthlyAttendanceName) {
formState.userBasicDetailVO.monthlyAttendanceName = processedBasicDetail.monthlyAttendanceName;
formState.userBasicDetailVO.selectedAttendanceType = 'custom';
} else if (attendanceOptions.value.length > 0) {
// 如果没有考勤组名称但有考勤选项,设置第一个考勤选项
const firstOption = attendanceOptions.value[0];
formState.userBasicDetailVO.selectedAttendanceType = firstOption.value;
formState.userBasicDetailVO.monthlyAttendanceIds = firstOption.ids;
formState.userBasicDetailVO.monthlyAttendanceName = firstOption.label;
}
}
delete processedBasicDetail.userID11; // 删除原字段
}
// 如果没有userID11但有monthlyAttendanceIds,且为数组格式
else if (Array.isArray(processedBasicDetail.monthlyAttendanceIds) && processedBasicDetail.monthlyAttendanceIds.length > 0) {
formState.userBasicDetailVO.monthlyAttendanceIds = processedBasicDetail.monthlyAttendanceIds;
// 根据第一个ID查找对应的选项
const firstId = processedBasicDetail.monthlyAttendanceIds[0];
let foundMatch = false;
// 遍历所有考勤选项
for (const option of attendanceOptions.value) {
if (option.ids.includes(firstId)) {
formState.userBasicDetailVO.selectedAttendanceType = option.value;
formState.userBasicDetailVO.monthlyAttendanceName = option.label;
foundMatch = true;
break;
}
}
// 如果没找到匹配项
if (!foundMatch) {
// 如果有考勤组名称,使用自定义选项
if (processedBasicDetail.monthlyAttendanceName) {
formState.userBasicDetailVO.monthlyAttendanceName = processedBasicDetail.monthlyAttendanceName;
formState.userBasicDetailVO.selectedAttendanceType = 'custom';
} else if (attendanceOptions.value.length > 0) {
// 如果没有考勤组名称但有考勤选项,设置第一个考勤选项
formState.userBasicDetailVO.selectedAttendanceType = attendanceOptions.value[0].value;
formState.userBasicDetailVO.monthlyAttendanceName = attendanceOptions.value[0].label;
}
}
delete processedBasicDetail.monthlyAttendanceIds;
}
// 如果只有monthlyAttendanceName但没有ID
else if (processedBasicDetail.monthlyAttendanceName) {
formState.userBasicDetailVO.monthlyAttendanceName = processedBasicDetail.monthlyAttendanceName;
// 尝试通过名称匹配现有选项
let foundMatch = false;
for (const option of attendanceOptions.value) {
if (option.label === processedBasicDetail.monthlyAttendanceName) {
formState.userBasicDetailVO.selectedAttendanceType = option.value;
formState.userBasicDetailVO.monthlyAttendanceIds = option.ids;
foundMatch = true;
break;
}
}
// 如果没找到匹配项,使用自定义选项
if (!foundMatch) {
formState.userBasicDetailVO.selectedAttendanceType = 'custom';
}
delete processedBasicDetail.monthlyAttendanceName;
}
// 遍历处理后的对象进行赋值
Object.entries(processedBasicDetail).forEach(([key, value]) => {
if (value !== undefined && formState.userBasicDetailVO.hasOwnProperty(key) &&
key !== 'monthlyAttendanceIds' && key !== 'selectedAttendanceType' && key !== 'monthlyAttendanceName') {
formState.userBasicDetailVO[key] = value;
}
});
}
// 处理userWagesVO数据
if (recordWithCompanyId.userWagesVO) {
// 先处理普通字段
Object.entries(recordWithCompanyId.userWagesVO).forEach(([key, value]) => {
if (value !== undefined && formState.userWagesVO.hasOwnProperty(key) && key !== 'socialSetting') {
formState.userWagesVO[key] = value;
}
});
// 单独处理社保待遇字段
if (recordWithCompanyId.userWagesVO.socialSetting) {
const socialSettingValue = recordWithCompanyId.userWagesVO.socialSetting;
let selectedSocialSettingId; // 存储找到的选项ID
// 判断返回的socialSetting是ID格式还是"year:type"格式
if (socialSettingValue.toString().includes(':')) {
// 是"year:type"格式,查找对应的选项
const option = socialSettingOptions.value.find(opt => opt.value === socialSettingValue);
if (option) {
selectedSocialSettingId = option.id;
formState.userWagesVO.socialSetting = socialSettingValue;
formState.userWagesVO.socialSettingId = option.id;
formState.userWagesVO.socialSettingName = option.label;
}
} else {
// 是ID格式,直接使用
selectedSocialSettingId = parseInt(socialSettingValue);
formState.userWagesVO.socialSettingId = selectedSocialSettingId;
// 尝试查找对应的选项以获取显示值和名称
const option = socialSettingOptions.value.find(opt => opt.id === selectedSocialSettingId);
if (option) {
formState.userWagesVO.socialSetting = option.value;
formState.userWagesVO.socialSettingName = option.label;
} else {
formState.userWagesVO.socialSetting = socialSettingValue.toString();
}
}
// 根据找到的社保待遇ID加载保险数据
if (selectedSocialSettingId) {
// 使用query_list API获取系统设置数据
defHttp.post<any>({
url: '/order/erp/system_setting/query_list',
params: {
setting_type: [70, 71, 72,73]
}
}).then(settingList => {
if (Array.isArray(settingList)) {
const targetSetting = settingList.find(item => item.id === selectedSocialSettingId);
if (targetSetting && targetSetting.relationValue) {
tryParseAndFillInsurance(targetSetting.relationValue);
} else {
console.warn(`未找到ID为 ${selectedSocialSettingId} 的社保配置,检查保险字段是否已填充`);
// 如果保险字段值已经在返回数据中存在,则不需要额外填充
const hasInsuranceValues = Object.keys(formState.userWagesVO).some(key =>
key.includes('Insurance') && formState.userWagesVO[key] !== undefined
);
if (!hasInsuranceValues) {
console.warn('未找到保险字段值,使用测试数据填充');
parseTestData(selectedSocialSettingId);
} else {
console.log('保险字段值已存在,不需要额外填充');
}
}
}
}).catch(error => {
console.error('获取社保配置数据失败:', error);
// 如果保险字段值已经在返回数据中存在,则不需要额外填充
const hasInsuranceValues = Object.keys(formState.userWagesVO).some(key =>
key.includes('Insurance') && formState.userWagesVO[key] !== undefined
);
if (!hasInsuranceValues) {
console.warn('获取失败且未找到保险字段值,使用测试数据填充');
parseTestData(selectedSocialSettingId);
}
});
}
}
}
// ID字段特殊处理
formState.id = recordWithCompanyId.id;
// 设置组件库表单值 (保留原来的功能)
await nextTick(); // 再次确保表单已完全更新
setEmployeeFormValues(recordWithCompanyId);
}
} catch (error) {
console.error('设置表单值时出错:', error);
}
}
});
const getTitle = computed(() => {
if (!unref(isUpdate)) {
return accountType.value === 'employee' ? '新增员工账号' : '新增生产科账号';
}
return '编辑账号';
});
// 计算合同期限
const calculateContractDuration = computed(() => {
const { contractStartTime, contractEndTime } = formState.userBasicDetailVO;
if (contractStartTime && contractEndTime) {
const startDate = new Date(contractStartTime);
const endDate = new Date(contractEndTime);
// 计算年份差异
let years = endDate.getFullYear() - startDate.getFullYear();
// 检查月份和日期,调整年份差异
if (
endDate.getMonth() < startDate.getMonth() ||
(endDate.getMonth() === startDate.getMonth() && endDate.getDate() < startDate.getDate())
) {
years--;
}
// 计算剩余天数
// 先计算完整的日期差值(毫秒)
const diffTime = Math.abs(endDate.getTime() - startDate.getTime());
// 转换为天数
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// 减去整年的天数
const daysPart = diffDays - (years * 365);
// 返回年数和天数
return years > 0
? `${years}年(${daysPart}天)`
: `${diffDays}天`;
}
return '';
});
// 按年份分组的考勤组选项
const yearGroups = computed(() => {
// 按年份归类
const groupedByYear: Record<string, {value: string, label: string, ids: number[]}[]> = {};
// 遍历所有选项,提取年份信息并按年份分组
attendanceOptions.value.forEach(option => {
// 获取年份信息 (假设格式是 "type:year")
const valueArr = option.value.split(':');
if (valueArr.length === 2) {
const year = valueArr[1];
if (!groupedByYear[year]) {
groupedByYear[year] = [];
}
// 这里不再移除年份信息,直接使用原始的选项
groupedByYear[year].push(option);
} else {
// 如果没有年份信息,放入"其他"分组
if (!groupedByYear['其他']) {
groupedByYear['其他'] = [];
}
groupedByYear['其他'].push(option);
}
});
// 将分组转换为数组并按年份降序排序(新的年份在前)
return Object.entries(groupedByYear)
.map(([year, options]) => ({
year,
options: options.sort((a, b) => {
// 按考勤类型排序
const typeA = parseInt(a.value.split(':')[0]);
const typeB = parseInt(b.value.split(':')[0]);
return typeA - typeB;
})
}))
.sort((a, b) => b.year.localeCompare(a.year));
});
async function handleSubmit() {
// 如果当前正在提交中,直接返回,防止重复点击
if (submitLoading.value) {
console.log('正在提交中,请勿重复点击');
return;
}
try {
// 设置提交状态为true,禁用按钮
submitLoading.value = true;
setModalProps({ confirmLoading: true });
// 添加最小Loading时间,确保用户感知到按钮状态变化
const startTime = Date.now();
if (accountType.value === 'production') {
// 生产科账号逻辑
try {
// 执行表单验证
const values = await validateProductionForm();
// 设置提交数据类型
const submitData: Record<string, any> = {};
// 遍历values中的每个属性,只保留有值的字段
Object.entries(values).forEach(([key, value]) => {
// 跳过undefined、null和空字符串
if (value !== undefined && value !== null && value !== '') {
submitData[key] = value;
}
});
// 始终需要的字段
if (rowId.value) {
submitData.id = rowId.value;
}
// 生产科账号固定roleId
submitData.roleId = 6;
submitData.isAdmin = '0';
// 如果有公司ID但没有公司名称,尝试查找公司名称
if (submitData.companyId && !submitData.companyName) {
const selectedCompany = companyOptions.value.find(company => company.id === submitData.companyId);
if (selectedCompany?.name) {
submitData.companyName = selectedCompany.name;
}
}
closeModal();
emit('success', {
isUpdate: unref(isUpdate),
values: submitData,
});
} catch (error) {
// 表单验证失败,重置按钮状态
console.error('生产科表单验证失败:', error);
submitLoading.value = false;
setModalProps({ confirmLoading: false });
return;
}
} else {
// 员工账号逻辑
try {
// 验证表单
if (!employeeFormRef.value) {
console.error('表单实例不存在');
submitLoading.value = false;
setModalProps({ confirmLoading: false });
return;
}
// 使用Ant Design表单验证
await employeeFormRef.value.validate();
// 验证通过后,创建提交数据对象
const submitData: Record<string, any> = {};
// 处理formState中的主要字段
Object.entries(formState).forEach(([key, value]) => {
// 跳过userBasicDetailVO和userWagesVO,单独处理
if (key === 'userBasicDetailVO' || key === 'userWagesVO') return;
// 判断是否为默认值
const isDefaultValue =
(key === 'pensionInsurance' && value === 'basic') ||
(key === 'medicalInsurance' && value === 'basic') ||
(key === 'unemploymentInsurance' && value === 'basic');
// 只保留非空且非默认值的字段
if (value !== undefined && value !== null && value !== '' && !isDefaultValue) {
submitData[key] = value;
}
});
// 处理userBasicDetailVO对象中的字段
if (formState.userBasicDetailVO) {
const filteredUserBasicDetail: Record<string, any> = {};
let hasFilledValues = false;
// 先检查是否有需要提交的字段
const hasValues = Object.entries(formState.userBasicDetailVO).some(([key, value]) => {
return value !== undefined &&
value !== null &&
value !== '' &&
key !== 'selectedAttendanceType' &&
!(key === 'monthlyAttendanceIds' && Array.isArray(value) && value.length === 0);
});
if (hasValues) {
Object.entries(formState.userBasicDetailVO).forEach(([key, value]) => {
// 考勤组ID和名称的特殊处理 - 确保同时提交ID和名称
if (key === 'monthlyAttendanceIds' && Array.isArray(value) && value.length > 0) {
filteredUserBasicDetail[key] = value;
// 如果存在考勤组名称,也添加到提交数据中
const attendanceName = formState.userBasicDetailVO.monthlyAttendanceName;
if (attendanceName) {
filteredUserBasicDetail['monthlyAttendanceName'] = attendanceName;
}
hasFilledValues = true;
}
// 跳过selectedAttendanceType(仅用于UI选择,不需要提交)
else if (key !== 'selectedAttendanceType' && value !== undefined && value !== null && value !== '') {
filteredUserBasicDetail[key] = value;
hasFilledValues = true;
}
});
// 只有当有实际填写的字段时,才添加到提交数据
if (hasFilledValues && Object.keys(filteredUserBasicDetail).length > 0) {
submitData.userBasicDetailVO = filteredUserBasicDetail;
}
}
}
// 处理userWagesVO对象中的字段
if (formState.userWagesVO) {
const filteredUserWagesVO: Record<string, any> = {};
let hasFilledValues = false;
Object.entries(formState.userWagesVO).forEach(([key, value]) => {
// 社保待遇的特殊处理 - 使用ID而不是显示值
if (key === 'socialSetting' && value !== undefined && value !== null && value !== '') {
// 使用ID而不是显示值
const socialSettingId = formState.userWagesVO.socialSettingId;
if (socialSettingId !== undefined) {
// 使用ID作为socialSetting的值
filteredUserWagesVO['socialSetting'] = socialSettingId;
// 如果存在社保待遇名称,也添加到提交数据中
const socialSettingName = formState.userWagesVO.socialSettingName;
if (socialSettingName) {
filteredUserWagesVO['socialSettingName'] = socialSettingName;
}
hasFilledValues = true;
}
}
// 跳过socialSettingName和socialSettingId,因为我们已经处理过了
else if (key !== 'socialSettingName' && key !== 'socialSettingId' && value !== undefined && value !== null && value !== '') {
filteredUserWagesVO[key] = value;
hasFilledValues = true;
}
});
// 只有当有实际填写的字段时,才添加到提交数据
if (hasFilledValues && Object.keys(filteredUserWagesVO).length > 0) {
submitData.userWagesVO = filteredUserWagesVO;
}
}
// 员工账号类型
// if (unref(isUpdate)) {
// submitData.isAdmin = '1';
// }
submitData.isAdmin = '1';
// 如果有ID,添加到提交数据
if (rowId.value) {
submitData.id = rowId.value;
}
// 如果有公司ID但没有公司名称,尝试查找公司名称
if (submitData.companyId && !submitData.companyName) {
const selectedCompany = companyOptions.value.find(company => company.id === submitData.companyId);
if (selectedCompany?.name) {
submitData.companyName = selectedCompany.name;
}
}
closeModal();
emit('success', {
isUpdate: unref(isUpdate),
values: submitData,
});
} catch (error) {
// 表单验证失败,重置按钮状态,不关闭模态框
console.error('员工表单验证失败:', error);
submitLoading.value = false;
setModalProps({ confirmLoading: false });
return;
}
}
} catch (error) {
// 其他错误,重置按钮状态
console.error('提交过程中发生错误:', error);
submitLoading.value = false;
setModalProps({ confirmLoading: false });
} finally {
// 只有在成功提交的情况下才执行这里的逻辑
// 由于验证失败时会提前return,所以这里只处理成功的情况
if (!submitLoading.value) {
// 如果submitLoading已经被重置,说明验证失败,不需要执行后续逻辑
return;
}
// 确保最小loading时间为800ms,让用户有感知
const loadingTime = Date.now() - startTime;
const minLoadingTime = 800; // 最小loading时间,单位毫秒
if (loadingTime < minLoadingTime) {
await new Promise(resolve => setTimeout(resolve, minLoadingTime - loadingTime));
}
// 重置按钮状态
setModalProps({ confirmLoading: false });
submitLoading.value = false;
// 添加防抖功能,禁止短时间内再次点击
setTimeout(() => {
submitLoading.value = false;
}, 2000);
}
}
function handleTabChange(key: string) {
activeTabKey.value = key;
}
function handleCancel() {
submitLoading.value = false; // 重置提交状态
setModalProps({ confirmLoading: false }); // 确保模态框按钮状态也被重置
closeModal();
}
// 添加一个计算属性,用于检查是否存在匹配的考勤选项
const hasMatchingAttendanceOption = computed(() => {
if (!formState.userBasicDetailVO.monthlyAttendanceName || attendanceOptions.value.length === 0) {
return false;
}
// 检查是否有匹配的选项
return attendanceOptions.value.some(option =>
option.label === formState.userBasicDetailVO.monthlyAttendanceName ||
formState.userBasicDetailVO.selectedAttendanceType === option.value
);
});
return {
registerModal,
employeeFormRegister,
productionFormRegister,
getTitle,
handleSubmit,
handleTabChange,
handleCancel,
accountType,
formState,
companyOptions,
deptOptions,
roleOptions,
getAttendanceLabel,
handleAttendanceTypeChange,
handleSocialSettingChange,
calculateContractDuration,
activeTabKey,
employeeFormRef,
rules,
idCardRules,
handleIdCardInput,
handleIdCardChange,
attendanceOptions,
isDebug,
yearGroups,
socialSettingOptions,
socialSettingYearGroups,
parseTestData,
submitLoading,
hasMatchingAttendanceOption,
fieldLockStatus,
isFieldLocked,
isUpdate,
processFieldLockStatus,
refreshOptions: fetchOptions // 暴露刷新选项数据的方法
};
},
});
</script>
<style scoped>
.employee-file-form {
width: 100%;
}
.section-header {
font-weight: bold;
font-size: 16px;
padding: 10px;
background-color: #f5f5f5;
border-left: 4px solid #1890ff;
margin-bottom: 16px;
margin-top: 16px;
}
.form-section {
padding: 0 10px 16px 10px;
}
/* 卡片式配置样式 */
.config-cards {
margin-top: 20px;
border: 1px solid #e8e8e8;
border-radius: 4px;
overflow: hidden;
}
.card-tabs {
display: flex;
background-color: #f5f5f5;
border-bottom: 1px solid #e8e8e8;
}
.card-tab {
padding: 12px 16px;
font-size: 14px;
cursor: pointer;
transition: all 0.3s;
position: relative;
}
.card-tab.active {
color: #1890ff;
font-weight: bold;
}
.card-tab.active::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 2px;
background-color: #1890ff;
}
.card-tab:hover {
color: #40a9ff;
}
.card-content {
padding: 16px;
background-color: #fff;
}
/* 标签页样式 */
.tab-container {
margin-top: 10px;
}
.tab-container :deep(.ant-tabs-nav) {
margin-bottom: 16px;
background-color: #f5f5f5;
padding: 0;
border-bottom: 1px solid #e8e8e8;
}
.tab-container :deep(.ant-tabs-nav-list) {
width: 100%;
display: flex;
}
.tab-container :deep(.ant-tabs-tab) {
padding: 12px 0;
margin: 0;
flex: 1;
text-align: center;
transition: all 0.3s;
}
.tab-container :deep(.ant-tabs-tab.ant-tabs-tab-active .ant-tabs-tab-btn) {
color: #1890ff;
font-weight: bold;
}
.tab-container :deep(.ant-tabs-ink-bar) {
background-color: #1890ff;
}
.tab-content-container {
min-height: 500px;
padding: 20px 0;
background-color: #fff;
}
/* 确保所有标签页内容区域大小一致 */
.ant-tabs-content {
height: 100%;
}
.ant-tabs-tabpane {
height: 100%;
min-height: 500px;
}
/* 基本信息标签页可能内容较多,需要滚动 */
.ant-tabs-tabpane-basic {
overflow-y: auto;
max-height: 700px;
}
/* 空白填充区域 */
.spacer {
height: 300px;
width: 100%;
}
</style>