feat(盘点): 商品模式上报改为任务ID+stock_id,不再传 detail_id

- 商品视图点击改用 stock_id 进入商品作业页(goods 汇总视图行不再返回明细ID)
- 商品作业页 workDataDetail 改传 id + stock_id,并适配 summary + rows 新返回结构
- check.report 商品模式只传 id + stock_id + space_id,detail_id 改为可选(库位明细行仍必传)
- 库位/space 模式上报逻辑保持不变

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liufumingren 2026-10-28 07:36:33 +08:00
parent a4bfd09bff
commit d57cc44bdd
4 changed files with 86 additions and 52 deletions

View File

@ -462,9 +462,11 @@ export default {
method: "POST",
isSystemApi: true
},
// 单条盘点明细的作业数据(入参仅 detail_id,兼容 detailId)——库位明细返回 location 单行结构
// (detail_id/location_code/location_name/status/has_unknown/is_empty/checked_at/checkers/goods);
// 商品明细返回商品行结构(item_name/barcode/spec/store_name/images + 明盘 system/checked/diff_quantity);
// 盘点作业明细:入参二选一——① detail_id(盘点明细ID,兼容 detailId,库位明细必传);
// ② id(任务ID)+ stock_id(商品库存ID,兼容 stockId;goods 汇总视图行不再返回明细ID,商品钻取用)
// 库位明细返回 location 单行结构(detail_id/location_code/location_name/status/has_unknown/is_empty/checked_at/checkers/goods);
// 商品钻取返回 { stock_id/item_code/item_name/spec/store_name/barcode/images,
// summary(明盘:system_quantity/checked_quantity/diff_quantity/is_diff), rows(按库位分行) };
// warehouse_id 由服务端注入;仅 approved/checking 可拉取
workDataDetail: {
path: "stock.check.workDataDetail",
@ -482,6 +484,7 @@ export default {
isSystemApi: true
},
// 盘点作业上报:单条明细实盘数量(quantity>=0 整数)
// detail_id 可选:库位明细行必传;商品模式只传 id + stock_id + space_id,明细由服务端反查
report: {
path: "stock.check.report",
auth: true,

View File

@ -583,6 +583,7 @@ function buildWorkUnit(detailId, location, currentQuantity, reported, stockId, s
* 构造 check.report 入参(按 https 文档口径)
* - space_id 必传(wms_location_space.id,兼容 spaceId/location_id/locationId 写法):库位一律按库位ID落库
* - location 降级为可选一致性校验(与 space_id 对应编码不一致返回 400)
* - detail_id 可选:库位明细行必传;商品模式(goods 视图行不返回明细ID)只传 id + stock_id + space_id,服务端反查明细
* - 商品明细行:stock_id 固定为明细商品(与 space_id 一起定位「库位+商品」)
* - 库位明细行:必须带商品(stock_id 或 barcode 至少一项),space_id 对应编码须等于明细库位编码
* - 未知商品:只传 barcode(item_name 可选,缺省为条码)
@ -592,9 +593,14 @@ export function buildReportParams(taskId, payload = {}) {
const isEmpty = !!payload.isEmpty;
const params = {
id: Number(taskId),
detail_id: Number(payload.detailId),
quantity: isEmpty ? 0 : Number(payload.quantity)
};
const detailIdRaw = payload.detailId !== undefined && payload.detailId !== null && String(payload.detailId).trim() !== ''
? payload.detailId
: payload.detail_id;
if (detailIdRaw !== undefined && detailIdRaw !== null && String(detailIdRaw).trim() !== '') {
params.detail_id = Number(detailIdRaw);
}
// space_id 必传:兼容 spaceId/location_id/locationId 写法(取回接口 rows[].space_id、rows[].id、locations[].space_id 可直接回传)
const spaceId = payload.spaceId !== undefined && payload.spaceId !== null && String(payload.spaceId).trim() !== ''
? payload.spaceId
@ -693,10 +699,12 @@ function normalizeSpaceWorkRow(item, index, open) {
};
}
/** goods 视图:行=商品,locations 为按库位聚合的作业记录(商品任务的 is_goods=true) */
/** goods 视图:行=商品(后端不再返回行级 detail_id,跳转/上报改用 stock_id),locations 为按库位聚合的作业记录(商品任务的 is_goods=true) */
function normalizeGoodsWorkRow(item, index, open) {
const source = item && typeof item === 'object' ? item : {};
const detailId = firstValue(source, ['detail_id', 'detailId']);
// 行级明细ID 已不再返回,商品模式以 stock_id 定位(workDataDetail / report 均传 id + stock_id)
const stockId = firstValue(source, ['stock_id', 'stockId']);
const checkedRaw = source.checked_quantity !== undefined ? source.checked_quantity : source.checkedQuantity;
const rawLocations = Array.isArray(source.locations) ? source.locations : [];
const children = rawLocations.map((row, locIndex) => {
@ -731,10 +739,10 @@ function normalizeGoodsWorkRow(item, index, open) {
const done = status === 'checked' || recordCount > 0 || (checkedNumber !== null && checkedNumber > 0);
const reported = done;
return {
key: `goods-${detailId || index + 1}`,
key: `goods-${stockId || index + 1}`,
view: 'goods',
detailId: detailId ? String(detailId) : '',
stockId: firstValue(source, ['stock_id', 'stockId']) === undefined || firstValue(source, ['stock_id', 'stockId']) === null ? '' : String(firstValue(source, ['stock_id', 'stockId'])),
stockId: stockId || '',
title: firstValue(source, ['item_name', 'itemName']) || '--',
subtitle: joinText([firstValue(source, ['barcode']), firstValue(source, ['spec']), storeNameValue(source)]),
statusText: done ? '已盘' : '未盘',
@ -748,7 +756,7 @@ function normalizeGoodsWorkRow(item, index, open) {
),
quantityText: '',
children,
unit: buildWorkUnit(detailId, '', checkedRaw, reported, firstValue(source, ['stock_id', 'stockId'])),
unit: buildWorkUnit(detailId, '', checkedRaw, reported, stockId),
// 列表行(CountGoodsCard)与商品作业页(概况带入路由)用的字段:一行一个商品,操作剥离到操作页
images: imageList,
image: imageList[0] || '',
@ -943,19 +951,22 @@ export function normalizeGoodsRecords(rows) {
/**
* 单条明细的作业数据(stock.check.workDataDetail)→ 商品明细概况
* 用于商品作业页:只传 detail_id,概况由接口反查得出
* 商品行返回:detail_id/stock_id/item_code/item_name/spec/store_id/store_name/barcode/images(商品主图)
* + locations[](每库位:location_code/checked_at/checker_name/record_ids/images/system_quantity/quantity)
* + system_quantity/checked_quantity/diff_quantity/is_diff
* 库位行(商品信息在 goods 子列表里)也兼容:信息取 goods 首项兜底
* 用于商品作业页:传 id + stock_id(商品钻取),明细由接口反查得出
* 商品钻取返回:check_id/stock_id/item_code/item_name/spec/store_id/store_name/barcode/images(商品主图)
* + summary(仅明盘:system_quantity 账面快照合计/checked_quantity 实盘合计/diff_quantity/is_diff)
* + rows[](每库位:detail_id/location_code/checked_at/checker_name/record_ids/images,
* 明盘另含 system_quantity 当前账面/snapshot_quantity 账面快照/checked_quantity 实盘/diff_quantity)
* 兼容旧口径(扁平 system_quantity/checked_quantity + locations[]);库位行(商品信息在 goods 子列表里)取 goods 首项兜底
*/
export function normalizeGoodsDetailInfo(row, mode) {
const source = row && typeof row === 'object' && !Array.isArray(row) ? row : {};
if (!Object.keys(source).length) return null;
const summary = source.summary && typeof source.summary === 'object' && !Array.isArray(source.summary) ? source.summary : {};
// 行内只要带了任一数量字段就按明盘口径构建(任务 mode 可能没取到/缺失,别把盈亏丢掉)
const quantityFields = [
source.system_quantity, source.checked_quantity, source.diff_quantity,
source.systemQuantity, source.checkedQuantity, source.diffQuantity
source.systemQuantity, source.checkedQuantity, source.diffQuantity,
summary.system_quantity, summary.checked_quantity, summary.diff_quantity
];
const hasQuantity = quantityFields.some(value => value !== undefined && value !== null && value !== '');
const open = isOpenCheckMode(mode) || hasQuantity;
@ -972,7 +983,10 @@ export function normalizeGoodsDetailInfo(row, mode) {
// 库位明细(每库位一行:账面 / 实盘 / 盈亏),顺便汇总记录条数与最近上报时间
// 未盘点库位是任务范围占位:保留展示以便看到待盘库位,但实盘按 -- 处理、不参与盈亏、不计入记录条数
const rawLocations = Array.isArray(source.locations) ? source.locations : [];
// 商品钻取用 rows,旧口径用 locations
const rawLocations = Array.isArray(source.rows)
? source.rows
: (Array.isArray(source.locations) ? source.locations : []);
let recordCount = 0;
let lastCheckedAt = '';
const locations = rawLocations.map((item, index) => {
@ -982,9 +996,16 @@ export function normalizeGoodsDetailInfo(row, mode) {
const locationName = firstValue(loc, ['location_name', 'locationName']) || '';
const spaceId = firstValue(loc, ['space_id', 'location_id', 'locationId', 'spaceId']);
const recordIds = Array.isArray(loc.record_ids) ? loc.record_ids.filter(id => id !== null && id !== undefined && id !== '') : [];
const systemQuantity = toNumberOrNull(loc.system_quantity !== undefined ? loc.system_quantity : loc.systemQuantity);
// 未盘库位的 quantity 后端会回 0,直接展示会算出「账实相符」,因此按未盘置空
const quantity = checked ? toNumberOrNull(loc.quantity) : null;
// 账面:优先 snapshot_quantity(盘点开始时的账面快照,与 summary 口径一致),旧口径用 system_quantity
const systemRaw = loc.snapshot_quantity !== undefined && loc.snapshot_quantity !== null
? loc.snapshot_quantity
: (loc.system_quantity !== undefined ? loc.system_quantity : loc.systemQuantity);
const systemQuantity = toNumberOrNull(systemRaw);
// 实盘:商品钻取用 checked_quantity,旧口径用 quantity;未盘库位后端可能回 0,直接展示会算出「账实相符」,因此按未盘置空
const quantityRaw = loc.checked_quantity !== undefined && loc.checked_quantity !== null
? loc.checked_quantity
: (loc.quantity !== undefined && loc.quantity !== null ? loc.quantity : loc.checkedQuantity);
const quantity = checked ? toNumberOrNull(quantityRaw) : null;
const checkedAt = firstValue(loc, ['checked_at', 'checkedAt']);
const checkerName = firstValue(loc, ['checker_name', 'checkerName']);
recordCount += recordIds.length;
@ -1027,6 +1048,16 @@ export function normalizeGoodsDetailInfo(row, mode) {
};
});
const systemQuantityRaw = summary.system_quantity !== undefined && summary.system_quantity !== null
? summary.system_quantity
: (source.system_quantity !== undefined ? source.system_quantity : source.systemQuantity);
const checkedQuantityRaw = summary.checked_quantity !== undefined && summary.checked_quantity !== null
? summary.checked_quantity
: (source.checked_quantity !== undefined ? source.checked_quantity : source.checkedQuantity);
const diffQuantityRaw = summary.diff_quantity !== undefined && summary.diff_quantity !== null
? summary.diff_quantity
: (source.diff_quantity !== undefined ? source.diff_quantity : source.diffQuantity);
return {
detailId: pickText(['detail_id', 'detailId']),
stockId: stockIdRaw === undefined || stockIdRaw === null ? '' : String(stockIdRaw),
@ -1038,14 +1069,9 @@ export function normalizeGoodsDetailInfo(row, mode) {
images,
image: images[0] || '',
status: String(source.status || '').trim().toLowerCase(),
systemQuantity: toNumberOrNull(source.system_quantity !== undefined ? source.system_quantity : source.systemQuantity),
checkedQuantity: toNumberOrNull(source.checked_quantity !== undefined ? source.checked_quantity : source.checkedQuantity),
amount: buildWorkAmount(
source.system_quantity !== undefined ? source.system_quantity : source.systemQuantity,
source.checked_quantity !== undefined ? source.checked_quantity : source.checkedQuantity,
source.diff_quantity !== undefined ? source.diff_quantity : source.diffQuantity,
open
),
systemQuantity: toNumberOrNull(systemQuantityRaw),
checkedQuantity: toNumberOrNull(checkedQuantityRaw),
amount: buildWorkAmount(systemQuantityRaw, checkedQuantityRaw, diffQuantityRaw, open),
locations,
recordCount,
locationCodes: locations.map(item => item.locationCode).filter(Boolean),

View File

@ -635,16 +635,16 @@ export default {
this._pendingWorkRefresh = true;
uni.navigateTo({ url });
},
// ===== 商品视图(goods):点击进入商品作业页(只传 id,概况由接口反查) =====
// ===== 商品视图(goods):点击进入商品作业页(只传 task_id + stock_id,明细由服务端反查) =====
handleGoodsOpen(row) {
if (!row || !this.taskId) return;
if (!row.detailId) {
uni.showToast({ title: '缺少盘点明细ID', icon: 'none' });
if (!row.stockId) {
uni.showToast({ title: '缺少商品库存ID', icon: 'none' });
return;
}
const params = [
`task_id=${encodeURIComponent(this.taskId)}`,
`detail_id=${encodeURIComponent(row.detailId)}`
`stock_id=${encodeURIComponent(row.stockId)}`
].join('&');
// 从商品作业页返回后刷新列表(已盘状态/记录数已变化)
this._pendingWorkRefresh = true;

View File

@ -187,11 +187,11 @@ function resolveDiffText(goodsInfo) {
/**
* 商品作业页(goods 视图;从盘点作业商品列表点击/扫码进入)
* 入参:**只传 id** —— task_id(盘点任务ID)+ detail_id(盘点明细ID)
* 入参:**只传 id** —— task_id(盘点任务ID)+ stock_id(商品库存ID);明细由服务端反查
* 数据:
* - stock.check.workDataDetail(仅 detail_id)→ 本明细单行作业数据,含商品信息/主图/账面/已盘/差异 + locations(每库位:账面/实盘/盘点人/时间/记录ID/照片)
* - stock.check.workDataDetail(id + stock_id)→ 商品钻取数据,含商品信息/主图/账面/已盘/差异 + rows(每库位:账面/实盘/盘点人/时间/记录ID/照片)
* - stock.check.detail(仅主表 check)→ 任务状态 / 盘点模式
* 能力:扫码/输入库位 → 底部抽屉选库位 + 录数量(check.report);库位记录可左滑删除(recordDelete)
* 能力:扫码/输入库位 → 底部抽屉选库位 + 录数量(check.report:id + stock_id + space_id,不传 detail_id);库位记录可左滑删除(recordDelete)
*/
export default {
components: {
@ -202,7 +202,7 @@ export default {
data() {
return {
taskId: '',
detailId: '',
stockId: '',
taskInfo: { status: '', mode: '', type: '' },
goodsInfo: EMPTY_GOODS_INFO(),
loading: false,
@ -265,15 +265,15 @@ export default {
},
// CountLocationDetail 只需要 row 结构(概况在卡片,children = 库位明细:账面/实盘/盈亏)
detailRow() {
if (!this.detailId) return null;
if (!this.stockId) return null;
const locations = this.goodsInfo.locations || [];
const meta = [];
const codes = this.goodsInfo.locationCodes || [];
if (codes.length) meta.push({ label: '库位', value: codes.length === 1 ? codes[0] : `${codes.length} 个` });
if (this.goodsInfo.lastCheckedAtText) meta.push({ label: '最近上报', value: this.goodsInfo.lastCheckedAtText });
return {
key: `goods-${this.detailId}`,
detailId: this.detailId,
key: `goods-${this.stockId}`,
detailId: '',
title: '',
subtitle: '',
statusText: '',
@ -287,9 +287,9 @@ export default {
}
},
onLoad(options = {}) {
// 页面只需两个 id:task_id(任务ID)+ detail_id(盘点明细ID)
// 页面只需两个 id:task_id(任务ID)+ stock_id(商品库存ID)
this.taskId = String(options.task_id || options.taskId || options.id || '').trim();
this.detailId = String(options.detail_id || options.detailId || '').trim();
this.stockId = String(options.stock_id || options.stockId || '').trim();
this.loadAll();
this.syncBroadcastWithMode();
@ -390,15 +390,14 @@ export default {
this.showEntryPopup = false;
this.pendingLocation = '';
},
/** 抽屉确认:库位 + 数量 → check.report */
/** 抽屉确认:库位 + 数量 → check.report(商品模式只传任务ID + stock_id,不传 detail_id) */
async handleEntryConfirm(payload) {
if (!payload || !payload.location) return;
const ok = await this.submitReport({
detailId: this.detailId,
location: payload.location,
spaceId: payload.locationId,
quantity: payload.quantity,
stockId: this.goodsInfo.stockId
stockId: this.goodsInfo.stockId || this.stockId
});
// 成功才收起抽屉并清空顶部关键字,失败保留输入便于重试
if (ok) {
@ -406,11 +405,12 @@ export default {
this.closeEntryPopup();
}
},
/** 上报(check.report:detail_id=商品明细,location=库位) */
/** 上报(check.report:id=盘点任务,stock_id=商品,space_id=库位;明细由服务端反查) */
async submitReport(payload) {
if (!this.editable || this.submitting) return false;
if (!payload || !payload.detailId) {
uni.showToast({ title: '缺少盘点明细ID', icon: 'none' });
const stockId = String((payload && payload.stockId) || '').trim();
if (!stockId) {
uni.showToast({ title: '缺少商品库存ID(stock_id)', icon: 'none' });
return false;
}
const location = String(payload.location || '').trim();
@ -431,11 +431,10 @@ export default {
this.submitting = true;
try {
const response = await this.$http('check.report', buildReportParams(this.taskId, {
detailId: payload.detailId,
location,
spaceId,
quantity,
stockId: payload.stockId,
stockId,
barcode: this.goodsInfo.barcode,
itemName: this.goodsInfo.itemName
}));
@ -576,17 +575,23 @@ export default {
return null;
}
},
/** 商品明细(stock.check.workDataDetail:入参仅 detail_id)——含商品信息/主图/账面/已盘/差异 + locations 库位明细 */
/** 商品钻取数据(stock.check.workDataDetail:id + stock_id,明细由服务端反查)——含商品信息/主图/账面/已盘/差异 + rows 库位明细 */
async loadInfo() {
const detailId = Number(this.detailId);
if (!Number.isFinite(detailId) || detailId <= 0) {
this.loadError = '缺少盘点明细ID';
const stockId = Number(this.stockId);
if (!Number.isFinite(stockId) || stockId <= 0) {
this.loadError = '缺少商品库存ID';
uni.showToast({ title: this.loadError, icon: 'none' });
return null;
}
const taskId = Number(this.taskId);
if (!Number.isFinite(taskId) || taskId <= 0) {
this.loadError = '缺少盘点任务ID';
uni.showToast({ title: this.loadError, icon: 'none' });
return null;
}
this.loading = true;
try {
const response = await this.$http('check.workDataDetail', { detail_id: detailId });
const response = await this.$http('check.workDataDetail', { id: taskId, stock_id: stockId });
if (response?.flag === 'failure') {
this.goodsInfo = EMPTY_GOODS_INFO();
this.loadError = response.message || '盘点明细加载失败';