WEB/src/views/storage/inventory/inventory-config.ts
liufumingren 06d49f83b9 1
2026-07-04 00:50:25 +08:00

221 lines
8.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { scanWorkflowField } from '@/views/order/orderManagement/config/order-common-config'
/** ScanBox 基础信息分组(对齐收货单排版) */
export const INVENTORY_SCAN_BASIC_INFO_GROUP = '基础信息'
/** ScanBox 筛选字段分组(库存模块专用) */
export const INVENTORY_SCAN_FIELD_GROUPS = {
basic: '基础信息',
options: '查询设置'
} as const
type InventoryScanFieldGroupKey = keyof typeof INVENTORY_SCAN_FIELD_GROUPS
export function inventoryScanField<G extends InventoryScanFieldGroupKey>(
group: G,
field: Record<string, any>
): InventoryScanFieldConfig {
return { ...field, group: INVENTORY_SCAN_FIELD_GROUPS[group] } as InventoryScanFieldConfig
}
/** 为库存 ScanBox 基础信息字段附加分组标签 */
export type InventoryScanFieldConfig = Record<string, any> & {
group: string
value: string
label: string
type?: string
options?: Array<{ label: string; value: unknown }>
}
export function inventoryScanBasicField(field: Record<string, any>): InventoryScanFieldConfig {
return { ...field, group: INVENTORY_SCAN_BASIC_INFO_GROUP } as InventoryScanFieldConfig
}
/** ScanBox 默认 props(与波次模块 scan-box 侧栏一致) */
export const inventoryScanBoxConfig = {
width: '250px',
treeProps: { children: 'children', label: 'label' } as const,
autoSubmit: false
}
export const availableFields: InventoryScanFieldConfig[] = [
inventoryScanBasicField({
label: '商品ID',
value: 'stock_id',
type: 'text',
placeholder: '请输入商品ID',
extraAction: { label: '编码筛选' }
}),
inventoryScanBasicField({ label: '库位', value: 'space_id', type: 'text' }),
inventoryScanBasicField({ label: '货主', value: 'store_id', type: 'select', multiple: true, options: [] }),
inventoryScanBasicField({ label: '批次号', value: 'batch_no', type: 'text' }),
inventoryScanBasicField({ label: '入库单号', value: 'inbound_order_no', type: 'text' }),
inventoryScanBasicField({ label: '创建日期', value: 'created_at', type: 'daterange' }),
// 流程/状态(每项独立分组,对齐收货单 scanWorkflowField 排版)
scanWorkflowField({
label: '库存类型',
value: 'inventory_type',
type: 'select',
options: [
{ label: '正品', value: 'ZP' },
{ label: '次品', value: 'CC' },
{ label: '机损', value: 'JS' },
{ label: '箱损', value: 'XS' },
{ label: '在途', value: 'ZT' },
{ label: '冻结', value: 'DJ' },
{ label: '分配', value: 'FP' }
]
}) as InventoryScanFieldConfig,
]
/** 库位展示名:优先 custom_name,其次 space_code */
export function formatInventorySpaceLabel(space?: Record<string, any> | null, fallback = ''): string {
if (!space || typeof space !== 'object') return fallback
const customName = String(space.custom_name ?? '').trim()
if (customName) return customName
const spaceCode = String(space.space_code ?? '').trim()
if (spaceCode) return spaceCode
const name = String(space.name ?? '').trim()
return name || fallback
}
/** 解析商品条码并过滤空值 */
export function normalizeInventoryBarcodesList(value: unknown): string[] {
if (value === null || value === undefined || value === '') return []
if (Array.isArray(value)) {
return value
.map((item) => String(item ?? '').trim())
.filter(Boolean)
}
if (typeof value === 'string') {
const text = value.trim()
if (!text || text === '[""]' || text === '[]') return []
if (text.startsWith('[') && text.endsWith(']')) {
try {
const parsed = JSON.parse(text)
if (Array.isArray(parsed)) {
return parsed
.map((item) => String(item ?? '').trim())
.filter(Boolean)
}
} catch {
// ignore invalid json
}
}
if (text.includes('|')) {
return text.split('|').map((item) => item.trim()).filter(Boolean)
}
return [text]
}
const text = String(value).trim()
return text ? [text] : []
}
/** 商品条码展示:数组用 | 连接,忽略空条码 */
export function formatInventoryBarcodes(value: unknown): string {
const items = normalizeInventoryBarcodesList(value)
return items.length ? items.join('|') : '--'
}
/** 是否类字段(Y/N、0/1、boolean)转是/否 */
export function isInventoryFlagEnabled(value: unknown): boolean {
return value === true || String(value).toLowerCase() === 'y' || String(value) === '1'
}
export function formatInventoryFlagLabel(value: unknown): string {
if (value === null || value === undefined || value === '') return '--'
return isInventoryFlagEnabled(value) ? '是' : '否'
}
export function formatInventoryOptionalText(value: unknown): string {
if (value === null || value === undefined || value === '') return '--'
return String(value)
}
const inventoryTypeLabelMap: Record<string, string> = {
ZP: '正品',
CC: '次品',
JS: '机损',
XS: '箱损',
ZT: '在途',
DJ: '冻结',
FP: '分配'
}
export function formatInventoryTypeLabel(value: unknown): string {
const key = String(value ?? '').trim()
if (!key) return '--'
return inventoryTypeLabelMap[key] || key
}
const inventoryBarcodesColumn = {
prop: 'barcodes',
label: '商品条码',
width: '150',
showOverflowTooltip: true
}
/** 库存列表选中导出列 */
export const inventoryExportColumns = [
{ prop: 'store_name', label: '货主' },
{ prop: 'item_code', label: '商品编码' },
{ prop: 'item_name', label: '商品名称' },
{ ...inventoryBarcodesColumn },
{ prop: 'sku_property', label: '规格' },
{ prop: 'stock_unit', label: '单位' },
{ prop: 'space_code', label: '库位名称' },
{ prop: 'space_id', label: '库位ID' },
{ prop: 'inventory_type', label: '库存类型' },
{ prop: 'quantity', label: '总数量' },
{ prop: 'available_quantity', label: '可用数量' },
{ prop: 'locked_quantity', label: '锁定数量' },
{ prop: 'batch_count', label: '批次数' },
{ prop: 'first_inbound_time', label: '首次入库时间' },
{ prop: 'last_inbound_time', label: '最后入库时间' },
{ prop: 'is_shelf_life_mgmt', label: '保质期管理' },
{ prop: 'remaining_threshold_days', label: '临期阈值(天)' }
]
export const productstockColums = [
{ prop: 'stock_id', label: '商品ID', width: '100' },
{ prop: 'item_code', label: '商品编码', width: '150' },
{ prop: 'item_name', label: '商品名称', width: '200' },
{ ...inventoryBarcodesColumn },
{ prop: 'sku_property', label: '规格', width: '140', showOverflowTooltip: true },
{ prop: 'stock_unit', label: '单位', width: '80' },
{ prop: 'production_date', label: '生产日期', width: '120' },
{ prop: 'expiry_date', label: '到期日期', width: '120' },
{ prop: 'shelf_life_days', label: '保质期', width: '100' },
{ prop: 'sale_ban_period', label: '禁售期', width: '110' },
{ prop: 'space_code', label: '库位名称', width: '150' },
{ prop: 'space_id', label: '库位ID', width: '90' },
{ prop: 'store_name', label: '货主', width: '120' },
{ prop: 'inventory_type', label: '库存类型', width: '100' },
{ prop: 'quantity', label: '总数量', width: '100' },
{ prop: 'available_quantity', label: '可用数量', width: '100' },
{ prop: 'locked_quantity', label: '锁定数量', width: '100' },
{ prop: 'first_inbound_time', label: '首次入库时间', width: '160' },
{ prop: 'last_inbound_time', label: '最后入库时间', width: '160' },
{ prop: 'is_shelf_life_mgmt', label: '保质期管理', width: '100' },
{ prop: 'remaining_threshold_days', label: '临期阈值(天)', width: '110' },
{ prop: 'is_batch_mgmt_enabled', label: '批次管理', width: '100' },
{ prop: 'batch_count', label: '批次数', width: '80' }
]
export const productstockDetail = [
{ prop: 'id', label: 'ID', width: '80' },
{ prop: 'sku_code', label: '商品编码', width: '150' },
{ prop: 'barcode', label: '条码', width: '150' },
{ prop: 'product_name', label: '商品名称', width: '250' },
{ prop: 'spec_name', label: '规格', width: '120' },
{ prop: 'unit', label: '单位', width: '80' },
{ prop: 'actual_qty', label: '入库数量', width: '100' },
{ prop: 'available_qty', label: '可用库存', width: '100' },
{ prop: 'batch_no', label: '批次号', width: '120' },
{ prop: 'warehouse_name', label: '库房', width: '120' },
{ prop: 'area_name', label: '库区', width: '100' },
{ prop: 'location_name', label: '库位', width: '120' },
{ prop: 'inventory_status', label: '库存状态', width: '100' }
]