feat(盘点): 适配 0.3.318 账面口径(快照/当前库存)并兼容商品视图 stock_id 入口

- countModel: 新增 is_static / book_source / storage_quantity / snapshot_quantity 归一化
- countModel: resolveBookMeta 统一输出「账面(快照)|账面(当前库存)」标签及另一口径提示
  (静态盘点提示当前库存,普通盘点提示基准快照,不一致时才显示)
- countModel: workDataDetail 兼容 0.3.309+ 的 { summary, rows[] } 商品钻取结构,保留旧 locations 结构
- countModel: buildReportParams 的 detail_id 改为可选,支持仅用 stock_id + space_id 由服务端反查明细
- countModel: goods 视图行优先以 stock_id 作为行标识;已盘库位识别补充 status=checked / is_checked
- countModel: 任务/列表归一化透出 isStatic / isStaticText(静态盘点标识)
- inventoryCountDetail: 作业行归一化传入任务级 is_static 兜底;goods 行无 detail_id 时改用 stock_id 进入商品作业页
- inventoryCountGoods: 支持 stock_id 路由与 workDataDetail 入参(id + detail_id/stock_id)
- inventoryCountGoods: 多库位商品上报按所选库位(space_id/location_code)取对应 detail_id
- inventoryCountSpace: 读取 check.is_static 作为 space 视图商品行的口径兜底
- CountWorkCard / CountGoodsCard / CountLocationDetail: 展示账面来源标签与另一口径提示
- CountSummaryPanel: 新增「盘点性质」(静态盘点/普通盘点)
- CountRecordCard: 静态盘点任务显示「静态」标签

兼容性:旧后端无 is_static/book_source 时按「当前库存」展示,数量与上报逻辑不变;
盲盘、库位任务、状态机与分页流程未改动。

验证:countModel.js ESLint 通过;8 个改动 Vue 文件的 script 语法与模板编译通过。
This commit is contained in:
zm2000 2026-10-28 16:14:01 +08:00
parent 630f2a3a3c
commit f4c40e454b
9 changed files with 376 additions and 67 deletions

View File

