import { $t } from '@/locales'
|
|
function translate(t, key, params) {
|
return (typeof t === 'function' ? t : $t)(key, params)
|
}
|
|
export function getWaveReportTitle(t) {
|
return translate(t, 'pages.orders.wave.reportTitle')
|
}
|
export const WAVE_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong',
|
orientation: 'landscape',
|
density: 'compact',
|
showSequence: true
|
}
|
|
const WAVE_STATUS_TAG_MAP = {
|
0: 'info',
|
1: 'warning',
|
2: 'warning',
|
3: 'success'
|
}
|
|
const WAVE_ITEM_STATUS_TAG_MAP = {
|
0: 'info',
|
1: 'warning',
|
2: 'warning',
|
3: 'primary',
|
4: '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, t) {
|
const statusKey = `pages.orders.wave.status.exceStatus.${Number(status)}`
|
const fallbackLabel = statusText || translate(t, statusKey)
|
return {
|
label: fallbackLabel || '-',
|
tagType: WAVE_STATUS_TAG_MAP[Number(status)] || 'info'
|
}
|
}
|
|
function getItemStatusConfig(status, statusText, t) {
|
const statusKey = `pages.orders.waveItem.status.exceStatus.${Number(status)}`
|
const fallbackLabel = statusText || translate(t, statusKey)
|
return {
|
label: fallbackLabel || '-',
|
tagType: WAVE_ITEM_STATUS_TAG_MAP[Number(status)] || 'info'
|
}
|
}
|
|
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 = {}, t) {
|
const statusConfig = getStatusConfig(record.exceStatus, record['exceStatus$'], t)
|
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$'] || translate(t, `pages.orders.wave.status.type.${record.type}`) || record.type || '-',
|
exceStatusText: statusConfig.label,
|
exceStatusTagType: statusConfig.tagType,
|
statusLabel:
|
record['status$'] ||
|
translate(t, Number(record.status) === 1 ? 'common.status.normal' : 'common.status.disabled') ||
|
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 = {}, t) {
|
const statusConfig = getItemStatusConfig(record.exceStatus, record['exceStatus$'], t)
|
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 = [], t) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeWaveRow(record, t))
|
}
|
|
export function buildWaveReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = WAVE_REPORT_STYLE.orientation,
|
t
|
} = {}) {
|
return {
|
reportTitle: getWaveReportTitle(t),
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...WAVE_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|
|
export function getWaveActionList(row = {}, t) {
|
const normalizedRow = normalizeWaveRow(row, t)
|
return [
|
{
|
key: 'view',
|
label: translate(t, 'pages.orders.wave.actions.view'),
|
icon: 'ri:eye-line'
|
},
|
{
|
key: 'publicTask',
|
label: translate(t, 'pages.orders.wave.actions.publicTask'),
|
icon: 'ri:play-circle-line',
|
disabled: !normalizedRow.canPublicTask
|
},
|
{
|
key: 'pause',
|
label: translate(t, 'pages.orders.wave.actions.pause'),
|
icon: 'ri:pause-circle-line',
|
disabled: !normalizedRow.canPause
|
},
|
{
|
key: 'continue',
|
label: translate(t, 'pages.orders.wave.actions.continue'),
|
icon: 'ri:play-line',
|
disabled: !normalizedRow.canContinue
|
},
|
{
|
key: 'stop',
|
label: translate(t, 'pages.orders.wave.actions.stop'),
|
icon: 'ri:stop-circle-line',
|
disabled: !normalizedRow.canStop
|
},
|
{
|
key: 'print',
|
label: translate(t, 'pages.orders.wave.actions.print'),
|
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)
|
}
|
}
|