WEB/src/views/storage/receiving/receiving-config.ts

616 lines
24 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 {
type ToolbarButtonConfig
} from '@/views/order/orderManagement/config/order-common-config'
/** ScanBox 基础信息分组(对齐待处理订单排版) */
export const RECEIVING_SCAN_BASIC_INFO_GROUP = '基础信息'
/** ScanBox 流程状态分组 */
export const RECEIVING_SCAN_WORKFLOW_GROUP = '流程状态'
/** ScanBox 时间分组 */
export const RECEIVING_SCAN_TIME_GROUP = '时间'
/** 为收货 ScanBox 基础信息字段附加分组标签 */
export type ReceivingScanFieldConfig = Record<string, any> & {
group: string
value: string
label: string
type?: string
options?: Array<{ label: string; value: unknown }>
}
export function receivingScanBasicField(field: Record<string, any>): ReceivingScanFieldConfig {
return { ...field, group: RECEIVING_SCAN_BASIC_INFO_GROUP } as ReceivingScanFieldConfig
}
export function receivingScanWorkflowField(field: Record<string, any>): ReceivingScanFieldConfig {
return { ...field, group: RECEIVING_SCAN_WORKFLOW_GROUP } as ReceivingScanFieldConfig
}
export function receivingScanTimeField(field: Record<string, any>): ReceivingScanFieldConfig {
return { ...field, group: RECEIVING_SCAN_TIME_GROUP } as ReceivingScanFieldConfig
}
/** ScanBox 默认 props(与波次模块 scan-box 侧栏一致) */
export const receivingScanBoxConfig = {
width: '250px',
treeProps: { children: 'children', label: 'label' } as const,
autoSubmit: false
}
export const statusConfig = {
receiving: { text: '收货中', tagType: 'warning' },
completed: { text: '已完成', tagType: 'success' },
cancelled: { text: '已作废', tagType: 'danger' }
}
export const detailStatusConfig = {
all_matched: { text: '全部匹配', tagType: 'success' },
partial_matched: { text: '部分匹配', tagType: 'warning' },
unmatched: { text: '未匹配', tagType: 'info' }
}
export const storageStatusConfig = {
all: { text: '全部入库', tagType: 'success' },
partial: { text: '部分入库', tagType: 'warning' },
waiting: { text: '待入库', tagType: 'primary' },
none: { text: '未入库', tagType: 'info' }
}
// 商品入库状态映射
export const productStorageStatusConfig: any = {
all: { text: '全部入库', tagType: 'success', color: '#67C23A' },
partial: { text: '部分入库', tagType: 'warning', color: '#E6A23C' },
waiting: { text: '待入库', tagType: 'primary', color: '#409EFF' },
none: { text: '未入库', tagType: 'info', color: '#909399' }
}
// 格式化产品入库状态
export function formatProductStorageStatus(value: string): { text: string; config: any } {
const config = productStorageStatusConfig[value] || productStorageStatusConfig.none
return { text: config.text, config }
}
export const deliveryMethodConfig: any = {
truck: { text: '货车', tagType: 'primary' },
express: { text: '快递', tagType: 'success' },
air_freight: { text: '空运', tagType: 'info' },
sea_freight: { text: '海运', tagType: 'warning' },
other: { text: '其他', tagType: '' }
}
export const loadingMethodConfig: any = {
with_pallet: { text: '带托盘', tagType: 'success' },
without_pallet: { text: '不带托盘', tagType: 'info' }
}
// 收货单号的枚举配置(类似 statusConfig),用于在筛选中加载对应选项
export const receivingConfig: any = {
eq: { text: '等于' },
ne: { text: '不等于' },
contains: { text: '包含' },
starts_with: { text: '开头为' },
like: { text: '模糊匹配' },
// 保留全部项定义以便未来扩展,但 availableFields 只会启用上面五个
ends_with: { text: '结尾为' },
// regex: { text: '正则匹配' }
}
// 数值字段通用配置,只开启常用的比较/范围操作
export const numberConfig: any = {
operators: ['eq', 'ne', 'gt', 'lt', 'ge', 'le'],
defaultOperator: 'ge'
}
// 时间格式化函数
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 '--'
}
}
function calculateValidityDays(productionDate?: string, expiryDate?: string): string {
if (!productionDate || !expiryDate) return '--'
const start = new Date(productionDate)
const end = new Date(expiryDate)
if (isNaN(start.getTime()) || isNaN(end.getTime())) return '--'
const diffDays = Math.floor((end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000))
return `${diffDays}天`
}
export const receivingColumns = [
{ prop: 'receiving_number', label: '收货单号', width: '110', fixed: 'left' },
{
prop: 'images',
label: '收货图片',
width: '120',
imgs: (row: any) => {
return row.images || []
}
},
{ prop: 'status', label: '收货状态', width: '90' },
{ prop: 'detail_status', label: '匹配状态', width: '90' },
{ prop: 'storage_status', label: '入库状态', width: '90' },
{ prop: 'is_review', label: '审核状态', width: '90' },
{ prop: 'store_name', label: '货主', width: '100' },
{ prop: 'total_items', label: '商品种类', width: '90', sortable: true },
{ prop: 'total_quantity', label: '总数量', width: '90', sortable: true },
{ prop: 'total_boxes', label: '总箱数', width: '90', sortable: true },
{ prop: 'total_pallets', label: '总托盘数', width: '90', sortable: true },
{ prop: 'license_plate', label: '车牌号', width: '100' },
{ prop: 'tracking_number', label: '物流单号', width: '120' },
{ prop: 'video_device_id', label: '录像设备ID', width: '140' },
{ prop: 'delivery_method', label: '来货方式', width: '90' },
{ prop: 'loading_method', label: '装卸方式', width: '100' },
{ prop: 'creator_name', label: '创建人', width: '100' },
{ prop: 'receiving_start_time', label: '收货开始', width: '150', sortable: true, formatter: (row: any) => formatDateTime(row.receiving_start_time) },
{ prop: 'receiving_end_time', label: '收货结束', width: '150', sortable: true, formatter: (row: any) => formatDateTime(row.receiving_end_time) },
{ prop: 'created_at', label: '创建时间', width: '150', sortable: true, formatter: (row: any) => formatDateTime(row.created_at) },
{ prop: 'updated_at', label: '更新时间', width: '150', sortable: true, formatter: (row: any) => formatDateTime(row.updated_at) },
{ prop: 'remark', label: '备注', minWidth: '120' },
{ prop: 'actions', label: '操作', width: '120', fixed: 'right' },
]
/** 货主侧收货单列表列(getStoreReceivingList 返回字段) */
export const receivingStoreColumns = [
{ prop: 'receiving_number', label: '收货单号', width: '110', fixed: 'left' },
{ prop: 'status', label: '收货状态', width: '90' },
{ prop: 'detail_status', label: '匹配状态', width: '90' },
{ prop: 'storage_status', label: '入库状态', width: '90' },
{ prop: 'total_items', label: '商品种类', width: '90', sortable: true },
{ prop: 'total_quantity', label: '总数量', width: '90', sortable: true },
{ prop: 'total_boxes', label: '总箱数', width: '90', sortable: true },
{ prop: 'total_pallets', label: '总托盘数', width: '90', sortable: true },
{ prop: 'available_quantity', label: '可用数量', width: '90' },
{ prop: 'lock_rate_display', label: '锁定率', width: '90' },
{ prop: 'license_plate', label: '车牌号', width: '100' },
{ prop: 'tracking_number', label: '物流单号', width: '120' },
{ prop: 'delivery_method', label: '来货方式', width: '90' },
{ prop: 'loading_method', label: '装卸方式', width: '100' },
{ prop: 'creator_name', label: '创建人', width: '100' },
{ prop: 'receiving_start_time', label: '收货开始', width: '150', sortable: true, formatter: (row: any) => formatDateTime(row.receiving_start_time) },
{ prop: 'receiving_end_time', label: '收货结束', width: '150', sortable: true, formatter: (row: any) => formatDateTime(row.receiving_end_time) },
{ prop: 'create_at_display', label: '创建时间', width: '150' },
{ prop: 'update_at_display', label: '更新时间', width: '150' },
{ prop: 'remark', label: '备注', minWidth: '120' },
]
// receiving配置(基础信息在前,流程状态在后;对齐待处理订单 ScanBox 分组)
export const availableFields: ReceivingScanFieldConfig[] = [
// ── 基础信息 ──
receivingScanBasicField({
value: 'receiving_number',
label: '收货单号',
type: 'text',
placeholder: '请输入收货单号',
operators: ['eq', 'ne', 'contains', 'starts_with', 'like'],
defaultOperator: 'eq'
}),
receivingScanBasicField({
value: 'store_id',
label: '货主',
type: 'select',
multiple: true,
filterable: true,
options: []
}),
receivingScanBasicField({
value: 'delivery_method',
label: '来货方式',
type: 'select',
options: Object.entries(deliveryMethodConfig).map(([v, c]: [string, any]) => ({ value: v, label: c.text }))
}),
receivingScanBasicField({
value: 'loading_method',
label: '装卸方式',
type: 'select',
placeholder: '请选择装卸方式',
options: Object.entries(loadingMethodConfig).map(([value, config]: [string, any]) => ({
value,
label: (config as any).text
}))
}),
receivingScanBasicField({
value: 'license_plate',
label: '车牌号',
type: 'text',
placeholder: '请输入车牌号',
operators: ['eq', 'contains'],
defaultOperator: 'eq'
}),
receivingScanBasicField({
value: 'tracking_number',
label: '物流单号',
type: 'text',
placeholder: '请输入物流单号',
operators: ['eq', 'contains'],
defaultOperator: 'eq'
}),
receivingScanBasicField({
value: 'total_items',
label: '商品种类',
type: 'number',
placeholder: '请输入商品种类数',
operators: numberConfig.operators,
defaultOperator: numberConfig.defaultOperator
}),
receivingScanBasicField({
value: 'total_quantity',
label: '总数量',
type: 'number',
placeholder: '请输入总数量',
operators: numberConfig.operators,
defaultOperator: numberConfig.defaultOperator
}),
receivingScanBasicField({
value: 'total_boxes',
label: '总箱数',
type: 'number',
placeholder: '请输入总箱数',
operators: numberConfig.operators,
defaultOperator: numberConfig.defaultOperator
}),
receivingScanBasicField({
value: 'total_pallets',
label: '总托盘数',
type: 'number',
placeholder: '请输入总托盘数',
operators: numberConfig.operators,
defaultOperator: numberConfig.defaultOperator
}),
receivingScanBasicField({
value: 'creator_id',
label: '创建人',
type: 'select',
placeholder: '请选择创建人',
filterable: true,
options: []
}),
receivingScanBasicField({
value: 'remark',
label: '备注',
type: 'text',
placeholder: '请输入备注关键词',
operators: ['eq', 'contains'],
defaultOperator: 'eq'
}),
receivingScanBasicField({
value: 'video_device_id',
label: '录像设备ID',
type: 'text',
placeholder: '请输入录像设备ID',
operators: ['eq', 'contains'],
defaultOperator: 'eq'
}),
// ── 流程状态 ──
receivingScanWorkflowField({
value: 'status',
label: '收货状态',
type: 'select',
options: Object.entries(statusConfig).map(([v, c]) => ({ value: v, label: c.text }))
}),
receivingScanWorkflowField({
value: 'detail_status',
label: '匹配状态',
type: 'select',
options: Object.entries(detailStatusConfig).map(([v, c]) => ({ value: v, label: c.text }))
}),
receivingScanWorkflowField({
value: 'storage_status',
label: '入库状态',
type: 'select',
options: [
{ value: 'waiting', label: '待入库' },
{ value: 'none', label: '未入库' },
{ value: 'partial', label: '部分入库' },
{ value: 'all', label: '已入库' }
]
}),
receivingScanWorkflowField({
value: 'is_review',
label: '审核状态',
type: 'select',
placeholder: '请选择审核状态',
options: [
{ value: 0, label: '未审核' },
{ value: 1, label: '已审核' }
]
}),
// ── 时间 ──
receivingScanTimeField({
value: 'created_at',
label: '创建时间',
type: 'daterange',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间'
}),
receivingScanTimeField({
value: 'updated_at',
label: '更新时间',
type: 'daterange',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间'
}),
receivingScanTimeField({
value: 'receiving_start_time',
label: '收货开始时间',
type: 'daterange',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间'
}),
receivingScanTimeField({
value: 'receiving_end_time',
label: '收货结束时间',
type: 'daterange',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间'
}),
]
export const addReceving = [
{ prop: 'receiving_number', label: '收货单号', type: 'input' },
]
// 详情面板表单配置
export const detailpanel = [
{ prop: 'receiving_number', label: '收货单号', type: 'input', disabled: true },
{ prop: 'store_name', label: '货主', type: 'input', disabled: true },
{ prop: 'creator_name', label: '创建人', type: 'input', disabled: true },
// { prop: 'status', label: '收货状态', type: 'select', disabled: true},
// { prop: 'detail_status', label: '匹配状态', type: 'select' },
// { prop: 'storage_status', label: '入库状态', type: 'select' },
{ prop: 'delivery_method', label: '来货方式', type: 'select' },
{ prop: 'license_plate', label: '车牌号', type: 'input' },
{ prop: 'loading_method', label: '装卸方式', type: 'select' },
// { prop: 'total_items', label: '商品种类', type: 'number' },
// { prop: 'total_quantity', label: '总数量', type: 'number' },
// { prop: 'total_boxes', label: '总箱数', type: 'number' },
// { prop: 'total_pallets', label: '总托盘数', type: 'number' },
{ prop: 'remark', label: '备注', type: 'textarea' },
]
export const productsnapshop = [
{prop: 'id', label: '系统商品ID', width: '160', fixed: 'left' },
{ prop: 'name', label: '商品名称', width: '160' },
{ prop: 'barcode', label: '商品条码', width: '160' },
{ prop: 'spec', label: '规格型号', width: '160' },
{prop: 'origin', label: '产地', width: '160' },
{ prop: 'brand', label: '品牌', width: '160' },
{ prop: 'module', label: '所属模块', width: '160' },
]
export const productdetail = [
{ prop: 'id', label: 'ID', width: '100' },
{ prop: 'product_name', label: '商品名称', width: '160', fixed: 'left' },
{ prop: 'barcode', label: '商品条码', width: '160' },
{ prop: 'product_snapshot', label: '商品信息快照', width: '160' },
{ prop: 'system_product_id', label: '关联系统商品ID', width: '160' },
{ prop: 'actual_quantity', label: '实际收货数量', width: '160' },
{ prop: 'box_quantity', label: '箱数', width: '160' },
{ prop: 'boxes_per_pallet', label: '箱规', width: '160' },
{ prop: 'weight', label: '重量(g)', width: '160' },
{ prop: 'pallet_quantity', label: '托盘数', width: '160' },
{ prop: 'receiving_time', label: '收货时间', width: '160' },
{ prop: 'receiving_status', label: '收货状态', width: '160' },
{ prop: 'storage_status', label: '入库状态', width: '160' },
{ prop: 'stored_quantity', label: '已入库数量', width: '160' },
{ prop: 'batch_number', label: '批次号', width: '160' },
{ prop: 'production_date', label: '生产日期', width: '160' },
{ prop: 'expiry_date', label: '保质期', width: '160' },
{ prop: 'remark', label: '备注', width: '160' },
{ prop: 'box_length', label: '箱长', width: '160' },
{ prop: 'box_width', label: '箱宽', width: '160' },
{ prop: 'box_height', label: '箱高', width: '160' },
{ prop: 'space_id', label: '存放位置', width: '160' },
{ prop: 'creator_id', label: '创建人ID', width: '160' },
{ prop: 'updated_at', label: '更新时间', width: '160' },
{ prop: 'created_at', label: '创建时间', width: '160' },
]
/** 商品明细 UpperTable 右侧操作列(明细绑定、编辑等按钮通过 #column-actions 渲染) */
export const PRODUCT_DETAIL_ACTIONS_COLUMN = {
prop: 'actions',
label: '操作',
minWidth: 400,
width: 400,
align: 'center',
fixed: 'right',
showOverflowTooltip: false,
className: 'product-detail-actions-col'
} as const
export const productquick = [
{ prop: 'images', label: '图片', width: '120', align: 'center', fixed: 'left' },
{ prop: 'product_name', label: '商品名称', width: '200', fixed: 'left' },
{ prop: 'barcode', label: '条码', width: '150' },
{ prop: 'match_status', label: '匹配状态', width: '100', align: 'center' },
{ prop: 'actual_quantity', label: '收货数量', width: '100', align: 'right' },
{ prop: 'box_quantity', label: '箱数', width: '100', align: 'right' },
{ prop: 'boxes_per_pallet', label: '箱规', width: '100', align: 'right' },
{ prop: 'weight', label: '重量(g)', width: '100', align: 'right' },
{ prop: 'batch_number', label: '批次号', width: '120' },
{ prop: 'production_date', label: '生产日期', width: '120' },
{ prop: 'expiry_date', label: '到期日期', width: '120' },
{ prop: 'validity_period', label: '有效期', width: '120' },
{ prop: 'storage_status', label: '入库', width: '80', align: 'center' },
{ prop: 'space_id', label: '库位', width: '120' },
{ prop: 'remark', label: '备注', minWidth: '150' },
PRODUCT_DETAIL_ACTIONS_COLUMN,
]
/** 明细绑定表单:仅 detail_id + system_product_id 提交 bindDetailProduct */
export const bindDetailProductFormConfig = [
{ prop: 'detail_id', label: '明细ID', type: 'display' },
{ prop: 'product_name', label: '收货商品名称', type: 'display' },
{ prop: 'barcode', label: '收货条码', type: 'display' },
{ prop: 'current_system_product_id', label: '当前关联系统商品', type: 'display' },
{
prop: 'system_product_id',
label: '绑定系统商品',
type: 'product-picker',
required: true,
hint: '须选择当前仓库下的系统商品(StockWarehouse.id)'
}
]
export const windowtopbar = [
{ label: '基本信息', key: 'basic' },
// { label: '商品信息', key: 'product' },
{ label: '操作日志', key: 'logs' }
]
// 打印配置表单
export const printFormConfig = [
{ group: '基本信息', fields: [
{ prop: 'delivery_method', label: '来货方式', type: 'select', options: Object.entries(deliveryMethodConfig).map(([v, c]: [string, any]) => ({ value: v, label: c.text })) },
{ prop: 'license_plate', label: '车牌号', type: 'input' },
{ prop: 'receiving_number', label: '收货单号', type: 'input' },
{ prop: 'store_name', label: '货主', type: 'input' },
{ prop: 'total_items', label: '总商品种类', type: 'number' },
{ prop: 'total_quantity', label: '总商品数量', type: 'number' },
{ prop: 'total_boxes', label: '总箱数', type: 'number' },
]},
{ group: '商品明细', fields: [
{ prop: 'product_name', label: '商品名称', type: 'input' },
{ prop: 'barcode', label: '商品条码', type: 'input' },
{ prop: 'box_quantity', label: '箱数', type: 'number' },
{ prop: 'boxes_per_pallet', label: '箱规', type: 'number' },
{ prop: 'weight', label: '重量(g)', type: 'number' },
{ prop: 'actual_quantity', label: '实际收货数量', type: 'number' },
{ prop: 'remark', label: '明细备注', type: 'input' },
]}
]
export const printFormFields = [
...(printFormConfig[0]?.fields || []),
...(printFormConfig[1]?.fields || [])
]
export function formatReceivingData(list: any[] = []) {
return (list || []).map(item => ({
...item,
store_name: item.store?.store_remask || item['store.store_remask'] || '--',
creator_name: (() => {
try {
const s = JSON.parse(item.creator_snapshot || '{}')
return s.name || s.username || item.creator_id || '--'
} catch (e) {
return item.creator_id || '--'
}
})()
,
// 确保总箱数、总托盘数和更新时间字段存在并提供合理默认值
total_boxes: item.total_boxes ?? item.totalBoxes ?? ((item.details && Array.isArray(item.details)) ? item.details.reduce((sum: number, d: any) => sum + (d.box_count || d.boxes || 0), 0) : 0),
total_pallets: item.total_pallets ?? item.totalPallets ?? ((item.details && Array.isArray(item.details)) ? item.details.reduce((sum: number, d: any) => sum + (d.pallet_count || d.pallets || 0), 0) : 0),
updated_at: item.updated_at || item.updatedAt || item.update_time || item.last_modified || item.modified_at || item.updated || ''
}))
}
// 新建收货单配置
export const addReceivingFields = [
{ prop: 'store_id', label: '货主', type: 'select', filterable: true, options: [] },
{ prop: 'delivery_method', label: '来货方式', type: 'select', options: Object.entries(deliveryMethodConfig).map(([v, c]: [string, any]) => ({ value: v, label: c.text })) },
{ prop: 'loading_method', label: '装卸方式', type: 'select', options: Object.entries(loadingMethodConfig).map(([v, c]: [string, any]) => ({ value: v, label: c.text })) },
// 新增可选的总箱数与总托盘数字段
{ prop: 'total_boxes', label: '总箱数', type: 'input', placeholder: '请输入总箱数', optional: true },
{ prop: 'total_pallets', label: '总托盘数', type: 'input', placeholder: '请输入总托盘数', optional: true },
{ prop: 'license_plate', label: '车牌号', type: 'input' },
{ prop: 'tracking_number', label: '物流单号', type: 'input' },
{ prop: 'remark', label: '备注', type: 'textarea' }
]
/** 收货单列表主工具栏按钮(action 与 receiving/index.vue 内 toolbarActionMap 键一致) */
export const receivingToolbarButtons: ToolbarButtonConfig[] = [
{ key: 'refresh', label: '刷新', type: 'primary', size: 'small', loadingKey: 'loading', action: 'loadData' },
{ key: 'create', label: '添加收货单', type: 'primary', size: 'small', action: 'handleCreateReceiving' },
{
key: 'export',
label: '导出',
size: 'small',
loadingKey: 'exportLoading',
action: 'handleExportWaybill',
buttonType: 'dropdown',
dropdownOptions: [
{ label: '不含明细', action: 'handleExportWaybill' },
{ label: '含明细', action: 'handleExportItem', divided: true }
]
},
{ key: 'columnConfig', label: '字段设置', size: 'small', action: 'openColumnConfigPanel' },
{
key: 'toggleDetail',
label: '显示详情',
dynamicLabelKey: 'detailToggleLabel',
size: 'small',
action: 'toggleDetailVisible'
},
{
key: 'complete',
label: '完成收货',
type: 'primary',
size: 'small',
disabledKey: 'hasNoSelection',
action: 'confirmcomplete'
},
{
key: 'batchCancel',
label: '批量作废',
size: 'small',
disabledKey: 'hasNoSelection',
action: 'confirmBatchCancel'
},
{
key: 'reject',
label: '批量驳回',
type: 'warning',
size: 'small',
disabledKey: 'hasNoSelection',
action: 'handleRejectReceiving'
},
{
key: 'review',
label: '批量审核',
type: 'primary',
size: 'small',
disabledKey: 'hasNoSelection',
loadingKey: 'reviewLoading',
action: 'handleReviewReceiving'
},
{
key: 'quickPutaway',
label: '快捷入库',
type: 'success',
size: 'small',
disabledKey: 'singleSelectionOnly',
loadingKey: 'quickPutawayLoading',
action: 'handleQuickPutaway'
},
{
key: 'print',
label: '打印收货单',
type: 'info',
size: 'small',
disabledKey: 'hasNoSelection',
action: 'handleOpenPrintDialog'
}
]