@ -21,11 +21,12 @@
<text v-if="row.subtitle" class="goods-card__subtitle">{{ row.subtitle }}</text>
<view class="goods-card__metrics">
<template v-if="row.amount">
<text class="goods-card__metric">账面 {{ row.amount.systemText }}</text>
<text class="goods-card__metric">{{ row.amount.systemLabel || '账面' }} {{ row.amount.systemText }}</text>
<text class="goods-card__metric">已盘 {{ row.amount.checkedText }}</text>
<text v-if="row.amount.diffText" class="goods-card__diff" :class="diffClass(row)">
{{ row.amount.diffText }}
</text>
<text v-if="row.amount.bookHint" class="goods-card__metric goods-card__metric--hint">{{ row.amount.bookHint }}</text>
</template>
<text v-else class="goods-card__metric">已盘记录 {{ row.recordCount || 0 }} 条</text>
<text v-if="locationText" class="goods-card__metric">{{ locationText }}</text>
@ -171,6 +172,12 @@ export default {
color: #303133;
}
/* 另一种账面口径提示(静态看当前库存 / 普通看基准快照) */
.goods-card__metric--hint {
color: #b8811a;
font-size: 28rpx;
}
.goods-card__diff {
margin-right: 20rpx;
font-size: 34rpx;

View File

@ -71,11 +71,12 @@
<text
class="loc-detail__row-amount"
:class="{ 'loc-detail__row-amount--stock': child.amounts.hasSystemStock }"
>账面 {{ child.amounts.systemText }}</text>
>{{ child.amounts.systemLabel || '账面' }} {{ child.amounts.systemText }}</text>
<text class="loc-detail__row-amount loc-detail__row-amount--checked">实盘 {{ child.amounts.checkedText }}</text>
<text v-if="child.amounts.diffText" class="loc-detail__row-diff" :class="diffClass(child.amounts)">
{{ child.amounts.diffText }}
</text>
<text v-if="child.amounts.bookHint" class="loc-detail__row-hint">{{ child.amounts.bookHint }}</text>
</view>
</view>
<view class="loc-detail__row-side">
@ -428,6 +429,13 @@ export default {
font-weight: 600;
}
/* 另一种账面口径提示(静态看当前库存 / 普通看基准快照) */
.loc-detail__row-hint {
margin-right: 20rpx;
font-size: 26rpx;
color: #b8811a;
}
.loc-detail__row-diff--gain {
color: #18a058;
}

View File

@ -15,6 +15,7 @@
class="record-card__type"
:class="item.typeClass"
>{{ item.typeLabel }}</text>
<text v-if="item.isStatic" class="record-card__type record-card__type--static">静态</text>
</view>
<!-- 第三行:左(创建人 / 创建时间)· 右(进度 / 状态) -->
<view class="record-card__body">
@ -111,6 +112,11 @@ export default {
background: #e8f7ee;
}
.record-card__type--static {
color: #d46b08;
background: #fff4e6;
}
/* 第三行:左右结构 */
.record-card__body {
margin-top: 20rpx;

View File

@ -22,6 +22,10 @@
<text class="summary-panel__label">盘点方式</text>
<text class="summary-panel__value">{{ info.modeText || '--' }}</text>
</view>
<view v-if="info.isStaticText" class="summary-panel__row">
<text class="summary-panel__label">盘点性质</text>
<text class="summary-panel__value">{{ info.isStaticText }}</text>
</view>
<view class="summary-panel__row">
<text class="summary-panel__label">状态</text>
<text class="summary-panel__value" :class="info.statusClass">{{ info.statusText || '--' }}</text>

View File

@ -15,7 +15,7 @@
<!-- 行级数量(明盘) -->
<view v-if="row.amount" class="work-card__amount">
<view class="work-card__metric">
<text class="work-card__label">账面数量</text>
<text class="work-card__label">{{ row.amount.systemLabel || '账面数量' }}</text>
<text class="work-card__value">{{ row.amount.systemText }}</text>
</view>
<view class="work-card__metric">
@ -23,6 +23,7 @@
<text class="work-card__value">{{ row.amount.checkedText }}</text>
</view>
<text v-if="row.amount.diffText" class="work-card__diff" :class="row.amount.diffClass">{{ row.amount.diffText }}</text>
<text v-if="row.amount.bookHint" class="work-card__book-hint">{{ row.amount.bookHint }}</text>
</view>
<!-- 行级录入(库位任务的库位行 / 商品任务的商品行) -->
@ -66,9 +67,10 @@
<view class="work-child__side">
<text v-if="child.statusText" class="work-card__tag" :class="child.statusClass">{{ child.statusText }}</text>
<text v-if="child.amount" class="work-child__amount">
账面 {{ child.amount.systemText }} · 已盘 {{ child.amount.checkedText }}
{{ child.amount.systemLabel || '账面' }} {{ child.amount.systemText }} · 已盘 {{ child.amount.checkedText }}
</text>
<text v-else-if="child.quantityText !== ''" class="work-child__amount">实盘 {{ child.quantityText }}</text>
<text v-if="child.amount && child.amount.bookHint" class="work-child__hint">{{ child.amount.bookHint }}</text>
</view>
<view v-if="child.unit" class="work-child__input">
<view class="work-input" :class="{ 'work-input--reported': child.unit.reported }">
@ -275,6 +277,14 @@ export default {
background: #f5f7fa;
}
/* 另一种账面口径提示(静态看当前库存 / 普通看基准快照) */
.work-card__book-hint {
width: 100%;
margin-top: 6rpx;
font-size: 26rpx;
color: #b8811a;
}
.work-card__input-row {
margin-top: 20rpx;
display: flex;
@ -389,6 +399,13 @@ export default {
color: #606266;
}
.work-child__hint {
margin-top: 4rpx;
margin-left: 16rpx;
font-size: 26rpx;
color: #b8811a;
}
.work-child__side .work-card__amount {
margin-left: 16rpx;
}

View File

@ -284,6 +284,10 @@ export function normalizeCheckRecords(list, fallbackPage = 1) {
const id = firstValue(source, ['id', 'check_id', 'checkId', 'task_id', 'taskId'])
|| `${fallbackPage}-${index + 1}`;
const tone = statusTone(status);
// 静态盘点标记(0.3.310):仅商品盘点任务有效,库位盘点恒为 0
const staticRaw = source.is_static !== undefined ? source.is_static : source.isStatic;
const hasStaticFlag = staticRaw !== undefined && staticRaw !== null && String(staticRaw).trim() !== '';
const isStatic = hasStaticFlag && toBool(staticRaw);
return {
id,
checkNo,
@ -293,6 +297,9 @@ export function normalizeCheckRecords(list, fallbackPage = 1) {
typeText: composeType(typeValue, modeValue),
typeLabel: typeText(typeValue),
typeClass: typeTone(typeValue) ? `record-card__type--${typeTone(typeValue)}` : '',
isStatic,
hasStaticFlag,
isStaticText: hasStaticFlag ? (isStatic ? '静态' : '') : '',
operator,
progressText,
status,
@ -326,6 +333,10 @@ export function normalizeCheckTaskInfo(check, storeNameFallback = '') {
const creatorName = firstValue(source, ['creator_name', 'creatorName', 'creator']);
const remark = firstValue(source, ['remark']);
const tone = statusTone(status);
// 静态盘点标记(0.3.310):detail/workData 的 check 均返回;库位盘点恒为 0
const staticRaw = source.is_static !== undefined ? source.is_static : source.isStatic;
const hasStaticFlag = staticRaw !== undefined && staticRaw !== null && String(staticRaw).trim() !== '';
const isStatic = hasStaticFlag && toBool(staticRaw);
return {
id,
checkNo,
@ -348,6 +359,9 @@ export function normalizeCheckTaskInfo(check, storeNameFallback = '') {
creatorId,
creatorName,
remark,
isStatic,
hasStaticFlag,
isStaticText: hasStaticFlag ? (isStatic ? '静态盘点' : '普通盘点') : '',
startTimeText: formatDateTime(firstValue(source, ['start_time', 'startTime'])),
endTimeText: formatDateTime(firstValue(source, ['end_time', 'endTime'])),
createTimeText: formatDateTime(firstValue(source, ['created_at', 'createdAt', 'create_time', 'createTime'])),
@ -492,6 +506,74 @@ export function isOpenCheckMode(mode) {
return String(mode || '').trim().toLowerCase() === 'open';
}
/** 静态盘点标记归一化(兼容 1/'1'/true) */
export function isStaticCheck(value) {
return toBool(value);
}
/**
* 账面来源归一化(0.3.318):
* snapshot = 明细快照(静态盘点冻结基准);storage = 当前库存 wms_storage(普通盘点实时账面)
*/
export function normalizeBookSource(bookSource, isStatic) {
const key = String(bookSource || '').trim().toLowerCase();
if (key === 'snapshot' || key === 'storage') return key;
return toBool(isStatic) ? 'snapshot' : 'storage';
}
/**
* 从作业行读取 0.3.318 账面字段(兼容驼峰)
* storage_quantity=当前 storage 账面;snapshot_quantity=明细快照;is_static/book_source=口径来源
*/
function pickBookMeta(source, fallbackIsStatic) {
const obj = source && typeof source === 'object' ? source : {};
const storageRaw = obj.storage_quantity !== undefined ? obj.storage_quantity : obj.storageQuantity;
const snapshotRaw = obj.snapshot_quantity !== undefined ? obj.snapshot_quantity : obj.snapshotQuantity;
const staticRaw = obj.is_static !== undefined ? obj.is_static : obj.isStatic;
const bookRaw = obj.book_source !== undefined ? obj.book_source : obj.bookSource;
const hasStaticFlag = staticRaw !== undefined && staticRaw !== null && String(staticRaw).trim() !== '';
// 行级未带 is_static 时(如 space 视图 goods)用任务级标记兜底,避免静态任务误显「当前库存」
const hasFallback = typeof fallbackIsStatic === 'boolean';
const resolvedStatic = hasStaticFlag ? staticRaw : (hasFallback ? fallbackIsStatic : undefined);
return {
storageQuantity: toNumberOrNull(storageRaw),
snapshotQuantity: toNumberOrNull(snapshotRaw),
isStatic: hasStaticFlag || hasFallback ? toBool(resolvedStatic) : false,
hasStaticFlag: hasStaticFlag || hasFallback,
bookSource: normalizeBookSource(bookRaw, resolvedStatic)
};
}
/**
* 账面口径元信息:system_quantity 为本次参与差异计算的账面(静态=快照、普通=当前库存),
* storage_quantity / snapshot_quantity 为另一口径参考值,两者不一致时给出提示文案。
*/
export function resolveBookMeta(systemQuantity, options = {}) {
const sys = toNumberOrNull(systemQuantity);
const storage = toNumberOrNull(options.storageQuantity);
const snapshot = toNumberOrNull(options.snapshotQuantity);
const source = normalizeBookSource(options.bookSource, options.isStatic);
const sourceText = source === 'snapshot' ? '快照' : '当前库存';
let hint = '';
if (sys !== null) {
if (source === 'snapshot') {
// 静态盘点:账面取快照,若当前库存已偏离(理论上盘点期间禁止出入库)则提示
if (storage !== null && storage !== sys) hint = `当前库存 ${storage}`;
} else if (snapshot !== null && snapshot !== sys) {
// 普通盘点:账面取当前库存,补充展示审核时的基准快照
hint = `基准快照 ${snapshot}`;
}
}
return {
bookSource: source,
bookSourceText: sourceText,
systemLabel: `账面(${sourceText})`,
bookHint: hint,
storageQuantity: storage,
snapshotQuantity: snapshot
};
}
/**
* 作业解析视图:
* 库位任务(location)一律 location;商品任务(goods/store)默认 space,isGoods=true 时为 goods
@ -514,13 +596,15 @@ function toBool(value) {
return key === '1' || key === 'true';
}
/** 库位明细是否已盘:有记录ID(record_ids)、盘点人或上报时间之一即视为已盘 */
/** 库位明细是否已盘:有记录ID(record_ids)、盘点人、上报时间或状态为 checked 之一即视为已盘 */
function isCheckedLocation(loc) {
if (!loc || typeof loc !== 'object') return false;
const ids = Array.isArray(loc.record_ids) ? loc.record_ids.filter(id => id !== null && id !== undefined && id !== '') : [];
return ids.length > 0
|| !!firstValue(loc, ['checked_at', 'checkedAt'])
|| !!firstValue(loc, ['checker_name', 'checkerName']);
|| !!firstValue(loc, ['checker_name', 'checkerName'])
|| String(loc.status || '').trim().toLowerCase() === 'checked'
|| toBool(loc.is_checked);
}
/** 宫格格子里显示的短库位号(取末两段,如 E07-01-02-01 → 02-01) */
@ -537,11 +621,14 @@ function toNumberString(value) {
return num === null ? '' : String(num);
}
/** 明盘数量块(盲盘返回 null,不展示任何数量) */
function buildWorkAmount(systemQuantity, checkedQuantity, diffQuantity, open) {
/** 明盘数量块(盲盘返回 null,不展示任何数量)
* meta(0.3.318):storageQuantity / snapshotQuantity / isStatic / bookSource ——
* 账面 systemText 始终取接口 system_quantity(静态=快照、普通=当前库存),另一种口径仅作提示 */
function buildWorkAmount(systemQuantity, checkedQuantity, diffQuantity, open, meta = {}) {
if (!open) return null;
const sys = toNumberOrNull(systemQuantity);
const chk = toNumberOrNull(checkedQuantity);
const book = resolveBookMeta(sys, meta);
// 差异统一以「实盘 - 账面」为准,避免后端 diff_quantity 与账面/实盘不一致(如未盘项返回 0)
let diff = null;
if (sys !== null && chk !== null) {
@ -558,7 +645,14 @@ function buildWorkAmount(systemQuantity, checkedQuantity, diffQuantity, open) {
diffText: diff === null ? '' : (diff > 0 ? `盘盈 +${diff}` : (diff < 0 ? `盘亏 ${-diff}` : '账实相符')),
diff,
diffTone,
diffClass: diff === null ? '' : (diff > 0 ? 'work-card__diff--gain' : (diff < 0 ? 'work-card__diff--loss' : 'work-card__diff--match'))
diffClass: diff === null ? '' : (diff > 0 ? 'work-card__diff--gain' : (diff < 0 ? 'work-card__diff--loss' : 'work-card__diff--match')),
// 账面口径(0.3.318):标签 + 另一口径提示
systemLabel: book.systemLabel,
bookSource: book.bookSource,
bookSourceText: book.bookSourceText,
bookHint: book.bookHint,
storageQuantity: book.storageQuantity,
snapshotQuantity: book.snapshotQuantity
};
}
@ -590,11 +684,13 @@ function buildWorkUnit(detailId, location, currentQuantity, reported, stockId, s
*/
export function buildReportParams(taskId, payload = {}) {
const isEmpty = !!payload.isEmpty;
const detailId = Number(payload.detailId);
const params = {
id: Number(taskId),
detail_id: Number(payload.detailId),
quantity: isEmpty ? 0 : Number(payload.quantity)
};
// detail_id 可选(0.3.309):商品钻取上报可改传 stock_id + space_id 由服务端反查明细
if (Number.isFinite(detailId) && detailId > 0) params.detail_id = detailId;
// 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
@ -629,7 +725,7 @@ function joinText(parts, sep = ' · ') {
}
/** space 视图:行=库位,goods 为该库位下的任务商品(商品任务默认视图;作业列表按库位宫格展示,仅统计不可点击) */
function normalizeSpaceWorkRow(item, index, open) {
function normalizeSpaceWorkRow(item, index, open, options = {}) {
const source = item && typeof item === 'object' ? item : {};
const spaceCode = firstValue(source, ['space_code', 'spaceCode']) || `#${index + 1}`;
// space 视图行:space_id 与 location_id 均等于既有 id(wms_location_space.id)
@ -640,13 +736,20 @@ function normalizeSpaceWorkRow(item, index, open) {
const detailId = firstValue(good, ['detail_id', 'detailId']);
const checkedRaw = good.checked_quantity !== undefined ? good.checked_quantity : good.checkedQuantity;
const done = String(good.status || '').trim().toLowerCase() === 'checked';
const bookMeta = pickBookMeta(good, options.isStatic);
return {
key: `${spaceCode}-${detailId || goodIndex + 1}`,
title: firstValue(good, ['item_name', 'itemName']) || '--',
subtitle: joinText([firstValue(good, ['barcode']), firstValue(good, ['spec']), storeNameValue(good)]),
statusText: done ? '已盘' : '未盘',
statusClass: done ? 'work-card__tag--done' : 'work-card__tag--todo',
amount: buildWorkAmount(good.system_quantity !== undefined ? good.system_quantity : good.systemQuantity, checkedRaw, null, open),
amount: buildWorkAmount(
good.system_quantity !== undefined ? good.system_quantity : good.systemQuantity,
checkedRaw,
null,
open,
bookMeta
),
quantityText: '',
unit: buildWorkUnit(detailId, spaceCode, checkedRaw, done, firstValue(good, ['stock_id', 'stockId']), rowSpaceId)
};
@ -694,7 +797,7 @@ function normalizeSpaceWorkRow(item, index, open) {
}
/** goods 视图:行=商品,locations 为按库位聚合的作业记录(商品任务的 is_goods=true) */
function normalizeGoodsWorkRow(item, index, open) {
function normalizeGoodsWorkRow(item, index, open, options = {}) {
const source = item && typeof item === 'object' ? item : {};
const detailId = firstValue(source, ['detail_id', 'detailId']);
const checkedRaw = source.checked_quantity !== undefined ? source.checked_quantity : source.checkedQuantity;
@ -719,6 +822,11 @@ function normalizeGoodsWorkRow(item, index, open) {
};
});
const checkedNumber = toNumberOrNull(checkedRaw);
// 账面口径(0.3.318):is_static/book_source/storage_quantity/snapshot_quantity
const bookMeta = pickBookMeta(source, options.isStatic);
const stockIdValue = firstValue(source, ['stock_id', 'stockId']);
// 行唯一键:0.3.309 起 goods 视图行不再返回 detail_id,优先用 stock_id
const rowKey = stockIdValue || detailId || `${index + 1}`;
// 行级商品主图(goods 视图行级 images 仍为商品主图)
const imageList = Array.isArray(source.images) ? source.images.filter(Boolean) : [];
// 作业记录条数(locations[].record_ids 汇总)——已盘判断与概况展示用
@ -731,10 +839,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-${rowKey}`,
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: stockIdValue === '' || stockIdValue === undefined || stockIdValue === null ? '' : String(stockIdValue),
title: firstValue(source, ['item_name', 'itemName']) || '--',
subtitle: joinText([firstValue(source, ['barcode']), firstValue(source, ['spec']), storeNameValue(source)]),
statusText: done ? '已盘' : '未盘',
@ -744,11 +852,18 @@ function normalizeGoodsWorkRow(item, index, open) {
source.system_quantity !== undefined ? source.system_quantity : source.systemQuantity,
done ? checkedRaw : null,
done ? (source.diff_quantity !== undefined ? source.diff_quantity : source.diffQuantity) : null,
open
open,
bookMeta
),
quantityText: '',
children,
unit: buildWorkUnit(detailId, '', checkedRaw, reported, firstValue(source, ['stock_id', 'stockId'])),
// 账面口径字段(商品作业页 / 商品卡片展示用)
isStatic: bookMeta.isStatic,
hasStaticFlag: bookMeta.hasStaticFlag,
bookSource: bookMeta.bookSource,
storageQuantity: bookMeta.storageQuantity,
snapshotQuantity: bookMeta.snapshotQuantity,
// 列表行(CountGoodsCard)与商品作业页(概况带入路由)用的字段:一行一个商品,操作剥离到操作页
images: imageList,
image: imageList[0] || '',
@ -857,14 +972,14 @@ function normalizeLocationWorkRow(item, index, open) {
};
}
/** 作业数据行归一化(view: space / goods / location) */
export function normalizeWorkRows(rows, view, mode) {
/** 作业数据行归一化(view: space / goods / location;options.isStatic 为任务级静态标记兜底) */
export function normalizeWorkRows(rows, view, mode, options = {}) {
if (!Array.isArray(rows)) return [];
const open = isOpenCheckMode(mode);
return rows.map((item, index) => {
if (view === 'goods') return normalizeGoodsWorkRow(item, index, open);
if (view === 'goods') return normalizeGoodsWorkRow(item, index, open, options);
if (view === 'location') return normalizeLocationWorkRow(item, index, open);
return normalizeSpaceWorkRow(item, index, open);
return normalizeSpaceWorkRow(item, index, open, options);
});
}
@ -882,9 +997,9 @@ export function normalizeLocationWorkDetail(payload, mode) {
* 单库位作业数据归一化(stock.check.workDataSpaceDetails,rows 只有该库位一行)
* 返回结构与 workData space 视图单行一致;rows 为空时返回 null。
*/
export function normalizeSpaceWorkDetail(rows, mode) {
export function normalizeSpaceWorkDetail(rows, mode, options = {}) {
if (!Array.isArray(rows) || !rows.length) return null;
return normalizeWorkRows(rows.slice(0, 1), 'space', mode)[0] || null;
return normalizeWorkRows(rows.slice(0, 1), 'space', mode, options)[0] || null;
}
/**
@ -943,22 +1058,40 @@ 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
* 兼容两种结构:
* - 商品钻取(0.3.309+):{ check_id, stock_id, ..., summary{ system_quantity/checked_quantity/diff_quantity }, rows[] }
* rows[] 每个库位一行:detail_id/space_id/location_code/system_quantity/checked_quantity/diff_quantity/record_ids/...
* 0.3.318 起顶层增加 is_static/book_source,rows[] 增加 storage_quantity(另有 snapshot_quantity)
* - 旧单行结构:顶层 system_quantity/checked_quantity/diff_quantity + locations[](每库位 quantity)
* 库位行(商品信息在 goods 子列表里)也兼容:信息取 goods 首项兜底
*/
export function normalizeGoodsDetailInfo(row, mode) {
export function normalizeGoodsDetailInfo(row, mode, options = {}) {
const source = row && typeof row === 'object' && !Array.isArray(row) ? row : {};
if (!Object.keys(source).length) return null;
const summarySource = source.summary && typeof source.summary === 'object' && !Array.isArray(source.summary)
? source.summary : null;
const drillRows = Array.isArray(source.rows) ? source.rows : null;
const isDrillLayout = !!summarySource || !!drillRows;
// 商品级合计:钻取结构取 summary,旧结构取顶层
const systemRaw = isDrillLayout
? (summarySource ? summarySource.system_quantity : undefined)
: (source.system_quantity !== undefined ? source.system_quantity : source.systemQuantity);
const checkedRaw = isDrillLayout
? (summarySource ? summarySource.checked_quantity : undefined)
: (source.checked_quantity !== undefined ? source.checked_quantity : source.checkedQuantity);
const diffRaw = isDrillLayout
? (summarySource ? summarySource.diff_quantity : undefined)
: (source.diff_quantity !== undefined ? source.diff_quantity : source.diffQuantity);
// 行内只要带了任一数量字段就按明盘口径构建(任务 mode 可能没取到/缺失,别把盈亏丢掉)
const quantityFields = [
systemRaw, checkedRaw, diffRaw,
source.system_quantity, source.checked_quantity, source.diff_quantity,
source.systemQuantity, source.checkedQuantity, source.diffQuantity
];
const hasQuantity = quantityFields.some(value => value !== undefined && value !== null && value !== '');
const open = isOpenCheckMode(mode) || hasQuantity;
// 账面口径(0.3.318):顶层 is_static/book_source
const bookMeta = pickBookMeta(source, options.isStatic);
// 库位行形态:商品信息/图片取 goods 首项兜底
const firstGoods = Array.isArray(source.goods) && source.goods.length ? (source.goods[0] || {}) : {};
const pickText = keys => firstValue(source, keys) || firstValue(firstGoods, keys) || '';
@ -972,7 +1105,27 @@ export function normalizeGoodsDetailInfo(row, mode) {
// 库位明细(每库位一行:账面 / 实盘 / 盈亏),顺便汇总记录条数与最近上报时间
// 未盘点库位只是任务范围占位(record_ids 空且无盘点人/上报时间),不作为「盘点记录」展示
const rawLocations = Array.isArray(source.locations) ? source.locations : [];
const rawLocations = isDrillLayout
? (drillRows || [])
: (Array.isArray(source.locations) ? source.locations : []);
// 商品级另一种口径合计(含未盘库位,避免账面/当前库存合计只统计已盘行)
const rowBookTotals = rawLocations.reduce((acc, item) => {
const book = pickBookMeta(item);
if (book.storageQuantity !== null) acc.storage = (acc.storage === null ? 0 : acc.storage) + book.storageQuantity;
if (book.snapshotQuantity !== null) acc.snapshot = (acc.snapshot === null ? 0 : acc.snapshot) + book.snapshotQuantity;
return acc;
}, { storage: null, snapshot: null });
const pageDetailId = pickText(['detail_id', 'detailId']);
// 全部库位(含未盘占位行)的明细ID映射:商品作业页按库位上报时定位 detail_id
const allLocations = rawLocations.map((item, index) => {
const loc = item && typeof item === 'object' ? item : {};
return {
key: `all-loc-${index + 1}`,
detailId: firstValue(loc, ['detail_id', 'detailId']) || pageDetailId,
spaceId: firstValue(loc, ['space_id', 'location_id', 'locationId', 'spaceId']) || '',
locationCode: firstValue(loc, ['location_code', 'locationCode']) || ''
};
});
const checkedLocations = rawLocations.filter(isCheckedLocation);
let recordCount = 0;
let lastCheckedAt = '';
@ -981,16 +1134,27 @@ export function normalizeGoodsDetailInfo(row, mode) {
const locationCode = firstValue(loc, ['location_code', 'locationCode']) || '';
const locationName = firstValue(loc, ['location_name', 'locationName']) || '';
const spaceId = firstValue(loc, ['space_id', 'location_id', 'locationId', 'spaceId']);
// 钻取结构每个库位有自己的明细ID(report 按 detail_id + stock_id + space_id 定位)
const rowDetailId = firstValue(loc, ['detail_id', 'detailId']) || pageDetailId;
const recordIds = Array.isArray(loc.record_ids) ? loc.record_ids.filter(id => id !== null && id !== undefined && id !== '') : [];
const rowBook = pickBookMeta(loc);
const systemQuantity = toNumberOrNull(loc.system_quantity !== undefined ? loc.system_quantity : loc.systemQuantity);
const quantity = toNumberOrNull(loc.quantity);
// 实盘:旧结构为 quantity,钻取结构为 checked_quantity
const quantity = toNumberOrNull(
loc.quantity !== undefined
? loc.quantity
: (loc.checked_quantity !== undefined ? loc.checked_quantity : loc.checkedQuantity)
);
const checkedAt = firstValue(loc, ['checked_at', 'checkedAt']);
const checkerName = firstValue(loc, ['checker_name', 'checkerName']);
const rowBookInfo = resolveBookMeta(systemQuantity, rowBook);
recordCount += recordIds.length;
if (checkedAt && checkedAt > lastCheckedAt) lastCheckedAt = checkedAt;
const diff = systemQuantity === null || quantity === null ? null : quantity - systemQuantity;
return {
key: `loc-${locationCode || index + 1}`,
// 该库位对应的盘点明细ID(多库位商品上报时按行回传)
detailId: rowDetailId,
// 左滑删除用:整库位的记录 ID 列表(recordDelete 支持数组)
recordIds,
recordId: recordIds.length === 1 ? recordIds[0] : '',
@ -1000,6 +1164,9 @@ export function normalizeGoodsDetailInfo(row, mode) {
locationId: spaceId || '',
systemQuantity,
quantity,
// 账面口径(0.3.318):当前 storage 账面 / 明细快照
storageQuantity: rowBook.storageQuantity,
snapshotQuantity: rowBook.snapshotQuantity,
title: locationName || locationCode || '未指定库位',
subtitle: joinText([
checkerName ? `盘点人 ${checkerName}` : '',
@ -1015,6 +1182,8 @@ export function normalizeGoodsDetailInfo(row, mode) {
// 明细面板展示:账面 / 实盘 / 盈亏(账面>0 时高亮,方便找账面库位)
amounts: systemQuantity === null && quantity === null ? null : {
systemText: systemQuantity === null ? '--' : String(systemQuantity),
systemLabel: rowBookInfo.systemLabel,
bookHint: rowBookInfo.bookHint,
checkedText: quantity === null ? '--' : String(quantity),
diffText: diff === null ? '' : (diff > 0 ? `盘盈 +${diff}` : (diff < 0 ? `盘亏 ${-diff}` : '账实相符')),
diffTone: diff === null ? '' : (diff > 0 ? 'gain' : (diff < 0 ? 'loss' : 'match')),
@ -1024,8 +1193,15 @@ export function normalizeGoodsDetailInfo(row, mode) {
};
});
const summaryBook = resolveBookMeta(toNumberOrNull(systemRaw), {
isStatic: bookMeta.isStatic,
bookSource: bookMeta.bookSource,
storageQuantity: bookMeta.storageQuantity !== null ? bookMeta.storageQuantity : rowBookTotals.storage,
snapshotQuantity: bookMeta.snapshotQuantity !== null ? bookMeta.snapshotQuantity : rowBookTotals.snapshot
});
return {
detailId: pickText(['detail_id', 'detailId']),
detailId: pageDetailId || (locations[0] && locations[0].detailId) || '',
stockId: stockIdRaw === undefined || stockIdRaw === null ? '' : String(stockIdRaw),
itemName: pickText(['item_name', 'itemName']),
itemCode: pickText(['item_code', 'itemCode']),
@ -1035,15 +1211,24 @@ 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
),
// 账面口径(0.3.318):静态盘点取快照、普通盘点取当前库存;另一口径仅作提示
isStatic: bookMeta.isStatic,
hasStaticFlag: bookMeta.hasStaticFlag,
bookSource: bookMeta.bookSource,
bookSourceText: summaryBook.bookSourceText,
storageQuantity: summaryBook.storageQuantity,
snapshotQuantity: summaryBook.snapshotQuantity,
systemQuantity: toNumberOrNull(systemRaw),
checkedQuantity: toNumberOrNull(checkedRaw),
amount: buildWorkAmount(systemRaw, checkedRaw, diffRaw, open, {
isStatic: bookMeta.isStatic,
bookSource: bookMeta.bookSource,
storageQuantity: summaryBook.storageQuantity,
snapshotQuantity: summaryBook.snapshotQuantity
}),
locations,
// 全部库位(含未盘)——仅用于按库位定位明细ID,不用于列表展示
allLocations,
recordCount,
locationCodes: locations.map(item => item.locationCode).filter(Boolean),
checkers,

View File

@ -635,20 +635,21 @@ export default {
this._pendingWorkRefresh = true;
uni.navigateTo({ url });
},
// ===== 商品视图(goods):点击进入商品作业页(只传 id,概况由接口反查) =====
// ===== 商品视图(goods):点击进入商品作业页(0.3.309 起行内不再有 detail_id,优先按 stock_id 进入) =====
handleGoodsOpen(row) {
if (!row || !this.taskId) return;
if (!row.detailId) {
const params = [`task_id=${encodeURIComponent(this.taskId)}`];
if (row.detailId) {
params.push(`detail_id=${encodeURIComponent(row.detailId)}`);
} else if (row.stockId) {
params.push(`stock_id=${encodeURIComponent(row.stockId)}`);
} else {
uni.showToast({ title: '缺少盘点明细ID', icon: 'none' });
return;
}
const params = [
`task_id=${encodeURIComponent(this.taskId)}`,
`detail_id=${encodeURIComponent(row.detailId)}`
].join('&');
// 从商品作业页返回后刷新列表(已盘状态/记录数已变化)
this._pendingWorkRefresh = true;
uni.navigateTo({ url: `/pages/warehouse/inventoryCountGoods?${params}` });
uni.navigateTo({ url: `/pages/warehouse/inventoryCountGoods?${params.join('&')}` });
},
// 刷新/分页后保证存在有效选中项(无选中时不高亮任何格子)
ensureLocationSelection() {
@ -692,7 +693,9 @@ export default {
this.taskInfo = normalizeCheckTaskInfo(payload.check, this.routeStoreName);
}
const rows = extractListPayload(payload, response);
this.workList = normalizeWorkRows(rows, this.workView, this.taskInfo.mode);
this.workList = normalizeWorkRows(rows, this.workView, this.taskInfo.mode, {
isStatic: this.taskInfo.hasStaticFlag ? this.taskInfo.isStatic : undefined
});
this.workTotal = resolveListTotal(payload, response, rows);
const pageNo = Number(payload?.page);
this.workPage = Number.isFinite(pageNo) && pageNo > 0 ? pageNo : targetPage;

View File

@ -54,9 +54,10 @@
</view>
<text class="inv-goods-card__line">{{ goodsMetaText }}</text>
<view class="inv-goods-card__metrics">
<text v-if="systemQuantityValue !== null" class="inv-goods-card__metric">账面 {{ systemQuantityValue }}</text>
<text v-if="systemQuantityValue !== null" class="inv-goods-card__metric">{{ systemLabel }} {{ systemQuantityValue }}</text>
<text class="inv-goods-card__metric">已盘 {{ checkedTotalText }}</text>
<text v-if="diffText" class="inv-goods-card__diff" :class="diffValueClass">{{ diffText }}</text>
<text v-if="bookHintText" class="inv-goods-card__hint">{{ bookHintText }}</text>
</view>
</view>
</view>
@ -124,6 +125,7 @@ import {
normalizeScanResult,
extractObjectPayload,
normalizeGoodsDetailInfo,
isStaticCheck,
buildReportParams
} from './inventoryCount-comps/countModel.js';
@ -139,7 +141,14 @@ function EMPTY_GOODS_INFO() {
systemQuantity: null,
checkedQuantity: null,
amount: null,
// 账面口径(0.3.318):静态盘点取快照、普通盘点取当前库存
isStatic: false,
bookSource: '',
storageQuantity: null,
snapshotQuantity: null,
locations: [],
// 全部库位(含未盘)的明细ID映射:按库位上报时定位 detail_id
allLocations: [],
recordCount: 0,
locationCodes: [],
lastCheckedAtText: ''
@ -155,6 +164,19 @@ function resolveSystemQuantity(goodsInfo) {
return sys === null || sys === undefined ? null : Number(sys);
}
/** 账面口径标签:静态盘点=账面(快照)、普通盘点=账面(当前库存) */
function resolveSystemLabel(goodsInfo) {
const amount = (goodsInfo || {}).amount;
if (amount && amount.systemLabel) return amount.systemLabel;
return (goodsInfo || {}).isStatic ? '账面(快照)' : '账面(当前库存)';
}
/** 另一种口径提示(静态看当前库存 / 普通看基准快照,不一致时才提示) */
function resolveBookHint(goodsInfo) {
const amount = (goodsInfo || {}).amount;
return amount && amount.bookHint ? amount.bookHint : '';
}
/** 是否已盘(有库位明细/作业记录) */
function resolveHasChecked(goodsInfo) {
const info = goodsInfo || {};
@ -186,10 +208,10 @@ function resolveDiffText(goodsInfo) {
/**
* 商品作业页(goods 视图;从盘点作业商品列表点击/扫码进入)
* 入参:**只传 id** —— task_id(盘点任务ID)+ detail_id(盘点明细ID)
* 入参:**只传 id** —— task_id(盘点任务ID)+ detail_id(盘点明细ID)或 stock_id(商品库存ID)
* 数据:
* - stock.check.workDataDetail(仅 detail_id)→ 本明细单行作业数据,含商品信息/主图/账面/已盘/差异 + locations(每库位:账面/实盘/盘点人/时间/记录ID/照片)
* - stock.check.detail(仅主表 check)→ 任务状态 / 盘点模式
* - stock.check.workDataDetail(id + stock_id / detail_id)→ 商品钻取数据:summary(商品级账面/已盘/差异)+ rows(按库位分行)
* - stock.check.detail(仅主表 check)→ 任务状态 / 盘点模式 / 是否静态盘点
* 能力:扫码/输入库位 → 底部抽屉选库位 + 录数量(check.report);库位记录可左滑删除(recordDelete)
*/
export default {
@ -202,7 +224,9 @@ export default {
return {
taskId: '',
detailId: '',
taskInfo: { status: '', mode: '', type: '' },
// 商品库存ID(0.3.309 起 goods 行不再返回 detail_id,改用 stock_id 进入)
stockId: '',
taskInfo: { status: '', mode: '', type: '', isStatic: false, hasStaticFlag: false },
goodsInfo: EMPTY_GOODS_INFO(),
loading: false,
refreshing: false,
@ -233,6 +257,13 @@ export default {
systemQuantityValue() {
return resolveSystemQuantity(this.goodsInfo);
},
// 账面口径标签(快照 / 当前库存)与另一种口径提示
systemLabel() {
return resolveSystemLabel(this.goodsInfo);
},
bookHintText() {
return resolveBookHint(this.goodsInfo);
},
// 已盘合计(接口 checked_quantity,缺失时用库位明细合计;未盘显示 --)
checkedTotalText() {
if (!this.hasChecked) return '--';
@ -264,14 +295,14 @@ export default {
},
// CountLocationDetail 只需要 row 结构(概况在卡片,children = 库位明细:账面/实盘/盈亏)
detailRow() {
if (!this.detailId) return null;
if (!this.detailId && !this.stockId && !this.goodsInfo.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}`,
key: `goods-${this.detailId || this.stockId || this.goodsInfo.stockId}`,
detailId: this.detailId,
title: '',
subtitle: '',
@ -285,9 +316,10 @@ export default {
}
},
onLoad(options = {}) {
// 页面只需两个 id:task_id(任务ID)+ detail_id(盘点明细ID)
// 页面需 task_id +(detail_id 或 stock_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();
@ -388,11 +420,11 @@ export default {
this.showEntryPopup = false;
this.pendingLocation = '';
},
/** 抽屉确认:库位 + 数量 → check.report */
/** 抽屉确认:库位 + 数量 → check.report(多库位商品按所选库位取对应明细ID) */
async handleEntryConfirm(payload) {
if (!payload || !payload.location) return;
const ok = await this.submitReport({
detailId: this.detailId,
detailId: this.resolveLocationDetailId(payload),
location: payload.location,
spaceId: payload.locationId,
quantity: payload.quantity,
@ -404,10 +436,25 @@ export default {
this.closeEntryPopup();
}
},
/** 上报(check.report:detail_id=商品明细,location=库位) */
/** 按库位定位盘点明细ID(同一商品多库位时每个库位一条明细) */
resolveLocationDetailId(payload) {
const target = payload || {};
const spaceId = target.locationId !== undefined && target.locationId !== null ? String(target.locationId).trim() : '';
const code = String(target.location || '').trim();
const candidates = []
.concat(Array.isArray(this.goodsInfo.allLocations) ? this.goodsInfo.allLocations : [])
.concat(Array.isArray(this.goodsInfo.locations) ? this.goodsInfo.locations : []);
const matched = candidates.find(loc => {
const locSpaceId = String(loc.spaceId || loc.locationId || '').trim();
if (spaceId && locSpaceId && locSpaceId === spaceId) return true;
return !!code && String(loc.locationCode || '').trim() === code;
});
return (matched && matched.detailId) || this.detailId;
},
/** 上报(check.report:detail_id=该库位明细,location=库位) */
async submitReport(payload) {
if (!this.editable || this.submitting) return false;
if (!payload || !payload.detailId) {
if (!payload || (!payload.detailId && !payload.stockId)) {
uni.showToast({ title: '缺少盘点明细ID', icon: 'none' });
return false;
}
@ -566,7 +613,10 @@ export default {
this.taskInfo = {
status: String(check.status || '').trim().toLowerCase(),
mode: String(check.mode || '').trim().toLowerCase(),
type: check.type || ''
type: check.type || '',
// 静态盘点:账面取明细快照;普通盘点取当前库存(0.3.318)
isStatic: isStaticCheck(check.is_static !== undefined ? check.is_static : check.isStatic),
hasStaticFlag: (check.is_static !== undefined ? check.is_static : check.isStatic) !== undefined
};
return this.taskInfo;
} catch (error) {
@ -574,24 +624,40 @@ export default {
return null;
}
},
/** 商品明细(stock.check.workDataDetail:入参仅 detail_id)——含商品信息/主图/账面/已盘/差异 + locations 库位明细 */
/** 商品明细(stock.check.workDataDetail:id + stock_id / detail_id,兼容 summary+rows 钻取结构)——含商品信息/主图/账面/已盘/差异 + 各库位明细 */
async loadInfo() {
const taskId = Number(this.taskId);
if (!Number.isFinite(taskId) || taskId <= 0) {
this.loadError = '缺少盘点任务ID';
uni.showToast({ title: this.loadError, icon: 'none' });
return null;
}
const detailId = Number(this.detailId);
if (!Number.isFinite(detailId) || detailId <= 0) {
this.loadError = '缺少盘点明细ID';
const routeStockId = Number(this.stockId);
const knownStockId = Number(this.goodsInfo.stockId);
const stockId = Number.isFinite(knownStockId) && knownStockId > 0
? knownStockId
: (Number.isFinite(routeStockId) && routeStockId > 0 ? routeStockId : 0);
const params = { id: taskId };
if (Number.isFinite(detailId) && detailId > 0) params.detail_id = detailId;
if (stockId > 0) params.stock_id = stockId;
if (!params.detail_id && !params.stock_id) {
this.loadError = '缺少盘点明细ID/商品库存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', params);
if (response?.flag === 'failure') {
this.goodsInfo = EMPTY_GOODS_INFO();
this.loadError = response.message || '盘点明细加载失败';
uni.showToast({ title: this.loadError, icon: 'none' });
return null;
}
const info = normalizeGoodsDetailInfo(extractObjectPayload(response), this.taskInfo.mode);
const info = normalizeGoodsDetailInfo(extractObjectPayload(response), this.taskInfo.mode, {
isStatic: this.taskInfo.hasStaticFlag ? this.taskInfo.isStatic : undefined
});
if (info) this.goodsInfo = Object.assign({}, this.goodsInfo, info);
this.loadError = '';
return this.goodsInfo;
@ -738,6 +804,13 @@ export default {
color: #e64340;
}
/* 另一种账面口径提示(静态看当前库存 / 普通看基准快照) */
.inv-goods-card__hint {
margin-right: 20rpx;
font-size: 28rpx;
color: #b8811a;
}
.inv-goods-tip {
margin: 0 12rpx 16rpx;
padding: 24rpx;

View File

@ -61,6 +61,7 @@ import {
extractObjectPayload,
extractListPayload,
normalizeSpaceWorkDetail,
isStaticCheck,
buildReportParams
} from './inventoryCount-comps/countModel.js';
@ -81,7 +82,7 @@ export default {
return {
taskId: '',
locationId: '',
taskInfo: { status: '', mode: '' },
taskInfo: { status: '', mode: '', isStatic: false, hasStaticFlag: false },
row: null,
loading: false,
refreshing: false,
@ -327,7 +328,10 @@ export default {
const check = extractObjectPayload(response).check || {};
this.taskInfo = {
status: String(check.status || '').trim().toLowerCase(),
mode: String(check.mode || '').trim().toLowerCase()
mode: String(check.mode || '').trim().toLowerCase(),
// 静态盘点:账面取明细快照;普通盘点取当前库存(0.3.318)
isStatic: isStaticCheck(check.is_static !== undefined ? check.is_static : check.isStatic),
hasStaticFlag: (check.is_static !== undefined ? check.is_static : check.isStatic) !== undefined
};
return this.taskInfo;
} catch (error) {
@ -382,7 +386,9 @@ export default {
}
const payload = extractObjectPayload(response);
const rows = extractListPayload(payload, response);
this.row = normalizeSpaceWorkDetail(rows, this.taskInfo.mode);
this.row = normalizeSpaceWorkDetail(rows, this.taskInfo.mode, {
isStatic: this.taskInfo.hasStaticFlag ? this.taskInfo.isStatic : undefined
});
this.applyLocalQuantities();
this.loadError = this.row ? '' : '该库位暂无任务商品';
return this.row;