feat:【antd】【crm】优化合同配置的代码
This commit is contained in:
@@ -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,80 +17,76 @@ import { $t } from '#/locales';
|
|||||||
|
|
||||||
const emit = defineEmits(['success']);
|
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({
|
const [Form, formApi] = useVbenForm({
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
// 所有表单项
|
|
||||||
labelClass: 'w-2/6',
|
labelClass: 'w-2/6',
|
||||||
},
|
},
|
||||||
layout: 'horizontal',
|
layout: 'horizontal',
|
||||||
wrapperClass: 'grid-cols-1',
|
wrapperClass: 'grid-cols-1',
|
||||||
actionWrapperClass: 'text-center',
|
actionWrapperClass: 'text-center',
|
||||||
schema: [
|
schema,
|
||||||
{
|
handleSubmit,
|
||||||
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,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
await saveContractConfig(data);
|
||||||
try {
|
await formApi.setValues(data);
|
||||||
await saveContractConfig(data);
|
emit('success');
|
||||||
// 关闭并提示
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
emit('success');
|
|
||||||
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();
|
await formApi.setValues(res);
|
||||||
formApi.setValues(res);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 初始化 */
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getConfigInfo();
|
getConfigInfo();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user