fix update customer code

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