index.vue
51.3 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
<template>
<div class="payroll-container">
<!-- 搜索表单 -->
<div class="search-form">
<a-form layout="inline" @submit.prevent="handleSearch">
<a-form-item label="姓名">
<a-input v-model:value="searchParams.chineseName" placeholder="输入姓名" />
</a-form-item>
<a-form-item label="昵称">
<a-input v-model:value="searchParams.nickName" placeholder="输入昵称" />
</a-form-item>
<a-form-item label="公司">
<a-select
v-model:value="searchParams.companyId"
style="width: 160px"
placeholder="请选择公司"
allowClear
>
<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-form-item label="工资月份" required>
<a-date-picker
v-model:value="searchParams.dateTime"
picker="month"
:format="monthFormat"
value-format="YYYY-MM"
placeholder="选择月份"
style="width: 120px"
/>
</a-form-item>
<a-form-item label="审核状态">
<a-select v-model:value="searchParams.wagesStatus" style="width: 120px">
<a-select-option value="0">待审核</a-select-option>
<a-select-option value="10">已审核</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="发放状态">
<a-select v-model:value="searchParams.distributionStatus" style="width: 120px">
<a-select-option value="20">未发放</a-select-option>
<a-select-option value="10">已发放</a-select-option>
</a-select>
</a-form-item>
<a-form-item>
<a-button type="primary" html-type="submit">查询</a-button>
<a-button style="margin-left: 8px" @click="handleReset">重置</a-button>
</a-form-item>
</a-form>
</div>
<!-- 工具栏 -->
<div class="toolbar">
<!-- 显示已选择数量 -->
<a-alert v-if="selectedRowKeys.length > 0" class="selected-alert" type="info" show-icon>
<template #message>
<span>已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> 项</span>
<a-button type="link" @click="onClearSelected">取消选择</a-button>
</template>
</a-alert>
<!-- 操作按钮始终显示 -->
<div class="batch-actions">
<!-- 设置审核状态 -->
<a-dropdown>
<a-button type="primary">
<span>设置审核状态</span>
<down-outlined />
</a-button>
<template #overlay>
<a-menu @click="handleSetWagesStatus">
<a-menu-item key="10">审核通过</a-menu-item>
<a-menu-item key="20">驳回</a-menu-item>
</a-menu>
</template>
</a-dropdown>
<!-- 设置发放状态 -->
<a-dropdown class="ml-2">
<a-button type="primary">
<span>设置发放状态</span>
<down-outlined />
</a-button>
<template #overlay>
<a-menu @click="handleSetDistributionStatus">
<a-menu-item key="10">已发放</a-menu-item>
<a-menu-item key="20">未发放</a-menu-item>
</a-menu>
</template>
</a-dropdown>
<!-- 导出按钮 -->
<a-button type="primary" class="ml-2" @click="handleExport">导出</a-button>
<!-- 工资汇总按钮 -->
<a-button type="primary" class="ml-2" @click="handleSalarySummary">工资汇总</a-button>
</div>
</div>
<!-- 原生表格显示数据 -->
<div class="table-container">
<a-table
:loading="loading"
:columns="columns"
:data-source="tableData"
:pagination="pagination"
:row-key="record => record.userId"
:row-selection="rowSelection"
@change="handleTableChange"
bordered
:scroll="{ x: 3800 }"
:customRow="customRow"
>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'wagesStatus'">
{{ getWagesStatusText(record.wagesStatus) }}
</template>
<template v-else-if="column.dataIndex === 'distributionStatus'">
{{ getDistributionStatusText(record.distributionStatus) }}
</template>
<template v-else-if="isNumericColumn(column.dataIndex) && record[column.dataIndex] !== null && record[column.dataIndex] !== undefined">
{{ formatNumber(record[column.dataIndex]) }}
</template>
<template v-else-if="column.dataIndex === 'action'">
<a-button type="link" @click="handleEdit(record, searchParams.dateTime)">编辑</a-button>
<a-divider type="vertical" />
<a-button type="link" @click="handleApplyPermission(record)">申请权限</a-button>
<a-divider type="vertical" />
<a-popconfirm
title="是否确认删除"
@confirm="handleDelete(record)"
>
<a-button type="link" danger>删除</a-button>
</a-popconfirm>
<a-popconfirm
v-if="record.wagesStatus === '0'"
title="确认审核通过?"
@confirm="handleApprove(record)"
>
<a-button type="link" style="color: #52c41a">审核通过</a-button>
</a-popconfirm>
<a-popconfirm
v-if="record.wagesStatus === '0'"
title="确认驳回?"
@confirm="handleReject(record)"
>
<a-button type="link" danger>驳回</a-button>
</a-popconfirm>
<a-popconfirm
v-if="record.wagesStatus === '10' && record.distributionStatus === '0'"
title="确认发放工资?"
@confirm="handleDistribute(record)"
>
<a-button type="link" style="color: #fa8c16">发放</a-button>
</a-popconfirm>
</template>
</template>
</a-table>
</div>
<!-- 工资记录编辑抽屉 -->
<PayrollModal @register="registerDrawer" @success="handleSuccess" />
<!-- 申请权限抽屉 -->
<BasicDrawer
v-bind="$attrs"
@register="registerApplyDrawer"
@ok="handleApplySubmit"
title="字段编辑权限申请"
width="60%"
:destroyOnClose="true"
:isDetail="true"
:showFooter="true"
okText="申请"
:showDetailBack="false"
:closable="true"
class="apply-permission-drawer"
>
<div>
<h3 style="margin-bottom: 16px; color: #1890ff;">请选择需要申请编辑权限的字段:</h3>
<BasicForm @register="registerApplyForm" />
</div>
</BasicDrawer>
<!-- 申请理由组件 -->
<ApproveReason @register="registerApproveReason" @success="handleApproveSuccess" />
<!-- 年月份选择对话框 -->
<a-modal
v-model:visible="dateSelectVisible"
title="选择年月份"
@ok="handleDateSelectOk"
@cancel="handleDateSelectCancel"
width="700px"
class="date-select-modal"
>
<div>
<p class="selection-title">请选择想要统计的年月份(可多选):</p>
<!-- 年份选择 -->
<div class="year-selection">
<p class="section-title">选择年份:</p>
<a-radio-group v-model:value="selectedYear" button-style="solid" size="large">
<a-radio-button
v-for="year in availableYears"
:key="year"
:value="year"
>
{{ year }}年
</a-radio-button>
</a-radio-group>
</div>
<!-- 月份选择 -->
<div class="month-selection" style="margin-top: 24px;">
<p class="section-title">选择月份:</p>
<a-checkbox-group v-model:value="selectedMonths" class="month-checkbox-group">
<a-row :gutter="[16, 16]">
<a-col :span="6" v-for="month in 12" :key="month">
<a-checkbox :value="month.toString().padStart(2, '0')" class="month-checkbox">
{{ month }}月
</a-checkbox>
</a-col>
</a-row>
</a-checkbox-group>
</div>
<!-- 已选择的年月份展示 -->
<div class="selected-dates" style="margin-top: 24px;">
<p class="section-title">已选择的年月:</p>
<div class="tag-container">
<a-tag
v-for="date in formattedSelectedDates"
:key="date"
closable
@close="removeSelectedDate(date)"
class="date-tag"
>
{{ date }}
</a-tag>
</div>
</div>
</div>
</a-modal>
<!-- 工资汇总结果对话框 -->
<a-modal
v-model:visible="summaryResultVisible"
title="工资汇总结果"
@cancel="handleSummaryResultClose"
:footer="null"
width="600px"
>
<a-spin :spinning="summaryLoading">
<div class="summary-result">
<a-descriptions :column="1" bordered>
<a-descriptions-item label="月份含量">
{{ summaryData.monthlyCount || 0 }}
</a-descriptions-item>
<a-descriptions-item label="人数总额">
{{ summaryData.personCount || 0 }}
</a-descriptions-item>
<a-descriptions-item label="实际发放工资总额">
¥{{ formatNumber(summaryData.actualSalary || 0) }}
</a-descriptions-item>
<a-descriptions-item label="缴纳保险总金额">
¥{{ formatNumber(summaryData.insuranceSalary || 0) }}
</a-descriptions-item>
<a-descriptions-item label="合计本月用工成本">
¥{{ formatNumber(summaryData.totalMonthlyWorkCost || 0) }}
</a-descriptions-item>
<a-descriptions-item label="平均每月用工成本">
¥{{ formatNumber(summaryData.averageMonthlyWorkCost || 0) }}
</a-descriptions-item>
</a-descriptions>
</div>
</a-spin>
</a-modal>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, onMounted, computed, watch } from 'vue';
import { message } from 'ant-design-vue';
import { useModal } from '/@/components/Modal';
import { useDrawer } from '/@/components/Drawer';
import { BasicDrawer } from '/@/components/Drawer';
import { BasicForm, useForm } from '/@/components/Form/index';
import PayrollModal from './PayrollModal.vue';
import ApproveReason from '../attendance/ApproveReason.vue';
import type { WagesParams, WagesItem } from '/@/api/system/salary';
import { getWagesListByPage, deleteWages, approveWages, rejectWages, distributeWages } from '/@/api/system/salary';
import { defHttp } from '/@/utils/http/axios';
import dayjs from 'dayjs';
import { DownOutlined } from '@ant-design/icons-vue';
import axios from 'axios';
import { useUserStoreWithOut } from '/@/store/modules/user';
const userStore = useUserStoreWithOut();
export default defineComponent({
name: 'PayrollManagement',
components: {
PayrollModal,
BasicDrawer,
BasicForm,
ApproveReason,
DownOutlined
},
setup() {
// 表格数据相关状态
const loading = ref(false);
const tableData = ref<WagesItem[]>([]);
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showTotal: (total: number) => `共 ${total} 条数据`,
});
// 工资汇总相关状态
const dateSelectVisible = ref(false);
const summaryResultVisible = ref(false);
const summaryLoading = ref(false);
const selectedDateTimes = ref<string[]>([]);
// 新增年月份选择相关状态
const selectedYear = ref<string>('');
const selectedMonths = ref<string[]>([]);
const availableYears = ref<string[]>([]);
// 计算属性 - 格式化后的已选择年月
const formattedSelectedDates = computed(() => {
return selectedDateTimes.value.sort((a, b) => a.localeCompare(b));
});
// 移除已选择的年月
const removeSelectedDate = (date: string) => {
selectedDateTimes.value = selectedDateTimes.value.filter(d => d !== date);
};
const availableDateTimes = ref<{label: string, value: string}[]>([]);
const summaryData = ref<any>({
monthlyCount: 0,
personCount: 0,
actualSalary: 0,
insuranceSalary: 0,
totalMonthlyWorkCost: 0,
averageMonthlyWorkCost: 0
});
// 公司选项数据
const companyOptions = ref<{ id: number | string; name: string }[]>([]);
// 注册抽屉
const [registerDrawer, { openDrawer }] = useDrawer();
// 申请权限相关状态
const currentApplyRecord = ref<any>(null);
const selectedApplyFields = ref<any>({});
// 多选相关状态
const selectedRowKeys = ref<(string | number)[]>([]);
const selectedRows = ref<WagesItem[]>([]);
// 搜索参数
const monthFormat = 'YYYY-MM';
const searchParams = reactive<any>({
nickName: '',
chineseName: '',
companyId: undefined,
dateTime: dayjs().format(monthFormat),
wagesStatus: '',
distributionStatus: '',
page: 1,
pageSize: 10,
});
// 表格行选择配置
const rowSelection = computed(() => {
return {
selectedRowKeys: selectedRowKeys.value,
onChange: (keys: (string | number)[], rows: WagesItem[]) => {
selectedRowKeys.value = keys;
selectedRows.value = rows;
},
preserveSelectedRowKeys: true,
};
});
// 清除所有选择
const onClearSelected = () => {
selectedRowKeys.value = [];
selectedRows.value = [];
};
// 表格行自定义样式
const customRow = (record: WagesItem) => {
return {
style: {
fontSize: '14px',
},
};
};
// 定义表格列
const columns = [
{ title: '昵称', dataIndex: 'nickName', key: 'nickName', width: 80, fixed: 'left', className: 'column-left-fixed' },
{ title: '姓名', dataIndex: 'chineseName', key: 'chineseName', width: 80, fixed: 'left', className: 'column-left-fixed' },
{ title: '公司', dataIndex: 'companyName', key: 'companyName', width: 120, fixed: 'left', className: 'column-left-fixed' },
{
title: '应发工资',
className: 'column-group-header salary-payable',
children: [
{ title: '基本工资', dataIndex: 'basicWages', key: 'basicWages', width: 90, className: 'salary-payable-item' },
{ title: '岗位津贴', dataIndex: 'postAllowance', key: 'postAllowance', width: 90, className: 'salary-payable-item' },
{ title: '管理岗位津贴', dataIndex: 'managementAllowance', key: 'managementAllowance', width: 120, className: 'salary-payable-item' },
{ title: '话费补贴', dataIndex: 'phoneAllowance', key: 'phoneAllowance', width: 90, className: 'salary-payable-item' },
{ title: '餐补', dataIndex: 'mealAllowance', key: 'mealAllowance', width: 80, className: 'salary-payable-item' },
{ title: '交通补贴', dataIndex: 'transportationAllowance', key: 'transportationAllowance', width: 90, className: 'salary-payable-item' },
{ title: '全勤奖', dataIndex: 'attendanceAllowance', key: 'attendanceAllowance', width: 80, className: 'salary-payable-item' },
{ title: '绩效部分', dataIndex: 'performanceAllowance', key: 'performanceAllowance', width: 90, className: 'salary-payable-item' },
{ title: '提成', dataIndex: 'commissionPrice', key: 'commissionPrice', width: 80, className: 'salary-payable-item' },
{ title: '奖金', dataIndex: 'bonusPrice', key: 'bonusPrice', width: 80, className: 'salary-payable-item' },
{ title: '应扣工资', dataIndex: 'deductibleSalaryPrice', key: 'deductibleSalaryPrice', width: 90, className: 'salary-payable-item' },
{ title: '其他扣款', dataIndex: 'otherDeductionsPrice', key: 'otherDeductionsPrice', width: 90, className: 'salary-payable-item' },
{ title: '应发工资', dataIndex: 'salaryPrice', key: 'salaryPrice', width: 90, className: 'salary-payable-total' },
]
},
{
title: '个人承担社保公积金',
className: 'column-group-header personal-insurance',
children: [
{ title: '个人养老保险', dataIndex: 'personalPensionInsurance', key: 'personalPensionInsurance', width: 120, className: 'personal-insurance-item' },
{ title: '个人医疗保险', dataIndex: 'personalPensionMedicalInsurance', key: 'personalPensionMedicalInsurance', width: 120, className: 'personal-insurance-item' },
{ title: '个人失业保险', dataIndex: 'personalPensionUnemploymentInsurance', key: 'personalPensionUnemploymentInsurance', width: 120, className: 'personal-insurance-item' },
{ title: '个人大额医疗', dataIndex: 'personalPensionLargeScaleMedicalInsurance', key: 'personalPensionLargeScaleMedicalInsurance', width: 120, className: 'personal-insurance-item' },
{ title: '个人公积金', dataIndex: 'personalPensionProvidentFundInsurance', key: 'personalPensionProvidentFundInsurance', width: 120, className: 'personal-insurance-item' },
{ title: '个人合计', dataIndex: 'individualTotal', key: 'individualTotal', width: 90, className: 'personal-insurance-total' },
]
},
{
title: '公司承担社保公积金',
className: 'column-group-header company-insurance',
children: [
{ title: '公司养老保险', dataIndex: 'companyInsurance', key: 'companyInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司医疗保险', dataIndex: 'companyMedicalInsurance', key: 'companyMedicalInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司失业保险', dataIndex: 'companyUnemploymentInsurance', key: 'companyUnemploymentInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司工伤保险', dataIndex: 'companyEmploymentInjuryInsurance', key: 'companyEmploymentInjuryInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司生育保险', dataIndex: 'companyMaternityInsurance', key: 'companyMaternityInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司大额医疗', dataIndex: 'companyLargeScaleMedicalInsurance', key: 'companyLargeScaleMedicalInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司公积金', dataIndex: 'companyProvidentFundInsurance', key: 'companyProvidentFundInsurance', width: 120, className: 'company-insurance-item' },
{ title: '公司合计', dataIndex: 'companyTotal', key: 'companyTotal', width: 90, className: 'company-insurance-total' },
]
},
{ title: '个人所得税', dataIndex: 'tax', key: 'tax', width: 120, className: 'other-item' },
{ title: '实发金额', dataIndex: 'actualSalaryPrice', key: 'actualSalaryPrice', width: 100, className: 'other-item' },
{ title: '总成本', dataIndex: 'totalCost', key: 'totalCost', width: 90, className: 'other-item' },
{ title: '审核状态', dataIndex: 'wagesStatus', key: 'wagesStatus', width: 90, className: 'other-item' },
{ title: '发放状态', dataIndex: 'distributionStatus', key: 'distributionStatus', width: 90, className: 'other-item' },
{ title: '操作', dataIndex: 'action', key: 'action', width: 240, fixed: 'right', className: 'column-right-fixed' },
];
// 定义申请权限表单字段
const getApplySchema = () => [
{
field: 'basicWages',
label: '基本工资',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'postAllowance',
label: '岗位津贴',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'managementAllowance',
label: '管理岗位津贴',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'phoneAllowance',
label: '话费补贴',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'mealAllowance',
label: '餐补',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'transportationAllowance',
label: '交通补贴',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'attendanceAllowance',
label: '全勤奖',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'performanceAllowance',
label: '绩效部分',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'wages',
label: '社保配置',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'commissionPrice',
label: '提成',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'bonusPrice',
label: '奖金',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'deductibleSalaryPrice',
label: '应扣工资',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'otherDeductionsPrice',
label: '其他扣款',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
{
field: 'tax',
label: '个人所得税',
component: 'Switch',
componentProps: {
checkedValue: 'UN_LOCKED',
unCheckedValue: 'LOCKED',
},
colProps: {
span: 8,
},
},
];
// 注册申请权限表单
const [registerApplyForm, { getFieldsValue: getApplyFieldsValue }] = useForm({
labelWidth: 180,
schemas: getApplySchema(),
showActionButtonGroup: false,
actionColOptions: {
span: 24,
},
});
// 注册申请权限抽屉
const [registerApplyDrawer, { openDrawer: openApplyDrawer, closeDrawer: closeApplyDrawer }] = useDrawer();
// 注册申请理由模态框
const [registerApproveReason, { openModal: openApproveReasonModal }] = useModal();
// 格式化日期为YYYY-MM格式
function formatYearMonth(date: any): string {
if (!date) return getCurrentYearMonth();
if (typeof date === 'string' && /^\d{4}-\d{2}$/.test(date)) {
return date;
}
let dateObj;
try {
dateObj = new Date(date);
if (isNaN(dateObj.getTime())) {
return getCurrentYearMonth();
}
} catch (e) {
return getCurrentYearMonth();
}
const year = dateObj.getFullYear();
const month = String(dateObj.getMonth() + 1).padStart(2, '0');
return `${year}-${month}`;
}
// 获取当前年月
function getCurrentYearMonth(): string {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
return `${year}-${month}`;
}
// 获取审核状态文本
function getWagesStatusText(status: string): string {
if (status === undefined || status === null || status === '') {
return '未创建';
}
const statusMap: Record<string, string> = {
'0': '待审核',
'10': '已审核',
'20': '已驳回',
};
return statusMap[status] || '未创建';
}
// 获取发放状态文本
function getDistributionStatusText(status: string): string {
const statusMap: Record<string, string> = {
'20': '未发放',
'10': '已发放',
};
return statusMap[status] || status;
}
// 加载公司数据
const loadCompanyOptions = async () => {
try {
const result = await defHttp.post<any[]>({
url: '/order/erp/jobs/all'
});
if (Array.isArray(result)) {
companyOptions.value = result;
}
} catch (error) {
console.error('加载公司数据失败:', error);
}
};
// 加载数据
const loadData = async () => {
try {
loading.value = true;
const params: WagesParams = {
page: pagination.current,
pageSize: pagination.pageSize,
dateTime: formatYearMonth(searchParams.dateTime),
};
if (searchParams.nickName) params.nickName = searchParams.nickName;
if (searchParams.chineseName) params.chineseName = searchParams.chineseName;
if (searchParams.companyId) params.companyId = searchParams.companyId;
if (searchParams.wagesStatus) params.wagesStatus = searchParams.wagesStatus;
if (searchParams.distributionStatus) params.distributionStatus = searchParams.distributionStatus;
const result = await getWagesListByPage({
...params,
// 强制转换为数字确保API正确处理
page: Number(params.page),
pageSize: Number(params.pageSize)
});
if (result && result.records) {
// 检查记录中是否包含wagesName字段
if (result.records.length > 0) {
const sampleRecord = result.records[0];
console.log('记录样例:', {
wagesId: sampleRecord.wagesId,
userId: sampleRecord.userId,
chineseName: sampleRecord.chineseName,
wagesName: sampleRecord.wagesName,
dateTime: sampleRecord.dateTime,
});
}
tableData.value = [...result.records]; // 使用新数组确保Vue更新视图
pagination.total = result.total || 0;
} else {
tableData.value = [];
pagination.total = 0;
}
} catch (error) {
console.error('加载数据失败:', error);
message.error('加载数据失败,请稍后重试');
tableData.value = [];
pagination.total = 0;
} finally {
loading.value = false;
}
};
// 处理表格分页变化
const handleTableChange = (pag: any) => {
pagination.current = pag.current;
pagination.pageSize = pag.pageSize;
loadData();
};
// 处理搜索表单提交
const handleSearch = () => {
pagination.current = 1;
loadData();
};
// 重置搜索条件
const handleReset = () => {
Object.assign(searchParams, {
nickName: '',
chineseName: '',
companyId: undefined,
dateTime: dayjs().format(monthFormat),
wagesStatus: '',
distributionStatus: '',
});
pagination.current = 1;
loadData();
};
// 编辑记录
const handleEdit = (record: WagesItem, dateTime: string) => {
openDrawer(true, {
record,
isUpdate: true,
dateTime: dateTime,
});
};
// 删除记录
const handleDelete = async (record: WagesItem) => {
try {
// 使用新的删除接口
await defHttp.post({
url: '/order/erp/users/oldWages/delete',
data: {
userId: record.userId,
dateTime: searchParams.dateTime
}
});
message.success('删除成功');
if (selectedRowKeys.value.includes(record.userId)) {
selectedRowKeys.value = selectedRowKeys.value.filter(key => key !== record.userId);
selectedRows.value = selectedRows.value.filter(row => row.userId !== record.userId);
}
loadData();
} catch (error) {
console.error('删除失败', error);
message.error('删除失败');
}
};
// 审核通过
const handleApprove = async (record: WagesItem) => {
try {
await approveWages(record.wagesId);
message.success('审核通过');
loadData();
} catch (error) {
console.error('审核操作失败', error);
message.error('审核操作失败');
}
};
// 驳回
const handleReject = async (record: WagesItem) => {
try {
await rejectWages(record.wagesId);
message.success('驳回成功');
loadData();
} catch (error) {
console.error('驳回操作失败', error);
message.error('驳回操作失败');
}
};
// 发放
const handleDistribute = async (record: WagesItem) => {
try {
await distributeWages(record.wagesId);
message.success('发放成功');
loadData();
} catch (error) {
console.error('发放操作失败', error);
message.error('发放操作失败');
}
};
// 操作成功回调
const handleSuccess = () => {
loadData();
};
// 设置审核状态(批量)
const handleSetWagesStatus = async ({ key }) => {
if (selectedRowKeys.value.length === 0) {
message.warning('请先选择需要设置的记录');
return;
}
try {
// 获取用户IDs
const userIds = selectedRows.value.map(row => row.userId);
await defHttp.post({
url: '/order/erp/users/oldWages/setWagesStatus',
data: {
userIds: userIds,
dateTime: searchParams.dateTime,
wagesStatus: key
}
});
message.success('设置审核状态成功');
onClearSelected();
loadData();
} catch (error) {
console.error('设置审核状态失败:', error);
message.error('设置审核状态失败,请稍后重试');
}
};
// 设置发放状态(批量)
const handleSetDistributionStatus = async ({ key }) => {
if (selectedRowKeys.value.length === 0) {
message.warning('请先选择需要设置的记录');
return;
}
try {
// 获取用户IDs
const userIds = selectedRows.value.map(row => row.userId);
await defHttp.post({
url: '/order/erp/users/oldWages/setDistributionStatus',
data: {
userIds: userIds,
dateTime: searchParams.dateTime,
distributionStatus: key
}
});
message.success('设置发放状态成功');
onClearSelected();
loadData();
} catch (error) {
console.error('设置发放状态失败:', error);
message.error('设置发放状态失败,请稍后重试');
}
};
// 导出工资记录
const handleExport = async () => {
if (selectedRowKeys.value.length === 0) {
message.warning('请先选择需要导出的记录');
return;
}
// 获取用户IDs
const ids = selectedRows.value.map(row => row.userId);
loading.value = true;
message.loading({content:'正在导出数据,请稍候...',key:'exporting',duration:0});
const token = userStore.getToken;
// 方法一:直接通过axios请求二进制数据
axios
.post(
'basic-api/order/erp/users/oldWages/export',
{
ids: ids,
dateTime: searchParams.dateTime,
isExport: true
},
{
responseType: 'blob' ,
headers: {
Authorization: `${token}`, // 去掉引号
},
}
)
.then((response) => {
const blob = new Blob([response.data], { type: 'application/octet-stream' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = `工资表_${searchParams.dateTime}.xlsx`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
message.success({content:'导出成功',key:'exporting'});
})
.catch(async (error) => {
console.error('导出失败:', error);
if (error.response && error.response.data instanceof Blob) {
const text = await error.response.data.text();
console.error('服务器返回的错误信息:', text);
}
message.error({ content: '导出失败,请稍后重试', key: 'exporting' });
})
.finally(() => {
loading.value = false;
});
};
// 处理工资汇总
const handleSalarySummary = () => {
if (selectedRowKeys.value.length === 0) {
message.warning('请先选择需要汇总的记录');
return;
}
// 清空已选择的年月
selectedDateTimes.value = [];
// 准备年份选项 - 从当前年份往前5年
const now = new Date();
const currentYear = now.getFullYear();
const years = [];
for (let i = 0; i < 5; i++) {
years.push((currentYear - i).toString());
}
availableYears.value = years;
// 先设置年份
selectedYear.value = currentYear.toString(); // 默认选中当前年份
// 准备一个默认月份(当前月份)
const currentMonth = String(now.getMonth() + 1).padStart(2, '0');
// 再设置月份 - 这样会通过watch触发updateSelectedDateTimes
selectedMonths.value = [currentMonth];
dateSelectVisible.value = true;
};
// 更新已选年月列表
const updateSelectedDateTimes = () => {
const year = selectedYear.value;
if (!year) {
return;
}
// 清除当前年份的选择
selectedDateTimes.value = selectedDateTimes.value.filter(date => !date.startsWith(year));
// 只有当有选择的月份时才添加新的年月组合
if (selectedMonths.value.length > 0) {
// 添加新选择的年月
selectedMonths.value.forEach(month => {
const formattedDate = `${year}-${month}`;
if (!selectedDateTimes.value.includes(formattedDate)) {
selectedDateTimes.value.push(formattedDate);
}
});
}
};
// 处理日期选择确认
const handleDateSelectOk = async () => {
if (selectedDateTimes.value.length === 0) {
message.warning('请至少选择一个年月份');
return;
}
dateSelectVisible.value = false;
summaryLoading.value = true;
summaryResultVisible.value = true;
try {
// 获取用户IDs
const ids = selectedRows.value.map(row => row.userId);
// 调用汇总接口
const result = await defHttp.post({
url: '/order/erp/users/oldWages/count',
data: {
ids: ids,
dateTimes: selectedDateTimes.value
}
});
if (result) {
// 更新结果数据
summaryData.value = {
monthlyCount: result.monthlyCount || 0,
personCount: result.personCount || 0,
actualSalary: result.actualSalary || 0,
insuranceSalary: result.insuranceSalary || 0,
totalMonthlyWorkCost: result.totalMonthlyWorkCost || 0,
averageMonthlyWorkCost: result.averageMonthlyWorkCost || 0
};
} else {
message.warning('未获取到汇总数据');
summaryData.value = {
monthlyCount: 0,
personCount: 0,
actualSalary: 0,
insuranceSalary: 0,
totalMonthlyWorkCost: 0,
averageMonthlyWorkCost: 0
};
}
} catch (error) {
console.error('汇总数据失败:', error);
message.error('汇总数据失败,请稍后重试');
summaryResultVisible.value = false;
} finally {
summaryLoading.value = false;
}
};
// 处理日期选择取消
const handleDateSelectCancel = () => {
dateSelectVisible.value = false;
selectedDateTimes.value = [];
selectedMonths.value = [];
};
// 处理汇总结果关闭
const handleSummaryResultClose = () => {
summaryResultVisible.value = false;
};
// 处理申请权限
const handleApplyPermission = (record: WagesItem) => {
currentApplyRecord.value = { ...record };
openApplyDrawer(true);
};
// 处理申请权限提交
const handleApplySubmit = async () => {
try {
const fieldValues = getApplyFieldsValue();
selectedApplyFields.value = fieldValues;
closeApplyDrawer();
// 打开申请理由模态框
openApproveReasonModal(true, {
fieldValues: selectedApplyFields.value,
dateTime: searchParams.dateTime,
userId: currentApplyRecord.value?.userId,
apiUrl: '/order/erp/users/oldWages/applyEditFields'
});
} catch (error) {
console.error('获取表单数据失败:', error);
message.error('获取表单数据失败');
}
};
// 处理申请成功回调
const handleApproveSuccess = () => {
selectedApplyFields.value = {};
currentApplyRecord.value = null;
message.success('申请提交成功');
};
// 组件挂载后自动加载数据
onMounted(() => {
loadCompanyOptions();
loadData();
});
// 监听年份和月份选择的变更
watch([selectedYear, selectedMonths], () => {
updateSelectedDateTimes();
});
// 单独监听年份变化,清空月份选择
watch(selectedYear, (newYear, oldYear) => {
if (newYear !== oldYear) {
if (selectedMonths.value.length > 0) {
// 先存储选择的月份数量
const monthCount = selectedMonths.value.length;
// 清空月份选择
selectedMonths.value = [];
// 显示提示信息
message.info(`已切换至${newYear}年,请重新选择月份`);
}
}
});
// 格式化数字为两位小数
const formatNumber = (value: any): string => {
if (value === null || value === undefined || value === '') {
return '';
}
const num = parseFloat(value);
if (isNaN(num)) {
return '';
}
return num.toFixed(2);
};
// 判断是否为数值类型的列
const isNumericColumn = (dataIndex: string): boolean => {
const numericColumns = [
'basicWages', 'postAllowance', 'managementAllowance', 'phoneAllowance',
'mealAllowance', 'transportationAllowance', 'attendanceAllowance',
'performanceAllowance', 'commissionPrice', 'bonusPrice',
'deductibleSalaryPrice', 'otherDeductionsPrice', 'salaryPrice',
'personalPensionInsurance', 'personalPensionMedicalInsurance',
'personalPensionUnemploymentInsurance', 'personalPensionLargeScaleMedicalInsurance',
'personalPensionProvidentFundInsurance', 'individualTotal',
'companyInsurance', 'companyMedicalInsurance', 'companyUnemploymentInsurance',
'companyEmploymentInjuryInsurance', 'companyMaternityInsurance',
'companyLargeScaleMedicalInsurance', 'companyProvidentFundInsurance',
'companyTotal', 'tax', 'actualSalaryPrice', 'totalCost'
];
return numericColumns.includes(dataIndex);
};
return {
loading,
tableData,
columns,
pagination,
searchParams,
monthFormat,
companyOptions,
registerDrawer,
selectedRowKeys,
selectedRows,
rowSelection,
customRow,
onClearSelected,
loadData,
handleTableChange,
handleSearch,
handleReset,
handleEdit,
handleDelete,
handleSuccess,
handleApprove,
handleReject,
handleDistribute,
getWagesStatusText,
getDistributionStatusText,
formatNumber,
isNumericColumn,
handleSetWagesStatus,
handleSetDistributionStatus,
handleExport,
handleSalarySummary,
handleDateSelectOk,
handleDateSelectCancel,
handleSummaryResultClose,
dateSelectVisible,
summaryResultVisible,
summaryLoading,
selectedDateTimes,
availableDateTimes,
summaryData,
selectedYear,
selectedMonths,
availableYears,
formattedSelectedDates,
removeSelectedDate,
registerApplyForm,
getApplyFieldsValue,
registerApplyDrawer,
openApplyDrawer,
closeApplyDrawer,
registerApproveReason,
openApproveReasonModal,
handleApplyPermission,
handleApplySubmit,
handleApproveSuccess,
currentApplyRecord,
selectedApplyFields
};
},
});
</script>
<style lang="less" scoped>
.payroll-container {
padding: 16px;
.search-form {
margin-bottom: 16px;
background: #fff;
padding: 16px;
border-radius: 2px;
}
.toolbar {
margin-bottom: 16px;
margin-top: 16px;
.selected-alert {
margin-bottom: 16px;
}
.batch-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 8px;
@media (max-width: 576px) {
button {
margin-bottom: 8px;
}
}
}
}
.table-container {
background: #fff;
padding: 16px;
border-radius: 2px;
overflow-x: auto;
}
.ml-2 {
margin-left: 8px;
}
.summary-result {
max-height: 600px;
overflow-y: auto;
:deep(.ant-descriptions-item-label) {
width: 180px;
font-weight: bold;
background-color: #f5f5f5;
}
:deep(.ant-descriptions-item-content) {
font-size: 16px;
text-align: right;
padding-right: 16px;
}
}
.year-selection, .month-selection, .selected-dates {
margin-bottom: 16px;
p {
margin-bottom: 8px;
font-weight: 500;
}
}
.year-selection {
:deep(.ant-radio-button-wrapper) {
margin-right: 8px;
margin-bottom: 8px;
}
}
.month-selection {
:deep(.ant-checkbox-wrapper) {
margin-bottom: 8px;
}
}
.selected-dates {
.tag-container {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
:deep(.date-tag) {
font-size: 14px;
padding: 6px 10px;
margin-bottom: 8px;
.anticon-close {
font-size: 12px;
margin-left: 6px;
}
}
}
:deep(.ant-table) {
.column-group-header {
background-color: #e6f7ff;
font-weight: 600;
}
.column-left-fixed, .column-right-fixed {
background-color: #fafafa;
}
.salary-payable {
background-color: #e6f7ff;
}
.personal-insurance {
background-color: #f6ffed;
}
.company-insurance {
background-color: #fff7e6;
}
.salary-payable-total, .personal-insurance-total, .company-insurance-total {
font-weight: 600;
background-color: #f5f5f5;
}
}
// 年月份选择对话框样式
:deep(.date-select-modal) {
.ant-modal-content {
.ant-modal-body {
padding: 24px;
}
}
}
.selection-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 20px;
}
.section-title {
font-size: 15px;
font-weight: 500;
margin-bottom: 12px;
}
.year-selection, .month-selection, .selected-dates {
margin-bottom: 20px;
}
.year-selection {
:deep(.ant-radio-group) {
width: 100%;
display: flex;
flex-wrap: wrap;
}
:deep(.ant-radio-button-wrapper) {
height: 40px;
line-height: 38px;
padding: 0 16px;
font-size: 14px;
margin-right: 12px;
margin-bottom: 12px;
&.ant-radio-button-wrapper-checked {
font-weight: 600;
}
}
}
.month-selection {
:deep(.month-checkbox-group) {
width: 100%;
}
:deep(.ant-checkbox-wrapper) {
font-size: 14px;
margin-bottom: 12px;
.ant-checkbox {
top: 0.2em;
&-inner {
width: 18px;
height: 18px;
}
}
&.ant-checkbox-wrapper-checked {
font-weight: 600;
}
}
}
.selected-dates {
.tag-container {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
:deep(.date-tag) {
font-size: 14px;
padding: 6px 10px;
margin-bottom: 8px;
.anticon-close {
font-size: 12px;
margin-left: 6px;
}
}
}
}
// 申请权限抽屉样式
:deep(.apply-permission-drawer) {
.ant-drawer-content {
position: fixed;
z-index: 10;
}
}
</style>