feat: 客户编码校验
This commit is contained in:
@@ -63,9 +63,19 @@ async function isCustomerNameUnique(
|
||||
});
|
||||
}
|
||||
|
||||
/** 客户编号是否唯一 */
|
||||
async function isCustomerCodeUnique(
|
||||
code: number,
|
||||
id?: CustomerApi.Customer['id'],
|
||||
) {
|
||||
return requestClient.get<boolean>('/license/customer/code-unique', {
|
||||
params: { id, code },
|
||||
});
|
||||
}
|
||||
|
||||
/** 查询当前最大sn */
|
||||
async function getMaxSn() {
|
||||
return requestClient.get<boolean>('/license/customer/max-sn');
|
||||
}
|
||||
|
||||
export { getMaxSn, isCustomerNameUnique };
|
||||
export { getMaxSn, isCustomerCodeUnique, isCustomerNameUnique };
|
||||
|
||||
@@ -7,7 +7,10 @@ import { ref } from 'vue';
|
||||
import { useAccess } from '@vben/access';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { isCustomerNameUnique } from '#/api/license/customer';
|
||||
import {
|
||||
isCustomerCodeUnique,
|
||||
isCustomerNameUnique,
|
||||
} from '#/api/license/customer';
|
||||
import { getAreaTree } from '#/api/system/area';
|
||||
import { $t } from '#/locales';
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
@@ -52,8 +55,35 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: $t('customer.customerSn'),
|
||||
rules: 'required',
|
||||
component: 'Input',
|
||||
component: 'InputNumber',
|
||||
rules: z
|
||||
.number()
|
||||
.min(
|
||||
2000,
|
||||
$t('ui.formRules.range', [$t('customer.customerSn'), 2000, 9999]),
|
||||
)
|
||||
.max(
|
||||
9999,
|
||||
$t('ui.formRules.range', [$t('customer.customerSn'), 2000, 9999]),
|
||||
)
|
||||
.refine(
|
||||
async (value: number) => {
|
||||
return await isCustomerCodeUnique(value, formData.value?.id);
|
||||
},
|
||||
(value) => ({
|
||||
message: $t('ui.formRules.alreadyExists', [
|
||||
$t('customer.customerSn'),
|
||||
value,
|
||||
]),
|
||||
}),
|
||||
)
|
||||
.nullable()
|
||||
.refine(
|
||||
(value: null | number) => {
|
||||
return value;
|
||||
},
|
||||
{ message: $t('ui.formRules.required', [$t('customer.customerSn')]) },
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
|
||||
Reference in New Issue
Block a user