import { $t } from '@/locales'
|
|
export function getAsnOrderItemReportTitle(t = $t) {
|
return t('pages.orders.asnOrderItem.reportTitle')
|
}
|
|
export const ASN_ORDER_ITEM_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong',
|
orientation: 'landscape',
|
density: 'compact',
|
showSequence: true
|
}
|
|
function normalizeText(value, fallback = $t('common.placeholder.empty')) {
|
if (value === null || value === undefined || value === '') {
|
return fallback
|
}
|
return String(value)
|
}
|
|
function normalizeNumber(value) {
|
if (value === '' || value === null || value === undefined) {
|
return 0
|
}
|
const numericValue = Number(value)
|
return Number.isFinite(numericValue) ? numericValue : 0
|
}
|
|
function pushText(result, key, value) {
|
const text = normalizeText(value, '')
|
if (text) {
|
result[key] = text
|
}
|
}
|
|
function pushNumber(result, key, value) {
|
if (value === '' || value === null || value === undefined) {
|
return
|
}
|
const numericValue = Number(value)
|
if (Number.isFinite(numericValue)) {
|
result[key] = numericValue
|
}
|
}
|
|
function pushRange(result, key, value) {
|
if (!Array.isArray(value) || value.length === 0) {
|
return
|
}
|
const normalizedRange = value.filter((item) => item !== null && item !== undefined && item !== '')
|
if (normalizedRange.length === 2) {
|
result[key] = normalizedRange
|
}
|
}
|
|
function getOrderTypeLabel(type, t = $t) {
|
if (type === 'in') return t('pages.orders.asnOrderItem.orderType.in')
|
if (type === 'out') return t('pages.orders.asnOrderItem.orderType.out')
|
return normalizeText(type)
|
}
|
|
function getStatusConfig(status, t = $t) {
|
const numericStatus = Number(status)
|
if (numericStatus === 1) {
|
return { label: t('common.status.normal'), tagType: 'success' }
|
}
|
if (numericStatus === 0) {
|
return { label: t('common.status.frozen'), tagType: 'info' }
|
}
|
return { label: normalizeText(status), tagType: 'info' }
|
}
|
|
function getNtyStatusConfig(status, t = $t) {
|
const numericStatus = Number(status)
|
if (numericStatus === 0) {
|
return { label: t('pages.orders.asnOrderItem.ntyStatus.notReported'), tagType: 'info' }
|
}
|
if (numericStatus === 1) {
|
return { label: t('pages.orders.asnOrderItem.ntyStatus.reported'), tagType: 'success' }
|
}
|
return { label: normalizeText(status), tagType: 'info' }
|
}
|
|
export function createAsnOrderItemSearchState() {
|
return {
|
condition: '',
|
orderId: '',
|
orderCode: '',
|
poCode: '',
|
platWorkCode: '',
|
platItemId: '',
|
matnrCode: '',
|
maktx: '',
|
spec: '',
|
model: '',
|
batch: '',
|
stockUnit: '',
|
purUnit: '',
|
splrCode: '',
|
splrName: '',
|
splrBatch: '',
|
qrcode: '',
|
trackCode: '',
|
packName: '',
|
projectCode: '',
|
targetWarehouseId: '',
|
status: '',
|
ntyStatus: '',
|
createTimeRange: [],
|
updateTimeRange: []
|
}
|
}
|
|
export function buildAsnOrderItemSearchParams(params = {}) {
|
const result = {}
|
|
;[
|
'condition',
|
'orderId',
|
'orderCode',
|
'poCode',
|
'platWorkCode',
|
'platItemId',
|
'matnrCode',
|
'maktx',
|
'spec',
|
'model',
|
'batch',
|
'stockUnit',
|
'purUnit',
|
'splrCode',
|
'splrName',
|
'splrBatch',
|
'qrcode',
|
'trackCode',
|
'packName',
|
'projectCode',
|
'targetWarehouseId'
|
].forEach((key) => pushText(result, key, params[key]))
|
|
;['status', 'ntyStatus'].forEach((key) => pushNumber(result, key, params[key]))
|
;['createTimeRange', 'updateTimeRange'].forEach((key) => pushRange(result, key, params[key]))
|
|
return result
|
}
|
|
export function buildAsnOrderItemPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...(params.orderBy ? { orderBy: normalizeText(params.orderBy) } : {}),
|
...buildAsnOrderItemSearchParams(params)
|
}
|
}
|
|
export function normalizeAsnOrderItemRow(record = {}, t = $t) {
|
return {
|
...record,
|
id: record.id ?? null,
|
poCode: normalizeText(record.poCode),
|
typeLabel: getOrderTypeLabel(record.type, t),
|
wkTypeLabel: normalizeText(record['wkType$'] || record.wkType),
|
purchaseOrgName: normalizeText(record.purchaseOrgName),
|
purchaseUserName: normalizeText(record.purchaseUserName),
|
supplierId: normalizeText(record.supplierId),
|
supplierName: normalizeText(record.supplierName),
|
platWorkCode: normalizeText(record.platWorkCode),
|
platItemId: normalizeText(record.platItemId),
|
matnrCode: normalizeText(record.matnrCode),
|
maktx: normalizeText(record.maktx),
|
batch: normalizeText(record.batch),
|
stockUnit: normalizeText(record.stockUnit),
|
anfme: normalizeNumber(record.anfme),
|
qty: normalizeNumber(record.qty),
|
targetWarehouseId: normalizeText(record.targetWarehouseId),
|
businessTimeText: normalizeText(record.businessTime),
|
updateTimeText: normalizeText(record.updateTime),
|
memo: normalizeText(record.memo)
|
}
|
}
|
|
export function normalizeAsnOrderItemDetail(record = {}, t = $t) {
|
const statusConfig = getStatusConfig(record.status, t)
|
const ntyStatusConfig = getNtyStatusConfig(record.ntyStatus, t)
|
|
return {
|
...record,
|
id: record.id ?? null,
|
orderCode: normalizeText(record.orderCode),
|
poCode: normalizeText(record.poCode),
|
typeLabel: getOrderTypeLabel(record.type, t),
|
poDetlId: record.poDetlId ?? $t('common.placeholder.empty'),
|
platWorkCode: normalizeText(record.platWorkCode),
|
platItemId: normalizeText(record.platItemId),
|
projectCode: normalizeText(record.projectCode),
|
matnrCode: normalizeText(record.matnrCode),
|
maktx: normalizeText(record.maktx),
|
spec: normalizeText(record.spec),
|
model: normalizeText(record.model),
|
batch: normalizeText(record.batch),
|
stockUnit: normalizeText(record.stockUnit),
|
purQty: normalizeNumber(record.purQty),
|
purUnit: normalizeText(record.purUnit),
|
anfme: normalizeNumber(record.anfme),
|
qty: normalizeNumber(record.qty),
|
workQty: normalizeNumber(record.workQty),
|
splrCode: normalizeText(record.splrCode),
|
splrName: normalizeText(record.splrName),
|
splrBatch: normalizeText(record.splrBatch),
|
qrcode: normalizeText(record.qrcode),
|
barcode: normalizeText(record.barcode),
|
packName: normalizeText(record.packName),
|
prodTimeText: normalizeText(record.prodTime),
|
targetWarehouseId: normalizeText(record.targetWarehouseId),
|
sourceWarehouseId: normalizeText(record.sourceWarehouseId),
|
ntyStatusText: ntyStatusConfig.label,
|
ntyStatusTagType: ntyStatusConfig.tagType,
|
statusText: statusConfig.label,
|
statusTagType: statusConfig.tagType,
|
isptResultText: normalizeText(record['isptResult$'] || record.isptResult),
|
updateByText: normalizeText(record['updateBy$'] || record.updateBy),
|
updateTimeText: normalizeText(record['updateTime$'] || record.updateTime),
|
createByText: normalizeText(record['createBy$'] || record.createBy),
|
createTimeText: normalizeText(record['createTime$'] || record.createTime),
|
memo: normalizeText(record.memo),
|
extendFields: record.extendFields || {}
|
}
|
}
|
|
export function buildAsnOrderItemPrintRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeAsnOrderItemRow(record))
|
}
|
|
export function buildAsnOrderItemReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = ASN_ORDER_ITEM_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: getAsnOrderItemReportTitle(),
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...ASN_ORDER_ITEM_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|