| @@ -426,14 +426,69 @@ const fetchFgPickOrdersData = useCallback(async () => { | |||||
| return; | return; | ||||
| } | } | ||||
| // Use the non-auto-assign endpoint - this only fetches existing data | |||||
| const allLotDetails = await fetchAllPickOrderLotsHierarchical(userIdToUse); | |||||
| // ✅ Fix: fetchAllPickOrderLotsHierarchical returns hierarchical data, not a flat array | |||||
| const hierarchicalData = await fetchAllPickOrderLotsHierarchical(userIdToUse); | |||||
| console.log(" Hierarchical data:", hierarchicalData); | |||||
| // ✅ Fix: Ensure we always set an array | |||||
| // If hierarchicalData is not in the expected format, default to empty array | |||||
| let allLotDetails: any[] = []; | |||||
| if (hierarchicalData && Array.isArray(hierarchicalData)) { | |||||
| // If it's already an array, use it directly | |||||
| allLotDetails = hierarchicalData; | |||||
| } else if (hierarchicalData?.pickOrders && Array.isArray(hierarchicalData.pickOrders)) { | |||||
| // Process hierarchical data into flat array (similar to GoodPickExecutiondetail.tsx) | |||||
| const mergedPickOrder = hierarchicalData.pickOrders[0]; | |||||
| if (mergedPickOrder?.pickOrderLines) { | |||||
| mergedPickOrder.pickOrderLines.forEach((line: any) => { | |||||
| if (line.lots && line.lots.length > 0) { | |||||
| line.lots.forEach((lot: any) => { | |||||
| allLotDetails.push({ | |||||
| pickOrderConsoCode: mergedPickOrder.consoCode, | |||||
| pickOrderTargetDate: mergedPickOrder.targetDate, | |||||
| pickOrderStatus: mergedPickOrder.status, | |||||
| pickOrderId: line.pickOrderId || mergedPickOrder.pickOrderIds?.[0] || 0, | |||||
| pickOrderCode: mergedPickOrder.pickOrderCodes?.[0] || "", | |||||
| pickOrderLineId: line.id, | |||||
| pickOrderLineRequiredQty: line.requiredQty, | |||||
| pickOrderLineStatus: line.status, | |||||
| itemId: line.item?.id, | |||||
| itemCode: line.item?.code, | |||||
| itemName: line.item?.name, | |||||
| uomDesc: line.item?.uomDesc, | |||||
| uomShortDesc: line.item?.uomShortDesc, | |||||
| lotId: lot.id, | |||||
| lotNo: lot.lotNo, | |||||
| expiryDate: lot.expiryDate, | |||||
| location: lot.location, | |||||
| stockUnit: lot.stockUnit, | |||||
| availableQty: lot.availableQty, | |||||
| requiredQty: lot.requiredQty, | |||||
| actualPickQty: lot.actualPickQty, | |||||
| lotStatus: lot.lotStatus, | |||||
| lotAvailability: lot.lotAvailability, | |||||
| processingStatus: lot.processingStatus, | |||||
| stockOutLineId: lot.stockOutLineId, | |||||
| stockOutLineStatus: lot.stockOutLineStatus, | |||||
| stockOutLineQty: lot.stockOutLineQty, | |||||
| routerId: lot.router?.id, | |||||
| routerIndex: lot.router?.index, | |||||
| routerRoute: lot.router?.route, | |||||
| routerArea: lot.router?.area, | |||||
| }); | |||||
| }); | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||
| console.log(" All combined lot details:", allLotDetails); | console.log(" All combined lot details:", allLotDetails); | ||||
| setCombinedLotData(allLotDetails); | setCombinedLotData(allLotDetails); | ||||
| setOriginalCombinedData(allLotDetails); | setOriginalCombinedData(allLotDetails); | ||||
| // 计算完成状态并发送事件 | |||||
| const allCompleted = allLotDetails.length > 0 && allLotDetails.every((lot: any) => | |||||
| // ✅ Fix: Add safety check - ensure allLotDetails is an array before using .every() | |||||
| const allCompleted = Array.isArray(allLotDetails) && allLotDetails.length > 0 && allLotDetails.every((lot: any) => | |||||
| lot.processingStatus === 'completed' | lot.processingStatus === 'completed' | ||||
| ); | ); | ||||
| @@ -462,6 +517,7 @@ const fetchFgPickOrdersData = useCallback(async () => { | |||||
| } | } | ||||
| }, [currentUserId, combinedLotData]); | }, [currentUserId, combinedLotData]); | ||||
| // Only fetch existing data when session is ready, no auto-assignment | // Only fetch existing data when session is ready, no auto-assignment | ||||
| useEffect(() => { | useEffect(() => { | ||||
| if (session && currentUserId && !initializationRef.current) { | if (session && currentUserId && !initializationRef.current) { | ||||
| @@ -1038,10 +1094,15 @@ const fetchFgPickOrdersData = useCallback(async () => { | |||||
| }); | }); | ||||
| }, []); | }, []); | ||||
| // Pagination data with sorting by routerIndex | |||||
| const paginatedData = useMemo(() => { | const paginatedData = useMemo(() => { | ||||
| // ✅ Fix: Add safety check to ensure combinedLotData is an array | |||||
| if (!Array.isArray(combinedLotData)) { | |||||
| console.warn("⚠️ combinedLotData is not an array:", combinedLotData); | |||||
| return []; | |||||
| } | |||||
| // Sort by routerIndex first, then by other criteria | // Sort by routerIndex first, then by other criteria | ||||
| const sortedData = [...combinedLotData].sort((a, b) => { | |||||
| const sortedData = [...combinedLotData].sort((a: any, b: any) => { | |||||
| const aIndex = a.routerIndex || 0; | const aIndex = a.routerIndex || 0; | ||||
| const bIndex = b.routerIndex || 0; | const bIndex = b.routerIndex || 0; | ||||
| @@ -1063,9 +1124,6 @@ const fetchFgPickOrdersData = useCallback(async () => { | |||||
| const endIndex = startIndex + paginationController.pageSize; | const endIndex = startIndex + paginationController.pageSize; | ||||
| return sortedData.slice(startIndex, endIndex); | return sortedData.slice(startIndex, endIndex); | ||||
| }, [combinedLotData, paginationController]); | }, [combinedLotData, paginationController]); | ||||
| // ... existing code ... | |||||
| return ( | return ( | ||||
| <FormProvider {...formProps}> | <FormProvider {...formProps}> | ||||
| {/* 修复:改进条件渲染逻辑 */} | {/* 修复:改进条件渲染逻辑 */} | ||||