239 lines
9.7 KiB
TypeScript
239 lines
9.7 KiB
TypeScript
import { stockQueryScanField } from '@/views/order/orderManagement/config/order-common-config'
|
||
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { normalizeBarcodeList } from '@/utils/barcode'
|
||
|
||
/** 库存列表主工具栏按钮(action 与 inventory/index.vue 内 toolbarActionMap 键一致)
|
||
* 排序与样式分类对齐 storage/receiving:
|
||
* refresh → setting 组(导出/字段设置/详情)→ action 组 → cancel 组
|
||
*/
|
||
export const inventoryToolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadData' },
|
||
{
|
||
key: 'export',
|
||
label: '导出',
|
||
category: 'setting',
|
||
size: 'small',
|
||
loadingKey: 'exportLoading',
|
||
action: 'handleExportSelected',
|
||
buttonType: 'dropdown',
|
||
dropdownOptions: [
|
||
{ label: '导出选中', action: 'handleExportSelected' },
|
||
{ label: '导出全部', action: 'handleExportAll', divided: true },
|
||
]
|
||
},
|
||
{ key: 'columnConfig', label: '字段设置', category: 'setting', size: 'small', action: 'openColumnConfigPanel' },
|
||
{
|
||
key: 'toggleDetail',
|
||
label: '显示详情',
|
||
dynamicLabelKey: 'detailToggleLabel',
|
||
category: 'setting',
|
||
size: 'small',
|
||
action: 'toggleDetailVisible'
|
||
},
|
||
{
|
||
key: 'import',
|
||
label: '导入',
|
||
category: 'action',
|
||
size: 'small',
|
||
action: 'handleImport'
|
||
},
|
||
{
|
||
key: 'spaceStock',
|
||
label: '库位商品',
|
||
category: 'action',
|
||
size: 'small',
|
||
action: 'openSpaceStock'
|
||
},
|
||
{
|
||
key: 'batchCancel',
|
||
label: '批量作废',
|
||
category: 'cancel',
|
||
size: 'small',
|
||
disabledKey: 'hasNoSelection',
|
||
action: 'confirmBatchCancel'
|
||
},
|
||
]
|
||
|
||
/** 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: '220px',
|
||
treeProps: { children: 'children', label: 'label' } as const,
|
||
autoSubmit: false
|
||
}
|
||
|
||
export const availableFields: InventoryScanFieldConfig[] = [
|
||
inventoryScanBasicField({
|
||
...stockQueryScanField,
|
||
placeholder: '请输入商品编码/名称/条码'
|
||
}),
|
||
inventoryScanBasicField({ label: '货主', value: 'store_id', type: 'select', multiple: true, options: [] }),
|
||
inventoryScanBasicField({ label: '库位', value: 'space_keyword', type: 'text', placeholder: '库位名称或编码' }),
|
||
inventoryScanBasicField({ label: '创建日期', value: 'created_at', type: 'daterange' }),
|
||
]
|
||
/** 库位展示名:优先 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
|
||
}
|
||
|
||
/** 解析商品条码并过滤空值(兼容字符串数组与 `{ id, barcode }` 对象数组) */
|
||
export function normalizeInventoryBarcodesList(value: unknown): string[] {
|
||
return normalizeBarcodeList(value, { separators: ['|'] })
|
||
}
|
||
|
||
/** 商品条码展示:数组用 | 连接,忽略空条码 */
|
||
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,
|
||
copyAction: 'copy' as const
|
||
}
|
||
|
||
/** 库存列表选中导出列 */
|
||
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: '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', copyAction: 'copy' as const },
|
||
{ prop: 'item_code', label: '商品编码', width: '150', copyAction: 'copy' as const },
|
||
{ 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: 'store_name', label: '货主', width: '120' },
|
||
{ prop: 'space_code', label: '库位', width: '120' },
|
||
{ prop: 'quantity', label: '总数量', width: '100' },
|
||
{ prop: 'available_quantity', label: '可用数量', width: '100' },
|
||
{ prop: 'locked_quantity', label: '锁定数量', width: '100' },
|
||
{ prop: 'is_shelf_life_mgmt', label: '保质期管理', width: '100' },
|
||
{ prop: 'remaining_threshold_days', label: '临期阈值(天)', width: '110' },
|
||
{ prop: 'is_shelf_life_warning_triggered', label: '临期预警', width: '100' },
|
||
{ prop: 'is_batch_mgmt_enabled', label: '批次管理', width: '100' },
|
||
{ prop: 'batch_count', label: '批次数', width: '80' },
|
||
{ prop: 'first_inbound_time', label: '首次入库时间', width: '160' },
|
||
{ prop: 'last_inbound_time', label: '最后入库时间', width: '160' },
|
||
]
|
||
|
||
/** 库位商品弹窗表格列(storage.inventory.listBySpaceId 响应 data.list,按 stock_id 汇总) */
|
||
export const spaceStockColumns = [
|
||
{ prop: 'stock_id', label: '商品ID', width: '100' },
|
||
{ prop: 'item_code', label: '商品编码', width: '150' },
|
||
{ prop: 'item_name', label: '商品名称', width: '200' },
|
||
{ prop: 'barcodes', label: '商品条码', width: '150' },
|
||
{ prop: 'sku_property', label: '规格', width: '140' },
|
||
{ prop: 'stock_unit', label: '单位', width: '80' },
|
||
{ prop: 'store_name', label: '货主', width: '120' },
|
||
{ prop: 'quantity', label: '总数量', width: '100' },
|
||
{ prop: 'available_quantity', label: '可用数量', width: '100' },
|
||
{ prop: 'locked_quantity', label: '锁定数量', width: '100' },
|
||
{ prop: 'intercept_locked_quantity', label: '拦截锁定', width: '100' },
|
||
{ prop: 'batch_count', label: '批次数', width: '80' },
|
||
{ prop: 'first_inbound_time', label: '最早入库时间', width: '160' },
|
||
{ prop: 'last_inbound_time', label: '最晚入库时间', width: '160' }
|
||
]
|
||
|
||
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' }
|
||
] |