257 lines
8.9 KiB
TypeScript
257 lines
8.9 KiB
TypeScript
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
|
||
/** 出入库记录列表主工具栏按钮(action 与 log/index.vue 内 toolbarActionMap 键一致)
|
||
* 排序与样式分类对齐 storage/receiving:
|
||
* refresh → setting 组(导出/字段设置/详情)
|
||
*/
|
||
export const logToolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadData' },
|
||
{
|
||
key: 'export',
|
||
label: '导出',
|
||
category: 'setting',
|
||
size: 'small',
|
||
loadingKey: 'exportLoading',
|
||
action: 'handleExportWaybill',
|
||
buttonType: 'dropdown',
|
||
dropdownOptions: [
|
||
{ label: '不含明细', action: 'handleExportWaybill' },
|
||
{ label: '含明细', action: 'handleExportItem', divided: true },
|
||
]
|
||
},
|
||
{ key: 'columnConfig', label: '字段设置', category: 'setting', size: 'small', action: 'openColumnConfigPanel' },
|
||
{
|
||
key: 'toggleDetail',
|
||
label: '显示详情',
|
||
dynamicLabelKey: 'detailToggleLabel',
|
||
category: 'setting',
|
||
size: 'small',
|
||
action: 'toggleDetailVisible'
|
||
},
|
||
]
|
||
|
||
/** ScanBox 基础信息分组(对齐收货单排版) */
|
||
export const LOG_SCAN_BASIC_INFO_GROUP = '基础信息'
|
||
|
||
/** ScanBox 流程状态分组 */
|
||
export const LOG_SCAN_WORKFLOW_GROUP = '流程状态'
|
||
|
||
/** ScanBox 时间分组 */
|
||
export const LOG_SCAN_TIME_GROUP = '时间'
|
||
|
||
/** 为出入库日志 ScanBox 基础信息字段附加分组标签 */
|
||
export type LogScanFieldConfig = Record<string, any> & {
|
||
group: string
|
||
value: string
|
||
label: string
|
||
type?: string
|
||
options?: Array<{ label: string; value: unknown }>
|
||
}
|
||
|
||
export function logScanBasicField(field: Record<string, any>): LogScanFieldConfig {
|
||
return { ...field, group: LOG_SCAN_BASIC_INFO_GROUP } as LogScanFieldConfig
|
||
}
|
||
|
||
export function logScanWorkflowField(field: Record<string, any>): LogScanFieldConfig {
|
||
return { ...field, group: LOG_SCAN_WORKFLOW_GROUP } as LogScanFieldConfig
|
||
}
|
||
|
||
export function logScanTimeField(field: Record<string, any>): LogScanFieldConfig {
|
||
return { ...field, group: LOG_SCAN_TIME_GROUP } as LogScanFieldConfig
|
||
}
|
||
|
||
/** ScanBox 默认 props(与波次模块 scan-box 侧栏一致) */
|
||
export const logScanBoxConfig = {
|
||
width: '220px',
|
||
treeProps: { children: 'children', label: 'label' } as const,
|
||
autoSubmit: false
|
||
}
|
||
|
||
// 时间格式化函数
|
||
export function formatDateTime(dateStr: string): string {
|
||
if (!dateStr) return '--'
|
||
try {
|
||
const date = new Date(dateStr)
|
||
if (isNaN(date.getTime())) return '--'
|
||
// 转换为本地时间,格式:YYYY-MM-DD HH:mm:ss
|
||
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}`
|
||
} catch (e) {
|
||
return '--'
|
||
}
|
||
}
|
||
|
||
// 交易类型配置
|
||
export const transactionTypeConfig = {
|
||
INBOUND: { text: '入库', tagType: 'success' },
|
||
OUTBOUND: { text: '出库', tagType: 'danger' },
|
||
UNLOCK: { text: '解锁', tagType: 'warning' }
|
||
}
|
||
|
||
// 库存类型配置
|
||
export const inventoryTypeConfig = {
|
||
ZP: { text: '正品', tagType: 'success' },
|
||
CC: { text: '残次', tagType: 'warning' },
|
||
JS: { text: '机损', tagType: 'warning' },
|
||
XS: { text: '箱损', tagType: 'warning' },
|
||
ZT: { text: '在途', tagType: 'info' },
|
||
DJ: { text: '待检', tagType: 'warning' },
|
||
FP: { text: '返品', tagType: 'info' }
|
||
}
|
||
|
||
// 订单类型配置
|
||
export const orderTypeConfig: Record<string, string> = {
|
||
ORDER: '订单',
|
||
ORDER_CANCEL: '取消订单',
|
||
CGRK: '采购入库',
|
||
JYCK: '交易出库',
|
||
CGTH: '采购退货',
|
||
JYTH: '交易退货',
|
||
SCRK: '生产入库',
|
||
SHRK: '收货入库',
|
||
DELIVERY_ORDER: '出库单',
|
||
RECEIVING: '收货单',
|
||
ENTRY_ORDER: '入库单',
|
||
INVENTORY: '盘点单',
|
||
RETURN: '退货单',
|
||
PICK_OUTBOUND: '拣货出库',
|
||
PICK_RETURN: '拣货返还',
|
||
entry_order: '入库单',
|
||
INTERCEPT_GAP: '拦截差异'
|
||
}
|
||
|
||
export function getOrderTypeLabel(type: string): string {
|
||
return orderTypeConfig[type] || type || '—'
|
||
}
|
||
|
||
// 交易类型展示:文本 + tag 颜色(兼容 INBOUND/OUTBOUND/UNLOCK 等)
|
||
export function getTransactionTypeText(value: unknown): string {
|
||
if (value === undefined || value === null || value === '') return '—'
|
||
return transactionTypeConfig[value as keyof typeof transactionTypeConfig]?.text ?? String(value)
|
||
}
|
||
|
||
export function getTransactionTypeTagType(value: unknown): 'success' | 'warning' | 'danger' {
|
||
if (value === 'INBOUND') return 'success'
|
||
if (value === 'OUTBOUND') return 'danger'
|
||
return 'warning'
|
||
}
|
||
|
||
// 出入库记录列表列(列字段与 storage.transaction.list 实际返回逐条明细对齐)
|
||
export const transactionColumns = [
|
||
{ prop: 'stock_id', label: '商品ID', width: '100', copyAction: 'copy' as const },
|
||
{ prop: 'item_code', label: '商品编码', width: '140', copyAction: 'copy' as const },
|
||
{ prop: 'item_name', label: '商品名称', minWidth: '160' },
|
||
{ prop: 'transaction_type', label: '交易类型', width: '100' },
|
||
{ prop: 'inventory_type', label: '库存类型', width: '100', formatter: (row: any) => inventoryTypeConfig[row.inventory_type as keyof typeof inventoryTypeConfig]?.text ?? row.inventory_type ?? '—' },
|
||
{ prop: 'order_type', label: '订单类型', width: '110' },
|
||
{ prop: 'order_no', label: '单号', minWidth: '180', showOverflowTooltip: true },
|
||
{ prop: 'batch_no', label: '批次号', minWidth: '150', copyAction: 'copy' as const },
|
||
{ prop: 'space_id', label: '库位', width: '100' },
|
||
// { prop: 'warehouse_id', label: '仓库ID', width: '100' },
|
||
// { prop: 'store_id', label: '货主ID', width: '100' },
|
||
{ prop: 'quantity', label: '数量', width: '100' },
|
||
{ prop: 'operator_name', label: '操作人', width: '110' },
|
||
{ prop: 'remark', label: '备注', minWidth: '150', showOverflowTooltip: true },
|
||
{ prop: 'created_at', label: '创建时间', width: '168', sortable: true, formatter: (row: any) => formatDateTime(row.created_at) }
|
||
]
|
||
|
||
// scan-box 可用字段(基础信息在前,流程状态在后;与 storage.transaction.list 最新 where 设计对齐)
|
||
export const availableFields: LogScanFieldConfig[] = [
|
||
logScanBasicField({
|
||
value: 'keyword',
|
||
label: '关键字',
|
||
type: 'text',
|
||
placeholder: '搜索商品编码/名称/单号/批次号/操作人等',
|
||
operators: ['eq', 'contains'],
|
||
defaultOperator: 'contains'
|
||
}),
|
||
logScanBasicField({
|
||
value: 'stock_id',
|
||
label: '商品ID',
|
||
type: 'number',
|
||
placeholder: '请输入商品ID',
|
||
operators: ['eq', 'contains'],
|
||
defaultOperator: 'eq'
|
||
}),
|
||
logScanBasicField({
|
||
value: 'space_id',
|
||
label: '库位ID',
|
||
type: 'number',
|
||
placeholder: '请输入库位ID',
|
||
operators: ['eq', 'contains'],
|
||
defaultOperator: 'eq'
|
||
}),
|
||
logScanBasicField({
|
||
value: 'store_id',
|
||
label: '货主',
|
||
type: 'select',
|
||
multiple: true,
|
||
filterable: true,
|
||
options: []
|
||
}),
|
||
logScanBasicField({
|
||
value: 'order_no',
|
||
label: '单号',
|
||
type: 'text',
|
||
placeholder: '请输入单号',
|
||
operators: ['eq', 'contains'],
|
||
defaultOperator: 'eq'
|
||
}),
|
||
|
||
// ===== 流程状态(合并为一组,对齐波次列表 ScanBox) =====
|
||
logScanWorkflowField({
|
||
value: 'transaction_type',
|
||
label: '交易类型',
|
||
type: 'select',
|
||
options: Object.entries(transactionTypeConfig).map(([v, c]) => ({ value: v, label: c.text }))
|
||
}),
|
||
logScanWorkflowField({
|
||
value: 'order_type',
|
||
label: '订单类型',
|
||
type: 'select',
|
||
options: Object.entries(orderTypeConfig).map(([value, label]) => ({ value, label }))
|
||
}),
|
||
logScanWorkflowField({
|
||
value: 'inventory_type',
|
||
label: '库存类型',
|
||
type: 'select',
|
||
options: Object.entries(inventoryTypeConfig).map(([v, c]) => ({ value: v, label: c.text }))
|
||
}),
|
||
logScanWorkflowField({
|
||
value: 'operator_name',
|
||
label: '操作人',
|
||
type: 'text',
|
||
placeholder: '请输入操作人',
|
||
operators: ['like', 'contains', 'notlike'],
|
||
defaultOperator: 'like'
|
||
}),
|
||
|
||
// ===== 时间 =====
|
||
logScanTimeField({
|
||
value: 'created_at',
|
||
label: '创建时间',
|
||
type: 'date',
|
||
operators: ['between', 'eq', 'gt', 'lt'],
|
||
defaultOperator: 'between'
|
||
}),
|
||
]
|
||
|
||
// 格式化行数据
|
||
export function formatTransactionData(data: any[]): any[] {
|
||
return data.map(item => ({
|
||
...item,
|
||
item_code: item.stockItem?.item_code || '',
|
||
item_name: item.stockItem?.item_name || '',
|
||
record_count: item.record_count ?? 1,
|
||
first_created_at: item.first_created_at || item.created_at,
|
||
last_created_at: item.last_created_at || item.created_at,
|
||
// 接口现返回逐条明细(含真实 id);拼接兜底仅用于个别无 id 场景
|
||
id: item.id ?? `${item.stock_id}-${item.transaction_type}`
|
||
}))
|
||
}
|