auto submit when scan succeed

This commit is contained in:
Timi
2026-09-12 15:58:36 +08:00
parent b3c01545ab
commit cb4c19f9e4
+36 -2
View File
@@ -30,6 +30,16 @@
@status-change="handleScanStatusChange" @status-change="handleScanStatusChange"
/> />
</space> </space>
<t-cell-group class="auto-register-setting" theme="card" v-entrance-transition="55">
<t-cell title="识别成功自动登记">
<template #right-icon>
<t-switch v-model="autoRegisterEnabled" />
</template>
<template #description>
<div class="red">扫码匹配客户后自动提交登记,请注意已选登记事件</div>
</template>
</t-cell>
</t-cell-group>
<t-button <t-button
class="cell-button" class="cell-button"
theme="primary" theme="primary"
@@ -147,6 +157,8 @@ const settingStore = useSettingStore();
// ---------- 登记事件 ---------- // ---------- 登记事件 ----------
const EventItemStorageKey = "quick-scan-event-id"; const EventItemStorageKey = "quick-scan-event-id";
const AutoRegisterStorageKey = "quick-scan-auto-register";
const autoRegisterEnabled = ref(Storage.getDefault(AutoRegisterStorageKey, true));
const selectedEventIdList = ref<string[]>([]); const selectedEventIdList = ref<string[]>([]);
const eventList = ref<EventItem[]>([]); const eventList = ref<EventItem[]>([]);
const selectedOptionSelectionMap = reactive<EventOptionSelectionMap>({}); const selectedOptionSelectionMap = reactive<EventOptionSelectionMap>({});
@@ -243,8 +255,13 @@ 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>();
let latestDecodedText = ""; let latestDecodedText = "";
watch(autoRegisterEnabled, value => {
Storage.setString(AutoRegisterStorageKey, value);
});
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) {
@@ -254,8 +271,16 @@ async function handleDecodedText(rawText: string): Promise<void> {
scanCode.value = normalizedText; scanCode.value = normalizedText;
await settingStore.playScanSuccessSound(); await settingStore.playScanSuccessSound();
await loadCustomer(normalizedText); await loadCustomer(normalizedText);
if (matchedCustomer.value) { const customer = matchedCustomer.value;
if (customer) {
if (customer.id && registeredCustomerIdSet.has(customer.id)) {
scanStatus.value = `客户 ${customer.name || customer.code || normalizedText} 已在本页面登记`;
return;
}
scanStatus.value = `已识别 ${normalizedText},可直接登记`; scanStatus.value = `已识别 ${normalizedText},可直接登记`;
if (autoRegisterEnabled.value) {
await doSubmit();
}
return; return;
} }
scanStatus.value = `已识别 ${normalizedText},但未匹配客户档案`; scanStatus.value = `已识别 ${normalizedText},但未匹配客户档案`;
@@ -404,6 +429,14 @@ async function doSubmit(): Promise<void> {
if (!customer) { if (!customer) {
return; return;
} }
const customerId = customer.id;
if (!customerId) {
return;
}
if (registeredCustomerIdSet.has(customerId)) {
Message.warning("该客户已在本页面登记,请勿重复登记");
return;
}
if (!selectedEventIdList.value.length) { if (!selectedEventIdList.value.length) {
Message.warning("请至少选择一个登记事件"); Message.warning("请至少选择一个登记事件");
return; return;
@@ -425,12 +458,13 @@ async function doSubmit(): Promise<void> {
try { try {
await EventRecordAPI.createBatch(selectedEventIdList.value.map(eventId => ({ await EventRecordAPI.createBatch(selectedEventIdList.value.map(eventId => ({
eventId, eventId,
customerId: customer.id, customerId,
selectedOptionGroupList: resolveRecordOptionGroupList(eventId), selectedOptionGroupList: resolveRecordOptionGroupList(eventId),
numberValue: resolveNumberValue(eventId), numberValue: resolveNumberValue(eventId),
remark: "客户快速扫码登记", remark: "客户快速扫码登记",
attachmentList: buildPhotoAttachmentList() attachmentList: buildPhotoAttachmentList()
}))); })));
registeredCustomerIdSet.add(customerId);
scanStatus.value = `登记成功:${customer.name || customer.code || scanCode.value}。`; scanStatus.value = `登记成功:${customer.name || customer.code || scanCode.value}。`;
scanCode.value = ""; scanCode.value = "";
matchedCustomer.value = undefined; matchedCustomer.value = undefined;