diff --git a/src/api/stock/productflow.ts b/src/api/stock/productflow.ts new file mode 100644 index 0000000..4750fec --- /dev/null +++ b/src/api/stock/productflow.ts @@ -0,0 +1,415 @@ +/** + * 商品流水(`stock.transaction.storeList`,**货主侧**) + * + * 与 new3 Web 端 `src/views/storage/productflow/store/index.vue` **同一个接口** + * (它引的是 `@/api/stock/stock` 的 `stockTransactionStoreList`)。 + * ⚠️ 同文件另有 `stock.transaction.list`(仓库侧)—— 小程序是**货主侧**,别拿错。 + * + * ``` + * body = { where?, pagination: { page, pageSize }, sort: { sortField, sortOrder } } + * 返回 data = { list: [...], pagination: { page, pageSize, total } } + * ``` + * + * ⚠️ **`where` 的形状是「混的」** —— 这是 new3 该页 `normalizeToWhere()` + + * `applyWarehouseToWhere()` 的**真实输出**,不是笔误: + * + * | 字段 | 形状 | + * |---|---| + * | `order_no` | `{ operator: 'contains', value, type: 'text' }`(带操作符) | + * | `created_at` | `{ operator: 'between', value: [start, end], type: 'daterange' }` | + * | `transaction_type` / `order_type` / `warehouse_id` | **裸值**(ScanBox 的 select 不产生 operator) | + * + * 展示字段取自 new3 `productflow-config.ts` 的 `columns`,但按**详情面板**的粒度收敛成 + * 移动端卡片(Web 表格里 8 个数字列 → 「变动数量 / 库存 前→后 / 锁定库存 前→后」三行); + * 排序、列配置、导出、详情面板这些 Web 能力小程序不做。 + */ + +import request from '@/utils/request' +import type { BizResponse } from '@/utils/request' +import { SYSTEM_URL, gatewayParams } from '@/utils/gateway' + +/** + * 每页条数:**固定 50 条,页面不提供修改** + * + * 与「收货单」「库存报表」「入库单」取同一个值(纯文本行,单页多放一些少翻页) + */ +export const PRODUCTFLOW_PAGE_SIZE = 50 + +/** 商品流水行(只声明小程序用到的字段,其余用索引签名兜住) */ +export interface ProductFlowItem { + id?: number + /** 流水时间(后端原值,形如 `2026-10-03T12:00:00.000Z` 或 `2026-10-03 12:00:00`) */ + created_at?: string + /** 流水类型:INBOUND 入库 / OUTBOUND 出库 / LOCK 锁定库存 / UNLOCK 取消锁定 */ + transaction_type?: string + /** 商品ID(= `wms_stock_warehouse.id`,Web 列名就是「商品ID」) */ + stock_id?: number + store_id?: number + warehouse_id?: number + /** 变动数量原始值(有时后端直接给,否则用 `after_quantity - before_quantity` 算) */ + quantity?: number + /** 可用库存 变动前 / 变动后 */ + before_quantity?: number + after_quantity?: number + /** 锁定库存 变动前 / 变动后 */ + before_locked_quantity?: number + after_locked_quantity?: number + /** 批次号 */ + batch_no?: string + /** 订单类型:ORDER / CGRK / SHRK / RECEIVING / ENTRY_ORDER / RETURN ... */ + order_type?: string + /** 订单号 */ + order_no?: string + order_id?: number + receiving_id?: number + entry_order_id?: number + /** 操作人 */ + operator_name?: string + remark?: string + [key: string]: any +} + +/** 列表响应体 `data` */ +export interface ProductFlowPayload { + list?: ProductFlowItem[] + total?: number + pagination?: { page?: number; pageSize?: number; total?: number } + [key: string]: any +} + +/** 查询条件(页面传入) */ +export interface ProductFlowQuery { + page?: number + pageSize?: number + /** 订单号(`contains` 模糊),空表示不过滤 */ + order_no?: string + /** 流水类型 INBOUND / OUTBOUND / LOCK / UNLOCK,空表示全部 */ + transaction_type?: string + /** 订单类型,空表示全部 */ + order_type?: string + /** 流水时间区间(`YYYY-MM-DD HH:mm:ss`),两个都为空则不传时间条件 */ + start_time?: string + end_time?: string + /** 仓库 id,空表示全部 */ + warehouse_id?: number | string +} + +function isFilled(value: unknown): boolean { + return value !== undefined && value !== null && value !== '' +} + +/** + * 组装请求体 + * + * `sort` 固定 `created_at DESC`(与 new3 页面的默认排序一致;移动端不做排序 UI) + */ +function buildBody(query: ProductFlowQuery): Record { + const { + page = 1, + pageSize = PRODUCTFLOW_PAGE_SIZE, + order_no, + transaction_type, + order_type, + start_time, + end_time, + warehouse_id + } = query + + const where: Record = {} + + // 带操作符的一类 + if (order_no && String(order_no).trim()) { + where.order_no = { operator: 'contains', value: String(order_no).trim(), type: 'text' } + } + if (isFilled(start_time) && isFilled(end_time)) { + where.created_at = { operator: 'between', value: [start_time, end_time], type: 'daterange' } + } + + // 裸值的一类(ScanBox 的 select / 仓库筛选都是裸值) + if (isFilled(transaction_type)) where.transaction_type = transaction_type + if (isFilled(order_type)) where.order_type = order_type + if (isFilled(warehouse_id)) where.warehouse_id = warehouse_id + + const body: Record = { + pagination: { page, pageSize }, + sort: { sortField: 'created_at', sortOrder: 'DESC' } + } + // 无有效条件时不传 where(与 new3 `where: Object.keys(where).length > 0 ? where : undefined` 一致) + if (Object.keys(where).length) body.where = where + return body +} + +/** 商品流水列表(分页,货主侧) */ +export function fetchStoreProductFlowList( + query: ProductFlowQuery = {} +): Promise> { + return request({ + url: SYSTEM_URL, + method: 'POST', + params: gatewayParams('stock.transaction.storeList'), + data: buildBody(query), + // 需要登录:未登录时不发请求,直接弹登录抽屉 + auth: true + }) +} + +// ── 响应解析(⚠️ 别只认 `data.list`)───────────────────────────────────── + +/** + * 从响应里取流水数组 + * + * ⚠️ **本接口的业务字段在「响应顶层」,没有 `data` 包裹**(与 `index.loadStores` 同类): + * + * ```json + * { "flag":"success", "code":200, "message":"ok", + * "list":[...], "pagination":{ "page":1, "pageSize":20, "total":6279 }, "timestamp":... } + * ``` + * + * new3 的写法是 `const payload = res?.data ?? res` 后再取 `payload.list` → 说明 + * 「带 `data` 包裹」与「扁平」两种形态都可能出现,故这里两者都兼容: + * 顶层 `list`/`items`/`rows` → `data` 包裹 → 直接数组。 + */ +export function readList(res: any): ProductFlowItem[] { + const payload = res?.data ?? res + if (Array.isArray(payload)) return payload + + for (const key of ['list', 'items', 'rows'] as const) { + if (Array.isArray(payload?.[key])) return payload[key] + } + + // 兜底:`data` 存在但是别的对象,而列表在响应顶层 + for (const key of ['list', 'items', 'rows'] as const) { + if (Array.isArray(res?.[key])) return res[key] + } + + return [] +} + +/** + * 总数:`pagination.total` / `total` + * + * `data` 内外都找一遍(本接口实测形态见 `readList` 注释) + */ +export function readTotal(res: any): number { + const candidates = [ + res?.data?.pagination?.total, + res?.pagination?.total, + res?.data?.total, + res?.total + ] + for (const value of candidates) { + const num = Number(value) + if (Number.isFinite(num) && num > 0) return num + } + return 0 +} + +// ── 流水类型(`transaction_type`)───────────────────────────────────────── + +/** 流水类型 → 文案(与 new3 `productflow-config.ts` 的 `transactionTypeConfig` 对齐) */ +export const TRANSACTION_TYPE_TEXT: Record = { + INBOUND: '入库', + OUTBOUND: '出库', + LOCK: '锁定库存', + UNLOCK: '取消锁定' +} + +/** 流水类型 → 主题色(对齐 new3 的 tag:success / danger / warning / info) */ +export const TRANSACTION_TYPE_COLOR: Record = { + INBOUND: '#19be6b', + OUTBOUND: '#fa3534', + LOCK: '#ff9900', + UNLOCK: '#909399' +} + +/** 流水类型 → 标签底色(与上面的主题色同源,低透明度,用于卡片头部的类型胶囊) */ +export const TRANSACTION_TYPE_BG: Record = { + INBOUND: 'rgba(25, 190, 107, 0.12)', + OUTBOUND: 'rgba(250, 53, 52, 0.12)', + LOCK: 'rgba(255, 153, 0, 0.14)', + UNLOCK: 'rgba(144, 147, 153, 0.14)' +} + +/** 流水类型文案:未知值原样显示(后端加新类型也不会显示成空白) */ +export function readTransactionTypeText(type?: string): string { + if (!type) return '—' + const upper = String(type).toUpperCase() + return TRANSACTION_TYPE_TEXT[upper] || type +} + +/** 流水类型颜色 */ +export function readTransactionTypeColor(type?: string): string { + if (!type) return '#909399' + const upper = String(type).toUpperCase() + return TRANSACTION_TYPE_COLOR[upper] || '#909399' +} + +/** 流水类型标签底色;未知类型给中性灰 */ +export function readTransactionTypeBg(type?: string): string { + const upper = String(type ?? '').toUpperCase() + return TRANSACTION_TYPE_BG[upper] || 'rgba(144, 147, 153, 0.14)' +} + +/** 流水类型选项(筛选用,含「全部」) */ +export const TRANSACTION_TYPE_OPTIONS: Array<{ value: string; label: string }> = [ + { value: '', label: '全部' }, + { value: 'INBOUND', label: '入库' }, + { value: 'OUTBOUND', label: '出库' }, + { value: 'LOCK', label: '锁定库存' }, + { value: 'UNLOCK', label: '取消锁定' } +] + +// ── 订单类型(`order_type`)────────────────────────────────────────────── + +/** 订单类型 → 文案(与 new3 `productflow-config.ts` 的 `orderTypeConfig` 对齐) */ +export const ORDER_TYPE_TEXT: Record = { + ORDER: '订单', + ORDER_CANCEL: '取消订单', + CGRK: '采购入库', + JYCK: '交易出库', + CGTH: '采购退货', + JYTH: '交易退货', + SCRK: '生产入库', + SHRK: '收货入库', + DELIVERY_ORDER: '出库单', + RECEIVING: '收货单', + ENTRY_ORDER: '入库单', + INVENTORY: '盘点单', + RETURN: '退货单' +} + +/** 订单类型文案:未知值原样显示 */ +export function readOrderTypeText(type?: string): string { + if (!type) return '—' + return ORDER_TYPE_TEXT[type] || type +} + +/** 订单类型选项(筛选用,含「全部」) */ +export const ORDER_TYPE_OPTIONS: Array<{ value: string; label: string }> = [ + { value: '', label: '全部' }, + ...Object.entries(ORDER_TYPE_TEXT).map(([value, label]) => ({ value, label })) +] + +// ── 数量变动 ────────────────────────────────────────────────────────────── + +/** + * 变动数量(对齐 new3 `formatQuantityDelta`) + * + * 优先用后端给的 `quantity`;否则用 `after_quantity - before_quantity` 算。 + * 再按流水类型定正负:**出库 / 锁定为负,入库 / 解锁为正** + */ +export function readQuantityDelta(row: ProductFlowItem | undefined | null): number | undefined { + if (!row) return undefined + + let value: number | undefined + if (isFilled(row.quantity)) { + value = Number(row.quantity) + } else { + if (!isFilled(row.before_quantity) || !isFilled(row.after_quantity)) return undefined + value = Number(row.after_quantity) - Number(row.before_quantity) + } + if (!Number.isFinite(value)) return undefined + + const type = String(row.transaction_type || '').toUpperCase() + const abs = Math.abs(value) + return type === 'OUTBOUND' || type === 'LOCK' ? -abs : abs +} + +/** 变动数量文案:正数带 `+`,取不到显示 `—` */ +export function readQuantityText(row: ProductFlowItem | undefined | null): string { + const qty = readQuantityDelta(row) + if (qty === undefined) return '—' + return qty > 0 ? `+${qty}` : String(qty) +} + +/** 变动数量的颜色:正绿负红,0 / 取不到灰 */ +export function readQuantityColor(row: ProductFlowItem | undefined | null): string { + const qty = readQuantityDelta(row) + if (qty === undefined || qty === 0) return '#909399' + return qty > 0 ? '#19be6b' : '#fa3534' +} + +/** 「变动前 → 变动后」文案(可用库存 / 锁定库存各一行,取不到显示 `—`) */ +function readRangeText(before: unknown, after: unknown): string { + if (!isFilled(before) && !isFilled(after)) return '—' + const from = isFilled(before) ? String(before) : '—' + const to = isFilled(after) ? String(after) : '—' + return `${from} → ${to}` +} + +/** 可用库存变动:`100 → 125` */ +export function readStockRangeText(row: ProductFlowItem | undefined | null): string { + return readRangeText(row?.before_quantity, row?.after_quantity) +} + +/** 锁定库存变动:`0 → 3` */ +export function readLockRangeText(row: ProductFlowItem | undefined | null): string { + return readRangeText(row?.before_locked_quantity, row?.after_locked_quantity) +} + +// ── 时间 ────────────────────────────────────────────────────────────────── + +/** + * 流水时间文案:`YYYY-MM-DD HH:mm:ss` + * + * 与 new3 `productflow-config.ts` 的 `formatDateTime` 同口径(把 `T` 换成空格、截到秒), + * 已经是对口格式就用它;都解析不了就原样返回(不吞掉原值) + */ +export function readDateTimeText(value: unknown): string { + if (value === undefined || value === null || value === '') return '—' + const text = String(value).trim() + + // 已经是 `YYYY-MM-DD HH:mm:ss` → 原样 + if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(text)) return text + + // ISO 串(`2026-10-03T12:00:00.000Z`)→ 去掉 T 与毫秒/时区,截到秒 + if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(text)) return text.replace('T', ' ').slice(0, 19) + + return text +} + +// ── 流水时间预设(与 `api/stock/report.ts` 的区间预设同口径)────────────── + +/** 预设区间(含「全部」);默认「全部」= 不传时间条件 */ +export const PRODUCTFLOW_PERIOD_OPTIONS: Array<{ value: string; label: string }> = [ + { value: '', label: '全部' }, + { value: 'today', label: '今天' }, + { value: 'd7', label: '近 7 天' }, + { value: 'd30', label: '近 30 天' }, + { value: 'month', label: '本月' } +] + +const pad2 = (num: number): string => String(num).padStart(2, '0') + +/** 日期 → `YYYY-MM-DD HH:mm:ss`(开始取 00:00:00、结束取 23:59:59) */ +function toParam(date: Date, endOfDay = false): string { + const day = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}` + return `${day} ${endOfDay ? '23:59:59' : '00:00:00'}` +} + +function addDays(base: Date, days: number): Date { + const next = new Date(base.getTime()) + next.setDate(next.getDate() + days) + return next +} + +/** + * 预设区间 → `{ start_time, end_time }` + * + * @param key 预设标识;`''`(全部)返回 `null` = 不传时间条件 + * ⚠️ 天数**含今天**:近 7 天 = 今天往前推 6 天 + */ +export function buildPeriodRange(key: string): { start_time: string; end_time: string } | null { + if (!key) return null + + const now = new Date() + const end = toParam(now, true) + + if (key === 'today') return { start_time: toParam(now), end_time: end } + if (key === 'd7') return { start_time: toParam(addDays(now, -6)), end_time: end } + if (key === 'd30') return { start_time: toParam(addDays(now, -29)), end_time: end } + if (key === 'month') { + return { start_time: toParam(new Date(now.getFullYear(), now.getMonth(), 1)), end_time: end } + } + return null +} diff --git a/src/api/storage/entry.ts b/src/api/storage/entry.ts new file mode 100644 index 0000000..b274e36 --- /dev/null +++ b/src/api/storage/entry.ts @@ -0,0 +1,477 @@ +/** + * 入库单列表(`storage.entry.listStore`) + * + * 与 new3 Web 端 `src/views/storage/entry_owner/index.vue` **同一个接口** + * (它引的是 `@/api/storage.entry/entry` 的 `getEntryListStore`)。 + * ⚠️ 同模块另一个 `storage.entry.list` 是**仓库侧**(会多下发 `store_name` / + * `receivingBindings`),小程序是**货主侧**,与「收货单」「库存报表」保持一致。 + * + * ``` + * body = { pagination: { page, pageSize }, sort?, where: { <字段>: { operator, value, type } } } + * 返回 data = { list: [...], pagination: { total } } + * ``` + * + * ⚠️ **`where` 的条件形状是 `{ operator, value, type }`**(new3 的 ScanBox 契约, + * 见其 `normalizeToWhere()` / `applyWarehouseToWhere()`),**不是裸值** —— + * 和「外仓商品」那个 `where.keyword = 'xxx'` 的写法不一样,别混。 + * 对照:`stock.warehouse.externalList` = 裸值;`stock.report.searchStore` = 扁平值。 + * + * 小程序端展示的字段取自 new3 `entry-config.ts` 的 `entryStoreColums`(货主侧列, + * 无 `store_name` / `receivingBindings`),并按移动端取舍裁剪(去掉排序、列配置、导出、 + * 详情面板等 Web 能力),见 `pagesA/external-inventory/entry.vue`。 + * + * 筛选维度(对齐 new3 货主侧的 `availableFields`,去掉 `store_id` 货主项): + * 入库单号(like)/ 订单状态 / 入库状态 / 仓库。 + */ + +import request from '@/utils/request' +import type { BizResponse } from '@/utils/request' +import { SYSTEM_URL, gatewayParams } from '@/utils/gateway' + +/** + * 每页条数:**固定 50 条,页面不提供修改** + * + * 与「收货单」「库存报表」取同一个值(纯文本明细,单页多放一些少翻页); + * 「外仓商品」因为带图片、单页重,固定的是 20。 + */ +export const ENTRY_PAGE_SIZE = 50 + +/** 入库单列表项(只声明小程序用到的字段,其余用索引签名兜住) */ +export interface EntryItem { + id?: number + /** 入库单号 */ + entry_order_code?: string + /** 仓库名称 */ + warehouse_name?: string + /** 入库单类型:CGRK / THRK / QTRK / PDRK / SCRK / LYRK / CCRK / DBRK / B2BRK / XNRK */ + order_type?: string + /** 单据编号(外部/采购单号) */ + purchase_order_code?: string + /** 商品种类数 */ + total_order_lines?: number + /** 应收总数(计划数量) */ + total_quantity?: number + /** 实收总数(已完成数量) */ + received_quantity?: number + /** 订单状态:CREATED / PENDING / PARTIAL / PARTIAL_RECEIVED / COMPLETED / CANCELLED */ + order_status?: string + /** 收货绑定:true = 已绑定收货单 / false = 未绑定(new3 侧算出来的虚拟字段) */ + hasReceiving?: boolean + /** 入库(同步)状态:PENDING / SYNCING / SUCCESS / FAIL / FAILED */ + sync_status?: string + /** 同步信息(失败原因等) */ + sync_message?: string + /** 数据来源:QM 奇门 / API 接口 / WMS 系统 */ + source_type?: string + /** 供应商编码 / 名称 */ + supplier_code?: string + supplier_name?: string + /** 运单号 / 物流公司 */ + express_code?: string + logistics_code?: string + logistics_name?: string + /** 单据创建时间(后端原值) */ + order_create_time?: string + /** 预计开始 / 结束时间 */ + expect_start_time?: string + expect_end_time?: string + /** 创建 / 更新时间 */ + created_at?: string + updated_at?: string + /** 备注 */ + remark?: string + [key: string]: any +} + +/** 列表响应体 `data` */ +export interface EntryPayload { + list?: EntryItem[] + total?: number + pagination?: { page?: number; pageSize?: number; total?: number } + [key: string]: any +} + +/** 查询条件(页面传入) */ +export interface EntryQuery { + page?: number + pageSize?: number + /** 入库单号(模糊搜索),空字符串表示不过滤 */ + keyword?: string + /** 订单状态,空字符串表示全部 */ + order_status?: string + /** 入库(同步)状态,空字符串表示全部 */ + sync_status?: string + /** 仓库 id,空字符串表示全部 */ + warehouse_id?: number | string +} + +function isFilled(value: unknown): boolean { + return value !== undefined && value !== null && value !== '' +} + +/** `where` 条件统一为 `{ operator, value, type }`(后端契约,见文件头说明) */ +const eqText = (value: unknown) => ({ operator: 'eq', value, type: 'text' }) +const eqNumber = (value: unknown) => ({ operator: 'eq', value, type: 'number' }) +const likeText = (value: unknown) => ({ operator: 'like', value, type: 'text' }) + +/** + * 组装请求体(条件字段/操作符要调整时改这里) + * + * 与 new3 `normalizeToWhere()` + `applyWarehouseToWhere()` 的输出对齐: + * 文本条件 `type: 'text'`、仓库 `type: 'number'`。 + */ +function buildBody(query: EntryQuery): Record { + const { page = 1, pageSize = ENTRY_PAGE_SIZE, keyword, order_status, sync_status, warehouse_id } = + query + + const where: Record = {} + // 入库单号模糊搜索:new3 的字段配置里 `entry_order_code` 走 like + if (keyword && String(keyword).trim()) where.entry_order_code = likeText(String(keyword).trim()) + if (isFilled(order_status)) where.order_status = eqText(order_status) + if (isFilled(sync_status)) where.sync_status = eqText(sync_status) + if (isFilled(warehouse_id)) { + const num = Number(warehouse_id) + where.warehouse_id = eqNumber(Number.isFinite(num) ? num : warehouse_id) + } + + return { + pagination: { page, pageSize }, + where + } +} + +/** 入库单列表(分页,货主侧) */ +export function fetchStoreEntryList(query: EntryQuery = {}): Promise> { + return request({ + url: SYSTEM_URL, + method: 'POST', + params: gatewayParams('storage.entry.listStore'), + data: buildBody(query), + // 需要登录:未登录时不发请求,直接弹登录抽屉 + auth: true + }) +} + +/** 总数:后端放在 `pagination.total`(也可能在顶层 `total`) */ +export function readTotal(payload: EntryPayload | undefined | null): number { + const total = payload?.pagination?.total ?? payload?.total ?? 0 + const num = Number(total) + return Number.isFinite(num) && num > 0 ? num : 0 +} + +// ── 订单状态(`order_status`)────────────────────────────────────────────── + +/** 订单状态 → 文案(与 new3 `entry-config.ts` 的 `entryOrderStatusOptions` 对齐) + * + * ⚠️ 多一个 `CREATING`(创建中):new3 的选项表里没有,但 `wms_entry_order.order_status` + * 的 enum 里确实有(enum: CREATING/CREATED/PENDING/COMPLETED/CANCELLED) + */ +export const ENTRY_ORDER_STATUS_TEXT: Record = { + CREATING: '创建中', + CREATED: '已创建', + PENDING: '待入库', + PARTIAL: '入库中', + PARTIAL_RECEIVED: '部分收货', + COMPLETED: '已完成', + CANCELLED: '已作废' +} + +/** 订单状态 → 主题色(小程序没有 el-tag,用文字色区分) */ +export const ENTRY_ORDER_STATUS_COLOR: Record = { + CREATING: '#909399', // info + CREATED: '#909399', // info + PENDING: '#ff9900', // warning + PARTIAL: '#2979ff', // primary + PARTIAL_RECEIVED: '#2979ff', // primary + COMPLETED: '#19be6b', // success + CANCELLED: '#fa3534' // danger +} + +/** 状态文案:未知状态原样显示(后端加了新状态也不会显示成空白) */ +export function readStatusText(status?: string): string { + if (!status) return '—' + return ENTRY_ORDER_STATUS_TEXT[String(status).toUpperCase()] || status +} + +/** 状态颜色 */ +export function readStatusColor(status?: string): string { + if (!status) return '#909399' + return ENTRY_ORDER_STATUS_COLOR[String(status).toUpperCase()] || '#909399' +} + +/** 状态选项(筛选用,含「全部」) */ +export const ENTRY_ORDER_STATUS_OPTIONS: Array<{ value: string; label: string }> = [ + { value: '', label: '全部' }, + { value: 'CREATING', label: '创建中' }, + { value: 'CREATED', label: '已创建' }, + { value: 'PENDING', label: '待入库' }, + { value: 'PARTIAL', label: '入库中' }, + { value: 'PARTIAL_RECEIVED', label: '部分收货' }, + { value: 'COMPLETED', label: '已完成' }, + { value: 'CANCELLED', label: '已作废' } +] + +// ── 入库单类型(`order_type`)───────────────────────────────────────────── + +/** 入库单类型 → 文案(与 new3 `availableFields` 的 `order_type` 选项对齐) + * + * ⚠️ 表 enum(`wms_entry_order.order_type`)= SCRK/LYRK/CCRK/CGRK/DBRK/QTRK/B2BRK/XNRK/SHRK; + * 比 new3 选项表多一个 `SHRK`(收货入库,取自 new3 `storage/log-config.ts`), + * 少 new3 里没实际使用的 `PDRK` / `THRK`(保留兼容,未知值会原样显示) + */ +export const ENTRY_ORDER_TYPE_TEXT: Record = { + CGRK: '采购入库', + THRK: '退货入库', + SHRK: '收货入库', + QTRK: '其他入库', + PDRK: '盘点入库', + SCRK: '生产入库', + LYRK: '领用入库', + CCRK: '拆解入库', + DBRK: '调拨入库', + B2BRK: 'B2B入库', + XNRK: '虚拟入库' +} + +/** 入库类型文案:未知值原样显示 */ +export function readOrderTypeText(type?: string): string { + if (!type) return '—' + return ENTRY_ORDER_TYPE_TEXT[type] || type +} + +// ── 数据来源(`source_type`)────────────────────────────────────────────── + +/** 数据来源 → 文案(与 new3 `availableFields` 的 `source_type` 选项对齐) */ +export const ENTRY_SOURCE_TYPE_TEXT: Record = { + QM: '奇门', + API: '接口', + WMS: '系统' +} + +/** 数据来源 → 主题色(对齐 new3 列表模板:QM warning / WMS primary / 其它 success) */ +export const ENTRY_SOURCE_TYPE_COLOR: Record = { + QM: '#ff9900', + WMS: '#2979ff', + API: '#19be6b' +} + +/** 数据来源文案:未知值原样显示 */ +export function readSourceTypeText(type?: string): string { + if (!type) return '—' + return ENTRY_SOURCE_TYPE_TEXT[type] || type +} + +/** 数据来源颜色 */ +export function readSourceTypeColor(type?: string): string { + if (!type) return '#909399' + return ENTRY_SOURCE_TYPE_COLOR[type] || '#19be6b' +} + +// ── 入库(同步)状态(`sync_status`)────────────────────────────────────── + +/** 入库状态 → 文案(与 new3 `availableFields` 的 `sync_status` 选项对齐) */ +export const ENTRY_SYNC_STATUS_TEXT: Record = { + PENDING: '待推送', + SYNCING: '推送中', + SUCCESS: '成功', + FAIL: '失败', + FAILED: '失败' +} + +/** 入库状态 → 主题色(对齐 new3 `getSyncStatusType`) */ +export const ENTRY_SYNC_STATUS_COLOR: Record = { + PENDING: '#909399', // info + SYNCING: '#2979ff', // primary + SUCCESS: '#19be6b', // success + FAIL: '#fa3534', // danger + FAILED: '#fa3534' // danger +} + +/** 入库状态文案:未知值原样显示 */ +export function readSyncStatusText(status?: string): string { + if (!status) return '—' + const upper = String(status).toUpperCase() + return ENTRY_SYNC_STATUS_TEXT[upper] || status +} + +/** 入库状态颜色 */ +export function readSyncStatusColor(status?: string): string { + if (!status) return '#909399' + const upper = String(status).toUpperCase() + return ENTRY_SYNC_STATUS_COLOR[upper] || '#909399' +} + +/** 入库状态选项(筛选用,含「全部」) */ +export const ENTRY_SYNC_STATUS_OPTIONS: Array<{ value: string; label: string }> = [ + { value: '', label: '全部' }, + { value: 'PENDING', label: '待推送' }, + { value: 'SYNCING', label: '推送中' }, + { value: 'SUCCESS', label: '成功' }, + { value: 'FAIL', label: '失败' } +] + +// ── 收货绑定(`hasReceiving`)───────────────────────────────────────────── + +/** 收货绑定文案(对齐 new3 列表模板:「已绑定」success / 「未绑定」info) */ +export function readReceivingBindText(hasReceiving?: boolean): string { + return hasReceiving ? '已绑定' : '未绑定' +} + +/** 收货绑定颜色 */ +export function readReceivingBindColor(hasReceiving?: boolean): string { + return hasReceiving ? '#19be6b' : '#909399' +} + +// ── 展示文本 ────────────────────────────────────────────────────────────── + +/** + * 数量概览文案:`3 种 · 应收 120 / 实收 100 件` + * + * 缺失的字段直接省略(不显示 `0`,避免把「后端没给」误读成「没有货」); + * 应收与实收都有时才并列展示 + */ +export function readQuantityText(item: EntryItem | undefined | null): string { + const parts: string[] = [] + if (isFilled(item?.total_order_lines)) parts.push(`${Number(item?.total_order_lines)} 种`) + + const hasPlan = isFilled(item?.total_quantity) + const hasDone = isFilled(item?.received_quantity) + if (hasPlan && hasDone) parts.push(`应收 ${Number(item?.total_quantity)} / 实收 ${Number(item?.received_quantity)} 件`) + else if (hasPlan) parts.push(`应收 ${Number(item?.total_quantity)} 件`) + else if (hasDone) parts.push(`实收 ${Number(item?.received_quantity)} 件`) + + return parts.length ? parts.join(' · ') : '—' +} + +/** + * 时间文案:统一为 `YYYY-MM-DD HH:mm:ss` + * + * new3 侧用 `formatTime()` 现算(`order_create_time` 是 `datetime`,网关可能下发 + * ISO 串或 `YYYY-MM-DD HH:mm:ss`)。已经是对口格式就直接用,避免时区/解析差异改坏原值 + */ +export function readDateTimeText(value: unknown): string { + if (value === undefined || value === null || value === '') return '—' + const text = String(value).trim() + + // 已经是 `YYYY-MM-DD HH:mm:ss`(后端原值)→ 原样返回 + if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(text)) return text + + const date = new Date(text) + if (Number.isNaN(date.getTime())) return text + + const pad = (num: number): string => String(num).padStart(2, '0') + return ( + `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` + + `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}` + ) +} + +// ── 单张入库单详情(`storage.entry.getStore`,货主侧)────────────────────── + +/** + * 入库明细行 + * + * 后端返回的是**嵌套结构**(`items[].stock.{item_code,item_name,sku_property,barcodes[],quantity}`), + * 这里拍平成展示字段 —— 映射规则与 new3 `views/storage/entry/component/entrydetail.vue` + * 的 `loadEntryDetail()` **完全一致**(含 `planned ?? count`、`completed ?? received_quantity` 兜底)。 + */ +export interface EntryDetailItem { + id?: number + /** SKU(`item.stock_id ?? item.stock.id`) */ + stock_id?: number + /** 商品编码(`item.stock.item_code`) */ + warehouse_item_code?: string + /** 商品名称(`item.stock.item_name`) */ + warehouse_item_name?: string + /** 规格(`item.stock.sku_property`) */ + warehouse_item_spec?: string + /** 主条码(`item.stock.barcodes[0].barcode`) */ + barcode?: string + /** 应收数量(`item.planned ?? item.count`) */ + count?: number + /** 实收数量(`item.completed ?? item.received_quantity`) */ + received_quantity?: number + /** 库存数量(`item.stock.quantity`,可能为 null) */ + warehouse_quantity?: number | null + [key: string]: any +} + +/** 详情响应体 `data`;`entryOrder` 也可能直接在**顶层**(与 `wechat.getMyLoginCode` 同类容错) */ +export interface EntryDetailPayload { + entryOrder?: Record + items?: any[] + total_quantity?: number + received_quantity?: number + [key: string]: any +} + +/** + * 单张入库单详情(**货主侧**) + * + * 与 new3 `views/storage/entry/component/entrydetail.vue` 在 `store-mode` 下调用的是同一个方法 + * (仓库侧是 `storage.entry.get`,⚠️ 别混)。入参就一个 `id`。 + */ +export function fetchStoreEntryDetail( + id: number | string +): Promise> { + return request({ + url: SYSTEM_URL, + method: 'POST', + params: gatewayParams('storage.entry.getStore'), + data: { id: Number(id) }, + // 需要登录:未登录时不发请求,直接弹登录抽屉 + auth: true + }) +} + +/** 单头:优先 `data.entryOrder`,兼容顶层 `entryOrder` */ +export function readEntryOrder( + payload: EntryDetailPayload | undefined | null +): Record { + return payload?.entryOrder || {} +} + +/** + * 取原始明细数组 + * + * `data.items` 是 new3 读取的路径(权威);`data.entryOrder.items` 作为兜底, + * 防止后端把 items 挪进 entryOrder(`items: []` 且 entryOrder 里有时也要能取到) + */ +function pickRawItems(payload: EntryDetailPayload | undefined | null): any[] { + const topLevel = payload?.items + if (Array.isArray(topLevel) && topLevel.length) return topLevel + + const nested = payload?.entryOrder?.items + if (Array.isArray(nested)) return nested + + return Array.isArray(topLevel) ? topLevel : [] +} + +/** + * 入库明细:拍平 `items[].stock.*`(映射规则见 `EntryDetailItem` 注释) + * + * 取值优先级:`data.items`(new3 读取的路径,权威)→ `data.entryOrder.items`(兜底,防后端换位)。 + * ⚠️ 注意 `items: []` 时也要走兜底 —— 不能因为顶层是空数组就判定「没有明细」 + */ +export function normalizeEntryDetailItems( + payload: EntryDetailPayload | undefined | null +): EntryDetailItem[] { + return pickRawItems(payload).map((raw: any) => { + const stock = raw?.stock || {} + const barcodes = Array.isArray(stock.barcodes) ? stock.barcodes : [] + const planned = raw?.planned ?? raw?.count + const completed = raw?.completed ?? raw?.received_quantity + + return { + ...raw, + stock_id: raw?.stock_id ?? stock.id, + warehouse_item_code: stock.item_code || '', + warehouse_item_name: stock.item_name || '', + warehouse_item_spec: stock.sku_property || '', + barcode: barcodes.length ? barcodes[0]?.barcode || '' : '', + count: Number(planned) || 0, + received_quantity: Number(completed) || 0, + warehouse_quantity: stock.quantity ?? null + } + }) +} diff --git a/src/components/entry-detail-popup/entry-detail-popup.vue b/src/components/entry-detail-popup/entry-detail-popup.vue new file mode 100644 index 0000000..a3843f0 --- /dev/null +++ b/src/components/entry-detail-popup/entry-detail-popup.vue @@ -0,0 +1,392 @@ + + + + + diff --git a/src/pages.json b/src/pages.json index 7fade26..1a020cb 100644 --- a/src/pages.json +++ b/src/pages.json @@ -87,6 +87,24 @@ "backgroundTextStyle": "dark", "onReachBottomDistance": 80 } + }, + { + "path": "external-inventory/entry", + "style": { + "navigationBarTitleText": "入库单", + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark", + "onReachBottomDistance": 80 + } + }, + { + "path": "external-inventory/productflow", + "style": { + "navigationBarTitleText": "商品流水", + "enablePullDownRefresh": true, + "backgroundTextStyle": "dark", + "onReachBottomDistance": 80 + } } ] } diff --git a/src/pagesA/external-inventory/entry.vue b/src/pagesA/external-inventory/entry.vue new file mode 100644 index 0000000..e09973f --- /dev/null +++ b/src/pagesA/external-inventory/entry.vue @@ -0,0 +1,638 @@ + + + + + diff --git a/src/pagesA/external-inventory/productflow.vue b/src/pagesA/external-inventory/productflow.vue new file mode 100644 index 0000000..6caa869 --- /dev/null +++ b/src/pagesA/external-inventory/productflow.vue @@ -0,0 +1,673 @@ + + + + + diff --git a/src/router/pages.ts b/src/router/pages.ts index c4e1013..f80c7c7 100644 --- a/src/router/pages.ts +++ b/src/router/pages.ts @@ -168,6 +168,27 @@ export const PAGE_REGISTRY: PageMeta[] = [ auth: 'required' // 对应后端 id=637(父节点 632「外仓库存」分类,sort=1 排在「收货单」之后) // 接口 stock.report.searchStore(**货主侧**),见 api/stock/report.ts + }, + { + key: '/external-inventory/entry', + path: 'pagesA/external-inventory/entry', + title: '入库单', + // 本地兜底图标;后端 id=638 下发的也是 order(uview 图标表里存在同名图标) + icon: 'order', + auth: 'required' + // 对应后端 id=638(父节点 632「外仓库存」分类,sort=2 排在「库存报表」之后) + // 接口 storage.entry.listStore(**货主侧**,与 new3 views/storage/entry_owner 同源),见 api/storage/entry.ts + }, + { + key: '/external-inventory/productflow', + path: 'pagesA/external-inventory/productflow', + title: '商品流水', + // 本地兜底图标;后端 id=639 下发的是 list-dot(uview 图标表里存在同名图标) + icon: 'list-dot', + auth: 'required' + // 对应后端 id=639(父节点 632「外仓库存」分类,sort=3 排在「入库单」之后) + // 接口 stock.transaction.storeList(**货主侧**,与 new3 views/storage/productflow/store 同源), + // 见 api/stock/productflow.ts } // ─────────────── 待启用(页面文件就绪后再登记)───────────────