import { scanWorkflowField } from '@/views/order/orderManagement/config/order-common-config' /** ScanBox 基础信息分组(对齐收货/待处理订单排版) */ export const ENTRY_SCAN_BASIC_INFO_GROUP = '基础信息' /** ScanBox 时间分组 */ export const ENTRY_SCAN_TIME_GROUP = '时间' /** 为入库 ScanBox 基础信息字段附加分组标签 */ export type EntryScanFieldConfig = Record & { group: string value: string label: string type?: string options?: Array<{ label: string; value: unknown }> } export function entryScanBasicField(field: Record): EntryScanFieldConfig { return { ...field, group: ENTRY_SCAN_BASIC_INFO_GROUP } as EntryScanFieldConfig } export function entryScanTimeField(field: Record): EntryScanFieldConfig { return { ...field, group: ENTRY_SCAN_TIME_GROUP } as EntryScanFieldConfig } /** ScanBox 默认 props(与波次模块 scan-box 侧栏一致) */ export const entryScanBoxConfig = { width: '250px', treeProps: { children: 'children', label: 'label' } as const, autoSubmit: false } /** 入库单 order_status 枚举(与 storage.entry.list 及列表 tag 样式一致) */ export const entryOrderStatusOptions = [ { label: '已创建', value: 'CREATED' }, { label: '待入库', value: 'PENDING' }, { label: '入库中', value: 'PARTIAL' }, { label: '部分收货', value: 'PARTIAL_RECEIVED' }, { label: '已完成', value: 'COMPLETED' }, { label: '已作废', value: 'CANCELLED' } ] as const const entryOrderStatusLabelMap: Record = { ...Object.fromEntries(entryOrderStatusOptions.map((item) => [item.value, item.label])), 待入库: '待入库', 已完成: '已完成', 已创建: '已创建' } export function formatEntryOrderStatus(status: unknown): string { if (status === null || status === undefined || status === '') return '--' const normalized = String(status).trim() const upper = normalized.toUpperCase() const fromEnum = entryOrderStatusOptions.find( (item) => item.value === upper || item.value === normalized ) if (fromEnum) return fromEnum.label if (entryOrderStatusLabelMap[normalized]) return entryOrderStatusLabelMap[normalized] return normalized } export function getEntryOrderStatusTagType(status: unknown): string | undefined { const upper = String(status ?? '').trim().toUpperCase() const map: Record = { CREATED: 'info', PENDING: 'warning', PARTIAL: 'primary', PARTIAL_RECEIVED: 'primary', COMPLETED: 'success', CANCELLED: 'danger' } return map[upper] } export function translateEntryField(fieldValue: string, value: unknown): string { if (fieldValue === 'order_status') { return formatEntryOrderStatus(value) } if (value === null || value === undefined || value === '') return '--' const field = availableFields.find((f: any) => f.value === fieldValue) if (!field?.options) return String(value) const normalized = String(value).trim() const option = field.options.find((opt: any) => { if (opt.value === value) return true return String(opt.value).toUpperCase() === normalized.toUpperCase() }) return option ? option.label : normalized } export const availableFields: EntryScanFieldConfig[] = [ entryScanBasicField({ label: '入库单号', value: 'entry_order_code', type: 'text', placeholder: '请输入入库单号', }), entryScanBasicField({ label: '货主', value: 'store_id', type: 'select', multiple: true, options: [] }), entryScanBasicField({ label: '入库单类型', value: 'order_type', type: 'select', options: [ { label: '采购入库', value: 'CGRK' }, { label: '退货入库', value: 'THRK' }, { label: '其他入库', value: 'QTRK' }, { label: '盘点入库', value: 'PDRK' }, { label: '生产入库', value: 'SCRK' }, { label: '领用入库', value: 'LYRK' }, { label: '拆解入库', value: 'CCRK' }, { label: '调拨入库', value: 'DBRK' }, { label: 'B2B入库', value: 'B2BRK' }, { label: '虚拟入库', value: 'XNRK' }, ] }), entryScanBasicField({ label: '数据来源', value: 'source_type', type: 'select', options: [ { label: '奇门', value: 'QM' }, { label: '接口', value: 'API' }, { label: '系统', value: 'WMS' }, ] }), entryScanBasicField({ label: '费用是否记录', value: 'expense_record', type: 'select', options: [ { label: '是', value: true }, { label: '否', value: false }, ] }), entryScanBasicField({ label: '批次', value: 'batch', type: 'text' }), entryScanBasicField({ label: '编号', value: 'number', type: 'text' }), entryScanBasicField({ label: '备注', value: 'remark', type: 'text' }), entryScanBasicField({ label: 'ERP备注', value: 'erp_remark', type: 'text' }), entryScanBasicField({ label: '操作员ID', value: 'operator_id', type: 'text' }), // 流程/状态(每项独立分组,对齐收货/待处理订单 scanWorkflowField 排版) scanWorkflowField({ label: '状态', value: 'order_status', type: 'select', options: [...entryOrderStatusOptions] }) as EntryScanFieldConfig, scanWorkflowField({ label: '入库状态', value: 'sync_status', type: 'select', options: [ { label: '待推送', value: 'PENDING' }, { label: '推送中', value: 'SYNCING' }, { label: '成功', value: 'SUCCESS' }, { label: '失败', value: 'FAIL' }, { label: '失败', value: 'FAILED' }, ] }) as EntryScanFieldConfig, scanWorkflowField({ label: '收货绑定', value: 'hasReceiving', type: 'select', options: [ { label: '已绑定', value: true }, { label: '未绑定', value: false }, ] }) as EntryScanFieldConfig, // ── 时间 ── entryScanTimeField({ label: '创建时间', value: 'order_create_time', type: 'datetimerange', startPlaceholder: '开始时间', endPlaceholder: '结束时间' }), entryScanTimeField({ label: '预计开始时间', value: 'expect_start_time', type: 'datetimerange', startPlaceholder: '开始时间', endPlaceholder: '结束时间' }), entryScanTimeField({ label: '预计结束时间', value: 'expect_end_time', type: 'datetimerange', startPlaceholder: '开始时间', endPlaceholder: '结束时间' }), ] export const entryColums = [ { prop: 'id',label:'ID',width:'50' }, { prop: 'entry_order_code',label:'入库单号',width:'160',}, { prop: 'store_name',label:'货主',width:'140', }, { prop: 'order_type',label:'类型',width:'160' }, { prop: 'purchase_order_code',label:'单据编号 ',width:'160' }, { prop: 'total_order_lines',label:'商品数',width:'160', sortable: 'custom' }, { prop: 'order_status',label:'订单状态',width:'160' }, { prop: 'hasReceiving', label: '收货绑定', width: '100' }, { prop: 'receivingBindings', label: '绑定收货单', minWidth: '180' }, { prop: 'sync_status',label:'入库状态',width:'160' }, { prop: 'sync_message', label: '同步信息', minWidth: '220' }, { prop: 'supplier_code',label:'供应商编码',width:'160' }, { prop: 'supplier_name',label:'供应商名称',width:'160' }, // { prop: '',label:'',width:'160' }, { prop: 'express_code',label:'运单号',width:'160' }, { prop: 'logistics_code',label:'物流公司编码',width:'160' }, { prop: 'logistics_name',label:'物流公司名称',width:'160' }, // { prop: '',label:'',width:'160',fixed: 'left' }, // { prop: '',label:'',width:'160',fixed: 'left' }, { prop: 'order_create_time',label:'单据创建时间',width:'160' }, { prop: 'expect_start_time',label:'预计开始时间',width:'160' }, { prop: 'expect_end_time',label:'预计结束时间',width:'160' }, // { prop: '',label:'',width:'160',fixed: 'left' }, { prop: 'source_type',label:'数据来源',width:'160' }, { prop: 'remark',label:'备注',width:'160' }, // { prop: '',label:'',width:'160',fixed: 'left' }, // { prop: '',label:'',width:'160',fixed: 'left' }, { prop: 'row_action', label: '操作', width: '300', fixed: 'right' }, ] /** 货主侧入库单列表列(listStore 返回字段,无 store_name / receivingBindings) */ export const entryStoreColums = [ { prop: 'id', label: 'ID', width: '50' }, { prop: 'entry_order_code', label: '入库单号', width: '160' }, { prop: 'order_type', label: '类型', width: '100' }, { prop: 'purchase_order_code', label: '单据编号', width: '160' }, { prop: 'total_order_lines', label: '商品数', width: '80', sortable: 'custom' }, { prop: 'order_status', label: '订单状态', width: '100' }, { prop: 'hasReceiving', label: '收货绑定', width: '100' }, { prop: 'sync_status', label: '入库状态', width: '100' }, { prop: 'sync_message', label: '同步信息', minWidth: '220' }, { prop: 'supplier_code', label: '供应商编码', width: '120' }, { prop: 'supplier_name', label: '供应商名称', width: '140' }, { prop: 'express_code', label: '运单号', width: '140' }, { prop: 'logistics_code', label: '物流公司编码', width: '140' }, { prop: 'logistics_name', label: '物流公司名称', width: '140' }, { prop: 'order_create_time', label: '单据创建时间', width: '160' }, { prop: 'expect_start_time', label: '预计开始时间', width: '160' }, { prop: 'expect_end_time', label: '预计结束时间', width: '160' }, { prop: 'source_type', label: '数据来源', width: '100' }, { prop: 'remark', label: '备注', width: '160' }, ] const entryInventoryTypeLabelMap: Record = { ZP: '正品', CC: '次品', JS: '机损', XS: '箱损', ZT: '在途', DJ: '冻结', FP: '分配', } function formatEntryInventoryType(_row: any, _col: any, value: unknown) { if (value === null || value === undefined || value === '') return '--' const key = String(value) return entryInventoryTypeLabelMap[key] || key } /** 入库单是否为待入库状态(支持枚举值与中文文案) */ export function isPendingEntryOrderStatus(status: unknown): boolean { if (status === null || status === undefined || status === '') return false const normalized = String(status).trim() const upper = normalized.toUpperCase() return upper === 'PENDING' || upper === 'CREATED' || normalized === '待入库' || normalized === '已创建' } /** 是否允许快捷直入(storage.entry.quickInbound,仅 CREATED 且未绑定收货单) */ export function canQuickInbound(status: unknown, hasReceiving?: unknown, receivingBindings?: unknown): boolean { if (status === null || status === undefined || status === '') return false const normalized = String(status).trim() const upper = normalized.toUpperCase() if (upper !== 'CREATED' && normalized !== '已创建') return false // 已绑定收货单的排除虚拟直入 if (hasReceiving === true) return false if (Array.isArray(receivingBindings) && receivingBindings.length > 0) return false return true } /** 快捷直入表单只读字段(对应接口入参 id 及展示用单据信息) */ export const quickInboundFormFields = [ { label: '入库单ID', prop: 'id', disabled: true }, { label: '入库单号', prop: 'entry_order_code', disabled: true }, { label: '货主', prop: 'store_name', disabled: true }, { label: '入库类型', prop: 'order_type', type: 'select' as const, disabled: true }, { label: '订单状态', prop: 'order_status', type: 'select' as const, disabled: true }, { label: '商品种类', prop: 'total_order_lines', disabled: true }, { label: '数据来源', prop: 'source_type', type: 'select' as const, disabled: true }, { label: '备注', prop: 'remark', disabled: true, span: 24 }, ] /** 快捷直入明细预览列(按明细数量一键直入虚拟库位) */ export const quickInboundPreviewColumns = [ { prop: 'order_line_no', label: '行号', width: '70', align: 'center' }, { prop: 'warehouse_item_code', label: '商品编码', width: '140' }, { prop: 'warehouse_item_name', label: '商品名称', minWidth: '160' }, { prop: 'stock_id', label: 'SKU', width: '90' }, { prop: 'count', label: '直入数量', width: '100', align: 'right' }, ] export const entrydetail = [ { prop: 'entry_order_code', label: '入库单号', width: '180', fixed: 'left' }, { prop: 'store_name', label: '货主', width: '140' }, { prop: 'warehouse_item_code', label: '商品编码', width: '160' }, { prop: 'warehouse_item_name', label: '商品名称', minWidth: '200' }, { prop: 'stock_id', label: 'SKU', width: '100' }, { prop: 'barcode', label: '条码', width: '150' }, { prop: 'warehouse_item_spec', label: '规格', width: '140' }, { prop: 'stock_unit', label: '单位', width: '80' }, { prop: 'count', label: '应收数量', width: '100', align: 'right' }, { prop: 'received_quantity', label: '实收数量', width: '100', align: 'right' }, { prop: 'warehouse_quantity', label: '库存数量', width: '100', align: 'right' }, { prop: 'is_batch_mgmt', label: '批次管理', width: '100', align: 'center' }, { prop: 'is_shelf_life_mgmt', label: '效期管理', width: '100', align: 'center' }, ] export const detailpanel = [ { label: '入库单号', prop: 'entry_order_code', disabled: true }, { label: '货主名称', prop: 'store_name', disabled: true }, { label: '订单状态', prop: 'order_status', type: 'select' }, { label: '入库类型', prop: 'order_type', type: 'select' }, { label: '单据编号', prop: 'purchase_order_code' }, { label: '同步状态', prop: 'sync_status', type: 'select' }, { label: '供应商编码', prop: 'supplier_code' }, { label: '供应商名称', prop: 'supplier_name' }, { label: '运单号', prop: 'express_code' }, { label: '物流公司', prop: 'logistics_name' }, { label: '备注', prop: 'remark' } ] export const directInboundInboundTypeOptions = [ { label: '导入入库', value: 'import' }, { label: 'PDA入库', value: 'pda' }, ] as const export function formatDirectInboundType(value: unknown): string { if (value === null || value === undefined || value === '') return '--' const normalized = String(value).trim().toLowerCase() const option = directInboundInboundTypeOptions.find((item) => item.value === normalized) return option?.label ?? String(value) } /** 是否允许导入/PDA 入库操作(未完成、未作废) */ export function canDirectInboundOperate(status: unknown): boolean { if (status === null || status === undefined || status === '') return false const upper = String(status).trim().toUpperCase() return !['COMPLETED', 'CANCELLED'].includes(upper) && upper !== '已完成' && upper !== '已作废' } /** 是否允许绑定收货(仅 CREATED / 已创建 状态可操作) */ export function canBindEntryOrder(status: unknown): boolean { if (status === null || status === undefined || status === '') return false const normalized = String(status).trim() const upper = normalized.toUpperCase() return upper === 'CREATED' || normalized === '已创建' } /** 是否允许开始入库(状态为 CREATED 且已绑定收货单) */ export function canStartReceiving(status: unknown, hasReceiving: unknown, receivingBindings: unknown): boolean { if (status === null || status === undefined) return false const upper = String(status).trim().toUpperCase() if (upper !== 'CREATED') return false // hasReceiving 为 true 或 receivingBindings 数组非空表示已绑定收货单 if (hasReceiving === true) return true if (Array.isArray(receivingBindings) && receivingBindings.length > 0) return true return false } /** storage.entry.list 虚拟 where 字段(需原样传 boolean,不能包 operator) */ export const entryListVirtualWhereFields = ['hasReceiving'] as const export function parseEntryListVirtualBoolean(value: unknown): boolean | undefined { if (value === true || value === false) return value if (value === 'true' || value === 1 || value === '1') return true if (value === 'false' || value === 0 || value === '0') return false if (value && typeof value === 'object' && 'value' in (value as object)) { return parseEntryListVirtualBoolean((value as { value: unknown }).value) } return undefined } export function finalizeEntryListWhere(where: Record): Record { const result = { ...where } entryListVirtualWhereFields.forEach((key) => { if (!(key in result)) return const parsed = parseEntryListVirtualBoolean(result[key]) if (parsed === undefined) { delete result[key] } else { result[key] = parsed } }) return result } export function resolveEntryHasReceiving(row: { hasReceiving?: boolean receivingBindings?: unknown }): boolean { if (typeof row.hasReceiving === 'boolean') return row.hasReceiving return Array.isArray(row.receivingBindings) && row.receivingBindings.length > 0 } export function formatEntryHasReceiving( value: unknown, row?: { hasReceiving?: boolean; receivingBindings?: unknown } ): string { if (typeof value === 'boolean') return value ? '已绑定' : '未绑定' if (row) return resolveEntryHasReceiving(row) ? '已绑定' : '未绑定' return '未绑定' } export function getEntryHasReceivingTagType( value: unknown, row?: { hasReceiving?: boolean; receivingBindings?: unknown } ): string { const hasBound = typeof value === 'boolean' ? value : row ? resolveEntryHasReceiving(row) : false return hasBound ? 'success' : 'info' } export function formatReceivingBindingsSummary(bindings: unknown): string { if (!Array.isArray(bindings) || !bindings.length) return '—' const numbers = bindings .map((item) => { const binding = item as Record const receiving = (binding.receiving ?? {}) as Record const number = receiving.receiving_number ?? binding.receiving_number return number ? String(number) : '' }) .filter(Boolean) if (!numbers.length) return '—' if (numbers.length <= 2) return numbers.join('、') return `${numbers.slice(0, 2).join('、')} 等 ${numbers.length} 个` } function normalizeEntryDetailPayload(res: Record | null | undefined) { const entryOrder = (res?.entryOrder ?? (res?.data as Record | undefined)?.entryOrder) as | Record | null | undefined const dataItems = (res?.data as Record | undefined)?.items const items = Array.isArray(dataItems) ? dataItems : Array.isArray(entryOrder?.items) ? entryOrder.items : [] return { entryOrder: entryOrder ?? null, items } } function mapEntryPrintDetailItem( item: Record, idx: number, entryOrder: Record | null ): Record { const stock = (item.stock ?? {}) as Record const barcodes = Array.isArray(stock.barcodes) ? stock.barcodes : [] const firstBarcode = (barcodes[0] as Record | undefined)?.barcode const warehouse_item_code = String(stock.item_code ?? item.warehouse_item_code ?? item.external_item_code ?? '') const warehouse_item_name = String(stock.item_name ?? item.warehouse_item_name ?? item.product_name ?? '') const warehouse_item_spec = String(stock.sku_property ?? item.warehouse_item_spec ?? '') const count = Number(item.planned ?? item.count ?? 0) const received_quantity = Number(item.completed ?? item.received_quantity ?? 0) const barcode = String(item.barcode ?? firstBarcode ?? '') return { ...item, ...stock, seq_no: idx + 1, order_line_no: item.order_line_no ?? idx + 1, stock_id: item.stock_id ?? stock.id, warehouse_item_code, warehouse_item_name, warehouse_item_spec, item_code: warehouse_item_code, product_code: warehouse_item_code, product_name: warehouse_item_name, barcode, count, planned: count, received_quantity, completed: received_quantity, actual_quantity: received_quantity, confirm_quantity: item.confirm_quantity ?? '', external_item_code: item.external_item_code ?? '', inventory_type: item.inventory_type != null && item.inventory_type !== '' ? formatEntryInventoryType(null, null, item.inventory_type) : '', entry_order_code: entryOrder?.entry_order_code ?? '', purchase_order_code: entryOrder?.purchase_order_code ?? '', store_name: entryOrder?.store_remask ?? entryOrder?.store_name ?? '', } } /** 将 storage.entry.get 响应组装为入库单打印模板可用数据 */ export function buildEntryPrintFormData( res: Record | null | undefined, listRow?: Record | null ): Record { const { entryOrder, items } = normalizeEntryDetailPayload(res) if (!entryOrder) { throw new Error('入库单数据为空') } const receivingBindings = Array.isArray(entryOrder.receivingBindings) ? entryOrder.receivingBindings : Array.isArray(listRow?.receivingBindings) ? listRow.receivingBindings : [] const details = items.map((item, idx) => mapEntryPrintDetailItem(item as Record, idx, entryOrder) ) const total_items = details.length const total_quantity = details.reduce((sum, item) => sum + (Number(item.count) || 0), 0) const total_received_quantity = details.reduce( (sum, item) => sum + (Number(item.received_quantity) || 0), 0 ) const result: Record = { ...listRow, ...entryOrder, id: entryOrder.id ?? listRow?.id, entry_order_code: entryOrder.entry_order_code ?? listRow?.entry_order_code ?? '', purchase_order_code: entryOrder.purchase_order_code ?? listRow?.purchase_order_code ?? '', store_name: entryOrder.store_remask ?? entryOrder.store_name ?? listRow?.store_name ?? '', store_remask: entryOrder.store_remask ?? entryOrder.store_name ?? listRow?.store_remask ?? listRow?.store_name ?? '', order_status: translateEntryField('order_status', entryOrder.order_status ?? listRow?.order_status), order_type: translateEntryField('order_type', entryOrder.order_type ?? listRow?.order_type), sync_status: translateEntryField('sync_status', entryOrder.sync_status ?? listRow?.sync_status), source_type: translateEntryField('source_type', entryOrder.source_type ?? listRow?.source_type), total_order_lines: entryOrder.total_order_lines ?? listRow?.total_order_lines ?? total_items, total_items, total_quantity, total_received_quantity, receiving_bindings_summary: formatReceivingBindingsSummary(receivingBindings), receivingBindings, details, } if (details.length > 0) { const first = details[0] const promoteFields = [ 'warehouse_item_code', 'warehouse_item_name', 'warehouse_item_spec', 'product_name', 'product_code', 'barcode', 'count', 'received_quantity', 'actual_quantity', 'confirm_quantity', 'stock_id', 'order_line_no', 'seq_no', ] promoteFields.forEach((field) => { if (result[field] === undefined || result[field] === null || result[field] === '') { result[field] = first?.[field] ?? '' } }) } return result } export type EntryTableColumn = { prop: string label: string width?: number | string minWidth?: number | string align?: 'left' | 'center' | 'right' } /** 货单绑定弹窗 — 收货单列表展示列 */ export const entryBindReceivingListColumns: EntryTableColumn[] = [ { prop: 'receiving_number', label: '收货单号', minWidth: 140 }, { prop: 'created_at', label: '创建时间', width: 160 }, ] /** 货单绑定弹窗 — 对照表分组表头(名称 / 数量) */ export const entryBindCompareGroupHeaders = [ { key: 'name_group', label: '名称', span: 2 }, { key: 'qty_group', label: '数量', span: 2 }, ] as const /** 货单绑定弹窗 — 四列对照表头(名称组:入库/收货,数量组:入库/收货) */ export const entryBindCompareColumnHeaders = [ { key: 'entry_name', label: '入库单 · 名称' }, { key: 'receiving_name', label: '收货单 · 名称' }, { key: 'entry_qty', label: '入库单 · 数量' }, { key: 'receiving_qty', label: '收货单 · 数量' }, ] as const /** 绑定关系 — 主表已绑定收货单 */ export const entryReceivingBindingColumns: EntryTableColumn[] = [ { prop: 'receiving_number', label: '收货单号', minWidth: 150 }, { prop: 'status_label', label: '状态', width: 100 }, { prop: 'storage_status_label', label: '入库状态', width: 100 }, { prop: 'created_at', label: '创建时间', width: 160 }, ] /** 绑定关系 — 明细级 available_receiving_details */ export const entryItemBindingDetailColumns: EntryTableColumn[] = [ { prop: 'warehouse_item_code', label: '商品编码', minWidth: 120 }, { prop: 'warehouse_item_name', label: '商品名称', minWidth: 140 }, { prop: 'entry_plan_qty', label: '计划数量', width: 90, align: 'right' }, { prop: 'receiving_number', label: '收货单号', minWidth: 130 }, { prop: 'product_name', label: '收货商品', minWidth: 130 }, { prop: 'actual_quantity', label: '收货数量', width: 90, align: 'right' }, { prop: 'receiving_allocated', label: '已分配', width: 90, align: 'right' }, { prop: 'available_quantity', label: '可用量', width: 90, align: 'right' }, { prop: 'binding_status_label', label: '绑定状态', width: 100 }, ] /** 绑定关系 — receivingCompare 对照预览 */ export const entryBindingCompareColumns: EntryTableColumn[] = [ { prop: 'match_status_label', label: '匹配', width: 90, align: 'center' }, { prop: 'item_name', label: '商品名称', minWidth: 140 }, { prop: 'entry_plan_qty', label: '入库应收', width: 90, align: 'right' }, { prop: 'receiving_qty', label: '收货数量', width: 90, align: 'right' }, { prop: 'receiving_allocated', label: '已分配', width: 90, align: 'right' }, ] export function formatEntryBindingStatus(status: unknown): string { if (status === null || status === undefined || status === '') return '—' const key = String(status).trim().toLowerCase() const map: Record = { pending: '待入库', bound: '已绑定', allocated: '已分配', completed: '已完成', cancelled: '已作废', canceled: '已作废', active: '有效', } return map[key] || String(status) } export function formatDirectInboundDateTime( row: unknown, _col?: unknown, value?: unknown ): string { const raw = value !== undefined && value !== null && value !== '' ? value : (row as Record)?.created_at if (raw === null || raw === undefined || raw === '') return '--' if (typeof raw === 'object' && !(raw instanceof Date)) return '--' try { let date: Date if (raw instanceof Date) { date = raw } else if (typeof raw === 'number') { const ms = String(raw).length === 10 ? raw * 1000 : raw date = new Date(ms) } else { const text = String(raw).trim() if (!text) return '--' if (/^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}/.test(text)) { return text.replace('T', ' ').slice(0, 19) } date = new Date(text.includes('-') ? text.replace(/-/g, '/') : text) } if (Number.isNaN(date.getTime())) return '--' return formatEntryDateTime(date) } catch { return '--' } } function formatEntryDateTime(date: Date): string { const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') const hours = String(date.getHours()).padStart(2, '0') const minutes = String(date.getMinutes()).padStart(2, '0') const seconds = String(date.getSeconds()).padStart(2, '0') return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}` } export const directInboundLogColumns = [ { prop: 'stock_id', label: 'SKU', width: '100' }, { prop: 'warehouse_item_code', label: '商品编码', width: '150' }, { prop: 'warehouse_item_name', label: '商品名称', minWidth: '160' }, { prop: 'quantity', label: '入库数量', width: '100', align: 'right' }, { prop: 'inbound_type', label: '入库方式', width: '100', align: 'center' }, { prop: 'space_id', label: '库位ID', width: '100', align: 'right' }, { prop: 'remark', label: '备注', minWidth: '160' }, { prop: 'created_at', label: '操作时间', width: '160', formatter: formatDirectInboundDateTime, }, ] /** 入库记录操作列(移除记录,仅未提交入库单可用) */ export const directInboundLogActionColumn = { prop: 'operation', label: '操作', width: '80', fixed: 'right', align: 'center', } as const /** 收货对照 match_status 标签样式 */ export function getReceivingCompareStatusTagType(status: unknown): string { const key = String(status ?? '').trim().toLowerCase() if (key === 'matched') return 'success' if (key === 'entry_only') return 'warning' return 'info' } export function formatReceivingCompareStatus(status: unknown): string { const key = String(status ?? '').trim().toLowerCase() const map: Record = { matched: '已匹配', entry_only: '仅入库单', receiving_only: '仅收货单', } return map[key] || (status ? String(status) : '--') } /** 收货对照 - Git Diff 左侧(入库单)列 */ export const receivingCompareEntrySideColumns = [ { prop: 'stock_id', label: 'SKU', width: '72' }, { prop: 'item_code', label: '编码', minWidth: '110' }, { prop: 'item_name', label: '名称', minWidth: '130' }, { prop: 'plan_qty', label: '应收', width: '64', align: 'right' }, { prop: 'received_qty', label: '实收', width: '64', align: 'right' }, ] as const /** 收货对照 - Git Diff 右侧(收货单)列 */ export const receivingCompareReceivingSideColumns = [ { prop: 'stock_id', label: 'SKU', width: '72' }, { prop: 'item_code', label: '编码', minWidth: '110' }, { prop: 'item_name', label: '名称', minWidth: '130' }, { prop: 'receiving_qty', label: '收货量', width: '64', align: 'right' }, { prop: 'box_quantity', label: '箱数', width: '56', align: 'right' }, ] as const /** 收货对照 - 逐行对照列(合并表,保留兼容) */ export const receivingCompareColumns = [ { prop: 'match_status', label: '匹配状态', width: '90', align: 'center' }, { prop: 'stock_id', label: 'SKU', width: '90' }, { prop: 'item_code', label: '商品编码', width: '140' }, { prop: 'item_name', label: '商品名称', minWidth: '160' }, { prop: 'barcode', label: '条码', width: '130' }, { prop: 'entry_plan_qty', label: '入库应收', width: '90', align: 'right' }, { prop: 'entry_received_qty', label: '入库实收', width: '90', align: 'right' }, { prop: 'receiving_qty', label: '收货数量', width: '90', align: 'right' }, { prop: 'box_quantity', label: '收货箱数', width: '80', align: 'right' }, ] /** 收货对照 - 仅收货单商品列 */ export const receivingOnlyColumns = [ { prop: 'stock_id', label: 'SKU', width: '90' }, { prop: 'item_code', label: '商品编码', width: '140' }, { prop: 'item_name', label: '商品名称', minWidth: '160' }, { prop: 'barcode', label: '条码', width: '130' }, { prop: 'receiving_qty', label: '收货数量', width: '90', align: 'right' }, { prop: 'box_quantity', label: '收货箱数', width: '80', align: 'right' }, ] /** summary 字段中文标签(含 API 返回的 snake_case 键名) */ export const receivingCompareSummaryLabels: Record = { total_entry_items: '入库商品数', total_receiving_items: '收货商品数', matched_items: '已匹配商品', entry_only_items: '仅入库单商品', receiving_only_items: '仅收货单商品', total_rows: '对照行数', matched_count: '已匹配行数', entry_only_count: '仅入库单行数', receiving_only_count: '仅收货单行数', total_entry_qty: '入库数量合计', total_receiving_qty: '收货数量合计', matched_qty: '匹配数量合计', entry_only_qty: '仅入库数量', receiving_only_qty: '仅收货数量', unmatched_items: '未匹配商品', unmatched_count: '未匹配行数', match_rate: '匹配率', is_fully_matched: '是否完全匹配', fully_matched: '是否完全匹配', comparison_rows: '对照行数', } /** summary 展示顺序(优先展示核心指标) */ export const receivingCompareSummaryOrder: string[] = [ 'total_entry_items', 'total_receiving_items', 'matched_items', 'entry_only_items', 'receiving_only_items', 'unmatched_items', 'total_entry_qty', 'total_receiving_qty', 'matched_qty', 'match_rate', 'is_fully_matched', 'fully_matched', 'total_rows', 'matched_count', 'entry_only_count', 'receiving_only_count', 'entry_only_qty', 'receiving_only_qty', 'unmatched_count', 'comparison_rows', ] const receivingCompareSummaryWordLabels: Record = { total: '合计', entry: '入库', receiving: '收货', matched: '已匹配', unmatched: '未匹配', only: '仅', items: '商品数', item: '商品', qty: '数量', quantity: '数量', count: '数量', rows: '行数', rate: '比率', fully: '完全', comparison: '对照', } export function formatReceivingCompareSummaryLabel(key: string): string { const normalized = String(key ?? '').trim() if (!normalized) return '—' if (receivingCompareSummaryLabels[normalized]) { return receivingCompareSummaryLabels[normalized] } return normalized .split('_') .filter(Boolean) .map((part) => receivingCompareSummaryWordLabels[part.toLowerCase()] || part) .join('') } export function formatReceivingCompareSummaryValue(key: string, value: unknown): string { if (value === null || value === undefined || value === '') return '—' const normalizedKey = String(key ?? '').trim().toLowerCase() if (normalizedKey === 'is_fully_matched' || normalizedKey === 'fully_matched') { const text = String(value).toLowerCase() if (value === true || value === 1 || text === '1' || text === 'true' || text === 'yes') { return '是' } if (value === false || value === 0 || text === '0' || text === 'false' || text === 'no') { return '否' } } if (normalizedKey.includes('rate') || normalizedKey.includes('ratio')) { const num = Number(value) if (Number.isFinite(num)) { if (num > 0 && num <= 1) return `${(num * 100).toFixed(1)}%` return `${num}%` } } return String(value) } export function getReceivingCompareSummaryCardType( key: string ): 'success' | 'warning' | 'danger' | 'info' | 'primary' { const normalized = String(key ?? '').trim().toLowerCase() if (normalized.includes('receiving_only') || normalized.includes('unmatched')) return 'danger' if (normalized.includes('entry_only')) return 'warning' if (normalized.includes('matched') && !normalized.includes('unmatched')) return 'success' if (normalized.includes('total') || normalized.includes('rate')) return 'primary' return 'info' } /** 收货单状态下拉展示文案 */ export function formatReceivingOrderStatusLabel(status: unknown): string { if (status === null || status === undefined || status === '') return '' const key = String(status).trim().toLowerCase() const map: Record = { receiving: '收货中', completed: '已完成', cancelled: '已作废', canceled: '已作废', pending: '待收货', partial: '部分入库', all: '全部入库', none: '未入库', } return map[key] || String(status) } export function buildReceivingCompareSummaryItems( summary: Record | null | undefined ): Array<{ key: string; label: string; value: string; cardType: ReturnType }> { if (!summary || typeof summary !== 'object') return [] const used = new Set() const items: Array<{ key: string label: string value: string cardType: ReturnType }> = [] const pushItem = (key: string) => { if (used.has(key)) return const value = summary[key] if (value === null || value === undefined || value === '') return used.add(key) items.push({ key, label: formatReceivingCompareSummaryLabel(key), value: formatReceivingCompareSummaryValue(key, value), cardType: getReceivingCompareSummaryCardType(key), }) } receivingCompareSummaryOrder.forEach(pushItem) Object.keys(summary) .sort() .forEach(pushItem) return items } export const addEntryFields = [ { label: '业务类型', prop: 'order_type', type: 'select', options: [ { label: '生产入库', value: 'SCRK' }, { label: '领用入库', value: 'LYRK' }, { label: '拆解入库', value: 'CCRK' }, { label: '采购入库', value: 'CGRK' }, { label: '调拨入库', value: 'DBRK' }, { label: '其他入库', value: 'QTRK' }, { label: 'B2B入库', value: 'B2BRK' }, { label: '虚拟入库', value: 'XNRK' }, ]}, { label: '货主', prop: 'store_id', type: 'select', options: [] }, { label: '入库单号', prop: 'entry_order_code' }, { label: '采购单号', prop: 'purchase_order_code' }, { label: '备注', prop: 'remark', type: 'textarea' } ]