PayrollModal.vue
31.7 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
<template>
<BasicDrawer
v-bind="$attrs"
@register="registerDrawer"
:title="getTitle"
@ok="handleSubmit"
width="40%"
showFooter
:closable="true"
>
<BasicForm @register="registerForm" />
</BasicDrawer>
</template>
<script lang="ts">
import { defineComponent, ref, computed, unref, nextTick } from 'vue';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './payroll.data';
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
export default defineComponent({
name: 'PayrollModal',
components: { BasicDrawer, BasicForm },
emits: ['success', 'register'],
setup(_, { emit }) {
const { createMessage } = useMessage();
const isUpdate = ref(true);
const wagesId = ref('');
const userId = ref('');
const insuranceConfigOptions = ref<any[]>([]);
const dateYear = ref('');
// 获取社保配置列表
async function loadInsuranceConfig(year: string) {
try {
const res = await defHttp.post({
url: '/order/erp/system_setting/query_list',
params: {
settingValue: year,
settingType: [70, 71, 72, 73]
},
});
if (res && Array.isArray(res)) {
// 转换为下拉选项格式
const options = res.map(item => {
// 构建选项标签: "五险一金-特殊(2025)"
const label = `五险一金-${item.relationName}(${item.settingValue})`;
// 使用社保配置的ID作为value,以便在选择时可以获取完整的配置数据
// 并在提交时可以将此ID作为wagesId发送给后端
return {
label: label,
value: item.id,
data: item
};
});
insuranceConfigOptions.value = options;
// 更新表单组件选项
updateSchema([
{
field: 'socialSecurityConfig',
componentProps: {
options: insuranceConfigOptions.value,
onChange: handleInsuranceConfigChange,
},
},
]);
} else {
console.log('社保配置数据不是数组或为空');
}
} catch (error) {
console.error('加载社保配置出错:', error);
createMessage.error('加载社保配置失败');
}
}
// 处理社保配置选择变更
function handleInsuranceConfigChange(value: string) {
if (!value) return;
// 检查是否是字符串值而不是选项的值
// 只有当值是数字ID(从下拉列表选择的选项)时才处理
if (typeof value === 'string' && (isNaN(Number(value)) || !Number.isInteger(Number(value)))) {
return;
}
// 找到选中的配置选项(用户必须从列表中选择)
const selectedOption = insuranceConfigOptions.value.find(item => item.value === value);
if (!selectedOption) {
console.log('未找到选中的配置选项,不填充数据');
return;
}
if (!selectedOption.data) {
console.log('选中的配置选项数据为空');
return;
}
// 获取relationValue
const relationValue = selectedOption.data.relationValue;
// 检查relationValue是否存在
if (!relationValue) {
console.log('relationValue不存在');
return;
}
try {
// 解析社保配置JSON
let configData;
if (typeof relationValue === 'string') {
configData = JSON.parse(relationValue);
} else if (typeof relationValue === 'object') {
// 如果已经是对象,则直接使用
configData = relationValue;
} else {
console.log('relationValue格式不正确:', typeof relationValue);
return;
}
// 填充表单字段,确保处理null值
const filledValues = {
// 个人社保公积金字段
personalPensionInsurance: configData.personalPensionInsurance || 0,
personalPensionMedicalInsurance: configData.personalPensionMedicalInsurance || 0,
personalPensionUnemploymentInsurance: configData.personalPensionUnemploymentInsurance || 0,
personalPensionLargeScaleMedicalInsurance: configData.personalPensionLargeScaleMedicalInsurance || 0,
personalPensionProvidentFundInsurance: configData.personalPensionProvidentFundInsurance || 0,
// 公司社保公积金字段
companyInsurance: configData.companyInsurance || 0,
companyMedicalInsurance: configData.companyMedicalInsurance || 0,
companyUnemploymentInsurance: configData.companyUnemploymentInsurance || 0,
companyEmploymentInjuryInsurance: configData.companyEmploymentInjuryInsurance || 0,
companyMaternityInsurance: configData.companyMaternityInsurance || 0,
companyLargeScaleMedicalInsurance: configData.companyLargeScaleMedicalInsurance || 0,
companyProvidentFundInsurance: configData.companyProvidentFundInsurance || 0,
};
// 在设置表单值前确保所有字段为数字类型
Object.keys(filledValues).forEach(key => {
if (filledValues[key] === null || filledValues[key] === undefined) {
filledValues[key] = 0;
} else if (typeof filledValues[key] !== 'number') {
filledValues[key] = parseFloat(filledValues[key]) || 0;
}
});
// 更新表单值
setFieldsValue(filledValues);
// 先直接计算一次
calculateTotals();
// 使用多层nextTick确保视图完全更新后再次计算
nextTick(() => {
nextTick(() => {
calculateTotals();
});
});
} catch (error) {
console.error('解析社保配置数据出错:', error);
createMessage.error('应用社保配置失败');
}
}
const [registerForm, { resetFields, setFieldsValue, validate, getFieldsValue, updateSchema, getSchema }] = useForm({
labelWidth: 100,
baseColProps: { span: 24 },
schemas: formSchema,
showActionButtonGroup: false,
labelCol: { span: 6 },
wrapperCol: { span: 18 },
rowProps: { gutter: 24 },
});
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
resetFields();
setDrawerProps({ confirmLoading: false });
isUpdate.value = !!data?.isUpdate;
// 定义需要根据月份控制编辑状态的字段列表
const controlledFields = [
'basicWages', // 基本工资
'postAllowance', // 岗位津贴
'managementAllowance', // 管理岗位津贴
'phoneAllowance', // 话费补贴
'mealAllowance', // 餐补
'transportationAllowance', // 交通补贴
'attendanceAllowance', // 全勤奖
'performanceAllowance', // 绩效
'socialSecurityConfig' // 社保配置
];
if (unref(isUpdate)) {
// 记录原始ID,用于提交时判断是否修改了社保配置
wagesId.value = data.record.wagesId;
userId.value = data.record.userId;
// 获取年份和月份
const dateTime = data.dateTime || data.record.dateTime || '';
const year = dateTime.split('-')[0] || new Date().getFullYear().toString();
const month = dateTime.split('-')[1] || String(new Date().getMonth() + 1).padStart(2, '0');
dateYear.value = dateTime;
// 精确判断是否为当前月份
const now = new Date();
const currentYear = now.getFullYear().toString();
const currentMonth = String(now.getMonth() + 1).padStart(2, '0');
const isCurrentMonth = (year === currentYear && month === currentMonth);
// 获取当前记录的审核状态和字段权限信息
const currentRecord = data.record || {};
const wagesStatus = currentRecord.wagesStatus;
const fieldPermissions = currentRecord.userOldSalaryFieldVO || {};
// 更新字段状态,当前月份时禁用指定字段,非当前月份时可编辑
// 同时根据审核状态和字段权限进行额外控制
const updatedSchemas = controlledFields.map(field => {
// 判断当前字段是否应该被权限禁用
let shouldDisableByPermission = false;
// 如果审核状态为10,则根据字段权限判断是否禁用
if (wagesStatus === 10) {
const fieldKey = getFieldPermissionKey(field);
if (fieldKey && fieldPermissions[fieldKey] === 'LOCKED') {
shouldDisableByPermission = true;
}
}
// 最终的禁用状态:要么因为是当前月份,要么因为权限被锁定
const finalDisabled = isCurrentMonth || shouldDisableByPermission;
return {
field,
dynamicDisabled: finalDisabled
};
});
// 处理需要权限控制的可编辑字段
const editableFields = ['commissionPrice', 'bonusPrice', 'deductibleSalaryPrice', 'otherDeductionsPrice', 'tax'];
const editableFieldSchemas = editableFields.map(field => {
// 判断当前字段是否应该被权限禁用
let shouldDisableByPermission = false;
// 如果审核状态为10,则根据字段权限判断是否禁用
if (wagesStatus === 10) {
const fieldKey = getFieldPermissionKey(field);
if (fieldKey && fieldPermissions[fieldKey] === 'LOCKED') {
shouldDisableByPermission = true;
}
}
return {
field,
componentProps: {
disabled: shouldDisableByPermission,
}
};
});
updateSchema([...updatedSchemas, ...editableFieldSchemas]);
// 加载社保配置选项
await loadInsuranceConfig(year);
// 设置表单字段值
const formValues = {
...data.record,
};
// 处理wagesName直接显示,但不反向查找匹配
if (data.record.wagesName) {
// 只显示wagesName,不尝试匹配和选中选项
formValues.socialSecurityConfig = data.record.wagesName;
// 判断社保配置字段是否应该被权限禁用
let socialSecurityDisabled = isCurrentMonth;
if (wagesStatus === 10) {
const fieldKey = getFieldPermissionKey('socialSecurityConfig');
if (fieldKey && fieldPermissions[fieldKey] === 'LOCKED') {
socialSecurityDisabled = true;
}
}
// 更新社保配置选择框组件,显示为文本输入框
updateSchema([
{
field: 'socialSecurityConfig',
componentProps: {
options: insuranceConfigOptions.value,
onChange: handleInsuranceConfigChange,
mode: undefined,
showSearch: true,
placeholder: socialSecurityDisabled ? (isCurrentMonth ? '当前月份不可修改社保配置' : '该字段已被锁定,无法编辑') : '请选择社保配置',
disabled: socialSecurityDisabled
},
},
]);
} else {
console.log('记录中没有wagesName值');
// 判断社保配置字段是否应该被权限禁用
let socialSecurityDisabled = isCurrentMonth;
if (wagesStatus === 10) {
const fieldKey = getFieldPermissionKey('socialSecurityConfig');
if (fieldKey && fieldPermissions[fieldKey] === 'LOCKED') {
socialSecurityDisabled = true;
}
}
// 提供默认提示文本
// 更新社保配置选择框组件
updateSchema([
{
field: 'socialSecurityConfig',
componentProps: {
options: insuranceConfigOptions.value,
onChange: handleInsuranceConfigChange,
mode: undefined,
showSearch: true,
placeholder: socialSecurityDisabled ? (isCurrentMonth ? '请在员工档案中配置五险一金配置' : '该字段已被锁定,无法编辑') : '',
disabled: socialSecurityDisabled
},
},
]);
}
// 先设置表单字段值
setFieldsValue(formValues);
// 使用两层nextTick确保DOM完全更新后再计算
nextTick(() => {
nextTick(() => {
calculateTotals();
});
});
} else {
// 新增时设置默认值
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
// 新增模式默认使用当前月份,所以禁用相关字段
const updatedSchemas = controlledFields.map(field => ({
field,
dynamicDisabled: true // 新增且为当前月份时禁用字段
}));
updateSchema(updatedSchemas);
// 加载社保配置选项
await loadInsuranceConfig(year.toString());
// 额外更新社保配置框的组件属性
updateSchema([
{
field: 'socialSecurityConfig',
componentProps: {
options: insuranceConfigOptions.value,
onChange: handleInsuranceConfigChange,
mode: undefined,
showSearch: true,
placeholder: '当前月份不可修改社保配置,请在员工档案中配置五险一金配置',
disabled: true
},
},
]);
setFieldsValue({
dateTime: `${year}-${month}`,
wagesStatus: '0',
distributionStatus: '0',
});
// 使用两层nextTick确保DOM完全更新后再计算
nextTick(() => {
nextTick(() => {
calculateTotals();
});
});
}
// 检查社保配置选项是否加载
// 设置监听字段变化,自动计算合计
setupFieldWatchers();
});
const getTitle = computed(() => (!unref(isUpdate) ? '新增工资记录' : '编辑工资记录'));
// 添加自动计算逻辑
// 添加计算合计金额的函数
function calculateTotals() {
try {
// 强制获取最新的表单值
const values = getFieldsValue();
if (!values) {
console.log('未获取到表单值,无法计算合计');
return;
}
// 确保所有需要计算的字段都有值,即使它们被禁用
// 对于被禁用的字段,getFieldsValue可能不返回它们的值,所以需要特别处理
const fieldsThatMightBeDisabled = [
'basicWages',
'postAllowance',
'managementAllowance',
'phoneAllowance',
'mealAllowance',
'transportationAllowance',
'attendanceAllowance',
'performanceAllowance'
];
// 检查并确保上述字段都有值,如果没有值则使用0
fieldsThatMightBeDisabled.forEach(field => {
if (values[field] === undefined || values[field] === null) {
values[field] = 0;
}
});
// 计算个人社保公积金合计
const personalFields = [
'personalPensionInsurance',
'personalPensionMedicalInsurance',
'personalPensionUnemploymentInsurance',
'personalPensionLargeScaleMedicalInsurance',
'personalPensionProvidentFundInsurance'
];
let individualTotal = 0;
personalFields.forEach(field => {
// 确保使用最新的字段值,强制转换为数值
const value = parseFloat(values[field] || 0);
if (!isNaN(value)) {
individualTotal += value;
}
});
// 计算公司社保公积金合计
const companyFields = [
'companyInsurance',
'companyMedicalInsurance',
'companyUnemploymentInsurance',
'companyEmploymentInjuryInsurance',
'companyMaternityInsurance',
'companyLargeScaleMedicalInsurance',
'companyProvidentFundInsurance'
];
let companyTotal = 0;
companyFields.forEach(field => {
// 确保使用最新的字段值,强制转换为数值
const value = parseFloat(values[field] || 0);
if (!isNaN(value)) {
companyTotal += value;
}
});
// 计算应发工资
const salaryFields = [
'basicWages',
'postAllowance',
'managementAllowance',
'phoneAllowance',
'mealAllowance',
'transportationAllowance',
'attendanceAllowance',
'performanceAllowance',
'commissionPrice',
'bonusPrice'
];
let salaryPrice = 0;
salaryFields.forEach(field => {
const value = parseFloat(values[field] || 0);
if (!isNaN(value)) {
salaryPrice += value;
}
});
// 减去扣款项
const deductionFields = [
'deductibleSalaryPrice',
'otherDeductionsPrice'
];
deductionFields.forEach(field => {
const value = parseFloat(values[field] || 0);
if (!isNaN(value)) {
salaryPrice -= value;
}
});
// 计算实发金额 = 应发工资 - 个人社保公积金合计 - 个人所得税
const tax = parseFloat(values.tax || 0);
const actualSalaryPrice = salaryPrice - individualTotal - (isNaN(tax) ? 0 : tax);
// 计算总成本 = 实发工资 + 公司社保公积金合计
const totalCost = actualSalaryPrice + companyTotal;
// 更新表单字段,确保每次都正确更新
const updatedValues = {
individualTotal: Number(individualTotal.toFixed(2)),
companyTotal: Number(companyTotal.toFixed(2)),
salaryPrice: Number(salaryPrice.toFixed(2)),
actualSalaryPrice: Number(actualSalaryPrice.toFixed(2)),
totalCost: Number(totalCost.toFixed(2))
};
// 立即更新表单字段值,使用同步方式,传入数值而非字符串
setFieldsValue(updatedValues);
} catch (error) {
console.error('计算合计金额时出错:', error);
}
}
// 设置字段监听
function setupFieldWatchers() {
// 监听所有可能影响计算的字段
const watchFields = [
// 个人社保公积金字段
'personalPensionInsurance',
'personalPensionMedicalInsurance',
'personalPensionUnemploymentInsurance',
'personalPensionLargeScaleMedicalInsurance',
'personalPensionProvidentFundInsurance',
// 公司社保公积金字段
'companyInsurance',
'companyMedicalInsurance',
'companyUnemploymentInsurance',
'companyEmploymentInjuryInsurance',
'companyMaternityInsurance',
'companyLargeScaleMedicalInsurance',
'companyProvidentFundInsurance',
// 薪资相关字段
'basicWages',
'postAllowance',
'managementAllowance',
'phoneAllowance',
'mealAllowance',
'transportationAllowance',
'attendanceAllowance',
'performanceAllowance',
'commissionPrice',
'bonusPrice',
'deductibleSalaryPrice',
'otherDeductionsPrice',
// 税收
'tax'
];
// 优化字段监听,确保实时响应
const updatedSchemas = watchFields.map(field => {
return {
field: field,
componentProps: {
onChange: (e: any) => {
// 直接触发计算,然后用nextTick确保视图更新
calculateTotals();
// 再次计算以确保准确性
nextTick(() => {
calculateTotals();
});
}
}
};
});
// 为日期字段添加特殊监听,当日期变更时更新字段禁用状态
updatedSchemas.push({
field: 'dateTime',
componentProps: {
onChange: (date: string) => {
if (!date) return;
// 解析年月
const [year, month] = date.split('-');
if (!year || !month) return;
// 更新日期引用
dateYear.value = date;
// 判断是否为当前月份
const now = new Date();
const currentYear = now.getFullYear().toString();
const currentMonth = String(now.getMonth() + 1).padStart(2, '0');
const isCurrentMonth = (year === currentYear && month === currentMonth);
// 定义需要控制的字段
const controlledFields = [
'basicWages',
'postAllowance',
'managementAllowance',
'phoneAllowance',
'mealAllowance',
'transportationAllowance',
'attendanceAllowance',
'performanceAllowance',
'socialSecurityConfig' // 增加社保配置字段
];
// 根据是否为当前月份更新字段禁用状态
const fieldSchemas = controlledFields.map(field => ({
field,
dynamicDisabled: isCurrentMonth
}));
updateSchema(fieldSchemas);
// 额外更新社保配置框的placeholder
updateSchema([
{
field: 'socialSecurityConfig',
componentProps: {
placeholder: isCurrentMonth ? '当前月份不可修改社保配置' : '请选择社保配置或在员工档案中配置五险一金',
},
},
]);
}
}
});
// 批量更新所有字段的schema
updateSchema(updatedSchemas);
// 使用两层nextTick确保所有组件都已经完全渲染和更新后再计算
nextTick(() => {
nextTick(() => {
calculateTotals();
});
});
}
async function handleSubmit() {
try {
// 提交前强制计算所有合计
calculateTotals();
// 使用多层nextTick确保获取最新计算结果
await nextTick();
await nextTick();
// 再次计算以确保准确性
calculateTotals();
// 最后一次等待确保视图更新完成
await nextTick();
// 获取表单数据
const values = await validate();
// 检查并确保禁用字段的值能正确提交
// 我们需要获取当前表单的完整值,包括禁用字段的值
const completeValues = getFieldsValue();
const fieldsToCheck = [
'basicWages',
'postAllowance',
'managementAllowance',
'phoneAllowance',
'mealAllowance',
'transportationAllowance',
'attendanceAllowance',
'performanceAllowance'
];
// 使用getFieldsValue获取的值补充禁用字段的值
fieldsToCheck.forEach(field => {
if ((values[field] === undefined || values[field] === null) &&
completeValues[field] !== undefined) {
values[field] = completeValues[field];
}
});
setDrawerProps({ confirmLoading: true });
// 添加必要的ID字段
if (unref(isUpdate)) {
// 先使用原始的wagesId
values.wagesId = unref(wagesId);
values.userId = unref(userId);
}
// 处理wagesName和wagesId
if (values.socialSecurityConfig) {
// 检查是否为选项的值(数字ID)
const selectedOption = insuranceConfigOptions.value.find(
option => option.value === values.socialSecurityConfig
);
if (selectedOption) {
// 如果是从下拉列表选择的选项,使用该选项的ID作为wagesId
values.wagesId = selectedOption.value; // 更新wagesId为社保配置的ID
values.wagesName = selectedOption.label;
} else {
// 如果不是从下拉列表选择的,使用原始值
// 这可能是后端返回的wagesName或用户手动输入的值
values.wagesName = values.socialSecurityConfig;
}
}
// 确保所有数字字段为数字类型
const numericFields = [
// 原有字段
'basicWages', 'postAllowance', 'managementAllowance', 'phoneAllowance',
'mealAllowance', 'transportationAllowance', 'attendanceAllowance',
'performanceAllowance', 'commissionPrice', 'bonusPrice',
'deductibleSalaryPrice', 'otherDeductionsPrice',
// 新增字段
'personalPensionInsurance', 'personalPensionMedicalInsurance',
'personalPensionUnemploymentInsurance', 'personalPensionLargeScaleMedicalInsurance',
'personalPensionProvidentFundInsurance', 'individualTotal',
'companyInsurance', 'companyMedicalInsurance', 'companyUnemploymentInsurance',
'companyEmploymentInjuryInsurance', 'companyMaternityInsurance',
'companyLargeScaleMedicalInsurance', 'companyProvidentFundInsurance',
'companyTotal', 'tax', 'actualSalaryPrice', 'totalCost', 'salaryPrice'
];
values.dateTime = dateYear.value;
numericFields.forEach(field => {
if (values[field] !== undefined && values[field] !== null) {
values[field] = Number(values[field]);
} else {
values[field] = 0;
}
});
// 修改API调用,使用/order/erp/users/oldWages/edit接口
await defHttp.post({
url: '/order/erp/users/oldWages/edit',
data: values,
});
createMessage.success('保存成功');
closeDrawer();
emit('success');
} catch (error) {
console.error('保存失败', error);
createMessage.error('保存失败');
} finally {
setDrawerProps({ confirmLoading: false });
}
}
// 获取字段权限对应的key
function getFieldPermissionKey(fieldName: string): string | null {
const fieldMapping: Record<string, string> = {
'basicWages': 'basicWages', // 基本工资
'postAllowance': 'postAllowance', // 岗位津贴
'managementAllowance': 'managementAllowance', // 管理岗位津贴
'phoneAllowance': 'phoneAllowance', // 话费补贴
'mealAllowance': 'mealAllowance', // 餐补
'transportationAllowance': 'transportationAllowance', // 交通补贴
'attendanceAllowance': 'attendanceAllowance', // 全勤奖
'performanceAllowance': 'performanceAllowance', // 绩效部分
'commissionPrice': 'commissionPrice', // 提成
'bonusPrice': 'bonusPrice', // 奖金
'deductibleSalaryPrice': 'deductibleSalaryPrice', // 应扣工资
'otherDeductionsPrice': 'otherDeductionsPrice', // 其他扣款
'tax': 'tax', // 个人所得税
'socialSecurityConfig': 'wages' // 社保配置
};
return fieldMapping[fieldName] || null;
}
return {
registerDrawer,
registerForm,
getTitle,
handleSubmit,
calculateTotals,
setupFieldWatchers,
loadInsuranceConfig,
handleInsuranceConfigChange,
};
},
});
</script>