| @@ -197,12 +197,19 @@ const ApproverStockTake: React.FC<ApproverStockTakeProps> = ({ | |||||
| // Approver input | // Approver input | ||||
| const approverQtyValue = approverQty[detail.id]; | const approverQtyValue = approverQty[detail.id]; | ||||
| const approverBadQtyValue = approverBadQty[detail.id]; | const approverBadQtyValue = approverBadQty[detail.id]; | ||||
| if (!approverQtyValue || !approverBadQtyValue) { | |||||
| onSnackbar(t("Please enter Approver QTY and Bad QTY"), "error"); | |||||
| if (approverQtyValue === undefined || approverQtyValue === null || approverQtyValue === "") { | |||||
| onSnackbar(t("Please enter Approver QTY"), "error"); | |||||
| return; | |||||
| } | |||||
| if (approverBadQtyValue === undefined || approverBadQtyValue === null || approverBadQtyValue === "") { | |||||
| onSnackbar(t("Please enter Approver Bad QTY"), "error"); | |||||
| return; | return; | ||||
| } | } | ||||
| finalQty = parseFloat(approverQtyValue); | |||||
| finalBadQty = parseFloat(approverBadQtyValue); | |||||
| finalQty = parseFloat(approverQtyValue) || 0; | |||||
| finalBadQty = parseFloat(approverBadQtyValue) || 0; | |||||
| } | } | ||||
| setSaving(true); | setSaving(true); | ||||
| @@ -357,12 +364,37 @@ const ApproverStockTake: React.FC<ApproverStockTakeProps> = ({ | |||||
| ).join(", "); | ).join(", "); | ||||
| const isSubmitDisabled = useCallback((detail: InventoryLotDetailResponse): boolean => { | const isSubmitDisabled = useCallback((detail: InventoryLotDetailResponse): boolean => { | ||||
| // Only allow editing if there's a first stock take qty | |||||
| if (!detail.firstStockTakeQty || detail.firstStockTakeQty === 0) { | |||||
| // 如果已经有 finalQty(已完成审批),不允许再次编辑 | |||||
| if (detail.finalQty != null) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | |||||
| }, []); | |||||
| // 获取当前选择模式 | |||||
| const hasFirst = detail.firstStockTakeQty != null && detail.firstStockTakeQty >= 0; | |||||
| const hasSecond = detail.secondStockTakeQty != null && detail.secondStockTakeQty >= 0; | |||||
| const selection = qtySelection[detail.id] || (hasSecond ? "second" : "first"); | |||||
| // 如果选择了 "approver" 模式,检查用户是否已经输入了值 | |||||
| if (selection === "approver") { | |||||
| const approverQtyValue = approverQty[detail.id]; | |||||
| const approverBadQtyValue = approverBadQty[detail.id]; | |||||
| // 如果用户已经输入了值(包括0),允许保存 | |||||
| if (approverQtyValue !== undefined && approverQtyValue !== null && approverQtyValue !== "" && | |||||
| approverBadQtyValue !== undefined && approverBadQtyValue !== null && approverBadQtyValue !== "") { | |||||
| return false; // 允许保存 | |||||
| } | |||||
| // 如果用户还没有输入值,禁用按钮 | |||||
| return true; | |||||
| } | |||||
| // 对于 first 或 second 模式,需要检查是否有有效的数量(允许0) | |||||
| // 只要 firstStockTakeQty 不为 null,就允许保存(即使为0) | |||||
| if (detail.firstStockTakeQty == null) { | |||||
| return true; // 如果 firstStockTakeQty 为 null,禁用 | |||||
| } | |||||
| return false; // 允许保存 | |||||
| }, [qtySelection, approverQty, approverBadQty]); | |||||
| return ( | return ( | ||||
| <Box> | <Box> | ||||
| @@ -439,10 +471,10 @@ const ApproverStockTake: React.FC<ApproverStockTakeProps> = ({ | |||||
| </TableRow> | </TableRow> | ||||
| ) : ( | ) : ( | ||||
| filteredDetails.map((detail) => { | filteredDetails.map((detail) => { | ||||
| const submitDisabled = isSubmitDisabled(detail); | |||||
| const hasFirst = detail.firstStockTakeQty != null && detail.firstStockTakeQty > 0; | |||||
| const hasSecond = detail.secondStockTakeQty != null && detail.secondStockTakeQty > 0; | |||||
| const selection = qtySelection[detail.id] || (hasSecond ? "second" : "first"); | |||||
| // const submitDisabled = isSubmitDisabled(detail); | |||||
| const hasFirst = detail.firstStockTakeQty != null && detail.firstStockTakeQty >= 0; | |||||
| const hasSecond = detail.secondStockTakeQty != null && detail.secondStockTakeQty >= 0; // 改为 >= 0,允许0值 | |||||
| const selection = qtySelection[detail.id] || (hasSecond ? "second" : "first"); | |||||
| return ( | return ( | ||||
| <TableRow key={detail.id}> | <TableRow key={detail.id}> | ||||
| @@ -620,7 +652,7 @@ const ApproverStockTake: React.FC<ApproverStockTakeProps> = ({ | |||||
| size="small" | size="small" | ||||
| variant="contained" | variant="contained" | ||||
| onClick={() => handleSaveApproverStockTake(detail)} | onClick={() => handleSaveApproverStockTake(detail)} | ||||
| disabled={saving || submitDisabled || detail.stockTakeRecordStatus === "completed"} | |||||
| //disabled={saving || submitDisabled || detail.stockTakeRecordStatus === "completed"} | |||||
| > | > | ||||
| {t("Save")} | {t("Save")} | ||||
| </Button> | </Button> | ||||