fix auto submit for diff event

This commit is contained in:
Timi
2026-10-16 00:58:52 +08:00
parent b7bcbf3f1f
commit ad427bf2ea
+21 -8
View File
@@ -299,9 +299,21 @@ const scanCode = ref("");
const scanStatus = ref("正在启动扫码预览"); const scanStatus = ref("正在启动扫码预览");
const scannerSessionKey = ref(0); const scannerSessionKey = ref(0);
const matchedCustomer = ref<Customer>(); const matchedCustomer = ref<Customer>();
const registeredCustomerIdSet = new Set<string>(); const registeredCustomerIdSetByEvent = new Map<string, Set<string>>();
let latestDecodedText = ""; let latestDecodedText = "";
function isCustomerRegisteredForEvents(eventIdList: string[], customerId: string): boolean {
return eventIdList.some(eventId => registeredCustomerIdSetByEvent.get(eventId)?.has(customerId));
}
function markCustomerRegisteredForEvents(eventIdList: string[], customerId: string): void {
for (const eventId of eventIdList) {
const customerIdSet = registeredCustomerIdSetByEvent.get(eventId) || new Set<string>();
customerIdSet.add(customerId);
registeredCustomerIdSetByEvent.set(eventId, customerIdSet);
}
}
async function handleDecodedText(rawText: string): Promise<void> { async function handleDecodedText(rawText: string): Promise<void> {
const normalizedText = rawText.trim(); const normalizedText = rawText.trim();
if (!normalizedText || normalizedText === latestDecodedText) { if (!normalizedText || normalizedText === latestDecodedText) {
@@ -313,7 +325,7 @@ async function handleDecodedText(rawText: string): Promise<void> {
await loadCustomer(normalizedText); await loadCustomer(normalizedText);
const customer = matchedCustomer.value; const customer = matchedCustomer.value;
if (customer) { if (customer) {
if (customer.id && registeredCustomerIdSet.has(customer.id)) { if (customer.id && isCustomerRegisteredForEvents(selectedEventIdList.value, customer.id)) {
scanStatus.value = `客户 ${customer.name || customer.code || normalizedText} 已在本页面登记`; scanStatus.value = `客户 ${customer.name || customer.code || normalizedText} 已在本页面登记`;
return; return;
} }
@@ -485,12 +497,13 @@ async function doSubmit(isAutoRegister = false): Promise<void> {
if (!customerId) { if (!customerId) {
return; return;
} }
if (registeredCustomerIdSet.has(customerId)) { const eventIdList = [...selectedEventIdList.value];
Message.warning("该客户已在本页面登记,请勿重复登记"); if (!eventIdList.length) {
Message.warning("请至少选择一个登记事件");
return; return;
} }
if (!selectedEventIdList.value.length) { if (isCustomerRegisteredForEvents(eventIdList, customerId)) {
Message.warning("请至少选择一个登记事件"); Message.warning("该客户已在本页面登记,请勿重复登记");
return; return;
} }
if (recordPhotoUploading.value) { if (recordPhotoUploading.value) {
@@ -508,7 +521,7 @@ async function doSubmit(isAutoRegister = false): Promise<void> {
} }
submitting.value = true; submitting.value = true;
try { try {
await EventRecordAPI.createBatch(selectedEventIdList.value.map(eventId => ({ await EventRecordAPI.createBatch(eventIdList.map(eventId => ({
eventId, eventId,
customerId, customerId,
selectedOptionGroupList: resolveRecordOptionGroupList(eventId), selectedOptionGroupList: resolveRecordOptionGroupList(eventId),
@@ -516,7 +529,7 @@ async function doSubmit(isAutoRegister = false): Promise<void> {
remark: "客户快速扫码登记", remark: "客户快速扫码登记",
attachmentList: buildPhotoAttachmentList() attachmentList: buildPhotoAttachmentList()
}))); })));
registeredCustomerIdSet.add(customerId); markCustomerRegisteredForEvents(eventIdList, customerId);
const customerText = customer.name || customer.code || scanCode.value || "客户"; const customerText = customer.name || customer.code || scanCode.value || "客户";
scanStatus.value = `登记成功:${customerText}。`; scanStatus.value = `登记成功:${customerText}。`;
if (isAutoRegister) { if (isAutoRegister) {