From 37f9eeed01a97cbcf12ae42e315f0968c6ab7827 Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Sat, 14 Mar 2026 18:20:12 +0800 Subject: [PATCH] update stock take search --- src/app/api/stockTake/actions.ts | 58 +++++++++++++++++-- .../StockTakeManagement/PickerCardList.tsx | 38 +++++++----- src/i18n/zh/common.json | 1 + src/i18n/zh/inventory.json | 7 +++ 4 files changed, 86 insertions(+), 18 deletions(-) diff --git a/src/app/api/stockTake/actions.ts b/src/app/api/stockTake/actions.ts index 12083b7..c135dcf 100644 --- a/src/app/api/stockTake/actions.ts +++ b/src/app/api/stockTake/actions.ts @@ -96,9 +96,32 @@ export interface AllPickedStockTakeListReponse { startTime: string | null; endTime: string | null; planStartDate: string | null; + stockTakeSectionDescription: string | null; reStockTakeTrueFalse: boolean; } +export const getApproverInventoryLotDetailsAll = async ( + stockTakeId?: number | null, + pageNum: number = 0, + pageSize: number = 100 +) => { + const params = new URLSearchParams(); + params.append("pageNum", String(pageNum)); + params.append("pageSize", String(pageSize)); + if (stockTakeId != null && stockTakeId > 0) { + params.append("stockTakeId", String(stockTakeId)); + } + + const url = `${BASE_API_URL}/stockTakeRecord/approverInventoryLotDetailsAll?${params.toString()}`; + const response = await serverFetchJson>( + url, + { + method: "GET", + }, + ); + return response; +} + export const importStockTake = async (data: FormData) => { const importStockTake = await serverFetchJson( `${BASE_API_URL}/stockTake/import`, @@ -122,12 +145,20 @@ export const getStockTakeRecords = async () => { } export const getStockTakeRecordsPaged = async ( pageNum: number, - pageSize: number + pageSize: number, + params?: { sectionDescription?: string; stockTakeSections?: string } ) => { - const url = `${BASE_API_URL}/stockTakeRecord/AllPickedStockOutRecordList?pageNum=${pageNum}&pageSize=${pageSize}`; - const res = await serverFetchJson>(url, { - method: "GET", - }); + const searchParams = new URLSearchParams(); + searchParams.set("pageNum", String(pageNum)); + searchParams.set("pageSize", String(pageSize)); + if (params?.sectionDescription && params.sectionDescription !== "All") { + searchParams.set("sectionDescription", params.sectionDescription); + } + if (params?.stockTakeSections?.trim()) { + searchParams.set("stockTakeSections", params.stockTakeSections.trim()); + } + const url = `${BASE_API_URL}/stockTakeRecord/AllPickedStockOutRecordList?${searchParams.toString()}`; + const res = await serverFetchJson>(url, { method: "GET" }); return res; }; export const getApproverStockTakeRecords = async () => { @@ -228,6 +259,12 @@ export interface BatchSaveApproverStockTakeRecordResponse { errors: string[]; } +export interface BatchSaveApproverStockTakeAllRequest { + stockTakeId: number; + approverId: number; + variancePercentTolerance?: number | null; +} + export const saveApproverStockTakeRecord = async ( request: SaveApproverStockTakeRecordRequest, @@ -272,6 +309,17 @@ export const batchSaveApproverStockTakeRecords = cache(async (data: BatchSaveApp } ) +export const batchSaveApproverStockTakeRecordsAll = cache(async (data: BatchSaveApproverStockTakeAllRequest) => { + return serverFetchJson( + `${BASE_API_URL}/stockTakeRecord/batchSaveApproverStockTakeRecordsAll`, + { + method: "POST", + body: JSON.stringify(data), + headers: { "Content-Type": "application/json" }, + } + ) +}) + export const updateStockTakeRecordStatusToNotMatch = async ( stockTakeRecordId: number ) => { diff --git a/src/components/StockTakeManagement/PickerCardList.tsx b/src/components/StockTakeManagement/PickerCardList.tsx index b405693..b42009a 100644 --- a/src/components/StockTakeManagement/PickerCardList.tsx +++ b/src/components/StockTakeManagement/PickerCardList.tsx @@ -61,22 +61,27 @@ const sectionDescriptionOptions = Array.from( .filter((v): v is string => !!v) ) ); - +/* // 按 description + section 双条件过滤 const filteredSessions = stockTakeSessions.filter((s) => { const matchDesc = filterSectionDescription === "All" || s.stockTakeSectionDescription === filterSectionDescription; + const sessionParts = (filterStockTakeSession ?? "") + .split(",") + .map((p) => p.trim().toLowerCase()) + .filter(Boolean); + const matchSession = - !filterStockTakeSession || - (s.stockTakeSession ?? "") - .toString() - .toLowerCase() - .includes(filterStockTakeSession.toLowerCase()); + sessionParts.length === 0 || + sessionParts.some((part) => + (s.stockTakeSession ?? "").toString().toLowerCase().includes(part) + ); return matchDesc && matchSession; }); +*/ // SearchBox 的条件配置 const criteria: Criterion[] = [ @@ -88,7 +93,7 @@ const criteria: Criterion[] = [ }, { type: "text", - label: t("Stock Take Section"), + label: t("Stock Take Section (can use , to search multiple sections)"), paramName: "stockTakeSession", placeholder: "", }, @@ -97,17 +102,24 @@ const criteria: Criterion[] = [ const handleSearch = (inputs: Record) => { setFilterSectionDescription(inputs.sectionDescription || "All"); setFilterStockTakeSession(inputs.stockTakeSession || ""); + fetchStockTakeSessions(0, pageSize, { + sectionDescription: inputs.sectionDescription || "All", + stockTakeSections: inputs.stockTakeSession ?? "", + }); }; - const handleResetSearch = () => { setFilterSectionDescription("All"); setFilterStockTakeSession(""); + fetchStockTakeSessions(0, pageSize, { + sectionDescription: "All", + stockTakeSections: "", + }); }; const fetchStockTakeSessions = useCallback( - async (pageNum: number, size: number) => { + async (pageNum: number, size: number, filterOverrides?: { sectionDescription: string; stockTakeSections: string }) => { setLoading(true); try { - const res = await getStockTakeRecordsPaged(pageNum, size); + const res = await getStockTakeRecordsPaged(pageNum, size, filterOverrides); setStockTakeSessions(Array.isArray(res.records) ? res.records : []); setTotal(res.total || 0); setPage(pageNum); @@ -252,7 +264,7 @@ const handleResetSearch = () => { - {t("Total Sections")}: {stockTakeSessions.length} + {t("Total Sections")}: {total} {t("Start Stock Take Date")}: {planStartDate || "-"} @@ -269,7 +281,7 @@ const handleResetSearch = () => { - {filteredSessions.map((session: AllPickedStockTakeListReponse) => { + {stockTakeSessions.map((session: AllPickedStockTakeListReponse) => { const statusColor = getStatusColor(session.status || ""); const lastStockTakeDate = session.lastStockTakeDate ? dayjs(session.lastStockTakeDate).format(OUTPUT_DATE_FORMAT) @@ -338,7 +350,7 @@ const handleResetSearch = () => { })} - {stockTakeSessions.length > 0 && ( + {total > 0 && (