fix(分拣): 保存不再覆盖已存的手选批次
- Web/小程序提交时优先沿用已持久化的 outbound_batches,避免再次保存 被默认 FIFO 覆盖(Web「已完成单保存修改」会丢手选批次) - 已出库(≥40)单展示落库计划,不再用剩余库存重算 FIFO - 批次编辑器行按 batch_id 作 key
This commit is contained in:
@@ -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 || '',
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
<text class="batch-sheet-sub">需 {{editor.need}}{{editor.unit}} · 可扣 {{editor.claimable}}</text>
|
||||
</view>
|
||||
<view class="batch-sheet-body">
|
||||
<view wx:for="{{editor.rows}}" wx:key="batch_no" class="batch-row">
|
||||
<view wx:for="{{editor.rows}}" wx:key="batch_id" class="batch-row">
|
||||
<view class="batch-row-info">
|
||||
<text class="batch-row-no">{{item.batch_no}}</text>
|
||||
<text class="batch-row-meta">{{item.storage_zone || '未设区域'}} · 入库 {{item.inbound_date || '—'}} · 可用 {{item.available_qty}}</text>
|
||||
|
||||
@@ -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
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{batchEditorRows.map((row, index) => (
|
||||
<div key={row.batch_no} className="flex items-center gap-3">
|
||||
<div key={row.batch_id} className="flex items-center gap-3">
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="text-sm text-black truncate">{row.batch_no}</div>
|
||||
<div className="text-xs text-gray-500 truncate">
|
||||
|
||||
Reference in New Issue
Block a user