From 77ad12967bbd9d0d553b768b030b0937fecf2ea5 Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Sun, 15 Mar 2026 17:42:17 +0800 Subject: [PATCH] jo edit --- src/app/api/jo/index.ts | 1 + src/components/JoSearch/JoSearch.tsx | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/api/jo/index.ts b/src/app/api/jo/index.ts index b6d889c..ed8b99f 100644 --- a/src/app/api/jo/index.ts +++ b/src/app/api/jo/index.ts @@ -21,6 +21,7 @@ export interface JobOrder { reqQty: number; item: Item; itemName: string; + bomId: number; // uom: Uom; pickLines?: JoDetailPickLine[]; status: JoStatus; diff --git a/src/components/JoSearch/JoSearch.tsx b/src/components/JoSearch/JoSearch.tsx index d2dd42e..1206935 100644 --- a/src/components/JoSearch/JoSearch.tsx +++ b/src/components/JoSearch/JoSearch.tsx @@ -161,11 +161,20 @@ const JoSearch: React.FC = ({ defaultInputs, bomCombo, printerCombo, jobT const fetchBomForJo = useCallback(async (jo: JobOrder): Promise => { try { - const detailedJo = detailedJos.get(jo.id) || await fetchJoDetailClient(jo.id); - const matchingBom = bomCombo.find(bom => { - return true; // 临时占位 - }); - return matchingBom || null; + // 若列表的 jo 已有 bomId(之後若 API 有回傳),可直接用 + const bomId = (jo as { bomId?: number }).bomId; + if (bomId != null) { + const matchingBom = bomCombo.find(bom => bom.id === bomId); + if (matchingBom) return matchingBom; + } + // 否則打明細 API,明細會帶 bomId + const detailedJo = detailedJos.get(jo.id) ?? await fetchJoDetailClient(jo.id); + const detailBomId = (detailedJo as { bomId?: number }).bomId; + if (detailBomId != null) { + const matchingBom = bomCombo.find(bom => bom.id === detailBomId); + if (matchingBom) return matchingBom; + } + return null; } catch (error) { console.error("Error fetching BOM for JO:", error); return null;