AttendanceConfigModal.vue
4.01 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
<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_ADD: '/order/erp/system_setting/add',
};
// 生成年份选项
const generateYearOptions = () => {
const currentYear = new Date().getFullYear();
const years = [];
for (let i = -2; i <= 5; i++) {
const year = currentYear + i;
years.push({
label: `${year}年`,
value: year.toString(),
});
}
return years;
};
// 考勤类型选项
const attendanceTypeOptions = [
{ label: '9小时双休', value: 61 },
{ label: '9小时大小周双休(生产科)', value: 62 },
{ label: '8小时双休', value: 63 },
{ label: '8.5小时大小周', value: 64 },
];
export default defineComponent({
name: 'AttendanceConfigModal',
components: { BasicModal, BasicForm },
emits: ['success', 'register'],
setup(_, { emit }) {
const { createMessage } = useMessage();
const formParams = ref({});
const isUpdate = ref(false);
const title = computed(() => '新增考勤配置');
// 表单配置
const [registerForm, { resetFields, validate, setFieldsValue }] = useForm({
labelWidth: 100,
schemas: [
{
field: 'settingValue',
label: '年份',
component: 'Select',
required: true,
componentProps: {
options: generateYearOptions(),
placeholder: '请选择年份',
disabled: true,
},
},
{
field: 'settingType',
label: '考勤类型',
component: 'Select',
required: true,
componentProps: {
options: attendanceTypeOptions,
placeholder: '请选择考勤类型',
},
},
],
showActionButtonGroup: false,
actionColOptions: {
span: 24,
},
});
// 注册弹窗
const [registerModal, { closeModal }] = useModalInner(async (data) => {
resetFields();
// 如果有默认年份,设置默认值
const currentYear = new Date().getFullYear().toString();
await setFieldsValue({ settingValue: currentYear });
if (data) {
// 可以设置默认年份
if (data.year) {
await setFieldsValue({ settingValue: data.year });
}
}
});
// 提交表单
async function handleSubmit() {
try {
const values = await validate();
const params = {
settingType: values.settingType,
settingValue: values.settingValue,
settingCode:'monthlyAttendance',
settingName:'每月考勤',
relationCode:'month'
};
await defHttp.post({
url: Api.ATTENDANCE_CONFIG_ADD,
params,
}, {
successMsg: '添加考勤配置成功',
});
closeModal();
emit('success');
} catch (error) {
console.error('提交表单错误:', error);
createMessage.error('提交失败');
}
}
return {
registerModal,
registerForm,
title,
handleSubmit,
};
},
});
</script>