fix update customer code
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
<template>
|
||||
<div v-can="savePermissionCode" class="customer-edit">
|
||||
<t-form class="form" label-align="left" label-width="6rem" v-entrance-transition>
|
||||
<t-form class="form" label-align="left" label-width="6rem" :disabled="isCustomerBound" v-entrance-transition>
|
||||
<t-form-item label="客户编码">
|
||||
<t-input
|
||||
v-model.trim="formData.code"
|
||||
placeholder="客户编码"
|
||||
borderless
|
||||
:disabled="false"
|
||||
@blur="handleCodeBlur"
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<t-button
|
||||
theme="primary"
|
||||
size="extra-small"
|
||||
:disabled="false"
|
||||
@click="toggleScanner('code')"
|
||||
>
|
||||
<span v-text="scannerVisible && scannerTarget === 'code' ? '关闭扫码' : '扫码'" />
|
||||
@@ -32,12 +34,13 @@
|
||||
<customer-profile-card :customer="boundCodeCustomer" />
|
||||
<div class="tips red">
|
||||
<t-icon name="error-circle" />
|
||||
<span>该编码已绑定客户,不可新录入</span>
|
||||
<span v-text="isCreateMode ? '该编码已绑定客户,不可新录入' : '该编码已绑定其他客户,请使用新的编码'" />
|
||||
</div>
|
||||
<t-button
|
||||
block
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
:disabled="false"
|
||||
@click="toBoundCustomerEdit"
|
||||
>编辑该客户</t-button>
|
||||
</div>
|
||||
@@ -138,7 +141,7 @@
|
||||
v-entrance-transition="70"
|
||||
@edit="openTagSelector"
|
||||
/>
|
||||
<t-form class="form" label-align="left" label-width="3rem" v-entrance-transition="140">
|
||||
<t-form class="form" label-align="left" label-width="3rem" :disabled="isCustomerBound" v-entrance-transition="140">
|
||||
<t-form-item label="住址">
|
||||
<t-textarea
|
||||
class="textarea"
|
||||
@@ -251,7 +254,10 @@ const checkedCode = ref("");
|
||||
let codeCheckToken = 0;
|
||||
let pendingCodeCheck: Promise<void> | undefined;
|
||||
let pendingCode = "";
|
||||
const isCustomerBound = computed(() => isCreateMode.value && !!boundCodeCustomer.value?.id);
|
||||
const isCustomerBound = computed(() => {
|
||||
const boundCustomerId = boundCodeCustomer.value?.id;
|
||||
return !!boundCustomerId && boundCustomerId !== formData.id;
|
||||
});
|
||||
|
||||
async function toggleScanner(target: ScanTarget): Promise<void> {
|
||||
if (isCustomerBound.value && target !== "code") {
|
||||
@@ -291,17 +297,10 @@ function handleScanStatusChange(value: string): void {
|
||||
}
|
||||
|
||||
async function handleCodeBlur(): Promise<void> {
|
||||
if (!isCreateMode.value) {
|
||||
return;
|
||||
}
|
||||
await checkBoundCustomerCode();
|
||||
}
|
||||
|
||||
async function checkBoundCustomerCode(): Promise<void> {
|
||||
if (!isCreateMode.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedCode = formData.code?.trim() || "";
|
||||
if (!normalizedCode) {
|
||||
codeCheckToken++;
|
||||
@@ -379,9 +378,6 @@ const formData = reactive<Customer>({
|
||||
});
|
||||
|
||||
watch(() => formData.code, (value) => {
|
||||
if (!isCreateMode.value) {
|
||||
return;
|
||||
}
|
||||
const normalizedCode = value?.trim() || "";
|
||||
if (normalizedCode !== checkedCode.value && normalizedCode !== pendingCode) {
|
||||
codeCheckToken++;
|
||||
@@ -506,6 +502,7 @@ async function loadDetail() {
|
||||
const customer = await CustomerAPI.detail(id);
|
||||
Object.assign(formData, customer);
|
||||
formData.storeId = currentStoreStore.currentStoreId;
|
||||
await checkBoundCustomerCode();
|
||||
await loadCustomerTags(id);
|
||||
photoItemList.value = (customer.attachmentList || [])
|
||||
.filter(item => !!item.id)
|
||||
@@ -701,14 +698,14 @@ async function doSubmit(): Promise<void> {
|
||||
}
|
||||
|
||||
async function ensureCustomerCodeAvailable(): Promise<boolean> {
|
||||
if (!isCreateMode.value || !formData.code?.trim()) {
|
||||
if (!formData.code?.trim()) {
|
||||
return true;
|
||||
}
|
||||
await checkBoundCustomerCode();
|
||||
if (!boundCodeCustomer.value?.id) {
|
||||
if (!isCustomerBound.value) {
|
||||
return true;
|
||||
}
|
||||
Message.warning("该客户编码已绑定客户,不可新录入,请编辑已有客户");
|
||||
Message.warning(isCreateMode.value ? "该客户编码已绑定客户,不可新录入,请编辑已有客户" : "该客户编码已绑定其他客户,请使用新的编码");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user