| | |
| | | import { $t } from '@/locales' |
| | | |
| | | const DELIVERY_STATUS_META = { |
| | | 1: { text: $t('pages.orders.delivery.status.normal'), type: 'success', bool: true }, |
| | | 0: { text: $t('pages.orders.delivery.status.disabled'), type: 'danger', bool: false } |
| | | function getDeliveryStatusMetaMap(t = $t) { |
| | | return { |
| | | 1: { text: t('pages.orders.delivery.status.normal'), type: 'success', bool: true }, |
| | | 0: { text: t('pages.orders.delivery.status.disabled'), type: 'danger', bool: false } |
| | | } |
| | | } |
| | | |
| | | const DELIVERY_EXCE_STATUS_META = { |
| | | 0: { text: $t('pages.orders.delivery.status.pending'), type: 'info' }, |
| | | 1: { text: $t('pages.orders.delivery.status.running'), type: 'warning' }, |
| | | 2: { text: $t('pages.orders.delivery.status.partial'), type: 'primary' }, |
| | | 3: { text: $t('pages.orders.delivery.status.completed'), type: 'success' } |
| | | function getDeliveryExceStatusMetaMap(t = $t) { |
| | | return { |
| | | 0: { text: t('pages.orders.delivery.status.pending'), type: 'info' }, |
| | | 1: { text: t('pages.orders.delivery.status.running'), type: 'warning' }, |
| | | 2: { text: t('pages.orders.delivery.status.partial'), type: 'primary' }, |
| | | 3: { text: t('pages.orders.delivery.status.completed'), type: 'success' } |
| | | } |
| | | } |
| | | |
| | | export const DELIVERY_REPORT_TITLE = $t('pages.orders.delivery.reportTitle') |
| | | export function getDeliveryReportTitle(t = $t) { |
| | | return t('pages.orders.delivery.reportTitle') |
| | | } |
| | | export const DELIVERY_REPORT_STYLE = { |
| | | titleAlign: 'center', |
| | | titleLevel: 'strong', |
| | |
| | | return Number.isNaN(parsed) ? fallback : parsed |
| | | } |
| | | |
| | | function normalizeStatusMeta(status) { |
| | | function normalizeStatusMeta(status, t = $t) { |
| | | const deliveryStatusMeta = getDeliveryStatusMetaMap(t) |
| | | if (status === true || Number(status) === 1) { |
| | | return DELIVERY_STATUS_META[1] |
| | | return deliveryStatusMeta[1] |
| | | } |
| | | if (status === false || Number(status) === 0) { |
| | | return DELIVERY_STATUS_META[0] |
| | | return deliveryStatusMeta[0] |
| | | } |
| | | return { text: $t('common.status.unknown'), type: 'info', bool: false } |
| | | return { text: t('common.status.unknown'), type: 'info', bool: false } |
| | | } |
| | | |
| | | function normalizeExceStatusMeta(exceStatus, exceStatusText) { |
| | | function normalizeExceStatusMeta(exceStatus, exceStatusText, t = $t) { |
| | | const deliveryExceStatusMeta = getDeliveryExceStatusMetaMap(t) |
| | | if (exceStatusText) { |
| | | const numericValue = Number(exceStatus) |
| | | const fallback = DELIVERY_EXCE_STATUS_META[numericValue] || { |
| | | const fallback = deliveryExceStatusMeta[numericValue] || { |
| | | text: exceStatusText, |
| | | type: 'info' |
| | | } |
| | | return fallback |
| | | } |
| | | return DELIVERY_EXCE_STATUS_META[Number(exceStatus)] || { |
| | | return deliveryExceStatusMeta[Number(exceStatus)] || { |
| | | text: normalizeText(exceStatus) || '--', |
| | | type: 'info' |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | export function normalizeDeliveryRow(record = {}) { |
| | | const statusMeta = normalizeStatusMeta(record.statusBool ?? record.status) |
| | | const exceStatusMeta = normalizeExceStatusMeta(record.exceStatus, record['exceStatus$'] || record.exceStatusText) |
| | | export function normalizeDeliveryRow(record = {}, t = $t) { |
| | | const statusMeta = normalizeStatusMeta(record.statusBool ?? record.status, t) |
| | | const exceStatusMeta = normalizeExceStatusMeta(record.exceStatus, record['exceStatus$'] || record.exceStatusText, t) |
| | | return { |
| | | ...record, |
| | | id: record.id ?? null, |
| | |
| | | } |
| | | } |
| | | |
| | | export function normalizeDeliveryItemRow(record = {}) { |
| | | export function normalizeDeliveryItemRow(record = {}, t = $t) { |
| | | const statusMeta = normalizeStatusMeta(record.statusBool ?? record.status, t) |
| | | return { |
| | | ...record, |
| | | id: record.id ?? null, |
| | |
| | | trackCode: normalizeText(record.trackCode) || '--', |
| | | packName: normalizeText(record.packName) || '--', |
| | | prodTimeText: normalizeText(record['prodTime$'] || record.prodTimeText || record.prodTime) || '--', |
| | | statusText: normalizeStatusMeta(record.statusBool ?? record.status).text, |
| | | statusType: normalizeStatusMeta(record.statusBool ?? record.status).type, |
| | | statusText: statusMeta.text, |
| | | statusType: statusMeta.type, |
| | | statusBool: |
| | | record.statusBool !== void 0 |
| | | ? Boolean(record.statusBool) |
| | | : normalizeStatusMeta(record.statusBool ?? record.status).bool, |
| | | : statusMeta.bool, |
| | | createByText: normalizeText(record['createBy$'] || record.createByText) || '--', |
| | | createTimeText: normalizeText(record['createTime$'] || record.createTimeText || record.createTime) || '--', |
| | | updateByText: normalizeText(record['updateBy$'] || record.updateByText) || '--', |
| | |
| | | } |
| | | } |
| | | |
| | | export function buildDeliveryPrintRows(records = []) { |
| | | export function buildDeliveryPrintRows(records = [], t = $t) { |
| | | if (!Array.isArray(records)) { |
| | | return [] |
| | | } |
| | | return records.map((record) => normalizeDeliveryRow(record)) |
| | | return records.map((record) => normalizeDeliveryRow(record, t)) |
| | | } |
| | | |
| | | export function buildDeliveryItemPrintRows(records = []) { |
| | | export function buildDeliveryItemPrintRows(records = [], t = $t) { |
| | | if (!Array.isArray(records)) { |
| | | return [] |
| | | } |
| | | return records.map((record) => normalizeDeliveryItemRow(record)) |
| | | return records.map((record) => normalizeDeliveryItemRow(record, t)) |
| | | } |
| | | |
| | | export function buildDeliveryReportMeta({ |
| | | previewMeta = {}, |
| | | count = 0, |
| | | orientation = DELIVERY_REPORT_STYLE.orientation |
| | | orientation = DELIVERY_REPORT_STYLE.orientation, |
| | | t = $t |
| | | } = {}) { |
| | | return { |
| | | reportTitle: DELIVERY_REPORT_TITLE, |
| | | reportTitle: getDeliveryReportTitle(t), |
| | | reportDate: previewMeta.reportDate, |
| | | printedAt: previewMeta.printedAt, |
| | | operator: previewMeta.operator, |
| | |
| | | export function buildDeliveryItemReportMeta({ |
| | | previewMeta = {}, |
| | | count = 0, |
| | | orientation = DELIVERY_REPORT_STYLE.orientation |
| | | orientation = DELIVERY_REPORT_STYLE.orientation, |
| | | t = $t |
| | | } = {}) { |
| | | return { |
| | | reportTitle: $t('pages.orders.delivery.detailReportTitle'), |
| | | reportTitle: t('pages.orders.delivery.detailReportTitle'), |
| | | reportDate: previewMeta.reportDate, |
| | | printedAt: previewMeta.printedAt, |
| | | operator: previewMeta.operator, |