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