feat:【antd】【crm】优化合同配置的代码
This commit is contained in:
@@ -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,80 +17,76 @@ import { $t } from '#/locales';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const schema: VbenFormSchema[] = [
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
fieldName: 'notifyEnabled',
|
||||
label: '提前提醒设置',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '提醒', value: true },
|
||||
{ label: '不提醒', value: false },
|
||||
],
|
||||
},
|
||||
defaultValue: true,
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'notifyDays',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
precision: 0,
|
||||
},
|
||||
renderComponentContent: () => ({
|
||||
addonBefore: () => '提前',
|
||||
addonAfter: () => '天提醒',
|
||||
}),
|
||||
dependencies: {
|
||||
triggerFields: ['notifyEnabled'],
|
||||
show: (values) => values.notifyEnabled,
|
||||
trigger(values) {
|
||||
if (!values.notifyEnabled) {
|
||||
values.notifyDays = undefined;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
// 所有表单项
|
||||
labelClass: 'w-2/6',
|
||||
},
|
||||
layout: 'horizontal',
|
||||
wrapperClass: 'grid-cols-1',
|
||||
actionWrapperClass: 'text-center',
|
||||
schema: [
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
fieldName: 'notifyEnabled',
|
||||
label: '提前提醒设置',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '提醒', value: true },
|
||||
{ label: '不提醒', value: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
fieldName: 'notifyDays',
|
||||
componentProps: {
|
||||
min: 0,
|
||||
precision: 0,
|
||||
},
|
||||
renderComponentContent: () => ({
|
||||
addonBefore: () => '提前',
|
||||
addonAfter: () => '天提醒',
|
||||
}),
|
||||
dependencies: {
|
||||
triggerFields: ['notifyEnabled'],
|
||||
trigger(values) {
|
||||
values.notifyDays = undefined;
|
||||
},
|
||||
show: (value) => value.notifyEnabled,
|
||||
},
|
||||
},
|
||||
],
|
||||
// 提交函数
|
||||
handleSubmit: onSubmit,
|
||||
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);
|
||||
// 关闭并提示
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
formApi.setValues(data);
|
||||
}
|
||||
await saveContractConfig(data);
|
||||
await formApi.setValues(data);
|
||||
emit('success');
|
||||
message.success($t('ui.actionMessage.operationSuccess'));
|
||||
}
|
||||
|
||||
/** 获取配置 */
|
||||
async function getConfigInfo() {
|
||||
try {
|
||||
const res = await getContractConfig();
|
||||
formApi.setValues(res);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
const res = await getContractConfig();
|
||||
await formApi.setValues(res);
|
||||
}
|
||||
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getConfigInfo();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user