feat:【antd】【crm】优化合同配置的代码

This commit is contained in:
YunaiV
2025-09-28 23:09:44 +08:00
parent 252b530526
commit 41530a40e5

View File

@@ -1,4 +1,5 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '#/adapter/form';
import type { CrmContractConfigApi } from '#/api/crm/contract/config';
import { onMounted } from 'vue';
@@ -16,15 +17,7 @@ import { $t } from '#/locales';
const emit = defineEmits(['success']);
const [Form, formApi] = useVbenForm({
commonConfig: {
// 所有表单项
labelClass: 'w-2/6',
},
layout: 'horizontal',
wrapperClass: 'grid-cols-1',
actionWrapperClass: 'text-center',
schema: [
const schema: VbenFormSchema[] = [
{
component: 'RadioGroup',
fieldName: 'notifyEnabled',
@@ -35,6 +28,7 @@ const [Form, formApi] = useVbenForm({
{ label: '不提醒', value: false },
],
},
defaultValue: true,
},
{
component: 'InputNumber',
@@ -49,47 +43,50 @@ const [Form, formApi] = useVbenForm({
}),
dependencies: {
triggerFields: ['notifyEnabled'],
show: (values) => values.notifyEnabled,
trigger(values) {
if (!values.notifyEnabled) {
values.notifyDays = undefined;
},
show: (value) => value.notifyEnabled,
}
},
},
],
// 提交函数
handleSubmit: onSubmit,
},
];
const [Form, formApi] = useVbenForm({
commonConfig: {
labelClass: 'w-2/6',
},
layout: 'horizontal',
wrapperClass: 'grid-cols-1',
actionWrapperClass: 'text-center',
schema,
handleSubmit,
});
async function onSubmit() {
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
// 提交表单
const data = (await formApi.getValues()) as CrmContractConfigApi.Config;
if (!data.notifyEnabled) {
data.notifyDays = undefined;
}
formApi.setValues(data);
try {
await saveContractConfig(data);
// 关闭并提示
await formApi.setValues(data);
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
formApi.setValues(data);
}
}
/** 获取配置 */
async function getConfigInfo() {
try {
const res = await getContractConfig();
formApi.setValues(res);
} catch (error) {
console.error(error);
}
await formApi.setValues(res);
}
/** 初始化 */
onMounted(() => {
getConfigInfo();
});