From fd3228eac3862fb82ed7dbdbf53be54cffd576f7 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Mon, 5 Oct 2026 02:47:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(warehouse):=20=E7=9B=98=E7=82=B9?= =?UTF-8?q?=E5=88=97=E8=A1=A8/=E8=AF=A6=E6=83=85=E6=8B=86=E5=88=86?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E7=BB=84=E4=BB=B6=E5=B9=B6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=BA=93=E4=BD=8D=E6=98=8E=E7=BB=86=E5=AD=90=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 抽出 inventoryCount-comps/:countModel 纯函数 + 记录卡片/工具栏/汇总面板/搜索面板/明细面板/宫格/添加商品弹窗等 - 新增 pages/warehouse/inventoryCountLocation 库位明细子页(workDataDetail + 扫码预填添加商品 + 左滑删除记录) - apis.js 补 result / workData / workDataDetail / recordDelete / addDetail / addLocationDetail 别名 - pages.json 注册新页面 --- src/core/request/apis.js | 52 + src/pages.json | 7 + .../CountActionsPopup.vue | 163 ++ .../CountDetailPicker.vue | 309 ++++ .../inventoryCount-comps/CountItemCard.vue | 259 ++++ .../inventoryCount-comps/CountListToolbar.vue | 187 +++ .../CountLocationDetail.vue | 275 ++++ .../CountLocationGrid.vue | 174 +++ .../CountRecordAddPopup.vue | 510 ++++++ .../inventoryCount-comps/CountRecordCard.vue | 199 +++ .../inventoryCount-comps/CountSearchPanel.vue | 116 ++ .../CountSummaryPanel.vue | 190 +++ .../inventoryCount-comps/CountWorkCard.vue | 414 +++++ .../inventoryCount-comps/countModel.js | 848 ++++++++++ src/pages/warehouse/inventoryCount.vue | 572 +------ src/pages/warehouse/inventoryCountDetail.vue | 1365 ++++++++--------- .../warehouse/inventoryCountLocation.vue | 524 +++++++ 17 files changed, 4954 insertions(+), 1210 deletions(-) create mode 100644 src/pages/warehouse/inventoryCount-comps/CountActionsPopup.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountDetailPicker.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountItemCard.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountListToolbar.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountLocationDetail.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountLocationGrid.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountRecordAddPopup.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountRecordCard.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountSearchPanel.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountSummaryPanel.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/CountWorkCard.vue create mode 100644 src/pages/warehouse/inventoryCount-comps/countModel.js create mode 100644 src/pages/warehouse/inventoryCountLocation.vue diff --git a/src/core/request/apis.js b/src/core/request/apis.js index 61acbd7..8987e6f 100644 --- a/src/core/request/apis.js +++ b/src/core/request/apis.js @@ -443,6 +443,34 @@ export default { method: "POST", isSystemApi: true }, + // 盘点明细结果(按范围行聚合作业记录):返回 { check, rows, total }, + // rows 含已盘/差异聚合 + 作业记录/库位/未知商品;无状态限制(已完成任务也能拉) + result: { + path: "stock.check.result", + auth: true, + method: "POST", + isSystemApi: true + }, + // 盘点作业数据:入参 id + is_goods + keyword + pagination;视图由任务范围与 is_goods 驱动 + // (库位任务一律 location 视图;商品任务默认 space 聚合库位视图,is_goods=true 为 goods 商品视图) + // keyword 仅 location 视图生效(按 location_code/location_name 模糊匹配后分页) + // 仅任务状态 approved/checking 可拉取,其他状态返回 400 + workData: { + path: "stock.check.workData", + auth: true, + method: "POST", + isSystemApi: true + }, + // 单条盘点明细的作业数据(workData 单行版,仅库位任务明细): + // 入参仅 detail_id(兼容 detailId),warehouse_id 由服务端注入; + // 返回 data 为单行 location 结构(detail_id/location_id/location_code/location_name/ + // status/has_unknown/is_empty/checked_at/checkers/goods),仅 approved/checking 可拉取 + workDataDetail: { + path: "stock.check.workDataDetail", + auth: true, + method: "POST", + isSystemApi: true + }, // 盘点作业上报:单条明细实盘数量(quantity>=0 整数) report: { path: "stock.check.report", @@ -450,6 +478,14 @@ export default { method: "POST", isSystemApi: true }, + // 删除盘点作业记录(批量:record_ids 数组,单次≤200,兼容单值 recordId/record_id) + // 仅 approved/checking 允许;查不到的 ID 计入 skipped_ids 不报错;删除后重算进度、主表状态不回退 + recordDelete: { + path: "stock.check.recordDelete", + auth: true, + method: "POST", + isSystemApi: true + }, // 完成盘点作业:主表置 completed finish: { path: "stock.check.finish", @@ -470,6 +506,22 @@ export default { auth: true, method: "POST", isSystemApi: true + }, + // 添加盘点明细(按任务盘点类型决定维度):商品任务传 stock_ids; + // 库位任务传 locations/location_ids(location_ids 优先),type=all 两者都不传则自动拉全仓启用库位 + // 仅 created/rejected 允许;已存在的盘点项自动跳过(幂等);完成后重算主表 total_items + addDetail: { + path: "stock.check.addDetail", + auth: true, + method: "POST", + isSystemApi: true + }, + // 批量添加库位明细(兼容入口,转调 addDetail 的库位ID直查路径) + addLocationDetail: { + path: "stock.check.addLocationDetail", + auth: true, + method: "POST", + isSystemApi: true } }, pick: { diff --git a/src/pages.json b/src/pages.json index b141439..d4f89f1 100644 --- a/src/pages.json +++ b/src/pages.json @@ -138,6 +138,13 @@ "titleNView": false } }, + { + "path" : "pages/warehouse/inventoryCountLocation", + "style" : + { + "titleNView": false + } + }, { "path" : "pages/403", "style" : diff --git a/src/pages/warehouse/inventoryCount-comps/CountActionsPopup.vue b/src/pages/warehouse/inventoryCount-comps/CountActionsPopup.vue new file mode 100644 index 0000000..2439e53 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountActionsPopup.vue @@ -0,0 +1,163 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountDetailPicker.vue b/src/pages/warehouse/inventoryCount-comps/CountDetailPicker.vue new file mode 100644 index 0000000..c9716fc --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountDetailPicker.vue @@ -0,0 +1,309 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountItemCard.vue b/src/pages/warehouse/inventoryCount-comps/CountItemCard.vue new file mode 100644 index 0000000..da29552 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountItemCard.vue @@ -0,0 +1,259 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountListToolbar.vue b/src/pages/warehouse/inventoryCount-comps/CountListToolbar.vue new file mode 100644 index 0000000..9f10fe5 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountListToolbar.vue @@ -0,0 +1,187 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountLocationDetail.vue b/src/pages/warehouse/inventoryCount-comps/CountLocationDetail.vue new file mode 100644 index 0000000..f0f16bf --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountLocationDetail.vue @@ -0,0 +1,275 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountLocationGrid.vue b/src/pages/warehouse/inventoryCount-comps/CountLocationGrid.vue new file mode 100644 index 0000000..dbd445a --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountLocationGrid.vue @@ -0,0 +1,174 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountRecordAddPopup.vue b/src/pages/warehouse/inventoryCount-comps/CountRecordAddPopup.vue new file mode 100644 index 0000000..8171f05 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountRecordAddPopup.vue @@ -0,0 +1,510 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountRecordCard.vue b/src/pages/warehouse/inventoryCount-comps/CountRecordCard.vue new file mode 100644 index 0000000..aaab150 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountRecordCard.vue @@ -0,0 +1,199 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountSearchPanel.vue b/src/pages/warehouse/inventoryCount-comps/CountSearchPanel.vue new file mode 100644 index 0000000..7ebd9c5 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountSearchPanel.vue @@ -0,0 +1,116 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountSummaryPanel.vue b/src/pages/warehouse/inventoryCount-comps/CountSummaryPanel.vue new file mode 100644 index 0000000..d6cd7ab --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountSummaryPanel.vue @@ -0,0 +1,190 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/CountWorkCard.vue b/src/pages/warehouse/inventoryCount-comps/CountWorkCard.vue new file mode 100644 index 0000000..c61b0d6 --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/CountWorkCard.vue @@ -0,0 +1,414 @@ + + + + + diff --git a/src/pages/warehouse/inventoryCount-comps/countModel.js b/src/pages/warehouse/inventoryCount-comps/countModel.js new file mode 100644 index 0000000..3ab6eac --- /dev/null +++ b/src/pages/warehouse/inventoryCount-comps/countModel.js @@ -0,0 +1,848 @@ +/** + * 库存盘点共享逻辑(纯函数 / 无副作用) + * 供 pages/warehouse/inventoryCount.vue 与 inventoryCountDetail.vue 共用, + * 避免两个页面各维护一份字段映射与响应解析。 + */ + +// ===== 取值 / 文案 / 格式化 ===== + +/** 取第一个非空字段值 */ +export function firstValue(source, keys) { + const target = source && typeof source === 'object' ? source : {}; + for (let i = 0; i < keys.length; i += 1) { + const value = target[keys[i]]; + if (value !== null && value !== undefined && String(value).trim() !== '') { + return String(value).trim(); + } + } + return ''; +} + +/** 状态文案 */ +export function statusText(status) { + const map = { + created: '待提交', + submitted: '待审核', + rejected: '已驳回', + approved: '待盘点', + checking: '盘点中', + completed: '已完成', + cancelled: '已取消' + }; + const key = String(status || '').trim().toLowerCase(); + return map[key] || (status ? String(status) : '--'); +} + +/** 状态色调:success/warning/danger/muted/strong(各页面自行拼类名) */ +export function statusTone(status) { + const key = String(status || '').trim().toLowerCase(); + if (key === 'completed') return 'success'; + if (key === 'checking') return 'warning'; + if (key === 'rejected') return 'danger'; + if (key === 'cancelled') return 'muted'; + if (key === 'approved') return 'strong'; + return ''; +} + +/** 明细盘点进度文案 */ +export function detailStatusText(status) { + const map = { + none_checked: '未盘', + partial_checked: '部分已盘', + all_checked: '全部已盘' + }; + const key = String(status || '').trim().toLowerCase(); + return map[key] || ''; +} + +/** 盘点类型文案:goods=商品盘点 / location=库位盘点 */ +export function typeText(type) { + const map = { + goods: '商品盘点', + location: '库位盘点' + }; + const key = String(type || '').trim().toLowerCase(); + return map[key] || (type ? String(type) : '--'); +} + +/** 盘点类型色调:goods/location */ +export function typeTone(type) { + const key = String(type || '').trim().toLowerCase(); + if (key === 'goods') return 'goods'; + if (key === 'location') return 'location'; + return ''; +} + +/** 盘点方式文案 */ +export function modeText(mode) { + const map = { + all: '全盘', + full: '全盘', + open: '明盘', + blind: '盲盘', + store: '按货主', + by_store: '按货主', + owner: '按货主', + by_owner: '按货主', + space: '按库位', + by_space: '按库位', + location: '按库位', + item: '按商品', + by_item: '按商品', + product: '按商品' + }; + const key = String(mode || '').trim().toLowerCase(); + return map[key] || (mode ? String(mode) : ''); +} + +/** 类型 + 方式 */ +export function composeType(type, mode) { + const t = typeText(type); + const m = modeText(mode); + if (t === '--') return m || '--'; + return m ? `${t},${m}` : t; +} + +/** 时间格式化(yyyy-MM-dd HH:mm:ss) */ +export function formatDateTime(value) { + if (value === null || value === undefined || value === '') return ''; + const date = new Date(String(value).trim()); + if (Number.isNaN(date.getTime())) return String(value).trim(); + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const hour = String(date.getHours()).padStart(2, '0'); + const minute = String(date.getMinutes()).padStart(2, '0'); + const second = String(date.getSeconds()).padStart(2, '0'); + return `${year}-${month}-${day} ${hour}:${minute}:${second}`; +} + +/** 扫码结果归一化:兼容字符串 / {result:[]} / {data} 等多种回调结构 */ +export function normalizeScanResult(scanResult) { + if (!scanResult) return ''; + if (typeof scanResult === 'string') return scanResult.trim(); + if (typeof scanResult.result === 'string') return scanResult.result.trim(); + if (Array.isArray(scanResult.result)) { + const first = scanResult.result.find(item => item); + if (typeof first === 'string') return first.trim(); + if (first && typeof first.data === 'string') return first.data.trim(); + } + if (typeof scanResult.data === 'string') return scanResult.data.trim(); + return ''; +} + +// ===== 响应体解析 ===== + +/** 取响应里的第一个普通对象(各接口包裹层级不一) */ +export function extractObjectPayload(response) { + const candidates = [ + response?.data?.data, + response?.data, + response?.result, + response + ]; + for (let i = 0; i < candidates.length; i += 1) { + const current = candidates[i]; + if (current && typeof current === 'object' && !Array.isArray(current)) { + return current; + } + } + return {}; +} + +/** 取响应里的第一个数组(rows/list/items/records/details 等) */ +export function extractListPayload(payload, response) { + const candidates = [ + payload?.rows, + payload?.list, + payload?.items, + payload?.records, + payload?.details, + payload?.data?.rows, + payload?.data?.list, + payload?.data?.items, + response?.data?.rows, + response?.data?.list, + response?.data?.data?.rows, + response?.data?.data?.list, + response?.rows, + response?.list + ]; + for (let i = 0; i < candidates.length; i += 1) { + if (Array.isArray(candidates[i])) return candidates[i]; + } + return []; +} + +/** 解析分页总数 */ +export function resolveListTotal(payload, response, list) { + const pagination = (payload && typeof payload === 'object') ? (payload.pagination || {}) : {}; + const candidates = [ + pagination?.total, + pagination?.count, + payload?.pagination?.total, + payload?.total, + payload?.count, + payload?.totalCount, + response?.data?.pagination?.total, + response?.data?.total, + response?.total, + Array.isArray(list) ? list.length : 0 + ]; + for (let i = 0; i < candidates.length; i += 1) { + const value = Number(candidates[i]); + if (Number.isFinite(value) && value >= 0) return value; + } + return 0; +} + +// ===== 列表页:请求参数与记录归一化 ===== + +/** + * 列表状态筛选项 + * 只展示正式作业与结果:待盘点 / 盘点中 / 已完成; + * created(已创建未审核)、submitted(待审核)、rejected(已驳回)、cancelled(已取消)均不在 PDA 列表中拉取 + */ +export const RECORD_STATUS_OPTIONS = [ + { label: '全部', value: '' }, + { label: '待盘点', value: 'approved' }, + { label: '盘点中', value: 'checking' }, + { label: '已完成', value: 'completed' } +]; + +/** 列表拉取的状态范围(不含 created / submitted / rejected / cancelled) */ +const RECORD_VISIBLE_STATUS = ['approved', 'checking', 'completed']; + +/** 构造列表查询参数 */ +export function buildCheckListParams({ page = 1, pageSize = 20, keyword = '', statusFilter = '' } = {}) { + const targetPage = Math.max(1, Number(page || 1)); + const size = Math.max(1, Number(pageSize || 20)); + const params = { + pagination: { + page: targetPage, + pageSize: size + } + }; + const where = {}; + const kw = String(keyword || '').trim(); + if (kw) { + where.keyword = kw; + } + if (statusFilter) { + where.status = statusFilter; + } else { + where.status = RECORD_VISIBLE_STATUS.slice(); + } + if (Object.keys(where).length) { + params.where = where; + } + return params; +} + +/** 列表记录归一化(卡片展示字段) */ +export function normalizeCheckRecords(list, fallbackPage = 1) { + if (!Array.isArray(list)) return []; + return list + .map((item, index) => { + const source = item && typeof item === 'object' ? item : {}; + const checkNo = firstValue(source, ['check_no', 'checkNo', 'bill_no', 'billNo', 'code', 'no']); + const title = firstValue(source, ['title', 'name']); + const typeValue = firstValue(source, ['check_type', 'checkType', 'type']); + const modeValue = firstValue(source, ['mode', 'check_mode', 'checkMode']); + const operator = firstValue(source, [ + 'creator_name', 'creatorName', 'operator_name', 'operatorName', + 'create_user', 'createUser', 'creator', 'created_by', 'createdBy' + ]); + const timeValue = firstValue(source, ['created_at', 'createdAt', 'create_time', 'createTime']); + const status = firstValue(source, ['status', 'check_status', 'checkStatus', 'state']); + const totalItems = firstValue(source, ['total_items', 'totalItems']); + const checkedItems = firstValue(source, ['checked_items', 'checkedItems']); + let progressText = ''; + if (totalItems !== '') { + progressText = checkedItems !== '' ? `${checkedItems}/${totalItems}` : `0/${totalItems}`; + } + const id = firstValue(source, ['id', 'check_id', 'checkId', 'task_id', 'taskId']) + || `${fallbackPage}-${index + 1}`; + const tone = statusTone(status); + return { + id, + checkNo, + title, + type: typeValue, + typeText: composeType(typeValue, modeValue), + typeLabel: typeText(typeValue), + typeClass: typeTone(typeValue) ? `record-card__type--${typeTone(typeValue)}` : '', + operator, + progressText, + status, + statusText: statusText(status), + statusClass: tone ? `record-card__status--${tone}` : '', + timeText: formatDateTime(timeValue) + }; + }) + .filter(item => !!(item.checkNo || item.title || item.operator)); +} + +// ===== 详情页:单头与明细归一化 ===== + +/** 单头信息归一化(check.detail / check.workData / check.result 的 check 同口径,覆盖全部字段) */ +export function normalizeCheckTaskInfo(check) { + const source = check && typeof check === 'object' ? check : {}; + const id = firstValue(source, ['id']); + const checkNo = firstValue(source, ['check_no', 'checkNo', 'bill_no', 'billNo', 'code', 'no']); + const title = firstValue(source, ['title', 'name']); + const typeValue = firstValue(source, ['check_type', 'checkType', 'type']); + const modeValue = firstValue(source, ['mode', 'check_mode', 'checkMode']); + const status = firstValue(source, ['status', 'check_status', 'checkStatus', 'state']); + const totalItems = Number(firstValue(source, ['total_items', 'totalItems'])) || 0; + const checkedItems = Number(firstValue(source, ['checked_items', 'checkedItems'])) || 0; + const diffItems = Number(firstValue(source, ['diff_items', 'diffItems'])) || 0; + const detailStatus = firstValue(source, ['detail_status', 'detailStatus']); + const storeIdRaw = firstValue(source, ['store_id', 'storeId']); + const storeName = firstValue(source, ['store_name', 'storeName']); + const creatorId = firstValue(source, ['creator_id', 'creatorId']); + const creatorName = firstValue(source, ['creator_name', 'creatorName', 'creator']); + const remark = firstValue(source, ['remark']); + const tone = statusTone(status); + return { + id, + checkNo, + title, + // 盘点类型(商品盘点/库位盘点)与盘点方式(明盘/盲盘)分开展示 + type: typeValue, + typeText: typeText(typeValue), + mode: modeValue, + modeText: modeText(modeValue), + storeId: storeIdRaw === '' ? null : storeIdRaw, + storeName, + status, + statusText: statusText(status), + statusClass: tone ? `summary-panel__value--${tone}` : '', + detailStatus, + detailStatusText: detailStatusText(detailStatus), + totalItems, + checkedItems, + diffItems, + creatorId, + creatorName, + remark, + startTimeText: formatDateTime(firstValue(source, ['start_time', 'startTime'])), + endTimeText: formatDateTime(firstValue(source, ['end_time', 'endTime'])), + createTimeText: formatDateTime(firstValue(source, ['created_at', 'createdAt', 'create_time', 'createTime'])), + updateTimeText: formatDateTime(firstValue(source, ['updated_at', 'updatedAt', 'update_time', 'updateTime'])) + }; +} + +/** 依据已盘/差异数量刷新差异文案与样式类 */ +export function applyItemDiffText(item) { + if (!item || !item.reported) { + if (item) { + item.diffText = ''; + item.diffClass = ''; + } + return; + } + const diff = item.diffQuantity; + if (!Number.isFinite(diff)) { + item.diffText = ''; + item.diffClass = ''; + return; + } + if (diff > 0) { + item.diffText = `盘盈 +${diff}`; + item.diffClass = 'count-card__diff--gain'; + } else if (diff < 0) { + item.diffText = `盘亏 ${diff}`; + item.diffClass = 'count-card__diff--loss'; + } else { + item.diffText = '账实相符'; + item.diffClass = 'count-card__diff--match'; + } +} + +/** 明细归一化(商品/库位、账面/实盘/差异) */ +export function normalizeCheckItemList(list) { + if (!Array.isArray(list)) return []; + return list.map((item, index) => { + const source = item && typeof item === 'object' ? item : {}; + const barcode = firstValue(source, ['item_code', 'itemCode', 'barcode', 'bar_code']); + const name = firstValue(source, ['item_name', 'itemName', 'product_name', 'name', 'stock_name']); + const spec = firstValue(source, ['spec', 'specification', 'sku_property']); + const batchNo = firstValue(source, ['batch_no', 'batchNo', 'batch_number']); + const locationCode = firstValue(source, ['location_code', 'locationCode', 'space_code', 'spaceCode']); + const systemRaw = firstValue(source, ['system_quantity', 'systemQuantity', 'book_quantity', 'stock_quantity', 'quantity']); + const checkRaw = firstValue(source, ['checked_quantity', 'checkedQuantity', 'check_quantity', 'checkQuantity']); + const diffRaw = firstValue(source, ['diff_quantity', 'diffQuantity']); + const detailId = firstValue(source, ['id', 'detail_id', 'detailId']) || `${index + 1}`; + const systemNumber = systemRaw === '' ? null : Number(systemRaw); + const checkNumber = checkRaw === '' ? null : Number(checkRaw); + const diffNumber = diffRaw === '' ? null : Number(diffRaw); + const reported = checkRaw !== ''; + const normalized = { + key: `${index + 1}`, + detailId, + barcode, + name, + spec, + batchNo, + locationCode, + systemQuantity: Number.isFinite(systemNumber) ? systemNumber : null, + systemQuantityText: systemRaw === '' ? '--' : (Number.isFinite(systemNumber) ? String(systemNumber) : systemRaw), + checkQuantity: Number.isFinite(checkNumber) ? checkNumber : null, + diffQuantity: Number.isFinite(diffNumber) ? diffNumber : null, + reported, + inputValue: reported ? String(checkNumber) : '', + diffText: '', + diffClass: '', + reporting: false + }; + applyItemDiffText(normalized); + return normalized; + }); +} + +/** + * 盘点明细结果行归一化(stock.check.result,供明细 tab 只读展示) + * 商品行:挂 stock 商品快照 + checked_quantity/diff_quantity/is_diff/status + * 库位行:以 location_code 为主标识,含 is_empty/行级 checked_quantity + */ +export function normalizeCheckResultRows(rows) { + if (!Array.isArray(rows)) return []; + return rows.map((row, index) => { + const source = row && typeof row === 'object' ? row : {}; + const stock = source.stock && typeof source.stock === 'object' ? source.stock : {}; + const scopeType = firstValue(source, ['scope_type', 'scopeType']).toLowerCase(); + const isGoods = scopeType !== 'location'; + const locationCode = firstValue(source, ['location_code', 'locationCode']); + const itemCode = firstValue(source, ['item_code', 'itemCode']) + || firstValue(stock, ['item_code', 'itemCode', 'barcode', 'bar_code']); + const itemName = firstValue(source, ['item_name', 'itemName']) + || firstValue(stock, ['item_name', 'itemName', 'product_name', 'name']); + const spec = firstValue(source, ['spec']) || firstValue(stock, ['spec', 'specification']); + const batchNo = firstValue(source, ['batch_no', 'batchNo']); + const detailId = firstValue(source, ['id', 'detail_id', 'detailId']) || `${index + 1}`; + const systemRaw = source.system_quantity !== undefined && source.system_quantity !== null + ? source.system_quantity : source.systemQuantity; + const checkedRaw = source.checked_quantity !== undefined && source.checked_quantity !== null + ? source.checked_quantity : source.checkedQuantity; + const diffRaw = source.diff_quantity !== undefined && source.diff_quantity !== null + ? source.diff_quantity : source.diffQuantity; + const status = firstValue(source, ['status']).toLowerCase(); + const isEmpty = source.is_empty === 1 || source.is_empty === true; + const systemNumber = toNumberOrNull(systemRaw); + const checkedNumber = toNumberOrNull(checkedRaw); + const reported = isEmpty || status === 'checked' || checkedNumber !== null; + const normalized = { + key: `${detailId}`, + detailId, + scopeType: isGoods ? 'goods' : 'location', + name: isGoods ? (itemName || itemCode || '--') : (locationCode || `明细 #${detailId}`), + barcode: itemCode, + spec, + batchNo, + locationCode: isGoods ? locationCode : '', + isEmpty, + systemQuantity: systemNumber, + systemQuantityText: systemNumber === null ? '--' : String(systemNumber), + checkQuantity: checkedNumber, + diffQuantity: toNumberOrNull(diffRaw), + reported, + inputValue: reported && checkedNumber !== null ? String(checkedNumber) : (isEmpty ? '0' : ''), + diffText: '', + diffClass: '', + reporting: false + }; + applyItemDiffText(normalized); + return normalized; + }); +} + +// ===== 作业列表(stock.check.workData)===== + +/** 商品类任务:type=goods/store(库位类任务 type=location/all) */ +export function isGoodsTask(type) { + const key = String(type || '').trim().toLowerCase(); + return key === 'goods' || key === 'store'; +} + +/** 任务是否明盘(open);盲盘(blind)接口不返回任何数量字段 */ +export function isOpenCheckMode(mode) { + return String(mode || '').trim().toLowerCase() === 'open'; +} + +/** + * 作业解析视图: + * 库位任务(location/all)一律 location;商品任务(goods/store)默认 space,isGoods=true 时为 goods + */ +export function resolveWorkView(type, isGoods) { + if (!isGoodsTask(type)) return 'location'; + return isGoods ? 'goods' : 'space'; +} + +function toNumberOrNull(value) { + if (value === null || value === undefined || value === '') return null; + const num = Number(value); + return Number.isFinite(num) ? num : null; +} + +/** 布尔字段归一化(兼容 true/1/'1'/'true') */ +function toBool(value) { + if (value === true || value === 1) return true; + const key = String(value === null || value === undefined ? '' : value).trim().toLowerCase(); + return key === '1' || key === 'true'; +} + +/** 宫格格子里显示的短库位号(取末两段,如 E07-01-02-01 → 02-01) */ +export function shortLocationLabel(code) { + const text = String(code || '').trim(); + if (!text) return ''; + const parts = text.split('-').filter(part => part !== ''); + if (parts.length <= 2) return text; + return parts.slice(-2).join('-'); +} + +function toNumberString(value) { + const num = toNumberOrNull(value); + return num === null ? '' : String(num); +} + +/** 明盘数量块(盲盘返回 null,不展示任何数量) */ +function buildWorkAmount(systemQuantity, checkedQuantity, diffQuantity, open) { + if (!open) return null; + const sys = toNumberOrNull(systemQuantity); + const chk = toNumberOrNull(checkedQuantity); + let diff = toNumberOrNull(diffQuantity); + if (diff === null && sys !== null && chk !== null) diff = chk - sys; + return { + systemText: sys === null ? '--' : String(sys), + checkedText: chk === null ? '--' : String(chk), + diffText: diff === null ? '' : (diff > 0 ? `盘盈 +${diff}` : (diff < 0 ? `盘亏 ${diff}` : '账实相符')), + diffClass: diff === null ? '' : (diff > 0 ? 'work-card__diff--gain' : (diff < 0 ? 'work-card__diff--loss' : 'work-card__diff--match')) + }; +} + +/** 录入单元:detailId + location + 输入值(original 用于判断是否已修改) */ +function buildWorkUnit(detailId, location, currentQuantity, reported, stockId) { + const value = toNumberString(currentQuantity); + const done = !!reported; + return { + detailId: detailId ? String(detailId) : '', + location: location ? String(location) : '', + stockId: stockId === undefined || stockId === null ? '' : String(stockId), + inputValue: done ? value : '', + original: done ? value : '', + reported: done, + reporting: false + }; +} + +/** + * 构造 check.report 入参(按 https 文档口径) + * - 商品明细行:stock_id 固定为明细商品;location 可选(未传归入无库位分组) + * - 库位明细行:必须带商品(stock_id 或 barcode 至少一项),location 以明细库位为准 + * - 未知商品:只传 barcode(item_name 可选,缺省为条码) + * - 空库位标记:is_empty=true(仅库位明细行,quantity 恒为 0) + */ +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) + }; + if (isEmpty) { + params.is_empty = true; + return params; + } + const location = String(payload.location || '').trim(); + if (location) params.location = location; + const stockId = payload.stockId; + if (stockId !== undefined && stockId !== null && String(stockId).trim() !== '') { + params.stock_id = Number(stockId); + } + const barcode = String(payload.barcode || '').trim(); + if (barcode) params.barcode = barcode; + const itemName = String(payload.itemName || '').trim(); + if (itemName) params.item_name = itemName; + return params; +} + +function joinText(parts, sep = ' · ') { + return parts.filter(part => part !== null && part !== undefined && String(part).trim() !== '').map(part => String(part).trim()).join(sep); +} + +/** space 视图:行=库位,goods 为该库位下的任务商品(商品任务默认视图) */ +function normalizeSpaceWorkRow(item, index, open) { + const source = item && typeof item === 'object' ? item : {}; + const spaceCode = firstValue(source, ['space_code', 'spaceCode']) || `#${index + 1}`; + const rawGoods = Array.isArray(source.goods) ? source.goods : []; + const children = rawGoods.map((row, goodIndex) => { + const good = row && typeof row === 'object' ? row : {}; + 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'; + return { + key: `${spaceCode}-${detailId || goodIndex + 1}`, + title: firstValue(good, ['item_name', 'itemName']) || '--', + subtitle: joinText([firstValue(good, ['barcode']), firstValue(good, ['spec']), firstValue(good, ['store_name', 'storeName'])]), + 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), + quantityText: '', + unit: buildWorkUnit(detailId, spaceCode, checkedRaw, done, firstValue(good, ['stock_id', 'stockId'])) + }; + }); + return { + key: `space-${firstValue(source, ['id']) || spaceCode}`, + view: 'space', + title: spaceCode, + subtitle: joinText([firstValue(source, ['custom_name', 'customName']), firstValue(source, ['custom_barcode', 'customBarcode'])]), + statusText: '', + statusClass: '', + meta: children.length ? [] : [{ label: '商品', value: '该库位暂无任务商品' }], + amount: null, + quantityText: '', + children, + unit: null + }; +} + +/** goods 视图:行=商品,locations 为按库位聚合的作业记录(商品任务的 is_goods=true) */ +function normalizeGoodsWorkRow(item, index, open) { + 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; + const rawLocations = Array.isArray(source.locations) ? source.locations : []; + const children = rawLocations.map((row, locIndex) => { + const loc = row && typeof row === 'object' ? row : {}; + const code = firstValue(loc, ['location_code', 'locationCode']); + const time = firstValue(loc, ['checked_at', 'checkedAt']); + return { + key: `${detailId || index + 1}-loc-${locIndex + 1}`, + title: code || '未指定库位', + subtitle: joinText([firstValue(loc, ['checker_name', 'checkerName']), time ? formatDateTime(time) : '']), + statusText: '', + statusClass: '', + amount: null, + quantityText: open && loc.quantity !== undefined && loc.quantity !== null ? String(loc.quantity) : '', + unit: null + }; + }); + const reported = checkedRaw !== undefined && checkedRaw !== null && checkedRaw !== ''; + return { + key: `goods-${detailId || index + 1}`, + view: 'goods', + title: firstValue(source, ['item_name', 'itemName']) || '--', + subtitle: joinText([firstValue(source, ['spec']), firstValue(source, ['barcode']), firstValue(source, ['store_name', 'storeName'])]), + statusText: '', + statusClass: '', + meta: children.length ? [] : [{ label: '库位', value: '暂无作业记录' }], + amount: buildWorkAmount(source.system_quantity !== undefined ? source.system_quantity : source.systemQuantity, checkedRaw, source.diff_quantity !== undefined ? source.diff_quantity : source.diffQuantity, open), + quantityText: '', + children, + unit: buildWorkUnit(detailId, '', checkedRaw, reported, firstValue(source, ['stock_id', 'stockId'])) + }; +} + +/** location 视图:行=任务库位,goods 为该库位的作业记录(未知商品也在 goods 内,stock_id=null) */ +function normalizeLocationWorkRow(item, index, open) { + const source = item && typeof item === 'object' ? item : {}; + const locationCode = firstValue(source, ['location_code', 'locationCode']) || `#${index + 1}`; + const detailId = firstValue(source, ['detail_id', 'detailId']); + const status = String(source.status || '').trim().toLowerCase(); + const done = status === 'checked'; + const rawGoods = Array.isArray(source.goods) ? source.goods : []; + const children = []; + rawGoods.forEach((row, goodIndex) => { + const good = row && typeof row === 'object' ? row : {}; + const qty = toNumberOrNull(good.quantity); + // 未知商品:stock_id 为空(后端已不再返回独立 unknown 子列表) + const stockIdRaw = good.stock_id !== undefined && good.stock_id !== null ? good.stock_id : good.stockId; + const unknown = stockIdRaw === undefined || stockIdRaw === null || String(stockIdRaw).trim() === ''; + const itemCode = firstValue(good, ['item_code', 'itemCode', 'barcode']); + const checkerName = firstValue(good, ['checker_name', 'checkerName']); + // 用 record_id 做稳定 key:删记录后剩下的项不会因下标位移而复用旧的左滑节点 + const recordId = firstValue(good, ['record_id', 'recordId']); + children.push({ + key: `${locationCode}-${unknown ? 'u' : 'g'}-${recordId || goodIndex + 1}`, + recordId, + stockId: unknown ? '' : String(stockIdRaw), + title: firstValue(good, ['item_name', 'itemName']) || itemCode || (unknown ? '未知商品' : '--'), + subtitle: joinText([ + itemCode, + unknown ? '未知商品' : firstValue(good, ['store_name', 'storeName']), + checkerName ? `盘点人 ${checkerName}` : '' + ]), + statusText: unknown ? '未知' : '', + statusClass: unknown ? 'work-card__tag--unknown' : '', + amount: null, + quantityText: qty === null ? '' : String(qty), + images: Array.isArray(good.images) ? good.images : [], + unknown, + unit: null + }); + }); + const unknownCount = children.filter(child => child.unknown).length; + const goodsCount = children.length - unknownCount; + const checkersRaw = source.checkers; + const checkers = Array.isArray(checkersRaw) ? checkersRaw.filter(Boolean).join('、') : ''; + const checkedAt = firstValue(source, ['checked_at', 'checkedAt']); + const checkedAtText = checkedAt ? formatDateTime(checkedAt) : ''; + const locationName = firstValue(source, ['location_name', 'locationName']); + const isEmpty = toBool(source.is_empty); + const hasUnknown = toBool(source.has_unknown); + const meta = []; + if (checkers) meta.push({ label: '盘点人', value: checkers }); + if (checkedAtText) meta.push({ label: '最近上报', value: checkedAtText }); + if (hasUnknown) meta.push({ label: '提示', value: '含未知商品' }); + return { + key: `location-${detailId || locationCode}`, + view: 'location', + detailId: detailId ? String(detailId) : '', + location: locationCode, + title: locationCode, + subtitle: locationName && locationName !== locationCode ? locationName : '', + // 原始 location_name(跳转库位明细页时携带) + locationName: locationName || locationCode, + statusText: done ? '已盘' : '未盘', + statusClass: done ? 'work-card__tag--done' : 'work-card__tag--todo', + // 宫格 / 明细面板展示字段 + empty: isEmpty, + checked: done, + hasUnknown, + checkersText: checkers, + checkedAtText, + goodsCount, + unknownCount, + // 宫格主文本:优先完整 location_name,缺失时回退 location_code + gridText: locationName || locationCode, + gridLabel: shortLocationLabel(locationCode), + meta, + amount: null, + quantityText: '', + children, + // 库位明细行不直接录入数量:在库位下逐条添加商品记录,或标记空库位 + unit: null, + actions: [ + { key: 'add-goods', text: '添加商品' }, + { key: 'mark-empty', text: '标记空库位' } + ] + }; +} + +/** 作业数据行归一化(view: space / goods / location) */ +export function normalizeWorkRows(rows, view, mode) { + if (!Array.isArray(rows)) return []; + const open = isOpenCheckMode(mode); + return rows.map((item, index) => { + if (view === 'goods') return normalizeGoodsWorkRow(item, index, open); + if (view === 'location') return normalizeLocationWorkRow(item, index, open); + return normalizeSpaceWorkRow(item, index, open); + }); +} + +/** + * 单条盘点明细作业数据归一化(stock.check.workDataDetail) + * 返回结构与 workData location 视图单行一致;payload 为空时返回 null。 + */ +export function normalizeLocationWorkDetail(payload, mode) { + if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return null; + if (!Object.keys(payload).length) return null; + return normalizeLocationWorkRow(payload, 0, isOpenCheckMode(mode)); +} + +/** 作业行内可录入单元(行级 + 子项级) */ +export function collectWorkUnits(row) { + if (!row) return []; + const units = []; + if (row.unit) units.push(row.unit); + if (Array.isArray(row.children)) { + row.children.forEach(child => { + if (child && child.unit) units.push(child.unit); + }); + } + return units; +} + +/** 作业行内可用于扫码定位的文本(主标题/副标题 + 子项标题/副标题) */ +export function collectWorkSearchTexts(row) { + if (!row) return []; + const texts = [row.title, row.subtitle]; + if (Array.isArray(row.children)) { + row.children.forEach(child => { + if (!child) return; + texts.push(child.title, child.subtitle); + }); + } + return texts.filter(text => text !== null && text !== undefined && String(text).trim() !== ''); +} + +// ===== 选择器共用的查询结果归一化(stock.warehouse.search / common.searchSpace)===== + +/** 从各接口包裹层级里取数组 */ +export function pickResponseRows(response) { + const candidates = [ + response?.data, + response?.rows, + response?.list, + response?.data?.rows, + response?.data?.list + ]; + for (let i = 0; i < candidates.length; i += 1) { + if (Array.isArray(candidates[i])) return candidates[i]; + } + return []; +} + +/** 商品图片归一化成 URL 数组(兼容字符串 / {url|path|image_url|fileUrl|successUrl} / {file:{file_url}}) */ +export function normalizeImageUrls(list) { + if (!Array.isArray(list)) return []; + return list + .map(image => { + if (!image) return ''; + if (typeof image === 'string') return image.trim(); + if (typeof image !== 'object') return ''; + const file = image.file && typeof image.file === 'object' ? image.file : {}; + return String( + image.url || image.path || image.image_url || image.fileUrl || image.successUrl + || file.file_url || file.url || file.path || '' + ).trim(); + }) + .filter(Boolean); +} + +/** 商品搜索结果归一化:id=wms_stock_warehouse.id(即 report/addDetail 的 stock_id) */ +export function normalizeStockSearchRows(response) { + return pickResponseRows(response).map((row, index) => { + const source = row && typeof row === 'object' ? row : {}; + const name = source.item_name || source.product_name || source.name || source.goods_name || '未命名商品'; + const barcodeList = Array.isArray(source.barcodes) ? source.barcodes.filter(Boolean) : []; + const barcode = source.barcode || source.goods_code || source.item_code || barcodeList.join(';'); + const storeStock = source.store_stock || {}; + const storeName = storeStock.store_remask || storeStock.store_name || source.store_name || ''; + const spec = source.spec || source.specification || ''; + return { + key: `goods-${source.id || index}`, + id: source.id === undefined || source.id === null ? '' : source.id, + code: barcode, + title: name, + subtitle: [barcode, spec, storeName].filter(Boolean).join(' · '), + images: normalizeImageUrls(source.images) + }; + }).filter(item => item.id !== ''); +} + +/** 库位搜索结果归一化 */ +export function normalizeSpaceSearchRows(response) { + return pickResponseRows(response).map((row, index) => { + const source = row && typeof row === 'object' ? row : {}; + const code = source.space_code || source.spaceCode || ''; + return { + key: `space-${source.id || code || index}`, + id: source.id === undefined || source.id === null ? '' : source.id, + code, + title: code || `库位 #${index + 1}`, + subtitle: [source.custom_name, source.custom_barcode ? `条码:${source.custom_barcode}` : ''].filter(Boolean).join(' · ') + }; + }).filter(item => item.id !== ''); +} diff --git a/src/pages/warehouse/inventoryCount.vue b/src/pages/warehouse/inventoryCount.vue index b0619e5..5194e81 100644 --- a/src/pages/warehouse/inventoryCount.vue +++ b/src/pages/warehouse/inventoryCount.vue @@ -3,87 +3,40 @@ - - - - - - - - - - - 搜索 - - - - - - - {{ opt.label }} - - - - + + - - + + {{ loading ? '加载中...' : '暂无盘点任务' }} {{ keyword ? '请检查关键字后重试' : '请在上方输入关键字查询' }} - - - 盘点单号 - {{ item.checkNo || '--' }} - - - 标题 - {{ item.title }} - - - 盘点类型 - {{ item.typeText || '--' }} - - - 状态 - {{ item.statusText || '--' }} - - - 进度 - {{ item.progressText }} - - - 创建人 - {{ item.operator || '--' }} - - - 创建时间 - {{ item.timeText || '--' }} - - + /> @@ -108,23 +61,34 @@ + +