= {};
+ for (const item of taskItems) {
+ const manual = manualPlan[item.id];
+ const batches = batchInfo[item.id]?.data?.batches || [];
+ const need = settlementQtyOf(item.id, item);
+ let plan: BatchPlanEntry[] = [];
+ let shortfall = 0;
+ if (manual && manual.length) {
+ plan = manual;
+ shortfall = fifoAllocateBatches(batches, need).shortfall;
+ } else if (batches.length && need > 0) {
+ const alloc = fifoAllocateBatches(batches, need);
+ plan = alloc.plan;
+ shortfall = alloc.shortfall;
+ }
+ out[item.id] = { plan, shortfall, text: formatBatchPlanText(plan, batches) };
+ }
+ return out;
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [taskItems, batchInfo, manualPlan, draftQty, draftWeight]);
+
+ useEffect(() => {
+ if (!selectedTask) return;
+ const pickCode = selectedTask.pick_code;
+ if (batchCtxRef.current.pickCode !== pickCode) {
+ batchCtxRef.current = { pickCode, ids: new Set() };
+ setBatchInfo({});
+ setManualPlan({});
+ setBatchEditorItemId(null);
+ }
+ for (const item of taskItems) {
+ if (!item.id || !String(item.sku_code || '').trim()) continue;
+ if (batchCtxRef.current.ids.has(item.id)) continue;
+ batchCtxRef.current.ids.add(item.id);
+ setBatchInfo((prev) => ({ ...prev, [item.id]: { loading: true, data: null } }));
+ fetchPickingOutboundBatchesApi(item.id)
+ .then((res) => {
+ setBatchInfo((prev) => ({ ...prev, [item.id]: { loading: false, data: res.data } }));
+ })
+ .catch((error: unknown) => {
+ setBatchInfo((prev) => ({
+ ...prev,
+ [item.id]: {
+ loading: false,
+ data: null,
+ error: error instanceof Error ? error.message : '',
+ },
+ }));
+ });
+ }
+ }, [selectedTask, taskItems]);
+
+ const openBatchEditor = (item: PickingItemRow) => {
+ const batches = batchInfo[item.id]?.data?.batches || [];
+ if (!batches.length) {
+ notify(t('picking.batch.none'));
+ return;
+ }
+ const plan = resolveItemPlan(item) || [];
+ const qtyByNo = new Map(plan.map((p) => [p.batch_no, p.qty]));
+ setBatchEditorRows(
+ batches.map((b) => ({
+ batch_no: String(b.batch_no),
+ storage_zone: b.storage_zone || '',
+ inbound_date: b.inbound_date || '',
+ available_qty: Number(b.available_qty) || 0,
+ qty: String(qtyByNo.get(String(b.batch_no)) ?? 0),
+ }))
+ );
+ setBatchEditorItemId(item.id);
+ };
+
+ const resetBatchEditorFifo = () => {
+ const item = taskItems.find((row) => row.id === batchEditorItemId);
+ const data = batchEditorItemId ? batchInfo[batchEditorItemId]?.data : null;
+ if (!item || !data) return;
+ const { plan } = fifoAllocateBatches(data.batches, settlementQtyOf(item.id, item));
+ const qtyByNo = new Map(plan.map((p) => [p.batch_no, p.qty]));
+ setBatchEditorRows(
+ (data.batches || []).map((b) => ({
+ batch_no: String(b.batch_no),
+ storage_zone: b.storage_zone || '',
+ inbound_date: b.inbound_date || '',
+ available_qty: Number(b.available_qty) || 0,
+ qty: String(qtyByNo.get(String(b.batch_no)) ?? 0),
+ }))
+ );
+ };
+
+ const applyBatchEditor = () => {
+ if (!batchEditorItemId) return;
+ const plan = batchEditorRows
+ .map((row) => ({ batch_no: row.batch_no, qty: round3(Number(row.qty) || 0) }))
+ .filter((row) => row.qty > 0);
+ setManualPlan((prev) => ({ ...prev, [batchEditorItemId]: plan }));
+ setBatchEditorItemId(null);
+ };
+
+ const moveBatchEditorRow = (index: number, dir: number) => {
+ setBatchEditorRows((prev) => {
+ const target = index + dir;
+ if (target < 0 || target >= prev.length) return prev;
+ const next = [...prev];
+ const tmp = next[index];
+ next[index] = next[target];
+ next[target] = tmp;
+ return next;
+ });
+ };
+
const buildProgressItems = () =>
taskItems.map((item) => {
const pickedQty = Number(draftQty[item.id] ?? item.picked_qty ?? 0) || 0;
@@ -907,6 +1090,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
Math.abs(settlement - Number(item.required_qty || 0)) < 0.0001
? ''
: item.diff_reason || '',
+ outbound_batches: resolveItemPlan(item) || undefined,
};
});
@@ -948,6 +1132,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
picked_qty: Number(item.required_qty) || 0,
picked_weight: Number(draftWeight[item.id] ?? item.picked_weight ?? 0) || 0,
diff_reason: '',
+ outbound_batches: resolveItemPlan(item) || undefined,
})),
});
notify.success(t('picking.toast.confirmed'));
@@ -1166,6 +1351,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
picked_weight: pickedWeight,
unit: item.unit || '',
diff_reason: '',
+ outbound_batches: resolveItemPlan(item) || undefined,
};
})
.filter((row) => (Number(row.picked_weight) || Number(row.picked_qty) || 0) > 0);
@@ -2325,6 +2511,41 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
{item.container_code || '—'}
);
+ case 'batch': {
+ const info = planByItem[item.id];
+ const meta = batchInfo[item.id];
+ const editable =
+ Number(selectedTask.pick_status) < 40 &&
+ Boolean(String(item.sku_code || '').trim());
+ const summary = meta?.loading
+ ? t('picking.batch.loading')
+ : info?.text
+ ? info.text
+ : meta?.error
+ ? t('picking.batch.fail')
+ : t('picking.batch.none');
+ return (
+ |
+
+ {summary}
+ {editable ? (
+
+ ) : null}
+
+ {info?.shortfall > 0 ? (
+
+ {t('picking.batch.shortfall', { qty: formatQty(info.shortfall) })}
+
+ ) : null}
+ |
+ );
+ }
default:
return null;
}
@@ -2335,6 +2556,107 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
+ {batchEditorItemId
+ ? (() => {
+ const item = taskItems.find((row) => row.id === batchEditorItemId);
+ const data = batchInfo[batchEditorItemId]?.data;
+ const need = item ? settlementQtyOf(item.id, item) : 0;
+ const total = batchEditorRows.reduce((sum, row) => sum + (Number(row.qty) || 0), 0);
+ const shortfall = fifoAllocateBatches(data?.batches, need).shortfall;
+ return (
+
+
+
+ {t('picking.batch.title')} ·{' '}
+ {item?.item_name || t('picking.productFallback')}
+
+
+ {t('picking.batch.summary', {
+ need: formatQty(need),
+ unit: item?.unit || '',
+ claimable: formatQty(data?.claimable ?? 0),
+ })}
+
+
+
+ {batchEditorRows.map((row, index) => (
+
+
+
{row.batch_no}
+
+ {t('picking.batch.rowMeta', {
+ zone: row.storage_zone || t('picking.batch.noZone'),
+ date: row.inbound_date || '—',
+ qty: formatQty(row.available_qty),
+ })}
+
+
+
+
+
+
+
+ setBatchEditorRows((prev) =>
+ prev.map((r, i) => (i === index ? { ...r, qty: v } : r))
+ )
+ }
+ className="app-input app-focus-ring w-24 px-2 py-1 border rounded text-sm text-right"
+ />
+
+ ))}
+
+
+
+ {t('picking.batch.total', {
+ total: formatQty(round3(total)),
+ need: formatQty(need),
+ })}
+
+ {shortfall > 0 ? (
+
+ {t('picking.batch.shortfall', { qty: formatQty(shortfall) })}
+
+ ) : null}
+
+
+
+
+
+
+ );
+ })()
+ : null}
+
{Number(selectedTask.pick_status) < 30 && pickingBarcodeEnabled && (
{t('picking.modal.scanTitle')}
diff --git a/src/utils/picking.ts b/src/utils/picking.ts
index 5802aeb..5f63eae 100644
--- a/src/utils/picking.ts
+++ b/src/utils/picking.ts
@@ -32,6 +32,10 @@ export interface PickingItemRow {
sort_order?: number | null;
container_code?: string | null;
staged_at?: string | null;
+ /** 商品默认区域(`skus.storage_zone`),用于分拣按区域展示 */
+ storage_zone?: string | null;
+ /** 分拣「完成」时手选的出库批次计划(发车核货按此扣库;空=默认 FIFO) */
+ outbound_batches?: Array<{ batch_no: string; qty: number }> | null;
}
export interface PickingTaskRow {
diff --git a/src/utils/workflowApi.ts b/src/utils/workflowApi.ts
index 8089e81..7723bec 100644
--- a/src/utils/workflowApi.ts
+++ b/src/utils/workflowApi.ts
@@ -1133,6 +1133,31 @@ export async function savePickingProgressApi(body: Record
) {
});
}
+/** 分拣明细的出库批次候选(只读,默认 FIFO 顺序 + SKU 级可扣汇总) */
+export interface PickingOutboundBatches {
+ sku_code: string | null;
+ order_code: string | null;
+ total_available: number;
+ other_reserved: number;
+ claimable: number;
+ batches: Array<{
+ batch_id: string;
+ batch_no: string;
+ available_qty: number;
+ storage_zone: string | null;
+ inbound_date: string | null;
+ production_date: string | null;
+ }>;
+}
+
+/** 按分拣明细取「本次可扣批次」;不扣库 */
+export async function fetchPickingOutboundBatchesApi(pickItemId: string) {
+ const params = new URLSearchParams({ pick_item_id: pickItemId });
+ return workflowFetch<{ data: PickingOutboundBatches }>(
+ `/picking/outbound-batches?${params.toString()}`
+ );
+}
+
/** 分拣完成:回写订单结算量,置分拣完成(30),订单自动进入待配送 */
export async function confirmPickingCompleteApi(body: {
pick_code: string;
@@ -1142,6 +1167,7 @@ export async function confirmPickingCompleteApi(body: {
picked_qty: number;
picked_weight?: number;
diff_reason?: string;
+ outbound_batches?: Array<{ batch_no: string; qty: number }>;
}>;
}) {
return workflowFetch<{