scanner in CustomerSelector.vue
This commit is contained in:
@@ -6,7 +6,17 @@
|
||||
class="search"
|
||||
placeholder="搜索客户编码、姓名、拼音或电话"
|
||||
borderless
|
||||
/>
|
||||
>
|
||||
<template #suffix-icon>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
theme="primary"
|
||||
variant="outline"
|
||||
content="选择客户"
|
||||
@click.stop="customerSelectorVisible = true"
|
||||
/>
|
||||
</template>
|
||||
</t-input>
|
||||
</div>
|
||||
<t-pull-down-refresh
|
||||
class="list-wrapper"
|
||||
@@ -37,12 +47,19 @@
|
||||
</t-cell-group>
|
||||
<div class="center-tips" v-text="loadStateText" />
|
||||
</t-pull-down-refresh>
|
||||
<customer-selector
|
||||
v-model="selectedCustomerId"
|
||||
v-model:visible="customerSelectorVisible"
|
||||
@change="handleCustomerChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { type PageResult, useUserStore } from "timi-web-api";
|
||||
import CustomerAPI from "@/api/CustomerAPI";
|
||||
import PointAPI from "@/api/PointAPI";
|
||||
import CustomerSelector from "@/components/CustomerSelector.vue";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import type { PointAccount, PointAccountPage } from "@/types/Point";
|
||||
import { Message } from "@/utils/message";
|
||||
@@ -71,8 +88,31 @@ async function prepareStoreScope(): Promise<void> {
|
||||
// ---------- 筛选 ----------
|
||||
|
||||
const keyword = ref("");
|
||||
const selectedCustomerId = ref("");
|
||||
const customerSelectorVisible = ref(false);
|
||||
let selectedCustomerKeyword = "";
|
||||
let keywordTimer: number | undefined;
|
||||
|
||||
async function handleCustomerChange(value: string | string[]): Promise<void> {
|
||||
selectedCustomerId.value = Array.isArray(value) ? String(value[0] || "") : value;
|
||||
if (!selectedCustomerId.value) {
|
||||
selectedCustomerKeyword = "";
|
||||
keyword.value = "";
|
||||
await reload();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const customer = await CustomerAPI.detail(selectedCustomerId.value);
|
||||
selectedCustomerKeyword = customer.name?.trim() || customer.code?.trim() || "";
|
||||
keyword.value = selectedCustomerKeyword;
|
||||
await reload();
|
||||
} catch {
|
||||
selectedCustomerKeyword = "";
|
||||
Message.error("客户信息加载失败");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 分页 ----------
|
||||
|
||||
const page = reactive<PointAccountPage>({
|
||||
@@ -179,6 +219,11 @@ async function toDetail(item: PointAccount): Promise<void> {
|
||||
|
||||
watch(keyword, () => {
|
||||
window.clearTimeout(keywordTimer);
|
||||
if (selectedCustomerKeyword && keyword.value.trim() === selectedCustomerKeyword) {
|
||||
selectedCustomerKeyword = "";
|
||||
return;
|
||||
}
|
||||
selectedCustomerKeyword = "";
|
||||
keywordTimer = window.setTimeout(async () => {
|
||||
await reload();
|
||||
}, 300);
|
||||
|
||||
Reference in New Issue
Block a user