fix(分拣): 保存不再覆盖已存的手选批次
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

- Web/小程序提交时优先沿用已持久化的 outbound_batches,避免再次保存
  被默认 FIFO 覆盖(Web「已完成单保存修改」会丢手选批次)
- 已出库(≥40)单展示落库计划,不再用剩余库存重算 FIFO
- 批次编辑器行按 batch_id 作 key
This commit is contained in:
雨天
2026-10-11 13:52:17 +08:00
parent 219d538eae
commit efabb72e94
3 changed files with 57 additions and 25 deletions
+25 -14
View File
@@ -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>