1
This commit is contained in:
parent
cc7ce02a02
commit
8e0b5211e3
@ -2,11 +2,6 @@ import request from '@/utils/request'
|
|||||||
|
|
||||||
const v = '1.0'
|
const v = '1.0'
|
||||||
|
|
||||||
export type GetWavePrintDataParams = {
|
|
||||||
warehouse_id: number
|
|
||||||
wave_ids: Array<number | string>
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 接口文档:summary / wave_list / ext;wave_list 单项结构由后端定义 */
|
/** 接口文档:summary / wave_list / ext;wave_list 单项结构由后端定义 */
|
||||||
export type WavePrintDataPayload = {
|
export type WavePrintDataPayload = {
|
||||||
summary?: Record<string, unknown>
|
summary?: Record<string, unknown>
|
||||||
@ -49,21 +44,6 @@ export type WavePlatformPrintDataPayload = {
|
|||||||
ext?: Record<string, unknown>
|
ext?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 按波次 IDs 获取订单打印数据(order.print.getWavePrintData) */
|
|
||||||
export function getWavePrintData(data: GetWavePrintDataParams) {
|
|
||||||
return request({
|
|
||||||
url: '/system',
|
|
||||||
method: 'post',
|
|
||||||
params: {
|
|
||||||
method: 'order.print.getWavePrintData',
|
|
||||||
v,
|
|
||||||
timestamp: new Date().getTime()
|
|
||||||
},
|
|
||||||
data,
|
|
||||||
isSystemApi: true
|
|
||||||
} as any)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 按波次 IDs 获取平台打印中间态数据(order.print.getWavePlatformPrintData) */
|
/** 按波次 IDs 获取平台打印中间态数据(order.print.getWavePlatformPrintData) */
|
||||||
export function getWavePlatformPrintData(data: GetWavePlatformPrintDataParams) {
|
export function getWavePlatformPrintData(data: GetWavePlatformPrintDataParams) {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
@ -175,9 +175,8 @@ const visible = computed({
|
|||||||
})
|
})
|
||||||
const dialogTitle = computed(() => props.dialogTitle || '批量打印收货单')
|
const dialogTitle = computed(() => props.dialogTitle || '批量打印收货单')
|
||||||
const printDialogBodyStyle = {
|
const printDialogBodyStyle = {
|
||||||
overflow: 'hidden',
|
padding: '0',
|
||||||
height: 'calc(80vh - 88px)',
|
overflow: 'hidden'
|
||||||
boxSizing: 'border-box'
|
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
const printing = ref(false)
|
const printing = ref(false)
|
||||||
@ -291,10 +290,97 @@ function getStatusLabel(rowId: string | number) {
|
|||||||
return '待打印'
|
return '待打印'
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPreviewValue(item: any): string {
|
/** 判断是否为时间相关字段 */
|
||||||
if (item.field_code && printForm[item.field_code] !== undefined && printForm[item.field_code] !== '') {
|
function _isTimeField(fieldCode: string): boolean {
|
||||||
return String(printForm[item.field_code])
|
const timeFields = ['create_at', 'created_at', 'order_create_time', 'print_time', 'update_at', 'updated_at', 'place_order_time', 'pay_time', 'operate_time']
|
||||||
|
return timeFields.includes(fieldCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 判断字符串是否像 ISO 日期格式 */
|
||||||
|
function _looksLikeISODate(val: string): boolean {
|
||||||
|
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ISO 日期 → YYYY-MM-DD HH:mm:ss */
|
||||||
|
function _fmtISODate(val: string): string {
|
||||||
|
try {
|
||||||
|
const d = new Date(val)
|
||||||
|
if (isNaN(d.getTime())) return val
|
||||||
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||||
|
} catch {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPreviewValue(item: any): string {
|
||||||
|
// 有 field_code 时优先从 printForm 取值
|
||||||
|
if (item.field_code) {
|
||||||
|
|
||||||
|
// 处理 suffix_fields:将主字段 + 后缀字段拼接
|
||||||
|
if (Array.isArray(item.suffix_fields) && item.suffix_fields.length > 0) {
|
||||||
|
const parts: string[] = []
|
||||||
|
const mainVal = printForm[item.field_code]
|
||||||
|
if (mainVal !== undefined && mainVal !== null && String(mainVal).trim() !== '') {
|
||||||
|
parts.push(String(mainVal).trim())
|
||||||
|
}
|
||||||
|
item.suffix_fields.forEach((sf: string) => {
|
||||||
|
const sv = printForm[sf]
|
||||||
|
if (sv !== undefined && sv !== null && String(sv).trim() !== '') {
|
||||||
|
parts.push(String(sv).trim())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (parts.length > 0) {
|
||||||
|
const separator = item.separator || ''
|
||||||
|
return parts.join(separator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 普通字段取值
|
||||||
|
const raw = printForm[item.field_code]
|
||||||
|
if (raw !== undefined && raw !== null && String(raw).trim() !== '') {
|
||||||
|
const val = String(raw)
|
||||||
|
// 时间字段自动格式化 ISO → YYYY-MM-DD HH:mm:ss
|
||||||
|
if (_isTimeField(item.field_code) && _looksLikeISODate(val)) {
|
||||||
|
return _fmtISODate(val)
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
// express_code / waybill_code 为空时尝试多来源回退
|
||||||
|
if (item.field_code === 'express_code' || item.field_code === 'waybill_code') {
|
||||||
|
// 1) 交叉回退:express_code ↔ waybill_code(两个字段在 printForm 顶层互换取值)
|
||||||
|
const peerField = item.field_code === 'express_code' ? 'waybill_code' : 'express_code'
|
||||||
|
const peerVal = printForm[peerField]
|
||||||
|
if (peerVal !== undefined && peerVal !== null && String(peerVal).trim() !== '') {
|
||||||
|
return String(peerVal).trim()
|
||||||
|
}
|
||||||
|
console.log("printForm",JSON.stringify(printForm));
|
||||||
|
// 2) 先试 expresses 数组
|
||||||
|
const expresses = printForm.expresses
|
||||||
|
if (Array.isArray(expresses) && expresses.length > 0) {
|
||||||
|
const code = expresses[0]?.waybill_code || expresses[0]?.express_code
|
||||||
|
if (code) return String(code)
|
||||||
|
}
|
||||||
|
// 3) 再试 details 中第一条的 expresses
|
||||||
|
const details = printForm.details
|
||||||
|
if (Array.isArray(details) && details.length > 0) {
|
||||||
|
const firstDetail = details[0]
|
||||||
|
if (firstDetail) {
|
||||||
|
const dExpresses = firstDetail.expresses
|
||||||
|
if (Array.isArray(dExpresses) && dExpresses.length > 0) {
|
||||||
|
const code = dExpresses[0]?.waybill_code || dExpresses[0]?.express_code
|
||||||
|
if (code) return String(code)
|
||||||
|
}
|
||||||
|
// 直接取运单号字段
|
||||||
|
const directCode = firstDetail.express_code || firstDetail.waybill_code || firstDetail.waybill_no
|
||||||
|
if (directCode && String(directCode).trim()) return String(directCode).trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 回退到模板预设内容
|
||||||
return item.content || ''
|
return item.content || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,6 +473,18 @@ async function loadPrintFormData(index: number) {
|
|||||||
formData[f] = ''
|
formData[f] = ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 从 mainRow 传播 express_code / waybill_code / expresses 到 formData
|
||||||
|
// 这些字段不在 printFormConfig 中,但打印模板可能需要
|
||||||
|
if (mainRow.express_code !== undefined) {
|
||||||
|
formData.express_code = mainRow.express_code
|
||||||
|
}
|
||||||
|
if (mainRow.waybill_code !== undefined) {
|
||||||
|
formData.waybill_code = mainRow.waybill_code
|
||||||
|
}
|
||||||
|
if (Array.isArray(mainRow.expresses)) {
|
||||||
|
formData.expresses = [...mainRow.expresses]
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res: any = await receivingApi.getReceivingDetail({
|
const res: any = await receivingApi.getReceivingDetail({
|
||||||
id: mainRow.id,
|
id: mainRow.id,
|
||||||
@ -422,6 +520,18 @@ async function loadPrintFormData(index: number) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从 API 响应中传播运单相关信息
|
||||||
|
const receiving = res.data.receiving || {}
|
||||||
|
if (Array.isArray(receiving.expresses)) {
|
||||||
|
formData.expresses = receiving.expresses
|
||||||
|
}
|
||||||
|
if (receiving.express_code !== undefined) {
|
||||||
|
formData.express_code = receiving.express_code
|
||||||
|
}
|
||||||
|
if (receiving.waybill_code !== undefined) {
|
||||||
|
formData.waybill_code = receiving.waybill_code
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('加载打印明细失败', e)
|
console.error('加载打印明细失败', e)
|
||||||
@ -625,7 +735,8 @@ function browserPrint() {
|
|||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.print-dialog-layout {
|
.print-dialog-layout {
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 100%;
|
height: calc(80vh - 130px);
|
||||||
|
max-height: calc(80vh - 130px);
|
||||||
border: 1px solid #ebeef5;
|
border: 1px solid #ebeef5;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
|
|
||||||
@ -714,7 +825,6 @@ function browserPrint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.print-canvas-area {
|
.print-canvas-area {
|
||||||
min-height: 100%;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
@ -753,17 +863,13 @@ function browserPrint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
:deep(.el-dialog.print-dialog) {
|
:deep(.el-dialog.print-dialog) {
|
||||||
height: 80vh;
|
margin-top: 0 !important;
|
||||||
max-height: 80vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
top: 50% !important;
|
top: 50% !important;
|
||||||
transform: translateY(-50%) !important;
|
transform: translateY(-50%) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.el-dialog.print-dialog .el-dialog__body) {
|
:deep(.el-dialog.print-dialog .el-dialog__body) {
|
||||||
flex: 1;
|
padding: 0 !important;
|
||||||
min-height: 0;
|
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -872,7 +872,7 @@ import {
|
|||||||
formatWaveReviewAssignmentStatusLabel,
|
formatWaveReviewAssignmentStatusLabel,
|
||||||
getWaveAssignmentAggregateTagType,
|
getWaveAssignmentAggregateTagType,
|
||||||
buildOutboundPrintQueue,
|
buildOutboundPrintQueue,
|
||||||
unwrapWavePrintPayload as unwrapWavePrintPayloadFromConfig,
|
fetchOutboundWaveList,
|
||||||
resolveOutboundPrintRowKey
|
resolveOutboundPrintRowKey
|
||||||
} from './config/wave-config'
|
} from './config/wave-config'
|
||||||
import { safeInvoke } from '@/utils/safe-invoke'
|
import { safeInvoke } from '@/utils/safe-invoke'
|
||||||
@ -943,7 +943,8 @@ import type {
|
|||||||
WaveStrategyQuickScanTaskProgressResponse
|
WaveStrategyQuickScanTaskProgressResponse
|
||||||
} from '@/api/order.wave/orderwave'
|
} from '@/api/order.wave/orderwave'
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
import { useUserStore } from '@/stores/modules/user'
|
||||||
import { getWavePrintData, getWavePlatformPrintData } from '@/api/order.print/orderprint'
|
import { getWavePlatformPrintData } from '@/api/order.print/orderprint'
|
||||||
|
import { orderPendingOrderList, orderPendingOrderDetail } from '@/api/order.pendingorder/orderpendingOrder'
|
||||||
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
||||||
import pcasCodeData from 'china-division/dist/pcas-code.json'
|
import pcasCodeData from 'china-division/dist/pcas-code.json'
|
||||||
|
|
||||||
@ -1718,43 +1719,54 @@ async function handleBatchFinishAutoGrouping() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unwrapWavePrintPayload(res: any) {
|
/** 格式化 ISO 时间戳为 YYYY-MM-DD HH:mm:ss */
|
||||||
const inner =
|
function formatPrintTime(val: any): string {
|
||||||
res?.data !== undefined && res?.data !== null && typeof res.data === 'object' && !Array.isArray(res.data)
|
if (!val) return ''
|
||||||
? res.data
|
try {
|
||||||
: res
|
const d = new Date(val)
|
||||||
const summaryRaw = inner?.summary
|
if (isNaN(d.getTime())) return String(val)
|
||||||
const summary =
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
summaryRaw !== undefined && summaryRaw !== null && typeof summaryRaw === 'object' && !Array.isArray(summaryRaw)
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||||
? (summaryRaw as Record<string, unknown>)
|
} catch {
|
||||||
: {}
|
return String(val)
|
||||||
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 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWaveOrders(wave: Record<string, unknown>) {
|
/** 合并省/市/区/镇/详细地址为完整地址 */
|
||||||
const keys = ['orders', 'order_list', 'order_details', 'items', 'print_orders', 'order_rows', 'details']
|
function mergeAddress(order: Record<string, any>): string {
|
||||||
for (const key of keys) {
|
const parts = [order.province, order.city, order.area, order.town, order.detail_address]
|
||||||
const value = wave[key]
|
.map((v: any) => (v == null ? '' : String(v).trim()))
|
||||||
if (Array.isArray(value)) return value
|
.filter(Boolean)
|
||||||
}
|
return parts.join('')
|
||||||
return []
|
}
|
||||||
|
|
||||||
|
/** 处理单条订单的打印字段:补全 address、express_code,格式化时间 */
|
||||||
|
function normalizePrintOrder(order: Record<string, any>): Record<string, any> {
|
||||||
|
// 运单号:多来源回退
|
||||||
|
let expressCode = ''
|
||||||
|
const sources = [
|
||||||
|
order.express_code,
|
||||||
|
order.waybill_code,
|
||||||
|
order.waybill_no,
|
||||||
|
order.tracking_number,
|
||||||
|
order.tracking_code
|
||||||
|
]
|
||||||
|
for (const s of sources) {
|
||||||
|
if (s && String(s).trim()) { expressCode = String(s).trim(); break }
|
||||||
|
}
|
||||||
|
// 从 expresses 数组取
|
||||||
|
if (!expressCode && Array.isArray(order.expresses) && order.expresses.length > 0) {
|
||||||
|
expressCode = order.expresses[0]?.waybill_code || order.expresses[0]?.express_code || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function toWavePrintForm(wave: Record<string, unknown>) {
|
|
||||||
const details = getWaveOrders(wave)
|
|
||||||
return {
|
return {
|
||||||
...wave,
|
...order,
|
||||||
wave_no: String(wave.wave_no ?? wave.batch_no ?? wave.wave_code ?? wave.id ?? '—'),
|
address: mergeAddress(order),
|
||||||
details
|
express_code: expressCode,
|
||||||
|
waybill_code: expressCode, // 兼容不同模板
|
||||||
|
create_at: formatPrintTime(order.create_at ?? order.created_at ?? order.order_create_time),
|
||||||
|
order_create_time: formatPrintTime(order.order_create_time ?? order.create_at ?? order.created_at),
|
||||||
|
print_time: formatPrintTime(new Date().toISOString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1763,8 +1775,25 @@ function rowWaveKey(row: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadWavePrintFormData(row: any) {
|
async function loadWavePrintFormData(row: any) {
|
||||||
const key = rowWaveKey(row)
|
// 尝试多种 key 匹配
|
||||||
return wavePrintDataMap.value[key] || toWavePrintForm(row || {})
|
const keys = [
|
||||||
|
rowWaveKey(row),
|
||||||
|
String(row?.wave_id ?? ''),
|
||||||
|
String(row?.id ?? ''),
|
||||||
|
String(row?.wave_no ?? ''),
|
||||||
|
].filter(k => k)
|
||||||
|
|
||||||
|
const map = wavePrintDataMap.value
|
||||||
|
for (const k of keys) {
|
||||||
|
if (map[k]) return map[k]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果 map 只有一条数据,直接返回
|
||||||
|
const values = Object.values(map)
|
||||||
|
if (values.length === 1) return values[0]
|
||||||
|
|
||||||
|
// 最后 fallback:对原始行数据做 normalize 处理
|
||||||
|
return normalizePrintOrder({ ...row, details: [], expresses: row.expresses || [] })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openBatchPrintDialog(rows: any[]) {
|
async function openBatchPrintDialog(rows: any[]) {
|
||||||
@ -1786,23 +1815,108 @@ async function openBatchPrintDialog(rows: any[]) {
|
|||||||
|
|
||||||
batchPrintLoading.value = true
|
batchPrintLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res: any = await getWavePrintData({ warehouse_id: warehouseId, wave_ids })
|
// 使用 order.pendingOrder.list 按波次 ID 直接查询订单数据
|
||||||
const payload = unwrapWavePrintPayload(res)
|
const res: any = await orderPendingOrderList({
|
||||||
const waveList = Array.isArray(payload.wave_list) ? payload.wave_list : []
|
pagination: { page: 1, pageSize: 9999 },
|
||||||
const nextMap: Record<string, any> = {}
|
where: { wave_id: { operator: 'in', value: wave_ids, type: 'select' } }
|
||||||
waveList.forEach((wave: Record<string, unknown>) => {
|
|
||||||
const key = String(wave.id ?? wave.wave_id ?? wave.batch_id ?? wave.wave_no ?? '')
|
|
||||||
if (!key) return
|
|
||||||
nextMap[key] = toWavePrintForm(wave)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isSuccess = res && (res.code === 200 || res.code === 0 || res.flag === 'success')
|
||||||
|
if (!isSuccess) {
|
||||||
|
ElMessage.error(res?.message || '获取订单数据失败')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容多种 API 响应格式:data.list / data.data / data(数组) / data.detail(单条)
|
||||||
|
let rawList: any[] = []
|
||||||
|
const d = res.data
|
||||||
|
if (Array.isArray(d?.list)) {
|
||||||
|
rawList = d.list
|
||||||
|
} else if (Array.isArray(d?.data)) {
|
||||||
|
rawList = d.data
|
||||||
|
} else if (Array.isArray(d)) {
|
||||||
|
rawList = d
|
||||||
|
} else if (d?.detail && typeof d.detail === 'object') {
|
||||||
|
rawList = [d]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rawList.length) {
|
||||||
|
ElMessage.warning('未获取到波次订单数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// API 返回每条记录结构可能为 { detail: {...}, items: [...], expresses: [...] } 或直接是 detail 字段
|
||||||
|
// 提取 detail 并合并 items/expresses
|
||||||
|
let orderList = rawList.map((raw: any) => ({
|
||||||
|
...(raw.detail || raw),
|
||||||
|
items: raw.items || [],
|
||||||
|
expresses: raw.expresses || []
|
||||||
|
}))
|
||||||
|
console.log('[拣货单打印] rawList[0] keys:', rawList.length > 0 ? Object.keys(rawList[0]) : 'empty')
|
||||||
|
console.log('[拣货单打印] orderList[0] has expresses:', orderList.length > 0 ? Array.isArray(orderList[0].expresses) && orderList[0].expresses.length : 'empty')
|
||||||
|
|
||||||
|
// 通过 detail API 逐条补全运单号等完整数据(与 fetchPendingOrderDetailById 同样调用方式)
|
||||||
|
const enrichedMap: Record<string, any> = {}
|
||||||
|
for (const order of orderList) {
|
||||||
|
const oid = order.id
|
||||||
|
if (oid == null) continue
|
||||||
|
try {
|
||||||
|
const detailRes = await orderPendingOrderDetail({
|
||||||
|
id: oid,
|
||||||
|
ids: [oid],
|
||||||
|
tableType: 'order'
|
||||||
|
})
|
||||||
|
console.log('[拣货单打印] detail API 响应:', JSON.stringify({ oid, code: detailRes?.code, flag: detailRes?.flag, hasDetail: !!detailRes?.data?.detail, hasExpresses: !!detailRes?.data?.expresses, expressCount: detailRes?.data?.expresses?.length }))
|
||||||
|
if (detailRes && (detailRes.code === 200 || detailRes.code === 0 || detailRes.flag === 'success')) {
|
||||||
|
const payload = detailRes.data?.detail || detailRes.data || detailRes
|
||||||
|
if (payload && typeof payload === 'object') {
|
||||||
|
enrichedMap[String(oid)] = {
|
||||||
|
...payload,
|
||||||
|
items: detailRes.data?.items || payload.items || [],
|
||||||
|
expresses: detailRes.data?.expresses || payload.expresses || []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('[拣货单打印] detail API 异常:', e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('[拣货单打印] enrichedMap keys:', Object.keys(enrichedMap), 'enriched has expresses:', Object.values(enrichedMap).some((v: any) => Array.isArray(v.expresses) && v.expresses.length > 0))
|
||||||
|
if (Object.keys(enrichedMap).length > 0) {
|
||||||
|
orderList = orderList.map((o: any) => {
|
||||||
|
const enriched = enrichedMap[String(o.id ?? '')]
|
||||||
|
return enriched ? { ...o, ...enriched } : o
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按 wave_id 分组
|
||||||
|
const waveGroupMap: Record<string, any[]> = {}
|
||||||
|
orderList.forEach((order: any) => {
|
||||||
|
const wid = String(order.wave_id ?? '')
|
||||||
|
if (!wid) return
|
||||||
|
if (!waveGroupMap[wid]) waveGroupMap[wid] = []
|
||||||
|
waveGroupMap[wid].push(order)
|
||||||
|
})
|
||||||
|
|
||||||
|
// 构建 wavePrintDataMap:key=wave_id, value={ ...firstOrder(已处理地址和时间), details(已处理) }
|
||||||
|
const nextMap: Record<string, any> = {}
|
||||||
|
Object.entries(waveGroupMap).forEach(([wid, orders]) => {
|
||||||
|
const processedOrders = orders.map(normalizePrintOrder)
|
||||||
|
const first = processedOrders[0]
|
||||||
|
nextMap[wid] = {
|
||||||
|
...first,
|
||||||
|
wave_no: String(first.wave_no ?? first.wave_code ?? first.batch_no ?? wid),
|
||||||
|
details: processedOrders
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
wavePrintRows.value = rows.map((item: any) => ({
|
wavePrintRows.value = rows.map((item: any) => ({
|
||||||
...item,
|
...item,
|
||||||
wave_no: String(item?.wave_no ?? item?.batch_no ?? item?.wave_code ?? item?.id ?? '—')
|
wave_no: String(item?.wave_no ?? item?.batch_no ?? item?.wave_code ?? item?.id ?? '—')
|
||||||
}))
|
}))
|
||||||
wavePrintDataMap.value = nextMap
|
wavePrintDataMap.value = nextMap
|
||||||
wavePrintDialogVisible.value = true
|
wavePrintDialogVisible.value = true
|
||||||
const waveCount = waveList.length
|
ElMessage.success(`已获取打印数据,共 ${orderList.length} 条订单`)
|
||||||
ElMessage.success(res?.message || `已获取打印数据,返回 ${waveCount} 个波次`)
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
wavePrintRows.value = []
|
wavePrintRows.value = []
|
||||||
wavePrintDataMap.value = {}
|
wavePrintDataMap.value = {}
|
||||||
@ -1878,9 +1992,11 @@ async function openBatchOutboundPrintDialog(rows: any[]) {
|
|||||||
|
|
||||||
batchOutboundPrintLoading.value = true
|
batchOutboundPrintLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res: any = await getWavePrintData({ warehouse_id: warehouseId, wave_ids })
|
const waveList = await fetchOutboundWaveList(wave_ids)
|
||||||
const payload = unwrapWavePrintPayloadFromConfig(res)
|
if (!waveList.length) {
|
||||||
const waveList = Array.isArray(payload.wave_list) ? payload.wave_list : []
|
ElMessage.warning('未获取到波次订单数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
const { printRows, dataMap } = buildOutboundPrintQueue(waveList, rows)
|
const { printRows, dataMap } = buildOutboundPrintQueue(waveList, rows)
|
||||||
if (!printRows.length) {
|
if (!printRows.length) {
|
||||||
ElMessage.warning('未获取到可打印的出库单明细,请确认波次下存在订单且快递已完全分配')
|
ElMessage.warning('未获取到可打印的出库单明细,请确认波次下存在订单且快递已完全分配')
|
||||||
@ -1889,7 +2005,7 @@ async function openBatchOutboundPrintDialog(rows: any[]) {
|
|||||||
outboundPrintRows.value = printRows
|
outboundPrintRows.value = printRows
|
||||||
outboundPrintDataMap.value = dataMap
|
outboundPrintDataMap.value = dataMap
|
||||||
outboundPrintDialogVisible.value = true
|
outboundPrintDialogVisible.value = true
|
||||||
ElMessage.success(res?.message || `已获取出库单打印数据,共 ${printRows.length} 单`)
|
ElMessage.success(`已获取出库单打印数据,共 ${printRows.length} 单`)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
outboundPrintRows.value = []
|
outboundPrintRows.value = []
|
||||||
outboundPrintDataMap.value = {}
|
outboundPrintDataMap.value = {}
|
||||||
|
|||||||
@ -465,7 +465,7 @@ import {
|
|||||||
formatWaveReviewAssignmentStatusLabel,
|
formatWaveReviewAssignmentStatusLabel,
|
||||||
getWaveAssignmentAggregateTagType,
|
getWaveAssignmentAggregateTagType,
|
||||||
fetchOutboundPrintDataFromPendingOrders,
|
fetchOutboundPrintDataFromPendingOrders,
|
||||||
unwrapWavePrintPayload as unwrapWavePrintPayloadFromConfig,
|
fetchOutboundWaveList,
|
||||||
resolveOutboundPrintRowKey
|
resolveOutboundPrintRowKey
|
||||||
} from './config/wave-config'
|
} from './config/wave-config'
|
||||||
import { safeInvoke } from '@/utils/safe-invoke'
|
import { safeInvoke } from '@/utils/safe-invoke'
|
||||||
@ -519,7 +519,8 @@ import type {
|
|||||||
} from '@/api/order.wave/orderwave'
|
} from '@/api/order.wave/orderwave'
|
||||||
|
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
import { useUserStore } from '@/stores/modules/user'
|
||||||
import { getWavePrintData, getWavePlatformPrintData } from '@/api/order.print/orderprint'
|
import { getWavePlatformPrintData } from '@/api/order.print/orderprint'
|
||||||
|
import { orderPendingOrderList, orderPendingOrderDetail } from '@/api/order.pendingorder/orderpendingOrder'
|
||||||
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
import type { WavePlatformPrintDataPayload } from '@/api/order.print/orderprint'
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
/** 与路由 path 组合,隔离 ScanBox 筛选缓存(波次各标签页须各不相同) */
|
/** 与路由 path 组合,隔离 ScanBox 筛选缓存(波次各标签页须各不相同) */
|
||||||
@ -727,6 +728,9 @@ const toolbarActionMap: Record<string, () => void> = {
|
|||||||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||||||
toggleDetailVisible: () => toggleDetailVisible(),
|
toggleDetailVisible: () => toggleDetailVisible(),
|
||||||
handleBatchPrint: () => handleBatchPrint(),
|
handleBatchPrint: () => handleBatchPrint(),
|
||||||
|
handleBatchPrintPickingList: () => {
|
||||||
|
void handleBatchPrintPickingList()
|
||||||
|
},
|
||||||
handleBatchOutboundPrint: () => {
|
handleBatchOutboundPrint: () => {
|
||||||
void handleBatchOutboundPrint()
|
void handleBatchOutboundPrint()
|
||||||
},
|
},
|
||||||
@ -1149,43 +1153,45 @@ async function handleBatchFinishAutoGrouping() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unwrapWavePrintPayload(res: any) {
|
/** 格式化 ISO 时间戳为 YYYY-MM-DD HH:mm:ss */
|
||||||
const inner =
|
function formatPrintTime(val: any): string {
|
||||||
res?.data !== undefined && res?.data !== null && typeof res.data === 'object' && !Array.isArray(res.data)
|
if (!val) return ''
|
||||||
? res.data
|
try {
|
||||||
: res
|
const d = new Date(val)
|
||||||
const summaryRaw = inner?.summary
|
if (isNaN(d.getTime())) return String(val)
|
||||||
const summary =
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
summaryRaw !== undefined && summaryRaw !== null && typeof summaryRaw === 'object' && !Array.isArray(summaryRaw)
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||||||
? (summaryRaw as Record<string, unknown>)
|
} catch {
|
||||||
: {}
|
return String(val)
|
||||||
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 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWaveOrders(wave: Record<string, unknown>) {
|
/** 合并省/市/区/镇/详细地址为完整地址 */
|
||||||
const keys = ['orders', 'order_list', 'order_details', 'items', 'print_orders', 'order_rows', 'details']
|
function mergeAddress(order: Record<string, any>): string {
|
||||||
for (const key of keys) {
|
const parts = [order.province, order.city, order.area, order.town, order.detail_address]
|
||||||
const value = wave[key]
|
.map((v: any) => (v == null ? '' : String(v).trim()))
|
||||||
if (Array.isArray(value)) return value
|
.filter(Boolean)
|
||||||
}
|
return parts.join('')
|
||||||
return []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toWavePrintForm(wave: Record<string, unknown>) {
|
/** 处理单条订单的打印字段:补全 address、express_code,格式化时间 */
|
||||||
const details = getWaveOrders(wave)
|
function normalizePrintOrder(order: Record<string, any>): Record<string, any> {
|
||||||
|
let expressCode = ''
|
||||||
|
const sources = [order.express_code, order.waybill_code, order.waybill_no, order.tracking_number]
|
||||||
|
for (const s of sources) {
|
||||||
|
if (s && String(s).trim()) { expressCode = String(s).trim(); break }
|
||||||
|
}
|
||||||
|
if (!expressCode && Array.isArray(order.expresses) && order.expresses.length > 0) {
|
||||||
|
expressCode = order.expresses[0]?.waybill_code || order.expresses[0]?.express_code || ''
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...wave,
|
...order,
|
||||||
wave_no: String(wave.wave_no ?? wave.batch_no ?? wave.wave_code ?? wave.id ?? '—'),
|
address: mergeAddress(order),
|
||||||
details
|
express_code: expressCode,
|
||||||
|
waybill_code: expressCode,
|
||||||
|
create_at: formatPrintTime(order.create_at ?? order.created_at ?? order.order_create_time),
|
||||||
|
order_create_time: formatPrintTime(order.order_create_time ?? order.create_at ?? order.created_at),
|
||||||
|
print_time: formatPrintTime(new Date().toISOString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1194,8 +1200,14 @@ function rowWaveKey(row: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadWavePrintFormData(row: any) {
|
async function loadWavePrintFormData(row: any) {
|
||||||
const key = rowWaveKey(row)
|
const keys = [rowWaveKey(row), String(row?.wave_id ?? ''), String(row?.id ?? ''), String(row?.wave_no ?? '')].filter(k => k)
|
||||||
return wavePrintDataMap.value[key] || toWavePrintForm(row || {})
|
const map = wavePrintDataMap.value
|
||||||
|
for (const k of keys) {
|
||||||
|
if (map[k]) return map[k]
|
||||||
|
}
|
||||||
|
const values = Object.values(map)
|
||||||
|
if (values.length === 1) return values[0]
|
||||||
|
return normalizePrintOrder({ ...row, details: [], expresses: row.expresses || [] })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleBatchPlatformPrint() {
|
async function handleBatchPlatformPrint() {
|
||||||
@ -1341,23 +1353,178 @@ async function handleBatchPrint() {
|
|||||||
|
|
||||||
batchPrintLoading.value = true
|
batchPrintLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res: any = await getWavePrintData({ warehouse_id: warehouseId, wave_ids })
|
// 使用 order.pendingOrder.list 按波次 ID 直接查询订单数据
|
||||||
const payload = unwrapWavePrintPayload(res)
|
const res: any = await orderPendingOrderList({
|
||||||
const waveList = Array.isArray(payload.wave_list) ? payload.wave_list : []
|
pagination: { page: 1, pageSize: 9999 },
|
||||||
const nextMap: Record<string, any> = {}
|
where: { wave_id: { operator: 'in', value: wave_ids, type: 'select' } }
|
||||||
waveList.forEach((wave: Record<string, unknown>) => {
|
|
||||||
const key = String(wave.id ?? wave.wave_id ?? wave.batch_id ?? wave.wave_no ?? '')
|
|
||||||
if (!key) return
|
|
||||||
nextMap[key] = toWavePrintForm(wave)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isSuccess = res && (res.code === 200 || res.code === 0 || res.flag === 'success')
|
||||||
|
if (!isSuccess) {
|
||||||
|
ElMessage.error(res?.message || '获取订单数据失败')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let rawList: any[] = []
|
||||||
|
const d = res.data
|
||||||
|
if (Array.isArray(d?.list)) { rawList = d.list }
|
||||||
|
else if (Array.isArray(d?.data)) { rawList = d.data }
|
||||||
|
else if (Array.isArray(d)) { rawList = d }
|
||||||
|
else if (d?.detail && typeof d.detail === 'object') { rawList = [d] }
|
||||||
|
|
||||||
|
if (!rawList.length) {
|
||||||
|
ElMessage.warning('未获取到波次订单数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let orderList = rawList.map((raw: any) => ({
|
||||||
|
...(raw.detail || raw),
|
||||||
|
items: raw.items || [],
|
||||||
|
expresses: raw.expresses || []
|
||||||
|
}))
|
||||||
|
|
||||||
|
// 通过 detail API 逐条补全运单号
|
||||||
|
const enrichedMap: Record<string, any> = {}
|
||||||
|
for (const order of orderList) {
|
||||||
|
const oid = order.id
|
||||||
|
if (oid == null) continue
|
||||||
|
try {
|
||||||
|
const detailRes = await orderPendingOrderDetail({ id: oid, ids: [oid], tableType: 'order' })
|
||||||
|
if (detailRes && (detailRes.code === 200 || detailRes.code === 0 || detailRes.flag === 'success')) {
|
||||||
|
const payload = detailRes.data?.detail || detailRes.data || detailRes
|
||||||
|
if (payload && typeof payload === 'object') {
|
||||||
|
enrichedMap[String(oid)] = {
|
||||||
|
...payload,
|
||||||
|
items: detailRes.data?.items || payload.items || [],
|
||||||
|
expresses: detailRes.data?.expresses || payload.expresses || []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* 单条失败不影响其他 */ }
|
||||||
|
}
|
||||||
|
if (Object.keys(enrichedMap).length > 0) {
|
||||||
|
orderList = orderList.map((o: any) => {
|
||||||
|
const enriched = enrichedMap[String(o.id ?? '')]
|
||||||
|
return enriched ? { ...o, ...enriched } : o
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const waveGroupMap: Record<string, any[]> = {}
|
||||||
|
orderList.forEach((order: any) => {
|
||||||
|
const wid = String(order.wave_id ?? '')
|
||||||
|
if (!wid) return
|
||||||
|
if (!waveGroupMap[wid]) waveGroupMap[wid] = []
|
||||||
|
waveGroupMap[wid].push(order)
|
||||||
|
})
|
||||||
|
|
||||||
|
const nextMap: Record<string, any> = {}
|
||||||
|
Object.entries(waveGroupMap).forEach(([wid, orders]) => {
|
||||||
|
const processedOrders = orders.map(normalizePrintOrder)
|
||||||
|
const first = processedOrders[0]
|
||||||
|
nextMap[wid] = { ...first, wave_no: String(first.wave_no ?? first.wave_code ?? first.batch_no ?? wid), details: processedOrders }
|
||||||
|
})
|
||||||
|
|
||||||
wavePrintRows.value = rows.map((item: any) => ({
|
wavePrintRows.value = rows.map((item: any) => ({
|
||||||
...item,
|
...item,
|
||||||
wave_no: String(item?.wave_no ?? item?.batch_no ?? item?.wave_code ?? item?.id ?? '—')
|
wave_no: String(item?.wave_no ?? item?.batch_no ?? item?.wave_code ?? item?.id ?? '—')
|
||||||
}))
|
}))
|
||||||
wavePrintDataMap.value = nextMap
|
wavePrintDataMap.value = nextMap
|
||||||
wavePrintDialogVisible.value = true
|
wavePrintDialogVisible.value = true
|
||||||
const waveCount = waveList.length
|
const hasExpress = orderList.some((o: any) => Array.isArray(o.expresses) && o.expresses.length > 0)
|
||||||
ElMessage.success(res?.message || `已获取打印数据,返回 ${waveCount} 个波次`)
|
ElMessage.success(`已获取打印数据,共 ${orderList.length} 条订单${hasExpress ? '(含运单号)' : '(无运单号)'}`)
|
||||||
|
} catch (error: any) {
|
||||||
|
wavePrintRows.value = []
|
||||||
|
wavePrintDataMap.value = {}
|
||||||
|
ElMessage.error(error?.message || '获取波次打印数据失败')
|
||||||
|
} finally {
|
||||||
|
batchPrintLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleBatchPrintPickingList() {
|
||||||
|
if (!selectionRows.value.length) {
|
||||||
|
ElMessage.warning('请先勾选要打印拣货单的波次')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const rows = [...selectionRows.value]
|
||||||
|
await handleBatchPrintInternal(rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 内部打印逻辑(跳过 isGroupWaveTab 检查) */
|
||||||
|
async function handleBatchPrintInternal(rows: any[]) {
|
||||||
|
const wave_ids = rows
|
||||||
|
.map((row: any) => row?.id ?? row?.wave_id ?? row?.batch_id)
|
||||||
|
.filter((id: unknown) => id !== undefined && id !== null && id !== '')
|
||||||
|
|
||||||
|
if (!wave_ids.length) {
|
||||||
|
ElMessage.warning('当前勾选记录缺少可用的波次 ID')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
batchPrintLoading.value = true
|
||||||
|
try {
|
||||||
|
const res: any = await orderPendingOrderList({
|
||||||
|
pagination: { page: 1, pageSize: 9999 },
|
||||||
|
where: { wave_id: { operator: 'in', value: wave_ids, type: 'select' } }
|
||||||
|
})
|
||||||
|
|
||||||
|
const isSuccess = res && (res.code === 200 || res.code === 0 || res.flag === 'success')
|
||||||
|
if (!isSuccess) { ElMessage.error(res?.message || '获取订单数据失败'); return }
|
||||||
|
|
||||||
|
let rawList: any[] = []
|
||||||
|
const d = res.data
|
||||||
|
if (Array.isArray(d?.list)) { rawList = d.list }
|
||||||
|
else if (Array.isArray(d?.data)) { rawList = d.data }
|
||||||
|
else if (Array.isArray(d)) { rawList = d }
|
||||||
|
else if (d?.detail && typeof d.detail === 'object') { rawList = [d] }
|
||||||
|
|
||||||
|
if (!rawList.length) { ElMessage.warning('未获取到波次订单数据'); return }
|
||||||
|
|
||||||
|
let orderList = rawList.map((raw: any) => ({
|
||||||
|
...(raw.detail || raw),
|
||||||
|
items: raw.items || [],
|
||||||
|
expresses: raw.expresses || []
|
||||||
|
}))
|
||||||
|
|
||||||
|
const enrichedMap: Record<string, any> = {}
|
||||||
|
for (const order of orderList) {
|
||||||
|
const oid = order.id
|
||||||
|
if (oid == null) continue
|
||||||
|
try {
|
||||||
|
const detailRes = await orderPendingOrderDetail({ id: oid, ids: [oid], tableType: 'order' })
|
||||||
|
if (detailRes && (detailRes.code === 200 || detailRes.code === 0 || detailRes.flag === 'success')) {
|
||||||
|
const payload = detailRes.data?.detail || detailRes.data || detailRes
|
||||||
|
if (payload && typeof payload === 'object') {
|
||||||
|
enrichedMap[String(oid)] = { ...payload, items: detailRes.data?.items || payload.items || [], expresses: detailRes.data?.expresses || payload.expresses || [] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
if (Object.keys(enrichedMap).length > 0) {
|
||||||
|
orderList = orderList.map((o: any) => { const e = enrichedMap[String(o.id ?? '')]; return e ? { ...o, ...e } : o })
|
||||||
|
}
|
||||||
|
|
||||||
|
const waveGroupMap: Record<string, any[]> = {}
|
||||||
|
orderList.forEach((order: any) => {
|
||||||
|
const wid = String(order.wave_id ?? '')
|
||||||
|
if (!wid) return
|
||||||
|
if (!waveGroupMap[wid]) waveGroupMap[wid] = []
|
||||||
|
waveGroupMap[wid].push(order)
|
||||||
|
})
|
||||||
|
|
||||||
|
const nextMap: Record<string, any> = {}
|
||||||
|
Object.entries(waveGroupMap).forEach(([wid, orders]) => {
|
||||||
|
const p = orders.map(normalizePrintOrder)
|
||||||
|
nextMap[wid] = { ...p[0], wave_no: String(p[0].wave_no ?? p[0].wave_code ?? p[0].batch_no ?? wid), details: p }
|
||||||
|
})
|
||||||
|
|
||||||
|
wavePrintRows.value = rows.map((item: any) => ({
|
||||||
|
...item, wave_no: String(item?.wave_no ?? item?.batch_no ?? item?.wave_code ?? item?.id ?? '—')
|
||||||
|
}))
|
||||||
|
wavePrintDataMap.value = nextMap
|
||||||
|
wavePrintDialogVisible.value = true
|
||||||
|
const hasExpress = orderList.some((o: any) => Array.isArray(o.expresses) && o.expresses.length > 0)
|
||||||
|
ElMessage.success(`已获取打印数据,共 ${orderList.length} 条订单${hasExpress ? '(含运单号)' : '(无运单号)'}`)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
wavePrintRows.value = []
|
wavePrintRows.value = []
|
||||||
wavePrintDataMap.value = {}
|
wavePrintDataMap.value = {}
|
||||||
@ -1391,9 +1558,11 @@ async function openBatchOutboundPrintDialog(rows: any[]) {
|
|||||||
|
|
||||||
batchOutboundPrintLoading.value = true
|
batchOutboundPrintLoading.value = true
|
||||||
try {
|
try {
|
||||||
const res: any = await getWavePrintData({ warehouse_id: warehouseId, wave_ids })
|
const waveList = await fetchOutboundWaveList(wave_ids)
|
||||||
const payload = unwrapWavePrintPayloadFromConfig(res)
|
if (!waveList.length) {
|
||||||
const waveList = Array.isArray(payload.wave_list) ? payload.wave_list : []
|
ElMessage.warning('未获取到波次订单数据')
|
||||||
|
return
|
||||||
|
}
|
||||||
const { printRows, dataMap, missingDeliveryCodes } = await fetchOutboundPrintDataFromPendingOrders(
|
const { printRows, dataMap, missingDeliveryCodes } = await fetchOutboundPrintDataFromPendingOrders(
|
||||||
waveList,
|
waveList,
|
||||||
rows,
|
rows,
|
||||||
@ -1410,7 +1579,7 @@ async function openBatchOutboundPrintDialog(rows: any[]) {
|
|||||||
`${missingDeliveryCodes.length} 个发货单号未匹配到待处理订单,已使用波次原始数据填充:${missingDeliveryCodes.slice(0, 3).join('、')}${missingDeliveryCodes.length > 3 ? '…' : ''}`,
|
`${missingDeliveryCodes.length} 个发货单号未匹配到待处理订单,已使用波次原始数据填充:${missingDeliveryCodes.slice(0, 3).join('、')}${missingDeliveryCodes.length > 3 ? '…' : ''}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ElMessage.success(res?.message || `已获取出库单打印数据,共 ${printRows.length} 单`)
|
ElMessage.success(`已获取出库单打印数据,共 ${printRows.length} 单`)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
outboundPrintRows.value = []
|
outboundPrintRows.value = []
|
||||||
outboundPrintDataMap.value = {}
|
outboundPrintDataMap.value = {}
|
||||||
|
|||||||
@ -402,18 +402,18 @@ export const waveToolbarButtons: WaveToolbarButtonConfig[] = [
|
|||||||
action: 'openPrinterComponentConnectionDialog',
|
action: 'openPrinterComponentConnectionDialog',
|
||||||
onlyForWaveType: 2
|
onlyForWaveType: 2
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// key: 'batchPrintPickingList',
|
key: 'batchPrintPickingList',
|
||||||
// label: '批量打印拣货单(0)',
|
label: '批量打印拣货单(0)',
|
||||||
// dynamicLabelKey: 'batchPickingPrintTotal',
|
dynamicLabelKey: 'batchPickingPrintTotal',
|
||||||
// type: 'info',
|
type: 'info',
|
||||||
// plain: true,
|
plain: true,
|
||||||
// size: 'small',
|
size: 'small',
|
||||||
// disabledKey: 'noSelection',
|
disabledKey: 'noSelection',
|
||||||
// loadingKey: 'batchPrintLoading',
|
loadingKey: 'batchPrintLoading',
|
||||||
// action: 'handleBatchPrintPickingList',
|
action: 'handleBatchPrintPickingList',
|
||||||
// onlyForWaveType: 1
|
onlyForWaveType: 2
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
key: 'batchAutoGrouping',
|
key: 'batchAutoGrouping',
|
||||||
label: '批量改为自动加团',
|
label: '批量改为自动加团',
|
||||||
@ -1023,7 +1023,6 @@ export function buildOutboundPrintQueue(
|
|||||||
return { printRows, dataMap }
|
return { printRows, dataMap }
|
||||||
}
|
}
|
||||||
|
|
||||||
const OUTBOUND_DELIVERY_CODE_QUERY_BATCH_SIZE = 20
|
|
||||||
const OUTBOUND_DETAIL_FETCH_CONCURRENCY = 8
|
const OUTBOUND_DETAIL_FETCH_CONCURRENCY = 8
|
||||||
|
|
||||||
function formatOutboundPrintDateTime(date: Date): string {
|
function formatOutboundPrintDateTime(date: Date): string {
|
||||||
@ -1055,34 +1054,6 @@ async function runWithConcurrencyLimit<T>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 按发货单号批量查询待处理订单(order.pendingOrder.list) */
|
|
||||||
async function queryPendingOrdersByDeliveryCodes(codes: string[]): Promise<Record<string, unknown>[]> {
|
|
||||||
const normalizedCodes = [...new Set(codes.map((code) => String(code || '').trim()).filter(Boolean))]
|
|
||||||
if (!normalizedCodes.length) return []
|
|
||||||
|
|
||||||
const res: any = await orderPendingOrder.list({
|
|
||||||
pagination: { page: 1, pageSize: Math.max(50, normalizedCodes.length * 10) },
|
|
||||||
where: {
|
|
||||||
delivery_order_code: {
|
|
||||||
operator: 'contains',
|
|
||||||
value: normalizedCodes,
|
|
||||||
type: 'text',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
sort: {
|
|
||||||
sortField: 'updated_at',
|
|
||||||
sortOrder: 'DESC',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if (!isOrderIndexApiSuccess(res)) return []
|
|
||||||
|
|
||||||
const targetSet = new Set(normalizedCodes)
|
|
||||||
return parseOrderListResponse(res).list.filter((order) => {
|
|
||||||
const existingCode = resolvePendingOrderDeliveryCode(order)
|
|
||||||
return existingCode && targetSet.has(existingCode)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 查询单个订单详情(order.pendingOrder.detail) */
|
/** 查询单个订单详情(order.pendingOrder.detail) */
|
||||||
async function fetchPendingOrderDetailById(orderId: number | string): Promise<Record<string, unknown> | null> {
|
async function fetchPendingOrderDetailById(orderId: number | string): Promise<Record<string, unknown> | null> {
|
||||||
const res: any = await orderPendingOrder.detail({
|
const res: any = await orderPendingOrder.detail({
|
||||||
@ -1186,6 +1157,8 @@ export function mapPendingOrderToOutboundPrintForm(
|
|||||||
logistics_name: order.logistics_name ?? '',
|
logistics_name: order.logistics_name ?? '',
|
||||||
express_code: String(order.express_code ?? waybillStr).trim(),
|
express_code: String(order.express_code ?? waybillStr).trim(),
|
||||||
waybill_codes: waybillStr,
|
waybill_codes: waybillStr,
|
||||||
|
// 传播 expresses 数组,确保打印模板能从 expresses 获取运单号
|
||||||
|
expresses: Array.isArray(detailPayload.expresses) ? detailPayload.expresses : [],
|
||||||
name: order.name ?? '',
|
name: order.name ?? '',
|
||||||
mobile: order.mobile ?? order.tel ?? '',
|
mobile: order.mobile ?? order.tel ?? '',
|
||||||
tel: order.tel ?? '',
|
tel: order.tel ?? '',
|
||||||
@ -1202,7 +1175,51 @@ export function mapPendingOrderToOutboundPrintForm(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从波次打印数据提取发货单号,再通过 order.pendingOrder.list + detail 补全出库单字段与商品明细。
|
* 替换 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(
|
export async function fetchOutboundPrintDataFromPendingOrders(
|
||||||
waveList: Record<string, unknown>[],
|
waveList: Record<string, unknown>[],
|
||||||
@ -1213,27 +1230,16 @@ export async function fetchOutboundPrintDataFromPendingOrders(
|
|||||||
return { ...skeleton, missingDeliveryCodes: [] }
|
return { ...skeleton, missingDeliveryCodes: [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
const deliveryCodes = [
|
// 从 waveList 的 orders 中直接构建 code → orderId 映射(无需再调 list 接口)
|
||||||
...new Set(
|
|
||||||
skeleton.printRows
|
|
||||||
.map((row) => String(row.delivery_order_code ?? '').trim())
|
|
||||||
.filter(Boolean),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
const codeToOrderId = new Map<string, number | string>()
|
const codeToOrderId = new Map<string, number | string>()
|
||||||
const batches: string[][] = []
|
waveList.forEach((wave) => {
|
||||||
for (let i = 0; i < deliveryCodes.length; i += OUTBOUND_DELIVERY_CODE_QUERY_BATCH_SIZE) {
|
const orders = getWaveOrders(wave)
|
||||||
batches.push(deliveryCodes.slice(i, i + OUTBOUND_DELIVERY_CODE_QUERY_BATCH_SIZE))
|
orders.forEach((order: any) => {
|
||||||
}
|
if (!order || typeof order !== 'object') return
|
||||||
|
|
||||||
await runWithConcurrencyLimit(batches, 3, async (batch) => {
|
|
||||||
const orders = await queryPendingOrdersByDeliveryCodes(batch)
|
|
||||||
orders.forEach((order) => {
|
|
||||||
const code = resolvePendingOrderDeliveryCode(order)
|
const code = resolvePendingOrderDeliveryCode(order)
|
||||||
const orderId = order.id ?? order.order_id
|
const oid = order.id ?? order.order_id
|
||||||
if (code && orderId != null && orderId !== '') {
|
if (code && oid != null && oid !== '') {
|
||||||
codeToOrderId.set(code, orderId as number | string)
|
codeToOrderId.set(code, oid as number | string)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -7,6 +7,9 @@
|
|||||||
<el-icon><Document /></el-icon> 模板列表
|
<el-icon><Document /></el-icon> 模板列表
|
||||||
</span>
|
</span>
|
||||||
<span class="title-actions">
|
<span class="title-actions">
|
||||||
|
<el-button type="primary" link @click="handleRefresh">
|
||||||
|
<el-icon><Refresh /></el-icon> 刷新
|
||||||
|
</el-button>
|
||||||
<el-button type="primary" link @click="openCreateDialog">
|
<el-button type="primary" link @click="openCreateDialog">
|
||||||
<el-icon><Plus /></el-icon> 新建
|
<el-icon><Plus /></el-icon> 新建
|
||||||
</el-button>
|
</el-button>
|
||||||
@ -178,7 +181,7 @@
|
|||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import type { FormInstance, FormRules } from 'element-plus'
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
import { Document, Folder, Plus, Delete } from '@element-plus/icons-vue'
|
import { Document, Folder, Plus, Delete, Refresh } from '@element-plus/icons-vue'
|
||||||
import TemplateEditor from './components/TemplateEditor.vue'
|
import TemplateEditor from './components/TemplateEditor.vue'
|
||||||
import * as TemplatesApi from '@/api/setting.printtemplate/printTemplate'
|
import * as TemplatesApi from '@/api/setting.printtemplate/printTemplate'
|
||||||
import { usePrintTemplateStore } from '@/stores/modules/printTemplate'
|
import { usePrintTemplateStore } from '@/stores/modules/printTemplate'
|
||||||
@ -331,6 +334,11 @@ const loadTemplates = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleRefresh = async () => {
|
||||||
|
await loadTemplates()
|
||||||
|
ElMessage.success('模板列表已刷新')
|
||||||
|
}
|
||||||
|
|
||||||
const runTypeQuery = async () => {
|
const runTypeQuery = async () => {
|
||||||
const bt = String(typeQueryForm.value.businessType || '').trim()
|
const bt = String(typeQueryForm.value.businessType || '').trim()
|
||||||
if (!bt) {
|
if (!bt) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user