From 2fd1bfb4e8d800c3f45a1220230f656b734e3271 Mon Sep 17 00:00:00 2001 From: xianyi Date: Tue, 23 Dec 2025 11:56:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BD=93=E6=A3=80=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 31 ++++++++----- src/pages/ExamPage.tsx | 98 +++++++++++------------------------------- 2 files changed, 46 insertions(+), 83 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 59fba40..edeb89a 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -115,17 +115,26 @@ export type RevenueStatisticsResponse = CommonActionResult { const [examFilterTag, setExamFilterTag] = useState<(typeof EXAM_TAGS)[number]>('全部'); const [loading, setLoading] = useState(false); - // 将筛选标签映射为接口 filter_type - const filterType = useMemo(() => { - switch (examFilterTag) { - case '上午': - return 2; - case '下午': - return 3; - case '高客': - return 4; - case '普客': - return 5; - case '已登记': - return 6; - case '未登记': - return 7; - case '散客': - return 8; - case '团客': - return 9; - default: - return 1; // 全部 - } - }, [examFilterTag]); - - // 智能识别搜索内容类型 - const getSearchParams = useMemo(() => { + // 构建接口请求参数 + const getRequestPayload = useMemo(() => { const trimmed = searchValue.trim(); - if (!trimmed) { - return { - customer_name: undefined, - phone: undefined, - id_no: undefined, - }; - } + const query_text = trimmed || null; - // 判断是否为手机号(11位数字,以1开头) - if (/^1[3-9]\d{9}$/.test(trimmed)) { - return { - customer_name: undefined, - phone: trimmed, - id_no: undefined, - }; - } + // 根据筛选标签设置标志位 + const is_all = examFilterTag === '全部' ? 1 : 0; + const is_morning = examFilterTag === '上午' ? 1 : 0; + const is_afternoon = examFilterTag === '下午' ? 1 : 0; + const is_high_customer = examFilterTag === '高客' ? 1 : 0; + const is_general_customer = examFilterTag === '普客' ? 1 : 0; + const is_registered = examFilterTag === '已登记' ? 1 : 0; + const is_not_registered = examFilterTag === '未登记' ? 1 : 0; + const is_individual_customer = examFilterTag === '散客' ? 1 : 0; + const is_group_customer = examFilterTag === '团客' ? 1 : 0; - // 判断是否为身份证号(15位或18位,最后一位可能是X) - if (/^(\d{15}|\d{17}[\dXx])$/.test(trimmed)) { - return { - customer_name: undefined, - phone: undefined, - id_no: trimmed, - }; - } - - // 判断是否为卡号(纯数字,长度在6-20位之间) - if (/^\d{6,20}$/.test(trimmed)) { - // 接口中没有卡号字段,暂时使用 customer_name 搜索 - // 如果后续接口支持卡号字段,可以添加 card_no 参数 - return { - customer_name: trimmed, - phone: undefined, - id_no: undefined, - }; - } - - // 默认为姓名 return { - customer_name: trimmed, - phone: undefined, - id_no: undefined, + query_text, + is_all, + is_morning, + is_afternoon, + is_high_customer, + is_general_customer, + is_registered, + is_not_registered, + is_individual_customer, + is_group_customer, }; - }, [searchValue]); + }, [searchValue, examFilterTag]); // 从接口拉取体检客户列表 useEffect(() => { - const payload = { - ...getSearchParams, - filter_type: filterType, - }; setLoading(true); - getPhysicalExamCustomerList(payload) + getPhysicalExamCustomerList(getRequestPayload) .then((res) => { const list = res.Data || []; const mapped: ExamClient[] = list.map((item) => { @@ -166,7 +120,7 @@ export const ExamPage = () => { .finally(() => { setLoading(false); }); - }, [getSearchParams, filterType, examSelectedId]); + }, [getRequestPayload, examSelectedId]); const selectedExamClient: ExamClient | undefined = useMemo( () => clients.find((c) => c.id === examSelectedId) || clients[0],