export const WAVE_REPORT_TITLE = '波次单报表' export const WAVE_REPORT_STYLE = { titleAlign: 'center', titleLevel: 'strong', orientation: 'landscape', density: 'compact', showSequence: true } const WAVE_STATUS_MAP = { 0: { label: '等待执行', tagType: 'info' }, 1: { label: '正在执行', tagType: 'warning' }, 2: { label: '暂停执行', tagType: 'warning' }, 3: { label: '执行完成', tagType: 'success' } } const WAVE_ITEM_STATUS_MAP = { 0: { label: '未执行', tagType: 'info' }, 1: { label: '执行中', tagType: 'warning' }, 2: { label: '暂停', tagType: 'warning' }, 3: { label: '已下发', tagType: 'primary' }, 4: { label: '任务完成', tagType: 'success' } } function normalizeText(value) { return String(value ?? '').trim() } function normalizeNumber(value) { if (value === '' || value === null || value === undefined) { return 0 } const numericValue = Number(value) return Number.isFinite(numericValue) ? numericValue : 0 } function getStatusConfig(status, statusText) { const fallback = WAVE_STATUS_MAP[Number(status)] || { label: statusText || '-', tagType: 'info' } return { label: statusText || fallback.label, tagType: fallback.tagType } } function getItemStatusConfig(status, statusText) { const fallback = WAVE_ITEM_STATUS_MAP[Number(status)] || { label: statusText || '-', tagType: 'info' } return { label: statusText || fallback.label, tagType: fallback.tagType } } function normalizeStockLocs(stockLocs) { if (!stockLocs) { return '[]' } if (typeof stockLocs === 'string') { return stockLocs } try { return JSON.stringify(stockLocs) } catch { return '[]' } } export function createWaveSearchState() { return { condition: '', code: '', type: '', exceStatus: '', status: '', memo: '', timeStart: '', timeEnd: '' } } export function buildWaveSearchParams(params = {}) { const result = {} ;['condition', 'code', 'memo', 'timeStart', 'timeEnd'].forEach((key) => { const value = normalizeText(params[key]) if (value) { result[key] = value } }) if (params.type !== '' && params.type !== undefined && params.type !== null) { result.type = Number(params.type) } if (params.exceStatus !== '' && params.exceStatus !== undefined && params.exceStatus !== null) { result.exceStatus = Number(params.exceStatus) } if (params.status !== '' && params.status !== undefined && params.status !== null) { result.status = Number(params.status) } return result } export function buildWavePageQueryParams(params = {}) { return { current: params.current || 1, pageSize: params.pageSize || params.size || 20, ...buildWaveSearchParams(params) } } export function buildWaveDetailQueryParams(params = {}) { return { waveId: params.waveId, current: params.current || 1, pageSize: params.pageSize || params.size || 20 } } export function normalizeWaveRow(record = {}) { const statusConfig = getStatusConfig(record.exceStatus, record['exceStatus$']) const progress = normalizeNumber(record.anfme) > 0 ? Math.min(Math.round((normalizeNumber(record.workQty) / normalizeNumber(record.anfme)) * 100), 100) : 0 return { ...record, code: record.code || '-', typeLabel: record['type$'] || record.type || '-', exceStatusText: statusConfig.label, exceStatusTagType: statusConfig.tagType, statusLabel: record['status$'] || record.status || '-', anfme: normalizeNumber(record.anfme), qty: normalizeNumber(record.qty), workQty: normalizeNumber(record.workQty), orderNum: normalizeNumber(record.orderNum), groupQty: normalizeNumber(record.groupQty), progress, createTimeText: record['createTime$'] || record.createTime || '-', updateTimeText: record['updateTime$'] || record.updateTime || '-', createByText: record['createBy$'] || '-', updateByText: record['updateBy$'] || '-', memo: record.memo || '-', targSite: record.targSite || '-', stationId: record.stationId || '-', locCode: record.locCode || '-', canPublicTask: Number(record.exceStatus) === 0, canPause: Number(record.exceStatus) === 1, canContinue: Number(record.exceStatus) === 2, canStop: Number(record.exceStatus) !== 3 } } export function normalizeWaveItemRow(record = {}) { const statusConfig = getItemStatusConfig(record.exceStatus, record['exceStatus$']) return { ...record, waveCode: record.waveCode || '-', orderCode: record.orderCode || '-', matnrCode: record.matnrCode || '-', maktx: record.maktx || '-', batch: record.batch || '-', splrBatch: record.splrBatch || '-', unit: record.unit || '-', trackCode: record.trackCode || '-', fieldsIndex: record.fieldsIndex || '-', anfme: normalizeNumber(record.anfme), qty: normalizeNumber(record.qty), workQty: normalizeNumber(record.workQty), stockQty: normalizeNumber(record.stockQty), stockLocsText: normalizeStockLocs(record.stockLocs), statusLabel: record['status$'] || record.status || '-', exceStatusText: statusConfig.label, exceStatusTagType: statusConfig.tagType, updateTimeText: record['updateTime$'] || record.updateTime || '-', createTimeText: record['createTime$'] || record.createTime || '-' } } export function buildWavePrintRows(records = []) { if (!Array.isArray(records)) { return [] } return records.map((record) => normalizeWaveRow(record)) } export function buildWaveReportMeta({ previewMeta = {}, count = 0, orientation = WAVE_REPORT_STYLE.orientation } = {}) { return { reportTitle: WAVE_REPORT_TITLE, reportDate: previewMeta.reportDate, printedAt: previewMeta.printedAt, operator: previewMeta.operator, count, reportStyle: { ...WAVE_REPORT_STYLE, orientation } } } export function getWaveActionList(row = {}) { const normalizedRow = normalizeWaveRow(row) return [ { key: 'view', label: '查看详情', icon: 'ri:eye-line' }, { key: 'publicTask', label: '下发任务', icon: 'ri:play-circle-line', disabled: !normalizedRow.canPublicTask }, { key: 'pause', label: '暂停', icon: 'ri:pause-circle-line', disabled: !normalizedRow.canPause }, { key: 'continue', label: '继续', icon: 'ri:play-line', disabled: !normalizedRow.canContinue }, { key: 'stop', label: '终止', icon: 'ri:stop-circle-line', disabled: !normalizedRow.canStop }, { key: 'print', label: '打印', icon: 'ri:printer-line' } ] } export function createWaveItemSearchState() { return { condition: '', waveId: '', waveCode: '', matnrCode: '', maktx: '', batch: '', splrBatch: '', orderCode: '', unit: '', fieldsIndex: '', status: '', exceStatus: '', timeStart: '', timeEnd: '' } } export function buildWaveItemSearchParams(params = {}) { const result = {} ;[ 'condition', 'waveCode', 'matnrCode', 'maktx', 'batch', 'splrBatch', 'orderCode', 'unit', 'fieldsIndex', 'timeStart', 'timeEnd' ].forEach((key) => { const value = normalizeText(params[key]) if (value) { result[key] = value } }) if (params.waveId !== '' && params.waveId !== undefined && params.waveId !== null) { result.waveId = Number(params.waveId) } if (params.status !== '' && params.status !== undefined && params.status !== null) { result.status = Number(params.status) } if (params.exceStatus !== '' && params.exceStatus !== undefined && params.exceStatus !== null) { result.exceStatus = Number(params.exceStatus) } return result } export function buildWaveItemPageQueryParams(params = {}) { return { current: params.current || 1, pageSize: params.pageSize || params.size || 20, ...buildWaveItemSearchParams(params) } }