1291 lines
45 KiB
TypeScript
1291 lines
45 KiB
TypeScript
import {
|
||
buyerMessageHasFilterOptions,
|
||
scanBasicField,
|
||
type ToolbarButtonConfig
|
||
} from '@/views/order/orderManagement/config/order-common-config'
|
||
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
||
import { orderPendingOrder } from '@/api/order.pendingorder/orderpendingOrder'
|
||
import {
|
||
isOrderIndexApiSuccess,
|
||
normalizeOrderDetailItems,
|
||
parseOrderDetailPayload,
|
||
parseOrderListResponse
|
||
} from '@/views/order/orderManagement/utils/order-index-helpers'
|
||
|
||
/** ScanBox 筛选字段分组(波次模块专用) */
|
||
export const WAVE_SCAN_FIELD_GROUPS = {
|
||
wave: '波次信息',
|
||
process: '流程状态',
|
||
logistics: '物流信息',
|
||
person: '人员信息',
|
||
stats: '商品统计',
|
||
strategy: '策略配置',
|
||
task: '任务信息',
|
||
status: '状态筛选',
|
||
time: '时间范围',
|
||
} as const
|
||
|
||
type WaveScanFieldGroupKey = keyof typeof WAVE_SCAN_FIELD_GROUPS
|
||
|
||
/** 为波次 ScanBox 字段附加分组标签 */
|
||
export function waveScanField<G extends WaveScanFieldGroupKey>(
|
||
group: G,
|
||
field: Record<string, any>
|
||
) {
|
||
return { ...field, group: WAVE_SCAN_FIELD_GROUPS[group] }
|
||
}
|
||
|
||
/** 工具栏按钮:可限定仅在对应波次页签显示(1 团购 / 2 散单) */
|
||
export type WaveToolbarButtonConfig = ToolbarButtonConfig & {
|
||
onlyForWaveType?: 1 | 2
|
||
}
|
||
|
||
/** ScanBox 默认 props(全站 scan-box 侧栏宽度统一为 250px) */
|
||
export const waveScanBoxConfig = {
|
||
width: '250px',
|
||
treeProps: { children: 'children', label: 'label' } as const,
|
||
autoSubmit: false
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/** 主表 UpperTable 展示与行为默认值 */
|
||
export const waveUpperTableDefaults = {
|
||
title: '波次列表',
|
||
enableColumnConfig: true,
|
||
showIndex: true,
|
||
showSelection: true,
|
||
emptyText: '暂无波次数据'
|
||
}
|
||
|
||
/** 左侧筛选可用字段 */
|
||
export const waveAvailableFields = [
|
||
waveScanField('wave', { label: '波次号', value: 'wave_no', type: 'text' }),
|
||
waveScanField('wave', {
|
||
label: '波次类型',
|
||
value: 'wave_type',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '团购', value: 1 },
|
||
{ label: '散单', value: 2 }
|
||
]
|
||
}),
|
||
waveScanField('wave', {
|
||
label: '波次状态',
|
||
value: 'wave_status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '自动加团中', value: 0 },
|
||
{ label: '已就绪', value: 1 }
|
||
]
|
||
}),
|
||
waveScanField('wave', {
|
||
label: '区分快递',
|
||
value: 'distinguish_express',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '是', value: 1 },
|
||
{ label: '否', value: 0 }
|
||
]
|
||
}),
|
||
waveScanField('process', {
|
||
label: '库位分配',
|
||
value: 'storage_assignment_status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '未分配', value: '未分配' },
|
||
{ label: '已分配', value: '已分配' },
|
||
]
|
||
}),
|
||
waveScanField('process', {
|
||
label: '快递分配',
|
||
value: 'express_assignment_status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '未分配', value: 'unassigned' },
|
||
{ label: '已分配', value: 'assigned' },
|
||
]
|
||
}),
|
||
waveScanField('process', {
|
||
label: '打印状态',
|
||
value: 'print_assignment_status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '未打印', value: 'unprinted' },
|
||
{ label: '已打印', value: 'printed' },
|
||
]
|
||
}),
|
||
waveScanField('process', {
|
||
label: '复核状态',
|
||
value: 'review_assignment_status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '未复核', value: 'unreviewed' },
|
||
{ label: '已复核', value: 'reviewed' },
|
||
]
|
||
}),
|
||
waveScanField('logistics', { label: '快递', value: 'logistics_name', type: 'text' }),
|
||
waveScanField('person', { label: '创建人', value: 'creator', type: 'text' }),
|
||
waveScanField('stats', { label: '最小订单数', value: 'total_orders_min', type: 'number' }),
|
||
waveScanField('stats', { label: '最大订单数', value: 'total_orders_max', type: 'number' }),
|
||
waveScanField('stats', { label: '最小已处理订单', value: 'processed_orders_min', type: 'number' }),
|
||
waveScanField('stats', { label: '最大已处理订单', value: 'processed_orders_max', type: 'number' }),
|
||
]
|
||
|
||
/** 抓取散单候选:左侧筛选可用字段 */
|
||
export const fallbackOrderAvailableFields = [
|
||
scanBasicField({ label: '订单号', value: 'delivery_no', type: 'text' }),
|
||
scanBasicField({ label: '物流单号', value: 'tracking_no', type: 'text' }),
|
||
scanBasicField({ label: '店铺名称', value: 'store_name', type: 'text' }),
|
||
scanBasicField({ label: '平台', value: 'sys_platform_name', type: 'select', options: [] }),
|
||
scanBasicField({ label: '物流公司', value: 'sys_logistics_name', type: 'select', options: [] }),
|
||
waveScanField('stats', { label: '商品种数最小值', value: 'items_count_min', type: 'number' }),
|
||
waveScanField('stats', { label: '商品种数最大值', value: 'items_count_max', type: 'number' }),
|
||
waveScanField('stats', { label: '商品总数最小值', value: 'items_total_min', type: 'number' }),
|
||
waveScanField('stats', { label: '商品总数最大值', value: 'items_total_max', type: 'number' }),
|
||
scanBasicField({
|
||
label: '有无留言',
|
||
value: 'buyer_message_has',
|
||
type: 'select',
|
||
options: buyerMessageHasFilterOptions
|
||
}),
|
||
scanBasicField({ label: '买家留言', value: 'buyer_message', type: 'text' }),
|
||
]
|
||
|
||
/** 不符合波次策略订单列表:UpperTable 列配置 */
|
||
export const fallbackOrderColumns = [
|
||
{ prop: 'delivery_no', label: '订单号', minWidth: 180, fixed: 'left' },
|
||
{ prop: 'tracking_no', label: '物流单号', minWidth: 160 },
|
||
{ prop: 'store_name', label: '店铺', minWidth: 140 },
|
||
{ prop: 'sys_platform_name', label: '平台', minWidth: 120 },
|
||
{ prop: 'sys_logistics_name', label: '物流公司', minWidth: 130 },
|
||
{ prop: 'province', label: '省份', minWidth: 100 },
|
||
{ prop: 'items_count', label: '商品种数', minWidth: 100, align: 'right' },
|
||
{ prop: 'items_total', label: '商品总数', minWidth: 100, align: 'right' },
|
||
{ prop: 'items_weight', label: '商品重量kg', minWidth: 110, align: 'right' },
|
||
{ prop: 'item_snapshot', label: '商品快照', minWidth: 260 },
|
||
{ prop: 'wave_scan_result', label: '扫描结果', minWidth: 110, align: 'center' },
|
||
{ prop: 'buyer_message', label: '买家留言', minWidth: 180 },
|
||
{ prop: 'updated_at', label: '更新时间', minWidth: 170 }
|
||
]
|
||
|
||
/** 波次策略:左侧筛选可用字段 */
|
||
export const waveStrategyAvailableFields = [
|
||
waveScanField('strategy', { label: '策略名称', value: 'strategy_name', type: 'text' }),
|
||
waveScanField('strategy', {
|
||
label: '策略类型',
|
||
value: 'strategy_type',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '散单', value: 1 },
|
||
{ label: '团购', value: 2 }
|
||
]
|
||
}),
|
||
waveScanField('strategy', { label: '波次前缀', value: 'wave_prefix', type: 'text' }),
|
||
waveScanField('status', {
|
||
label: '启用状态',
|
||
value: 'status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '启用', value: 1 },
|
||
{ label: '停用', value: 0 }
|
||
]
|
||
}),
|
||
waveScanField('status', {
|
||
label: '批次模式',
|
||
value: 'batch_mode',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '团购', value: 0 },
|
||
{ label: '单品单件', value: 1 },
|
||
{ label: '先拣后分', value: 2 },
|
||
{ label: '边拣边分', value: 3 },
|
||
{ label: '边拣边分H型', value: 4 },
|
||
{ label: '播种墙', value: 5 },
|
||
{ label: '流利架', value: 6 }
|
||
]
|
||
}),
|
||
]
|
||
|
||
/** 波次策略:UpperTable 列配置 */
|
||
export const waveStrategyColumns = [
|
||
{ prop: 'id', label: 'ID', width: 72, align: 'center', fixed: 'left' },
|
||
{ prop: 'strategy_name', label: '策略名称', minWidth: 160, fixed: 'left' },
|
||
{ prop: 'wave_prefix', label: '波次前缀', width: 100, align: 'center' },
|
||
{ prop: 'matched_order_count_filtered', label: '匹配订单数', width: 110, align: 'center' },
|
||
{ prop: 'next_fetch_order_count', label: '下一波抓取数量', width: 130, align: 'center' },
|
||
{ prop: 'strategy_type', label: '策略类型', width: 90, align: 'center' },
|
||
{ prop: 'status', label: '状态', width: 80, align: 'center' },
|
||
{ prop: 'batch_mode', label: '批次模式', width: 110, align: 'center' },
|
||
{ prop: 'sku_range', label: 'SKU区间', minWidth: 120, align: 'center' },
|
||
{ prop: 'qty_range', label: '件数区间', minWidth: 120, align: 'center' },
|
||
{ prop: 'same_structure_range', label: '同结构区间', minWidth: 120, align: 'center' },
|
||
{ prop: 'require_same_express', label: '同快递', width: 80, align: 'center' },
|
||
{ prop: 'allow_cross_owner', label: '跨货主', width: 80, align: 'center' },
|
||
{ prop: 'batch_max_orders', label: '单波最大订单', width: 120, align: 'center' },
|
||
{ prop: 'batch_max_skus', label: '单波最大SKU', width: 120, align: 'center' },
|
||
{ prop: 'group_batch_max_orders', label: '团购单波最大', width: 120, align: 'center' },
|
||
{ prop: 'create_time', label: '创建时间', minWidth: 168 },
|
||
{ prop: 'update_time', label: '更新时间', minWidth: 168 },
|
||
{ prop: 'description', label: '说明', minWidth: 160 },
|
||
{ prop: 'operation', label: '操作', width: 170, fixed: 'right', align: 'center' }
|
||
]
|
||
|
||
/** 主表列配置 */
|
||
export const waveBatchColumns = [
|
||
// { prop: 'wave_id', label: '波次ID', minWidth: 160, fixed: 'left' },
|
||
{ prop: 'wave_no', label: '波次编号', minWidth: 180, fixed: 'left' },
|
||
{ prop: 'wave_type', label: '波次类型', minWidth: 96 },
|
||
{ prop: 'wave_status', label: '状态', minWidth: 110 },
|
||
{ prop: 'total_orders', label: '总订单数', minWidth: 110, align: 'right' },
|
||
{ prop: 'order_count', label: '订单数量', minWidth: 100, align: 'right' },
|
||
{ prop: 'processed_orders', label: '已处理订单', minWidth: 108, align: 'right' },
|
||
// { prop: 'item_detail_machine', label: '商品结构', minWidth: 320 },
|
||
// { prop: 'item_part_type', label: '商品类型', minWidth: 120 },
|
||
// { prop: 'item_part', label: '商品部位', minWidth: 220 },
|
||
{ prop: 'distinguish_express', label: '区分快递', minWidth: 100 },
|
||
{ prop: 'storage_assignment_status', label: '库位分配', minWidth: 120 },
|
||
{ prop: 'express_assignment_status', label: '快递分配', minWidth: 120 },
|
||
{ prop: 'print_assignment_status', label: '打印状态', minWidth: 110 },
|
||
{ prop: 'review_assignment_status', label: '复核状态', minWidth: 110 },
|
||
{ prop: 'unreviewed_order_count', label: '未复核数', minWidth: 96, align: 'right' },
|
||
{ prop: 'logistics_name', label: '快递', minWidth: 120 },
|
||
{ prop: 'item_snapshot_key', label: '商品快照键', minWidth: 320 },
|
||
{ prop: 'creator', label: '创建人', minWidth: 100 },
|
||
{ prop: 'warehouse_id', label: '仓库ID', minWidth: 110 },
|
||
{ prop: 'create_time', label: '创建时间', minWidth: 168 },
|
||
{ prop: 'update_time', label: '更新时间', minWidth: 168 },
|
||
{ prop: 'operation', label: '操作', minWidth: 110, fixed: 'right' }
|
||
]
|
||
|
||
/** 列表查询 where 白名单(与 sanitizeWaveWhere 一致) */
|
||
export const waveWhereAllowedFieldList = [
|
||
'wave_id',
|
||
'wave_no',
|
||
'wave_type',
|
||
'wave_status',
|
||
'creator',
|
||
'logistics_name',
|
||
'item_part_type',
|
||
'item_part',
|
||
'item_snapshot_key',
|
||
'item_detail_machine',
|
||
'distinguish_express',
|
||
'storage_assignment_status',
|
||
'express_assignment_status',
|
||
'print_assignment_status',
|
||
'review_assignment_status',
|
||
'total_orders_min',
|
||
'total_orders_max',
|
||
'processed_orders_min',
|
||
'processed_orders_max',
|
||
'source'
|
||
] as const
|
||
|
||
export const waveWhereAllowedFields = new Set<string>(waveWhereAllowedFieldList)
|
||
|
||
/** 列表/详情展示:接口可能返回英文枚举或历史中文 */
|
||
const waveExpressAssignmentStatusLabelMap: Record<string, string> = {
|
||
unassigned: '未分配',
|
||
partially_assigned: '部分分配',
|
||
assigned: '已分配',
|
||
未分配: '未分配',
|
||
部分分配: '部分分配',
|
||
已分配: '已分配'
|
||
}
|
||
|
||
const wavePrintAssignmentStatusLabelMap: Record<string, string> = {
|
||
unprinted: '未打印',
|
||
partially_printed: '部分打印',
|
||
printed: '已打印',
|
||
未打印: '未打印',
|
||
部分打印: '部分打印',
|
||
已打印: '已打印'
|
||
}
|
||
|
||
const waveReviewAssignmentStatusLabelMap: Record<string, string> = {
|
||
unreviewed: '未复核',
|
||
partially_reviewed: '部分复核',
|
||
reviewed: '已复核',
|
||
未复核: '未复核',
|
||
部分复核: '部分复核',
|
||
已复核: '已复核'
|
||
}
|
||
|
||
export function formatWaveExpressAssignmentStatusLabel(value: string | number | null | undefined): string {
|
||
if (value === undefined || value === null || value === '') return '—'
|
||
const key = String(value).trim()
|
||
return waveExpressAssignmentStatusLabelMap[key] ?? waveExpressAssignmentStatusLabelMap[key.toLowerCase()] ?? key
|
||
}
|
||
|
||
export function formatWavePrintAssignmentStatusLabel(value: string | number | null | undefined): string {
|
||
if (value === undefined || value === null || value === '') return '—'
|
||
const key = String(value).trim()
|
||
return wavePrintAssignmentStatusLabelMap[key] ?? wavePrintAssignmentStatusLabelMap[key.toLowerCase()] ?? key
|
||
}
|
||
|
||
export function formatWaveReviewAssignmentStatusLabel(value: string | number | null | undefined): string {
|
||
if (value === undefined || value === null || value === '') return '—'
|
||
const key = String(value).trim()
|
||
return waveReviewAssignmentStatusLabelMap[key] ?? waveReviewAssignmentStatusLabelMap[key.toLowerCase()] ?? key
|
||
}
|
||
|
||
/** 快递分配 / 打印状态 / 库位分配等聚合状态列的 tag 类型(兼容英文枚举与中文文案) */
|
||
export function getWaveAssignmentAggregateTagType(value: string | number | null | undefined): 'success' | 'warning' | 'info' | 'danger' {
|
||
const v = String(value ?? '').toLowerCase().trim()
|
||
if (v === 'unassigned' || v === 'unprinted' || v === 'unsynced' || v === 'unreviewed') return 'info'
|
||
if (v === 'partially_assigned' || v === 'partially_printed' || v === 'partially_synced' || v === 'partially_reviewed') return 'warning'
|
||
if (v === 'assigned' || v === 'printed' || v === 'synced' || v === 'reviewed') return 'success'
|
||
const text = String(value ?? '')
|
||
if (text.includes('异常') || text.includes('失败') || text.includes('超时')) return 'danger'
|
||
if (text.includes('处理中')) return 'warning'
|
||
if (text.includes('已分配') || text.includes('完成') || text.includes('已打印')) return 'success'
|
||
if (text.includes('部分')) return 'warning'
|
||
if (text.includes('未分配') || text.includes('未打印')) return 'info'
|
||
return 'info'
|
||
}
|
||
|
||
/**
|
||
* 主工具栏按钮(action 与波次列表页内 toolbarActionMap 键一致)
|
||
*/
|
||
export const waveToolbarButtons: WaveToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', type: 'primary', size: 'small', loadingKey: 'loading', action: 'loadData' },
|
||
{ key: 'columnConfig', label: '字段设置', size: 'small', action: 'openColumnConfigPanel' },
|
||
{
|
||
key: 'toggleDetail',
|
||
label: '显示详情',
|
||
dynamicLabelKey: 'detailToggleLabel',
|
||
size: 'small',
|
||
action: 'toggleDetailVisible'
|
||
},
|
||
{
|
||
key: 'batchPrint',
|
||
label: '批量打印(0)',
|
||
dynamicLabelKey: 'batchPrintTotal',
|
||
type: 'info',
|
||
size: 'small',
|
||
disabledKey: 'batchPrintDisabled',
|
||
loadingKey: 'batchPrintLoading',
|
||
action: 'handleBatchPrint',
|
||
onlyForWaveType: 1
|
||
},
|
||
{
|
||
key: 'batchOutboundPrint',
|
||
label: '打印货单(0)',
|
||
dynamicLabelKey: 'batchOutboundPrintTotal',
|
||
type: 'info',
|
||
size: 'small',
|
||
disabledKey: 'batchOutboundPrintDisabled',
|
||
loadingKey: 'batchOutboundPrintLoading',
|
||
action: 'handleBatchOutboundPrint',
|
||
onlyForWaveType: 2
|
||
},
|
||
{
|
||
key: 'batchPlatformPrint',
|
||
label: '批量打印(平台)(0)',
|
||
dynamicLabelKey: 'batchPlatformPrintTotal',
|
||
type: 'info',
|
||
plain: true,
|
||
size: 'small',
|
||
disabledKey: 'batchPlatformPrintDisabled',
|
||
loadingKey: 'batchPlatformPrintLoading',
|
||
action: 'handleBatchPlatformPrint'
|
||
},
|
||
{
|
||
key: 'printerComponentConnection',
|
||
label: '打印组件连接',
|
||
type: 'primary',
|
||
plain: true,
|
||
size: 'small',
|
||
action: 'openPrinterComponentConnectionDialog',
|
||
onlyForWaveType: 2
|
||
},
|
||
{
|
||
key: 'batchPrintPickingList',
|
||
label: '批量打印拣货单(0)',
|
||
dynamicLabelKey: 'batchPickingPrintTotal',
|
||
type: 'info',
|
||
plain: true,
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchPrintLoading',
|
||
action: 'handleBatchPrintPickingList',
|
||
onlyForWaveType: 2
|
||
},
|
||
{
|
||
key: 'batchAutoGrouping',
|
||
label: '批量改为自动加团',
|
||
type: 'warning',
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchAutoGroupingLoading',
|
||
action: 'handleBatchAutoGrouping'
|
||
},
|
||
{
|
||
key: 'batchFinishAutoGrouping',
|
||
label: '批量结束自动加团',
|
||
type: 'success',
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchFinishAutoGroupingLoading',
|
||
action: 'handleBatchFinishAutoGrouping'
|
||
},
|
||
{
|
||
key: 'batchCancel',
|
||
label: '批量取消波次',
|
||
type: 'danger',
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchCancelLoading',
|
||
action: 'handleBatchCancel'
|
||
},
|
||
{
|
||
key: 'batchAllocateExpress',
|
||
label: '快速分配快递号',
|
||
type: 'success',
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchAllocateExpressLoading',
|
||
action: 'handleBatchAllocateExpress'
|
||
},
|
||
{
|
||
key: 'batchAllocateStorage',
|
||
label: '批量分配储位',
|
||
type: 'primary',
|
||
plain: true,
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchAllocateStorageLoading',
|
||
action: 'handleBatchAllocateStorage'
|
||
},
|
||
{
|
||
key: 'batchRemoveExceptionOrders',
|
||
label: '批量移除异常订单',
|
||
type: 'danger',
|
||
plain: true,
|
||
size: 'small',
|
||
disabledKey: 'noSelection',
|
||
loadingKey: 'batchRemoveExceptionOrdersLoading',
|
||
action: 'handleBatchRemoveExceptionOrders'
|
||
},
|
||
{
|
||
key: 'fetchGroupOrder',
|
||
label: '抓取团购单',
|
||
type: 'warning',
|
||
size: 'small',
|
||
action: 'openGroupOrderDialog',
|
||
onlyForWaveType: 1
|
||
},
|
||
// {
|
||
// key: 'fetchSingleOrder',
|
||
// label: '抓取散单候选',
|
||
// type: 'warning',
|
||
// size: 'small',
|
||
// action: 'openSingleOrderDialog',
|
||
// onlyForWaveType: 2
|
||
// }
|
||
]
|
||
|
||
export function getWaveToolbarButtons(waveType: 1 | 2): WaveToolbarButtonConfig[] {
|
||
return waveToolbarButtons.filter(
|
||
(b) => b.onlyForWaveType === undefined || b.onlyForWaveType === waveType
|
||
)
|
||
}
|
||
|
||
/** 解析 order.print.getWavePlatformPrintData 响应(支持 res.data 包裹) */
|
||
export function unwrapWavePlatformPrintPayload(res: unknown): WavePlatformPrintDataPayload {
|
||
const toObject = (v: unknown): Record<string, unknown> | undefined => {
|
||
if (!v || typeof v !== 'object' || Array.isArray(v)) return undefined
|
||
return v as Record<string, unknown>
|
||
}
|
||
|
||
const toOrderList = (v: unknown): Record<string, unknown>[] => {
|
||
if (!Array.isArray(v)) return []
|
||
return v.filter((x) => x && typeof x === 'object') as Record<string, unknown>[]
|
||
}
|
||
|
||
// 兼容后端直接返回数组:[{ wave_id, wave_no, order_count, platforms: [...] }]
|
||
const normalizeWaveGroups = (list: unknown): unknown[] | undefined => {
|
||
if (!Array.isArray(list)) return undefined
|
||
const groups = list
|
||
.filter((x) => x && typeof x === 'object')
|
||
.map((wave) => {
|
||
const waveObj = wave as Record<string, unknown>
|
||
const rawPlatforms = Array.isArray(waveObj.platforms) ? waveObj.platforms : []
|
||
const platforms = rawPlatforms
|
||
.filter((p) => p && typeof p === 'object')
|
||
.map((p) => {
|
||
const platformObj = p as Record<string, unknown>
|
||
const orders = toOrderList(platformObj.orders ?? platformObj.order_list)
|
||
return {
|
||
...platformObj,
|
||
orders
|
||
}
|
||
})
|
||
return {
|
||
wave_id: waveObj.wave_id,
|
||
wave_no: waveObj.wave_no,
|
||
order_count: waveObj.order_count,
|
||
platforms
|
||
}
|
||
})
|
||
return groups
|
||
}
|
||
|
||
const r = res as Record<string, unknown> | null | undefined
|
||
|
||
// 情况1:顶层就是波次数组
|
||
if (Array.isArray(res)) {
|
||
const waveGroups = normalizeWaveGroups(res)
|
||
const wave_ids = (waveGroups || [])
|
||
.map((x) => (x && typeof x === 'object' ? (x as Record<string, unknown>).wave_id : undefined))
|
||
.filter((id) => id !== undefined && id !== null && id !== '') as Array<number | string>
|
||
return {
|
||
wave_ids: wave_ids.length ? wave_ids : undefined,
|
||
waveGroups,
|
||
platform_groups: undefined,
|
||
order_list: undefined,
|
||
summary: undefined,
|
||
ext: undefined
|
||
}
|
||
}
|
||
|
||
const inner =
|
||
r?.data !== undefined && r?.data !== null && typeof r.data === 'object' && !Array.isArray(r.data)
|
||
? (r.data as Record<string, unknown>)
|
||
: (r as Record<string, unknown>) || {}
|
||
|
||
// 情况2:res.data 是波次数组
|
||
if (Array.isArray(r?.data)) {
|
||
const waveGroups = normalizeWaveGroups(r.data)
|
||
const wave_ids = (waveGroups || [])
|
||
.map((x) => (x && typeof x === 'object' ? (x as Record<string, unknown>).wave_id : undefined))
|
||
.filter((id) => id !== undefined && id !== null && id !== '') as Array<number | string>
|
||
return {
|
||
wave_ids: wave_ids.length ? wave_ids : undefined,
|
||
waveGroups,
|
||
platform_groups: undefined,
|
||
order_list: undefined,
|
||
summary: undefined,
|
||
ext: undefined
|
||
}
|
||
}
|
||
|
||
const summaryRaw = inner?.summary
|
||
const summary = toObject(summaryRaw)
|
||
const wave_ids = Array.isArray(inner?.wave_ids) ? (inner.wave_ids as Array<number | string>) : undefined
|
||
const waveGroups = Array.isArray(inner?.waveGroups)
|
||
? inner.waveGroups
|
||
: normalizeWaveGroups((inner as Record<string, unknown>).wave_list)
|
||
const locked_wave_groups = Array.isArray(inner?.locked_wave_groups)
|
||
? normalizeWaveGroups(inner.locked_wave_groups)
|
||
: undefined
|
||
const locked_orders = toOrderList(inner?.locked_orders)
|
||
const locked_count_raw = (inner as Record<string, unknown>)?.locked_count
|
||
const locked_count =
|
||
locked_count_raw !== undefined && locked_count_raw !== null && Number.isFinite(Number(locked_count_raw))
|
||
? Number(locked_count_raw)
|
||
: undefined
|
||
const platform_groups = Array.isArray(inner?.platform_groups) ? inner.platform_groups : undefined
|
||
const order_list = toOrderList(inner?.order_list)
|
||
const extRaw = inner?.ext
|
||
const ext = toObject(extRaw)
|
||
return {
|
||
summary,
|
||
wave_ids,
|
||
waveGroups,
|
||
locked_wave_groups,
|
||
locked_orders: locked_orders.length ? locked_orders : undefined,
|
||
locked_count,
|
||
platform_groups,
|
||
order_list: order_list.length ? order_list : undefined,
|
||
ext
|
||
}
|
||
}
|
||
|
||
/** 异步任务状态文案 */
|
||
export const waveFetchTaskStatusTextMap: Record<string, string> = {
|
||
submitted: '已受理',
|
||
running: '进行中',
|
||
success: '成功',
|
||
failed: '失败',
|
||
not_found: '未找到'
|
||
}
|
||
|
||
/** 波次状态文案 */
|
||
export const waveStatusTextMap: Record<string, string> = {
|
||
'-1': '已取消',
|
||
'0': '自动加团中',
|
||
'1': '已就绪',
|
||
'2': '已打印',
|
||
'3': '拣货中',
|
||
'4': '拣货完成',
|
||
'5': '复核完成',
|
||
'6': '打包完成',
|
||
cancelled: '已取消',
|
||
pending: '自动加团中',
|
||
assigned: '已就绪'
|
||
}
|
||
|
||
/** 波次类型文案 */
|
||
export const waveTypeTextMap: Record<string, string> = {
|
||
'1': '团购',
|
||
'2': '散单'
|
||
}
|
||
|
||
/** 库位分配状态文案 */
|
||
export const waveStorageAssignmentStatusTextMap: Record<string, string> = {
|
||
none: '未分配',
|
||
no_error: '未分配',
|
||
pending: '处理中',
|
||
padding: '处理中',
|
||
processing: '处理中',
|
||
running: '处理中',
|
||
success: '已分配',
|
||
succeeded: '已分配',
|
||
fin: '已分配',
|
||
finished: '已分配',
|
||
done: '已分配',
|
||
completed: '已分配',
|
||
partial: '部分分配',
|
||
partial_failed: '部分分配',
|
||
error: '分配异常',
|
||
failed: '分配异常',
|
||
exception: '分配异常',
|
||
timeout: '处理超时',
|
||
not_found: '未找到'
|
||
}
|
||
|
||
/** 库位分配异常文案 */
|
||
export const waveStorageAssignmentErrorTextMap: Record<string, string> = {
|
||
none: '无',
|
||
no_error: '无',
|
||
no_exception: '无',
|
||
success: '无',
|
||
succeeded: '无',
|
||
fin: '无',
|
||
finished: '无',
|
||
done: '无',
|
||
completed: '无',
|
||
pending: '处理中',
|
||
padding: '处理中',
|
||
processing: '处理中',
|
||
running: '处理中',
|
||
error: '分配异常',
|
||
failed: '分配失败',
|
||
exception: '分配异常',
|
||
timeout: '处理超时',
|
||
not_found: '未找到',
|
||
partial: '部分异常',
|
||
partial_failed: '部分异常'
|
||
}
|
||
|
||
/** 库位分配异常短语翻译规则 */
|
||
export const waveStorageAssignmentErrorPhraseMap: Array<[RegExp, string]> = [
|
||
[/storage assignment/gi, '库位分配'],
|
||
[/assignment/gi, '分配'],
|
||
[/storage/gi, '库位'],
|
||
[/error/gi, '异常'],
|
||
[/failed/gi, '失败'],
|
||
[/exception/gi, '异常'],
|
||
[/timeout/gi, '超时'],
|
||
[/pending|padding|processing|running/gi, '处理中'],
|
||
[/partial/gi, '部分'],
|
||
[/not found/gi, '未找到'],
|
||
[/none|success|succeeded|finished|completed|done|fin/gi, '无']
|
||
]
|
||
|
||
/** 波次策略表单校验规则 */
|
||
export const waveStrategyFormRules = {
|
||
strategy_name: [{ required: true, message: '请输入策略名称', trigger: 'blur' }],
|
||
strategy_type: [{ required: true, message: '请输入策略类型', trigger: 'change' }],
|
||
batch_mode: [{ required: true, message: '请输入批次模式', trigger: 'change' }]
|
||
}
|
||
|
||
/** 波次策略状态选项 */
|
||
export const waveStrategyStatusOptions = [
|
||
{ label: '禁用', value: 0 },
|
||
{ label: '启用', value: 1 }
|
||
]
|
||
|
||
/** 通用布尔选项 */
|
||
export const waveBooleanOptions = [
|
||
{ label: '是', value: true },
|
||
{ label: '否', value: false }
|
||
]
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// 拣货中任务页(pickTaskWave):与散单页共用 waveScanBoxConfig;筛选字段见 pickTaskWaveAvailableFields
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/** 列表与工具栏文案 */
|
||
export const pickTaskWaveListDefaults = {
|
||
toolbarHint: '当前仓库拣货任务(order.wave.wavePickTaskList)',
|
||
listTitle: '拣货任务列表',
|
||
emptyText: '暂无拣货任务',
|
||
loadingEmptyText: '加载中...',
|
||
loadFailedEmptyText: '加载失败',
|
||
noWarehouseEmptyText: '未获取到仓库ID'
|
||
}
|
||
|
||
/** 分页与详情弹窗 */
|
||
export const pickTaskWavePaginationDefaults = {
|
||
pageSizes: [20, 50, 100, 200] as const,
|
||
layout: 'total, sizes, prev, pager, next, jumper' as const,
|
||
initialPageSize: 20
|
||
}
|
||
|
||
/** 供模板 :page-sizes 绑定(避免 readonly 元组在模板中的类型问题) */
|
||
export const pickTaskWavePaginationPageSizes = [20, 50, 100, 200]
|
||
|
||
export const pickTaskWaveDetailDialogDefaults = {
|
||
title: '拣货任务详情',
|
||
width: '920px'
|
||
}
|
||
|
||
/** 拣货任务页工具栏按钮(action 与 WavePickTaskListPanel 内 toolbarActionMap 键一致) */
|
||
export const pickTaskWaveToolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', size: 'small', action: 'loadData' },
|
||
{ key: 'search', label: '查询', type: 'primary', size: 'small', action: 'handleSearch' },
|
||
{
|
||
key: 'batchCancel',
|
||
label: '批量取消任务',
|
||
dynamicLabelKey: 'batchCancelTotal',
|
||
type: 'danger',
|
||
size: 'small',
|
||
loadingKey: 'batchCancelLoading',
|
||
disabledKey: 'batchCancelDisabled',
|
||
action: 'handleBatchCancelTasks'
|
||
}
|
||
]
|
||
|
||
/** 不符合波次策略订单页工具栏按钮 */
|
||
export const fallbackOrderToolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'search', label: '查询', type: 'primary', size: 'small', loadingKey: 'loading', action: 'loadData' },
|
||
{ key: 'reset', label: '重置', size: 'small', action: 'resetFallbackOrderCondition' },
|
||
{ key: 'columnConfig', label: '字段设置', size: 'small', action: 'openColumnConfigPanel' },
|
||
{
|
||
key: 'quickScan',
|
||
label: '快速扫描',
|
||
type: 'warning',
|
||
size: 'small',
|
||
loadingKey: 'waveStrategyQuickScanSubmitting',
|
||
action: 'submitWaveStrategyQuickScan'
|
||
},
|
||
{
|
||
key: 'fetchByIds',
|
||
label: '按订单IDs抓取删单',
|
||
type: 'warning',
|
||
size: 'small',
|
||
loadingKey: 'singleOrderSubmitting',
|
||
disabledKey: 'noSelection',
|
||
action: 'submitFallbackOrderFetchByIds'
|
||
}
|
||
]
|
||
|
||
/** 波次策略页工具栏按钮 */
|
||
export const waveStrategyToolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', type: 'primary', size: 'small', loadingKey: 'loading', action: 'loadData' },
|
||
{ key: 'columnConfig', label: '字段设置', size: 'small', action: 'openColumnConfigPanel' },
|
||
{ key: 'create', label: '新建策略', type: 'success', size: 'small', action: 'openCreateWaveStrategyDialog' }
|
||
]
|
||
|
||
/** 拣货任务 status 枚举(与 wavePickTaskList / wavePickTaskCancel 文档一致) */
|
||
export const pickTaskStatusFilterOptions = [
|
||
{ label: '待开始', value: 0 },
|
||
{ label: '拣货中', value: 1 },
|
||
{ label: '拣货完成', value: 2 },
|
||
{ label: '已完成', value: 3 },
|
||
{ label: '已取消', value: 9 }
|
||
] as const
|
||
|
||
/** 左侧筛选字段(与 order.wave.wavePickTaskList 入参对应) */
|
||
export const pickTaskWaveAvailableFields = [
|
||
waveScanField('task', { label: '任务编号', value: 'task_no', type: 'text' }),
|
||
waveScanField('status', {
|
||
label: '任务状态',
|
||
value: 'status',
|
||
type: 'multiple',
|
||
options: [...pickTaskStatusFilterOptions]
|
||
}),
|
||
waveScanField('status', {
|
||
label: '复核状态',
|
||
value: 'review_status',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '未就绪', value: 0 },
|
||
{ label: '待复核', value: 1 },
|
||
{ label: '复核中', value: 2 },
|
||
{ label: '复核通过', value: 3 },
|
||
{ label: '复核异常', value: 4 }
|
||
]
|
||
}),
|
||
waveScanField('status', {
|
||
label: '拣货模式',
|
||
value: 'pick_mode',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '小团购', value: 1 },
|
||
{ label: '单品单件', value: 2 },
|
||
{ label: '先拣后分', value: 3 },
|
||
{ label: '边拣边分', value: 4 },
|
||
{ label: '大团购', value: 5 }
|
||
]
|
||
}),
|
||
waveScanField('status', {
|
||
label: '来源',
|
||
value: 'source',
|
||
type: 'select',
|
||
options: [
|
||
{ label: '默认', value: 0 },
|
||
{ label: 'PDA', value: 1 },
|
||
{ label: '后台', value: 2 }
|
||
]
|
||
}),
|
||
waveScanField('time', { label: '开始时间', value: 'start_time_range', type: 'daterange' }),
|
||
]
|
||
|
||
export function formatPickTaskStatus(value: unknown): string {
|
||
const num = Number(value)
|
||
if (num === 0) return '待开始'
|
||
if (num === 1) return '拣货中'
|
||
if (num === 2) return '拣货完成'
|
||
if (num === 3) return '已完成'
|
||
if (num === 9) return '已取消'
|
||
return value === null || value === undefined || value === '' ? '-' : String(value)
|
||
}
|
||
|
||
export function formatPickTaskReviewStatus(value: unknown): string {
|
||
const num = Number(value)
|
||
if (num === 0) return '未就绪'
|
||
if (num === 1) return '待复核'
|
||
if (num === 2) return '复核中'
|
||
if (num === 3) return '复核通过'
|
||
if (num === 4) return '复核异常'
|
||
return value === null || value === undefined || value === '' ? '-' : String(value)
|
||
}
|
||
|
||
export function formatPickTaskPickMode(value: unknown): string {
|
||
const num = Number(value)
|
||
if (num === 1) return '小团购'
|
||
if (num === 2) return '单品单件'
|
||
if (num === 3) return '先拣后分'
|
||
if (num === 4) return '边拣边分'
|
||
if (num === 5) return '大团购'
|
||
return value === null || value === undefined || value === '' ? '-' : String(value)
|
||
}
|
||
|
||
export function formatPickTaskSource(value: unknown): string {
|
||
const num = Number(value)
|
||
if (num === 0) return '默认'
|
||
if (num === 1) return 'PDA'
|
||
if (num === 2) return '后台'
|
||
return value === null || value === undefined || value === '' ? '-' : String(value)
|
||
}
|
||
|
||
export function getPickTaskStatusTagType(value: unknown): 'info' | 'warning' | 'success' | 'danger' {
|
||
const num = Number(value)
|
||
if (num === 0) return 'info'
|
||
if (num === 1) return 'warning'
|
||
if (num === 2) return 'success'
|
||
if (num === 3) return 'success'
|
||
if (num === 9) return 'info'
|
||
return 'info'
|
||
}
|
||
|
||
export function getPickTaskReviewStatusTagType(value: unknown): 'info' | 'warning' | 'success' | 'danger' {
|
||
const num = Number(value)
|
||
if (num === 0) return 'info'
|
||
if (num === 1) return 'warning'
|
||
if (num === 2) return 'warning'
|
||
if (num === 3) return 'success'
|
||
if (num === 4) return 'danger'
|
||
return 'info'
|
||
}
|
||
|
||
export function getPickTaskSourceTagType(value: unknown): 'info' | 'success' {
|
||
const num = Number(value)
|
||
if (num === 1) return 'success'
|
||
return 'info'
|
||
}
|
||
|
||
export function unwrapWavePrintPayload(res: any) {
|
||
const inner =
|
||
res?.data !== undefined && res?.data !== null && typeof res.data === 'object' && !Array.isArray(res.data)
|
||
? res.data
|
||
: res
|
||
const summaryRaw = inner?.summary
|
||
const summary =
|
||
summaryRaw !== undefined && summaryRaw !== null && typeof summaryRaw === 'object' && !Array.isArray(summaryRaw)
|
||
? (summaryRaw as Record<string, unknown>)
|
||
: {}
|
||
const waveListRaw = inner?.wave_list
|
||
const wave_list = Array.isArray(waveListRaw)
|
||
? (waveListRaw.filter((x) => x && typeof x === 'object') as Record<string, unknown>[])
|
||
: []
|
||
const extRaw = inner?.ext
|
||
const ext =
|
||
extRaw !== undefined && extRaw !== null && typeof extRaw === 'object' && !Array.isArray(extRaw)
|
||
? (extRaw as Record<string, unknown>)
|
||
: undefined
|
||
return { summary, wave_list, ext }
|
||
}
|
||
|
||
export function getWaveOrders(wave: Record<string, unknown>) {
|
||
const keys = ['orders', 'order_list', 'order_details', 'items', 'print_orders', 'order_rows', 'details']
|
||
for (const key of keys) {
|
||
const value = wave[key]
|
||
if (Array.isArray(value)) return value
|
||
}
|
||
return []
|
||
}
|
||
|
||
export function getWaveOrderLineItems(order: Record<string, unknown>) {
|
||
const keys = ['items', 'order_items', 'details', 'order_details', 'sku_list', 'goods_list', 'lines']
|
||
for (const key of keys) {
|
||
const value = order[key]
|
||
if (Array.isArray(value)) return value
|
||
}
|
||
return []
|
||
}
|
||
|
||
export function resolveWaveRowKey(row: Record<string, unknown>) {
|
||
return String(row?.id ?? row?.wave_id ?? row?.batch_id ?? row?.wave_no ?? '')
|
||
}
|
||
|
||
export function resolveOutboundQueueNo(order: Record<string, unknown>, fallback = '—') {
|
||
return String(
|
||
order.delivery_order_code
|
||
?? order.delivery_no
|
||
?? order.order_sn
|
||
?? order.order_no
|
||
?? order.order_number
|
||
?? fallback
|
||
)
|
||
}
|
||
|
||
export function resolveOutboundPrintRowKey(
|
||
order: Record<string, unknown>,
|
||
waveKey: string,
|
||
index: number
|
||
) {
|
||
const orderId = order.order_id ?? order.id ?? `${waveKey}-${index}`
|
||
return `${waveKey}::${orderId}`
|
||
}
|
||
|
||
export function toOutboundPrintForm(order: Record<string, unknown>, wave: Record<string, unknown>) {
|
||
const lineItems = getWaveOrderLineItems(order) as Record<string, unknown>[]
|
||
return {
|
||
...wave,
|
||
...order,
|
||
wave_no: String(wave.wave_no ?? wave.batch_no ?? wave.wave_code ?? wave.id ?? '—'),
|
||
delivery_order_code: resolveOutboundQueueNo(order),
|
||
details: mapPendingOrderItemsToPrintDetails(lineItems),
|
||
}
|
||
}
|
||
|
||
export function buildOutboundPrintQueue(
|
||
waveList: Record<string, unknown>[],
|
||
selectedWaveRows: any[]
|
||
) {
|
||
const waveByKey = new Map<string, Record<string, unknown>>()
|
||
waveList.forEach((wave) => {
|
||
const key = resolveWaveRowKey(wave)
|
||
if (key) waveByKey.set(key, wave)
|
||
})
|
||
|
||
const printRows: any[] = []
|
||
const dataMap: Record<string, any> = {}
|
||
|
||
selectedWaveRows.forEach((waveRow) => {
|
||
const waveKey = resolveWaveRowKey(waveRow || {})
|
||
const wave = (waveKey ? waveByKey.get(waveKey) : undefined) || (waveRow as Record<string, unknown>)
|
||
const orders = getWaveOrders(wave)
|
||
orders.forEach((order, index) => {
|
||
const orderRec = order && typeof order === 'object' ? (order as Record<string, unknown>) : {}
|
||
const rowKey = resolveOutboundPrintRowKey(orderRec, waveKey || 'wave', index)
|
||
const queueNo = resolveOutboundQueueNo(orderRec, rowKey)
|
||
const queueRow = {
|
||
...orderRec,
|
||
id: rowKey,
|
||
delivery_order_code: queueNo,
|
||
wave_no: String(wave.wave_no ?? waveRow?.wave_no ?? waveRow?.batch_no ?? waveRow?.wave_code ?? '—'),
|
||
wave_id: waveKey || waveRow?.id
|
||
}
|
||
printRows.push(queueRow)
|
||
dataMap[rowKey] = toOutboundPrintForm(orderRec, wave)
|
||
})
|
||
})
|
||
|
||
return { printRows, dataMap }
|
||
}
|
||
|
||
const OUTBOUND_DETAIL_FETCH_CONCURRENCY = 8
|
||
|
||
function formatOutboundPrintDateTime(date: Date): string {
|
||
const pad = (n: number) => String(n).padStart(2, '0')
|
||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
||
}
|
||
|
||
function resolvePendingOrderDeliveryCode(order: Record<string, unknown>): string {
|
||
return String(order.delivery_order_code ?? order.order_code ?? '').trim()
|
||
}
|
||
|
||
async function runWithConcurrencyLimit<T>(
|
||
items: T[],
|
||
limit: number,
|
||
worker: (item: T) => Promise<void>,
|
||
): Promise<void> {
|
||
if (!items.length) return
|
||
let cursor = 0
|
||
const poolSize = Math.min(limit, items.length)
|
||
await Promise.all(
|
||
Array.from({ length: poolSize }, async () => {
|
||
while (cursor < items.length) {
|
||
const item = items[cursor]
|
||
cursor += 1
|
||
if (item === undefined) continue
|
||
await worker(item)
|
||
}
|
||
}),
|
||
)
|
||
}
|
||
|
||
/** 查询单个订单详情(order.pendingOrder.detail) */
|
||
async function fetchPendingOrderDetailById(orderId: number | string): Promise<Record<string, unknown> | null> {
|
||
const res: any = await orderPendingOrder.detail({
|
||
id: orderId,
|
||
ids: [orderId],
|
||
tableType: 'order',
|
||
})
|
||
if (!isOrderIndexApiSuccess(res)) return null
|
||
return parseOrderDetailPayload(res)
|
||
}
|
||
|
||
function resolveOutboundWaybillText(
|
||
detailPayload: Record<string, unknown>,
|
||
order: Record<string, unknown>,
|
||
): string {
|
||
const waybillCodes = detailPayload.waybill_codes ?? order.waybill_codes
|
||
if (Array.isArray(waybillCodes)) {
|
||
return waybillCodes.map((code) => String(code ?? '').trim()).filter(Boolean).join(', ')
|
||
}
|
||
return String(order.express_code ?? order.waybill_code ?? '').trim()
|
||
}
|
||
|
||
const SNAPSHOT_EMPTY_LABEL = '无'
|
||
|
||
function resolveItemSnapshot(item: Record<string, unknown>): Record<string, unknown> {
|
||
const raw = item.item_snapshot
|
||
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
||
return raw as Record<string, unknown>
|
||
}
|
||
if (typeof raw === 'string' && raw.trim()) {
|
||
try {
|
||
const parsed = JSON.parse(raw)
|
||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||
return parsed as Record<string, unknown>
|
||
}
|
||
} catch {
|
||
// ignore invalid snapshot json
|
||
}
|
||
}
|
||
return {}
|
||
}
|
||
|
||
function snapshotField(snap: Record<string, unknown>, key: string): string {
|
||
const value = snap[key]
|
||
if (value == null || value === '') return SNAPSHOT_EMPTY_LABEL
|
||
const text = String(value).trim()
|
||
return text || SNAPSHOT_EMPTY_LABEL
|
||
}
|
||
|
||
function orderLineQuantity(item: Record<string, unknown>): string {
|
||
const value = item.plan_qty ?? item.quantity ?? item.qty
|
||
if (value == null || value === '') return SNAPSHOT_EMPTY_LABEL
|
||
const text = String(value).trim()
|
||
return text || SNAPSHOT_EMPTY_LABEL
|
||
}
|
||
|
||
/** 商品明细:商品信息仅用 item_snapshot;数量取订单行 plan_qty */
|
||
function mapPendingOrderItemsToPrintDetails(items: Record<string, unknown>[]) {
|
||
return items.map((item) => {
|
||
const snap = resolveItemSnapshot(item)
|
||
const quantity = orderLineQuantity(item)
|
||
|
||
return {
|
||
item_snapshot: snap,
|
||
item_code: snapshotField(snap, 'item_code'),
|
||
item_name: snapshotField(snap, 'item_name'),
|
||
barcode: snapshotField(snap, 'barcode'),
|
||
sku_property: snapshotField(snap, 'sku_property'),
|
||
goods_code: snapshotField(snap, 'goods_code'),
|
||
brand_name: snapshotField(snap, 'brand_name'),
|
||
category_name: snapshotField(snap, 'category_name'),
|
||
stock_unit: snapshotField(snap, 'stock_unit'),
|
||
item_type: snapshotField(snap, 'item_type'),
|
||
inventory_type: snapshotField(snap, 'inventory_type'),
|
||
retail_price: snapshotField(snap, 'retail_price'),
|
||
plan_qty: quantity,
|
||
quantity,
|
||
actual_price: snapshotField(snap, 'retail_price'),
|
||
price: snapshotField(snap, 'retail_price'),
|
||
}
|
||
})
|
||
}
|
||
|
||
/** 将 order.pendingOrder.detail 响应映射为出库单打印表单字段 */
|
||
export function mapPendingOrderToOutboundPrintForm(
|
||
detailPayload: Record<string, unknown>,
|
||
wave: Record<string, unknown>,
|
||
): Record<string, unknown> {
|
||
const order = (detailPayload.order || detailPayload.detail || detailPayload) as Record<string, unknown>
|
||
const items = normalizeOrderDetailItems(detailPayload)
|
||
const waybillStr = resolveOutboundWaybillText(detailPayload, order)
|
||
const addressParts = [order.province, order.city, order.area, order.town, order.detail_address]
|
||
.map((value) => (value == null ? '' : String(value).trim()))
|
||
.filter(Boolean)
|
||
|
||
return {
|
||
...order,
|
||
wave_no: String(wave.wave_no ?? wave.batch_no ?? wave.wave_code ?? order.wave_no ?? '—'),
|
||
delivery_order_code: resolvePendingOrderDeliveryCode(order),
|
||
create_at: order.create_at ?? order.created_at ?? '',
|
||
logistics_name: order.logistics_name ?? '',
|
||
express_code: String(order.express_code ?? waybillStr).trim(),
|
||
waybill_codes: waybillStr,
|
||
// 传播 expresses 数组,确保打印模板能从 expresses 获取运单号
|
||
expresses: Array.isArray(detailPayload.expresses) ? detailPayload.expresses : [],
|
||
name: order.name ?? '',
|
||
mobile: order.mobile ?? order.tel ?? '',
|
||
tel: order.tel ?? '',
|
||
province: order.province ?? '',
|
||
city: order.city ?? '',
|
||
area: order.area ?? '',
|
||
town: order.town ?? '',
|
||
detail_address: order.detail_address ?? '',
|
||
address: addressParts.join(''),
|
||
remark: order.remark ?? order.seller_message ?? order.buyer_message ?? '',
|
||
print_time: formatOutboundPrintDateTime(new Date()),
|
||
details: mapPendingOrderItemsToPrintDetails(items),
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 替换 order.print.getWavePrintData:
|
||
* 通过 order.pendingOrder.list 按 wave_id 查询订单,按波次分组后返回 waveList 结构,
|
||
* 供 buildOutboundPrintQueue / fetchOutboundPrintDataFromPendingOrders 使用。
|
||
*/
|
||
export async function fetchOutboundWaveList(wave_ids: Array<number | string>): Promise<Record<string, unknown>[]> {
|
||
if (!wave_ids.length) return []
|
||
|
||
const res: any = await orderPendingOrder.list({
|
||
pagination: { page: 1, pageSize: 9999 },
|
||
where: { wave_id: { operator: 'in', value: wave_ids, type: 'select' } },
|
||
})
|
||
|
||
if (!isOrderIndexApiSuccess(res)) return []
|
||
|
||
const { list: rawList } = parseOrderListResponse(res)
|
||
if (!rawList.length) return []
|
||
|
||
// 将列表项展开(raw.detail 合并到顶层),按 wave_id 分组
|
||
const waveGroupMap = new Map<string, Record<string, unknown>[]>()
|
||
rawList.forEach((raw: any) => {
|
||
const order = { ...(raw.detail || raw), items: raw.items || [], expresses: raw.expresses || [] }
|
||
const wid = String(order.wave_id ?? '')
|
||
if (!wid) return
|
||
if (!waveGroupMap.has(wid)) waveGroupMap.set(wid, [])
|
||
waveGroupMap.get(wid)!.push(order)
|
||
})
|
||
|
||
// 构造 waveList 格式:每个 wave 对象包含 id / wave_no / orders 等字段
|
||
const waveList: Record<string, unknown>[] = []
|
||
waveGroupMap.forEach((orders, wid) => {
|
||
const first = orders[0]
|
||
waveList.push({
|
||
id: wid,
|
||
wave_id: wid,
|
||
wave_no: String(first?.wave_no ?? ''),
|
||
orders,
|
||
})
|
||
})
|
||
|
||
return waveList
|
||
}
|
||
|
||
/**
|
||
* 从 waveList 中已加载的订单直接构建 delivery_order_code → order_id 映射,
|
||
* 避免重复调用 order.pendingOrder.list。
|
||
*/
|
||
export async function fetchOutboundPrintDataFromPendingOrders(
|
||
waveList: Record<string, unknown>[],
|
||
selectedWaveRows: any[],
|
||
): Promise<{ printRows: any[]; dataMap: Record<string, any>; missingDeliveryCodes: string[] }> {
|
||
const skeleton = buildOutboundPrintQueue(waveList, selectedWaveRows)
|
||
if (!skeleton.printRows.length) {
|
||
return { ...skeleton, missingDeliveryCodes: [] }
|
||
}
|
||
|
||
// 从 waveList 的 orders 中直接构建 code → orderId 映射(无需再调 list 接口)
|
||
const codeToOrderId = new Map<string, number | string>()
|
||
waveList.forEach((wave) => {
|
||
const orders = getWaveOrders(wave)
|
||
orders.forEach((order: any) => {
|
||
if (!order || typeof order !== 'object') return
|
||
const code = resolvePendingOrderDeliveryCode(order)
|
||
const oid = order.id ?? order.order_id
|
||
if (code && oid != null && oid !== '') {
|
||
codeToOrderId.set(code, oid as number | string)
|
||
}
|
||
})
|
||
})
|
||
|
||
const printRows: any[] = new Array(skeleton.printRows.length)
|
||
const dataMap: Record<string, any> = {}
|
||
const missingDeliveryCodes: string[] = []
|
||
|
||
await runWithConcurrencyLimit(
|
||
skeleton.printRows.map((row, index) => ({ row, index })),
|
||
OUTBOUND_DETAIL_FETCH_CONCURRENCY,
|
||
async ({ row, index }) => {
|
||
const rowKey = String(row.id)
|
||
const deliveryCode = String(row.delivery_order_code ?? '').trim()
|
||
const wave = {
|
||
wave_no: row.wave_no,
|
||
wave_id: row.wave_id,
|
||
}
|
||
const orderId = deliveryCode ? codeToOrderId.get(deliveryCode) : undefined
|
||
|
||
if (!orderId) {
|
||
if (deliveryCode) missingDeliveryCodes.push(deliveryCode)
|
||
dataMap[rowKey] = skeleton.dataMap[rowKey] || toOutboundPrintForm({}, wave)
|
||
printRows[index] = row
|
||
return
|
||
}
|
||
|
||
const detailPayload = await fetchPendingOrderDetailById(orderId)
|
||
if (detailPayload) {
|
||
dataMap[rowKey] = mapPendingOrderToOutboundPrintForm(detailPayload, wave)
|
||
printRows[index] = {
|
||
...row,
|
||
order_id: orderId,
|
||
}
|
||
return
|
||
}
|
||
|
||
if (deliveryCode) missingDeliveryCodes.push(deliveryCode)
|
||
dataMap[rowKey] = skeleton.dataMap[rowKey] || toOutboundPrintForm({}, wave)
|
||
printRows[index] = row
|
||
},
|
||
)
|
||
|
||
return {
|
||
printRows: printRows.filter(Boolean),
|
||
dataMap,
|
||
missingDeliveryCodes: [...new Set(missingDeliveryCodes)],
|
||
}
|
||
}
|