auto submit when scan succeed
This commit is contained in:
@@ -30,6 +30,16 @@
|
||||
@status-change="handleScanStatusChange"
|
||||
/>
|
||||
</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
|
||||
class="cell-button"
|
||||
theme="primary"
|
||||
@@ -147,6 +157,8 @@ const settingStore = useSettingStore();
|
||||
// ---------- 登记事件 ----------
|
||||
|
||||
const EventItemStorageKey = "quick-scan-event-id";
|
||||
const AutoRegisterStorageKey = "quick-scan-auto-register";
|
||||
const autoRegisterEnabled = ref(Storage.getDefault(AutoRegisterStorageKey, true));
|
||||
const selectedEventIdList = ref<string[]>([]);
|
||||
const eventList = ref<EventItem[]>([]);
|
||||
const selectedOptionSelectionMap = reactive<EventOptionSelectionMap>({});
|
||||
@@ -243,8 +255,13 @@ const scanCode = ref("");
|
||||
const scanStatus = ref("正在启动扫码预览");
|
||||
const scannerSessionKey = ref(0);
|
||||
const matchedCustomer = ref<Customer>();
|
||||
const registeredCustomerIdSet = new Set<string>();
|
||||
let latestDecodedText = "";
|
||||
|
||||
watch(autoRegisterEnabled, value => {
|
||||
Storage.setString(AutoRegisterStorageKey, value);
|
||||
});
|
||||
|
||||
async function handleDecodedText(rawText: string): Promise<void> {
|
||||
const normalizedText = rawText.trim();
|
||||
if (!normalizedText || normalizedText === latestDecodedText) {
|
||||
@@ -254,8 +271,16 @@ async function handleDecodedText(rawText: string): Promise<void> {
|
||||
scanCode.value = normalizedText;
|
||||
await settingStore.playScanSuccessSound();
|
||||
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},可直接登记`;
|
||||
if (autoRegisterEnabled.value) {
|
||||
await doSubmit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
scanStatus.value = `已识别 ${normalizedText},但未匹配客户档案`;
|
||||
@@ -404,6 +429,14 @@ async function doSubmit(): Promise<void> {
|
||||
if (!customer) {
|
||||
return;
|
||||
}
|
||||
const customerId = customer.id;
|
||||
if (!customerId) {
|
||||
return;
|
||||
}
|
||||
if (registeredCustomerIdSet.has(customerId)) {
|
||||
Message.warning("该客户已在本页面登记,请勿重复登记");
|
||||
return;
|
||||
}
|
||||
if (!selectedEventIdList.value.length) {
|
||||
Message.warning("请至少选择一个登记事件");
|
||||
return;
|
||||
@@ -425,12 +458,13 @@ async function doSubmit(): Promise<void> {
|
||||
try {
|
||||
await EventRecordAPI.createBatch(selectedEventIdList.value.map(eventId => ({
|
||||
eventId,
|
||||
customerId: customer.id,
|
||||
customerId,
|
||||
selectedOptionGroupList: resolveRecordOptionGroupList(eventId),
|
||||
numberValue: resolveNumberValue(eventId),
|
||||
remark: "客户快速扫码登记",
|
||||
attachmentList: buildPhotoAttachmentList()
|
||||
})));
|
||||
registeredCustomerIdSet.add(customerId);
|
||||
scanStatus.value = `登记成功:${customer.name || customer.code || scanCode.value}。`;
|
||||
scanCode.value = "";
|
||||
matchedCustomer.value = undefined;
|
||||
|
||||
Reference in New Issue
Block a user