AttendanceEditModal.vue
5.78 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
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="title" @ok="handleSubmit">
<BasicForm @register="registerForm" />
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, computed } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';
const Api = {
ATTENDANCE_CONFIG_EDIT: '/order/erp/system_setting/edit',
};
// 生成月份选项
const generateMonthOptions = () => {
const months = [];
for (let i = 1; i <= 12; i++) {
months.push({
label: `${i}月`,
value: i.toString(),
});
}
return months;
};
// 考勤类型选项
const attendanceTypeOptions = [
{ label: '9小时双休', value: 61 },
{ label: '9小时大小周双休(生产科)', value: 62 },
{ label: '8小时双休', value: 63 },
{ label: '8.5小时大小周', value: 64 },
];
export default defineComponent({
name: 'AttendanceEditModal',
components: { BasicModal, BasicForm },
emits: ['success', 'register'],
setup(_, { emit }) {
const { createMessage } = useMessage();
const formParams = ref({});
const recordId = ref<string | number>('');
const currentSettingType = ref<number>(61);
const currentYear = ref<string>('');
const title = computed(() => '编辑考勤配置');
// 表单配置
const [registerForm, { resetFields, validate, setFieldsValue }] = useForm({
labelWidth: 100,
schemas: [
{
field: 'relation_name',
label: '月份',
component: 'Select',
required: true,
componentProps: {
options: generateMonthOptions(),
placeholder: '请选择月份',
},
},
{
field: 'monthlyWorkingDay',
label: '工作日',
component: 'InputNumber',
required: true,
componentProps: {
placeholder: '请输入工作日',
precision: 1,
},
},
{
field: 'payDay',
label: '计薪日',
component: 'InputNumber',
required: true,
componentProps: {
placeholder: '请输入计薪日',
precision: 1,
},
},
{
field: 'setting_type',
label: '考勤类型',
component: 'Select',
required: true,
componentProps: {
options: attendanceTypeOptions,
placeholder: '请选择考勤类型',
disabled: true, // 类型不可修改
},
},
],
showActionButtonGroup: false,
actionColOptions: {
span: 24,
},
});
// 注册弹窗
const [registerModal, { closeModal }] = useModalInner(async (data) => {
resetFields();
if (data) {
// 设置当前年份
currentYear.value = data.year || new Date().getFullYear().toString();
// 设置当前考勤类型
if (data.settingType) {
currentSettingType.value = data.settingType;
await setFieldsValue({
setting_type: data.settingType,
});
}
// 设置月份、工作日和计薪日(如果存在)
if (data.record) {
recordId.value = data.record.id;
if (data.record.month) {
await setFieldsValue({
relation_name: data.record.month.toString(),
});
}
if (data.record.workDays !== undefined) {
await setFieldsValue({
monthlyWorkingDay: data.record.workDays,
});
}
if (data.record.salaryDays !== undefined) {
await setFieldsValue({
payDay: data.record.salaryDays,
});
}
}
}
});
// 提交表单
async function handleSubmit() {
try {
const values = await validate();
const params = {
id: 1, // 如果有ID则传递,一直没有把id传递过来,就写死,通过后端去通过其他条件筛选,不采用id去查找。
setting_code: 'monthlyAttendance',
setting_name: '每月考勤',
setting_value: currentYear.value,
setting_type: values.setting_type,
relation_code: 'month',
relation_name: values.relation_name,
monthlyWorkingHoursItemVO: {
monthlyWorkingDay: values.monthlyWorkingDay,
payDay: values.payDay
}
};
await defHttp.post({
url: Api.ATTENDANCE_CONFIG_EDIT,
params,
}, {
successMsg: '编辑考勤配置成功',
});
closeModal();
emit('success');
} catch (error) {
console.error('提交表单错误:', error);
createMessage.error('提交失败');
}
}
return {
registerModal,
registerForm,
title,
handleSubmit,
};
},
});
</script>