From efabb72e94d6488ced83812ed8633d2f2b31906e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E5=A4=A9?= Date: Sun, 11 Oct 2026 13:52:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=88=86=E6=8B=A3):=20=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=A6=86=E7=9B=96=E5=B7=B2=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E6=89=8B=E9=80=89=E6=89=B9=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Web/小程序提交时优先沿用已持久化的 outbound_batches,避免再次保存 被默认 FIFO 覆盖(Web「已完成单保存修改」会丢手选批次) - 已出库(≥40)单展示落库计划,不再用剩余库存重算 FIFO - 批次编辑器行按 batch_id 作 key --- miniprogram/components/picking-panel/index.js | 39 +++++++++++------- .../components/picking-panel/index.wxml | 2 +- src/pages/picking/PickingManagement.tsx | 41 ++++++++++++++----- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/miniprogram/components/picking-panel/index.js b/miniprogram/components/picking-panel/index.js index b4ba777..b5a7360 100644 --- a/miniprogram/components/picking-panel/index.js +++ b/miniprogram/components/picking-panel/index.js @@ -48,6 +48,18 @@ function countPending(items) { return (items || []).filter((item) => isItemPending(item)).length; } +/** 归一化已持久化的批次计划;空返回 null */ +function normalizeSavedPlan(raw) { + if (!Array.isArray(raw)) return null; + const out = raw + .map((p) => ({ + batch_no: String((p && p.batch_no) || ''), + qty: Number(p && p.qty) || 0, + })) + .filter((p) => p.batch_no && p.qty > 0); + return out.length ? out : null; +} + function taskScopeType(task) { return String((task && task.scope_type) || 'order').trim() || 'order'; } @@ -566,14 +578,7 @@ Component({ production_date: b.production_date || '', })); const need = resolveItemNeed(item); - const serverPlan = Array.isArray(item.outbound_batches) - ? item.outbound_batches - .map((p) => ({ - batch_no: String((p && p.batch_no) || ''), - qty: Number(p && p.qty) || 0, - })) - .filter((p) => p.batch_no && p.qty > 0) - : []; + const serverPlan = normalizeSavedPlan(item.outbound_batches) || []; if (serverPlan.length) { this.setData({ [`batchesMap.${item.id}`]: { @@ -626,12 +631,16 @@ Component({ resolveItemPlan(item) { if (!item || !item.id) return null; const info = this.data.batchesMap[item.id]; - if (!info || !Array.isArray(info.batches) || !info.batches.length) return null; - if (info.manual && Array.isArray(info.plan) && info.plan.length) return info.plan; - const need = resolveItemNeed(item); - if (!(need > 0)) return null; - const plan = allocateBatchesFifo(info.batches, need).plan; - return plan.length ? plan : null; + if (info && Array.isArray(info.batches) && info.batches.length) { + if (info.manual && Array.isArray(info.plan) && info.plan.length) return info.plan; + const need = resolveItemNeed(item); + if (need > 0) { + const plan = allocateBatchesFifo(info.batches, need).plan; + if (plan.length) return plan; + } + } + // 批次拿不到(已完成单不再拉取 / 无库存)时回退已保存选择,避免被默认 FIFO 覆盖 + return normalizeSavedPlan(item.outbound_batches); }, /** 勾选/改量后,未手改过的行按新数量重算 FIFO 预分配 */ @@ -678,6 +687,7 @@ Component({ : allocateBatchesFifo(info.batches, need).plan; const qtyByNo = new Map((basePlan || []).map((p) => [String(p.batch_no), Number(p.qty) || 0])); const rows = info.batches.map((b) => ({ + batch_id: String(b.batch_id || b.batch_no), batch_no: String(b.batch_no), storage_zone: b.storage_zone || '', inbound_date: b.inbound_date || '', @@ -738,6 +748,7 @@ Component({ const { plan } = allocateBatchesFifo(info.batches, need); const qtyByNo = new Map(plan.map((p) => [String(p.batch_no), Number(p.qty) || 0])); const rows = info.batches.map((b) => ({ + batch_id: String(b.batch_id || b.batch_no), batch_no: String(b.batch_no), storage_zone: b.storage_zone || '', inbound_date: b.inbound_date || '', diff --git a/miniprogram/components/picking-panel/index.wxml b/miniprogram/components/picking-panel/index.wxml index baffd2b..e88b1c7 100644 --- a/miniprogram/components/picking-panel/index.wxml +++ b/miniprogram/components/picking-panel/index.wxml @@ -178,7 +178,7 @@ 需 {{editor.need}}{{editor.unit}} · 可扣 {{editor.claimable}} - + {{item.batch_no}} {{item.storage_zone || '未设区域'}} · 入库 {{item.inbound_date || '—'}} · 可用 {{item.available_qty}} diff --git a/src/pages/picking/PickingManagement.tsx b/src/pages/picking/PickingManagement.tsx index dfdf229..9171b2b 100644 --- a/src/pages/picking/PickingManagement.tsx +++ b/src/pages/picking/PickingManagement.tsx @@ -155,6 +155,7 @@ function formatQty(value: unknown) { type BatchPlanEntry = { batch_no: string; qty: number }; type BatchEditorRow = { + batch_id: string; batch_no: string; storage_zone: string; inbound_date: string; @@ -166,6 +167,14 @@ function round3(value: number) { return Math.round((Number(value) || 0) * 1000) / 1000; } +/** 归一化已持久化的批次计划(PickingItemRow.outbound_batches) */ +function normalizeSavedPlan(raw: PickingItemRow['outbound_batches']): BatchPlanEntry[] { + if (!Array.isArray(raw)) return []; + return raw + .map((p) => ({ batch_no: String(p?.batch_no || ''), qty: Number(p?.qty) || 0 })) + .filter((p) => p.batch_no && p.qty > 0); +} + /** 按先进先出把 need 量分配到候选批次(batches 已按 FIFO 排序) */ function fifoAllocateBatches( batches: Array<{ batch_no: string; available_qty: number }> | undefined, @@ -956,12 +965,18 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin const resolveItemPlan = (item: PickingItemRow): BatchPlanEntry[] | null => { const manual = manualPlan[item.id]; if (manual && manual.length) return manual; + // 已保存的手选计划优先(否则再次保存会被默认 FIFO 覆盖) + const saved = normalizeSavedPlan(item.outbound_batches); + if (saved.length) return saved; const batches = batchInfo[item.id]?.data?.batches; - if (!batches || !batches.length) return null; - const need = settlementQtyOf(item.id, item); - if (!(need > 0)) return null; - const plan = fifoAllocateBatches(batches, need).plan; - return plan.length ? plan : null; + if (batches && batches.length) { + const need = settlementQtyOf(item.id, item); + if (need > 0) { + const plan = fifoAllocateBatches(batches, need).plan; + if (plan.length) return plan; + } + } + return null; }; const planByItem = useMemo(() => { @@ -969,17 +984,19 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin for (const item of taskItems) { const manual = manualPlan[item.id]; const batches = batchInfo[item.id]?.data?.batches || []; + const saved = normalizeSavedPlan(item.outbound_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 (saved.length) { + // 已完成单展示已保存的选择,不用「剩余库存」重算(那会显示从未用过的计划) + plan = saved; } else if (batches.length && need > 0) { - const alloc = fifoAllocateBatches(batches, need); - plan = alloc.plan; - shortfall = alloc.shortfall; + plan = fifoAllocateBatches(batches, need).plan; } + if (batches.length) shortfall = fifoAllocateBatches(batches, need).shortfall; out[item.id] = { plan, shortfall, text: formatBatchPlanText(plan, batches) }; } return out; @@ -995,6 +1012,8 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin setManualPlan({}); setBatchEditorItemId(null); } + // 已出库(≥40)不再拉批次:计划已落库,展示保存值即可 + if (Number(selectedTask.pick_status) >= 40) return; for (const item of taskItems) { if (!item.id || !String(item.sku_code || '').trim()) continue; if (batchCtxRef.current.ids.has(item.id)) continue; @@ -1027,6 +1046,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin const qtyByNo = new Map(plan.map((p) => [p.batch_no, p.qty])); setBatchEditorRows( batches.map((b) => ({ + batch_id: String(b.batch_id), batch_no: String(b.batch_no), storage_zone: b.storage_zone || '', inbound_date: b.inbound_date || '', @@ -1045,6 +1065,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin const qtyByNo = new Map(plan.map((p) => [p.batch_no, p.qty])); setBatchEditorRows( (data.batches || []).map((b) => ({ + batch_id: String(b.batch_id), batch_no: String(b.batch_no), storage_zone: b.storage_zone || '', inbound_date: b.inbound_date || '', @@ -2580,7 +2601,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
{batchEditorRows.map((row, index) => ( -
+
{row.batch_no}