fix auto submit for diff event
This commit is contained in:
@@ -299,9 +299,21 @@ const scanCode = ref("");
|
||||
const scanStatus = ref("正在启动扫码预览");
|
||||
const scannerSessionKey = ref(0);
|
||||
const matchedCustomer = ref<Customer>();
|
||||
const registeredCustomerIdSet = new Set<string>();
|
||||
const registeredCustomerIdSetByEvent = new Map<string, Set<string>>();
|
||||
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> {
|
||||
const normalizedText = rawText.trim();
|
||||
if (!normalizedText || normalizedText === latestDecodedText) {
|
||||
@@ -313,7 +325,7 @@ async function handleDecodedText(rawText: string): Promise<void> {
|
||||
await loadCustomer(normalizedText);
|
||||
const customer = matchedCustomer.value;
|
||||
if (customer) {
|
||||
if (customer.id && registeredCustomerIdSet.has(customer.id)) {
|
||||
if (customer.id && isCustomerRegisteredForEvents(selectedEventIdList.value, customer.id)) {
|
||||
scanStatus.value = `客户 ${customer.name || customer.code || normalizedText} 已在本页面登记`;
|
||||
return;
|
||||
}
|
||||
@@ -485,12 +497,13 @@ async function doSubmit(isAutoRegister = false): Promise<void> {
|
||||
if (!customerId) {
|
||||
return;
|
||||
}
|
||||
if (registeredCustomerIdSet.has(customerId)) {
|
||||
Message.warning("该客户已在本页面登记,请勿重复登记");
|
||||
const eventIdList = [...selectedEventIdList.value];
|
||||
if (!eventIdList.length) {
|
||||
Message.warning("请至少选择一个登记事件");
|
||||
return;
|
||||
}
|
||||
if (!selectedEventIdList.value.length) {
|
||||
Message.warning("请至少选择一个登记事件");
|
||||
if (isCustomerRegisteredForEvents(eventIdList, customerId)) {
|
||||
Message.warning("该客户已在本页面登记,请勿重复登记");
|
||||
return;
|
||||
}
|
||||
if (recordPhotoUploading.value) {
|
||||
@@ -508,7 +521,7 @@ async function doSubmit(isAutoRegister = false): Promise<void> {
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
await EventRecordAPI.createBatch(selectedEventIdList.value.map(eventId => ({
|
||||
await EventRecordAPI.createBatch(eventIdList.map(eventId => ({
|
||||
eventId,
|
||||
customerId,
|
||||
selectedOptionGroupList: resolveRecordOptionGroupList(eventId),
|
||||
@@ -516,7 +529,7 @@ async function doSubmit(isAutoRegister = false): Promise<void> {
|
||||
remark: "客户快速扫码登记",
|
||||
attachmentList: buildPhotoAttachmentList()
|
||||
})));
|
||||
registeredCustomerIdSet.add(customerId);
|
||||
markCustomerRegisteredForEvents(eventIdList, customerId);
|
||||
const customerText = customer.name || customer.code || scanCode.value || "客户";
|
||||
scanStatus.value = `登记成功:${customerText}。`;
|
||||
if (isAutoRegister) {
|
||||
|
||||
Reference in New Issue
Block a user