tuqin
2 天以前 5b2222922a23a307a97204a01d7c2ca951855c6f
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
<script lang="ts" setup>
import type { HrmSalaryCalculationApi } from '#/api/hrm/salary/calculation';
 
import { computed, ref } from 'vue';
 
import { message, Modal, Form, FormItem, Input, InputNumber } from 'ant-design-vue';
 
import { updateSalaryCalculation } from '#/api/hrm/salary/calculation';
 
const emit = defineEmits(['success']);
 
const visible = ref(false);
const loading = ref(false);
/** 当前编辑的记录(含所有可编辑字段) */
const current = ref<Record<string, any>>({});
 
/** 收入项 */
const incomeFields = [
  { key: 'baseSalary', label: '基本工资' },
  { key: 'performanceSalary', label: '绩效工资' },
  { key: 'overtimePay', label: '加班费' },
  { key: 'mealAllowance', label: '餐补' },
  { key: 'transportAllowance', label: '交通补贴' },
  { key: 'otherAllowance', label: '其他补贴' },
];
 
/** 扣除项 */
const deductionFields = [
  { key: 'socialSecurityDeduction', label: '社保扣款' },
  { key: 'housingFundDeduction', label: '公积金扣款' },
  { key: 'taxDeduction', label: '个税扣款' },
  { key: 'otherDeduction', label: '其他扣款' },
  { key: 'leaveDeduction', label: '请假扣款' },
];
 
/** 实发工资(实时计算,与后端口径一致) */
const actualSalary = computed(() => {
  const num = (v: any) => (v === undefined || v === null || v === '' ? 0 : Number(v));
  const income = incomeFields.reduce((sum, f) => sum + num(current.value[f.key]), 0);
  const deduction = deductionFields.reduce((sum, f) => sum + num(current.value[f.key]), 0);
  return Number((income - deduction).toFixed(2));
});
 
function open(row: HrmSalaryCalculationApi.SalaryCalculation) {
  current.value = { ...row };
  visible.value = true;
}
 
async function handleOk() {
  loading.value = true;
  try {
    await updateSalaryCalculation({
      ...(current.value as HrmSalaryCalculationApi.SalaryCalculation),
      actualSalary: actualSalary.value,
    });
    message.success('修改成功');
    visible.value = false;
    emit('success');
  } finally {
    loading.value = false;
  }
}
 
defineExpose({ open });
</script>
 
<template>
  <Modal
    v-model:open="visible"
    :title="`修改薪酬核算${current.no ? ' - ' + current.no : ''}`"
    :width="760"
    :confirm-loading="loading"
    ok-text="保存"
    cancel-text="取消"
    @ok="handleOk"
  >
    <Form layout="vertical" class="mt-2">
      <div class="mb-2 text-sm font-semibold text-gray-700">收入项</div>
      <div class="grid grid-cols-3 gap-x-4">
        <FormItem v-for="f in incomeFields" :key="f.key" :label="f.label">
          <InputNumber
            v-model:value="current[f.key]"
            :min="0"
            :precision="2"
            style="width: 100%"
          />
        </FormItem>
      </div>
 
      <div class="mb-2 mt-2 text-sm font-semibold text-gray-700">扣除项</div>
      <div class="grid grid-cols-3 gap-x-4">
        <FormItem v-for="f in deductionFields" :key="f.key" :label="f.label">
          <InputNumber
            v-model:value="current[f.key]"
            :min="0"
            :precision="2"
            style="width: 100%"
          />
        </FormItem>
      </div>
 
      <div class="mb-2 mt-2 text-sm font-semibold text-gray-700">考勤 / 其他</div>
      <div class="grid grid-cols-3 gap-x-4">
        <FormItem label="出勤天数">
          <InputNumber v-model:value="current.workDays" :min="0" :max="31" :precision="0" style="width: 100%" />
        </FormItem>
        <FormItem label="加班时长(h)">
          <InputNumber v-model:value="current.overtimeHours" :min="0" :precision="1" style="width: 100%" />
        </FormItem>
        <FormItem label="实发工资(自动计算)">
          <Input :value="actualSalary.toFixed(2)" disabled class="font-bold text-green-600" />
        </FormItem>
      </div>
 
      <FormItem label="备注">
        <Input.TextArea v-model:value="current.remark" :rows="2" placeholder="请输入备注" />
      </FormItem>
    </Form>
  </Modal>
</template>