From b006a1115c9610a456e0eb24a698dbae1a46e363 Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Wed, 4 Feb 2026 01:59:08 +0800 Subject: [PATCH] update --- src/app/api/jo/actions.ts | 2 +- src/app/api/po/index.ts | 2 +- src/app/api/stockIn/index.ts | 1 + .../ProductionProcess/JobProcessStatus.tsx | 2 +- .../ProductionProcessList.tsx | 24 ++++---- src/components/PutAwayScan/PutAwayModal.tsx | 55 ++++++++----------- src/components/Qc/QcStockInModal.tsx | 26 +++++++-- 7 files changed, 61 insertions(+), 51 deletions(-) diff --git a/src/app/api/jo/actions.ts b/src/app/api/jo/actions.ts index 565393e..a5eee0f 100644 --- a/src/app/api/jo/actions.ts +++ b/src/app/api/jo/actions.ts @@ -1211,7 +1211,7 @@ export const fetchMaterialPickStatus = cache(async (): Promise { } const label = [ process.processName, - process.equipmentDescription, + process.equipmentName, process.equipmentDetailName ? `-${process.equipmentDetailName}` : "", ].filter(Boolean).join(" "); // 如果工序是必需的,显示三行(Start、Finish、Wait Time) diff --git a/src/components/ProductionProcess/ProductionProcessList.tsx b/src/components/ProductionProcess/ProductionProcessList.tsx index ee8dd11..d9cf11e 100644 --- a/src/components/ProductionProcess/ProductionProcessList.tsx +++ b/src/components/ProductionProcess/ProductionProcessList.tsx @@ -20,6 +20,8 @@ import { useSession } from "next-auth/react"; import { SessionWithTokens } from "@/config/authConfig"; import dayjs from "dayjs"; import { OUTPUT_DATE_FORMAT } from "@/app/utils/formatUtil"; + + import { fetchAllJoborderProductProcessInfo, AllJoborderProductProcessInfoResponse, @@ -50,6 +52,7 @@ const ProductProcessList: React.FC = ({ onSelectProcess const [openModal, setOpenModal] = useState(false); const [modalInfo, setModalInfo] = useState(); const currentUserId = session?.id ? parseInt(session.id) : undefined; + const [suggestedLocationCode, setSuggestedLocationCode] = useState(null); const handleAssignPickOrder = useCallback(async (pickOrderId: number, jobOrderId?: number, productProcessId?: number) => { if (!currentUserId) { @@ -87,17 +90,17 @@ const ProductProcessList: React.FC = ({ onSelectProcess alert(t(`Unknown error: ${error?.message || "Unknown error"}。Please try again later.`)); } }, [currentUserId, t, onSelectMatchingStock]); + const handleViewStockIn = useCallback((process: AllJoborderProductProcessInfoResponse) => { if (!process.stockInLineId) { alert(t("Invalid Stock In Line Id")); return; } - + setModalInfo({ id: process.stockInLineId, + //itemId: process.itemId, // 如果 process 中有 itemId,添加这一行 //expiryDate: dayjs().add(1, "month").format(OUTPUT_DATE_FORMAT), - - // 视需要补 itemId、jobOrderId 等 }); setOpenModal(true); }, [t]); @@ -316,13 +319,14 @@ const ProductProcessList: React.FC = ({ onSelectProcess })} + session={sessionToken} + open={openModal} + onClose={closeNewModal} + inputDetail={modalInfo} + printerCombo={printerCombo} + warehouse={[]} + printSource="productionProcess" + /> {processes.length > 0 && ( = ({ open, onClose, warehouse, stockInLineId // 根据 item 的 locationCode 设置默认 warehouseId useEffect(() => { - const fetchItemAndSetDefaultWarehouse = async () => { - if (itemDetail?.itemId && warehouse.length > 0 && firstWarehouseId === null) { - // 只在第一次上架时设置默认值 - try { - const itemResult = await fetchItemForPutAway(itemDetail.itemId); - const item = itemResult.item; - - // 获取 item 的 locationCode(处理大小写问题) - const locationCode = item.LocationCode || item.locationCode; - - if (locationCode) { - // 根据 locationCode 查找对应的 warehouse(通过 code 匹配) - const matchedWarehouse = warehouse.find( - (w) => w.code === locationCode || w.code?.toLowerCase() === locationCode?.toLowerCase() - ); - - if (matchedWarehouse) { - // 只设置用于显示的默认值,不通知父组件 - setItemDefaultWarehouseId(matchedWarehouse.id); - console.log("%c Set default warehouse from item locationCode (display only):", "color:green", { - locationCode, - warehouseId: matchedWarehouse.id, - warehouseCode: matchedWarehouse.code - }); - } - } - } catch (error) { - console.error("Error fetching item to get default warehouse:", error); + // 直接使用 fetchStockInLineInfo 返回的 locationCode + // 只在第一次上架时(firstWarehouseId === null)设置默认值 + if (itemDetail?.locationCode && warehouse.length > 0 && firstWarehouseId === null) { + const locationCode = itemDetail.locationCode; + + if (locationCode) { + // 根据 locationCode 查找对应的 warehouse(通过 code 匹配) + const matchedWarehouse = warehouse.find( + (w) => w.code === locationCode || w.code?.toLowerCase() === locationCode?.toLowerCase() + ); + + if (matchedWarehouse) { + // 只设置用于显示的默认值,不通知父组件 + setItemDefaultWarehouseId(matchedWarehouse.id); + console.log("%c Set default warehouse from item locationCode (from API, display only):", "color:green", { + locationCode, + warehouseId: matchedWarehouse.id, + warehouseCode: matchedWarehouse.code + }); + } else { + console.log("%c No warehouse found for locationCode:", "color:yellow", locationCode); } } - }; - - if (itemDetail && itemDetail.status === "received") { - fetchItemAndSetDefaultWarehouse(); } - }, [itemDetail, warehouse, firstWarehouseId]); + }, [itemDetail?.locationCode, warehouse, firstWarehouseId]); useEffect(() => { // 只使用实际扫描的 warehouseId,不使用默认值进行验证 diff --git a/src/components/Qc/QcStockInModal.tsx b/src/components/Qc/QcStockInModal.tsx index 024b79a..3743a6f 100644 --- a/src/components/Qc/QcStockInModal.tsx +++ b/src/components/Qc/QcStockInModal.tsx @@ -119,12 +119,20 @@ const QcStockInModal: React.FC = ({ const res = await fetchStockInLineInfo(stockInLineId); if (res) { console.log("%c Fetched Stock In Line: ", "color:orange", res); + console.log("%c [QC] itemId in response:", "color:yellow", res.itemId); + console.log("%c [QC] locationCode in response:", "color:yellow", res.locationCode); + // 如果 res 中没有 itemId,检查是否有其他方式获取 + if (!res.itemId) { + console.warn("%c [QC] Warning: itemId is missing in response!", "color:red"); + } setStockInLineInfo({...inputDetail, ...res, expiryDate: res.expiryDate}); - // fetchQcResultData(stockInLineId); - } else throw("Result is undefined"); } catch (e) { console.log("%c Error when fetching Stock In Line: ", "color:red", e); + console.log("%c Error details: ", "color:red", { + message: e instanceof Error ? e.message : String(e), + stack: e instanceof Error ? e.stack : undefined + }); alert("Something went wrong, please retry"); closeHandler({}, "backdropClick"); } @@ -144,16 +152,24 @@ const QcStockInModal: React.FC = ({ } }, [open]); useEffect(() => { + // 如果后端已经在 StockInLine 中返回了 locationCode,直接使用 + if (stockInLineInfo?.locationCode) { + setItemLocationCode(stockInLineInfo.locationCode); + console.log("%c [QC] item LocationCode from API:", "color:cyan", stockInLineInfo.locationCode); + return; + } + + // 如果没有 locationCode,尝试从 itemId 获取(向后兼容) const loadItemLocationCode = async () => { if (!stockInLineInfo?.itemId) return; - + try { const itemResult = await fetchItemForPutAway(stockInLineInfo.itemId); const item = itemResult.item; - + const locationCode = item.LocationCode || item.locationCode || null; setItemLocationCode(locationCode); - console.log("%c [QC] item LocationCode:", "color:cyan", locationCode); + console.log("%c [QC] item LocationCode from fetchItemForPutAway:", "color:cyan", locationCode); } catch (error) { console.error("Error fetching item to get LocationCode in QC:", error); setItemLocationCode(null);