import { $t } from '@/locales' function getTransferSourceMetaMap(t = $t) { return { 1: { text: t('pages.orders.transfer.status.sourceErp'), type: 'info' }, 2: { text: t('pages.orders.transfer.status.sourceWms'), type: 'primary' }, 3: { text: t('pages.orders.transfer.status.sourceExcel'), type: 'warning' }, 4: { text: t('pages.orders.transfer.status.sourceQms'), type: 'success' } } } function getTransferExceStatusMetaMap(t = $t) { return { 0: { text: t('pages.orders.transfer.status.pending'), type: 'info' }, 1: { text: t('pages.orders.transfer.status.running'), type: 'warning' }, 2: { text: t('pages.orders.transfer.status.completed'), type: 'success' } } } function getTransferStatusMetaMap(t = $t) { return { 1: { text: t('pages.orders.transfer.status.normal'), type: 'success', bool: true }, 0: { text: t('pages.orders.transfer.status.frozen'), type: 'danger', bool: false } } } export function getTransferReportTitle(t = $t) { return t('pages.orders.transfer.reportTitle') } export const TRANSFER_REPORT_STYLE = { titleAlign: 'center', titleLevel: 'strong', orientation: 'landscape', density: 'compact', showSequence: true } function normalizeText(value) { return String(value ?? '').trim() } function normalizeNumber(value, fallback = void 0) { if (value === '' || value === null || value === undefined) return fallback const parsed = Number(value) return Number.isNaN(parsed) ? fallback : parsed } function metaByValue(value, metaMap, fallbackText = '--') { const numericValue = Number(value) return metaMap[numericValue] || { text: normalizeText(value) || fallbackText, type: 'info' } } export function createTransferSearchState() { return { condition: '', code: '', type: '', source: '', exceStatus: '', orgWareName: '', tarWareName: '', orgAreaName: '', tarAreaName: '', memo: '', status: '', timeStart: '', timeEnd: '' } } export function createTransferFormState() { return { id: void 0, code: '', type: '', source: 2, exceStatus: 0, orgAreaId: void 0, tarAreaId: void 0, status: 1, memo: '' } } export function buildTransferDialogModel(record = {}) { return { ...createTransferFormState(), ...(record.id !== undefined && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}), code: normalizeText(record.code || ''), type: record.type !== undefined && record.type !== null && record.type !== '' ? Number(record.type) : '', source: record.source !== undefined && record.source !== null && record.source !== '' ? Number(record.source) : 2, exceStatus: record.exceStatus !== undefined && record.exceStatus !== null && record.exceStatus !== '' ? Number(record.exceStatus) : 0, orgAreaId: record.orgAreaId !== undefined && record.orgAreaId !== null && record.orgAreaId !== '' ? Number(record.orgAreaId) : void 0, tarAreaId: record.tarAreaId !== undefined && record.tarAreaId !== null && record.tarAreaId !== '' ? Number(record.tarAreaId) : void 0, status: record.status !== undefined && record.status !== null ? Number(record.status) : 1, memo: normalizeText(record.memo || '') } } export function getTransferPaginationKey() { return { current: 'current', size: 'pageSize' } } export function getTransferSourceOptions() { return [ { label: $t('pages.orders.transfer.status.sourceErp'), value: 1 }, { label: $t('pages.orders.transfer.status.sourceWms'), value: 2 }, { label: $t('pages.orders.transfer.status.sourceExcel'), value: 3 }, { label: $t('pages.orders.transfer.status.sourceQms'), value: 4 } ] } export function getTransferStatusOptions(t = $t) { return [ { label: t('pages.orders.transfer.status.normal'), value: 1 }, { label: t('pages.orders.transfer.status.frozen'), value: 0 } ] } export function getTransferExceStatusOptions(t = $t) { return [ { label: t('pages.orders.transfer.status.pending'), value: 0 }, { label: t('pages.orders.transfer.status.running'), value: 1 }, { label: t('pages.orders.transfer.status.completed'), value: 2 } ] } export function buildTransferSearchParams(params = {}) { const result = {} ;['condition', 'code', 'orgWareName', 'tarWareName', 'orgAreaName', 'tarAreaName', 'memo'].forEach((key) => { const value = normalizeText(params[key]) if (value) result[key] = value }) ;['type', 'source', 'exceStatus', 'status', 'orgWareId', 'tarWareId', 'orgAreaId', 'tarAreaId'].forEach((key) => { if (params[key] !== '' && params[key] !== undefined && params[key] !== null) { result[key] = normalizeNumber(params[key]) } }) if (params.timeStart !== '' && params.timeStart !== undefined && params.timeStart !== null) { result.timeStart = normalizeText(params.timeStart) } if (params.timeEnd !== '' && params.timeEnd !== undefined && params.timeEnd !== null) { result.timeEnd = normalizeText(params.timeEnd) } return result } export function buildTransferPageQueryParams(params = {}) { return { current: params.current || 1, pageSize: params.pageSize || params.size || 20, ...buildTransferSearchParams(params) } } export function buildTransferDetailOrderQueryParams(params = {}) { return { condition: normalizeText(params.code || params.condition), code: normalizeText(params.code || params.condition), current: params.current || 1, pageSize: params.pageSize || params.size || 20 } } export function buildTransferSavePayload(formData = {}, areaOptions = []) { const optionMap = new Map( (Array.isArray(areaOptions) ? areaOptions : []) .map((item) => { const value = normalizeNumber(item?.value ?? item?.id, void 0) if (value === void 0) return null return [value, item?.raw || item] }) .filter(Boolean) ) const orgAreaId = normalizeNumber(formData.orgAreaId, void 0) const tarAreaId = normalizeNumber(formData.tarAreaId, void 0) const orgArea = optionMap.get(orgAreaId) || {} const tarArea = optionMap.get(tarAreaId) || {} const orgWareId = normalizeNumber(orgArea.warehouseId ?? orgArea.warehouse_id ?? orgArea.warehouseIdValue, void 0) const tarWareId = normalizeNumber(tarArea.warehouseId ?? tarArea.warehouse_id ?? tarArea.warehouseIdValue, void 0) return { ...(formData.id !== undefined && formData.id !== null && formData.id !== '' ? { id: normalizeNumber(formData.id) } : {}), ...(normalizeText(formData.code) ? { code: normalizeText(formData.code) } : {}), ...(formData.type !== undefined && formData.type !== null && formData.type !== '' ? { type: normalizeNumber(formData.type) } : {}), ...(formData.source !== undefined && formData.source !== null && formData.source !== '' ? { source: normalizeNumber(formData.source) } : {}), ...(formData.exceStatus !== undefined && formData.exceStatus !== null && formData.exceStatus !== '' ? { exceStatus: normalizeNumber(formData.exceStatus) } : {}), ...(orgAreaId !== void 0 ? { orgAreaId } : {}), ...(tarAreaId !== void 0 ? { tarAreaId } : {}), ...(orgWareId !== void 0 ? { orgWareId } : {}), ...(tarWareId !== void 0 ? { tarWareId } : {}), ...(normalizeText(orgArea.name || orgArea.areaName) ? { orgAreaName: normalizeText(orgArea.name || orgArea.areaName) } : {}), ...(normalizeText(tarArea.name || tarArea.areaName) ? { tarAreaName: normalizeText(tarArea.name || tarArea.areaName) } : {}), ...(normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) ? { orgWareName: normalizeText(orgArea.warehouseId$ || orgArea.warehouseName) } : {}), ...(normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) ? { tarWareName: normalizeText(tarArea.warehouseId$ || tarArea.warehouseName) } : {}), ...(formData.status !== undefined && formData.status !== null && formData.status !== '' ? { status: normalizeNumber(formData.status) } : { status: 1 }), memo: normalizeText(formData.memo) || '' } } function resolveAreaText(record = {}, key) { return normalizeText(record[`${key}AreaName$`] || record[`${key}AreaName`] || record[`${key}AreaId$`] || record[`${key}AreaId`]) } function resolveWarehouseText(record = {}, key) { return normalizeText(record[`${key}WareName$`] || record[`${key}WareName`] || record[`${key}WareId$`] || record[`${key}WareId`]) } export function normalizeTransferRow(record = {}, t = $t) { const statusMeta = metaByValue(record.statusBool ?? record.status, getTransferStatusMetaMap(t), t('common.status.unknown')) const exceStatusMeta = metaByValue(record.exceStatus, getTransferExceStatusMetaMap(t), record.exceStatusText) const sourceMeta = metaByValue(record.source, getTransferSourceMetaMap(t), record.sourceText) return { ...record, id: record.id ?? null, code: normalizeText(record.code) || '--', typeLabel: normalizeText(record['type$'] || record.type) || '--', sourceText: sourceMeta.text, sourceTagType: sourceMeta.type, exceStatusText: normalizeText(record['exceStatus$'] || record.exceStatusText) || exceStatusMeta.text, exceStatusTagType: exceStatusMeta.type, orgWareName: resolveWarehouseText(record, 'org') || '--', tarWareName: resolveWarehouseText(record, 'tar') || '--', orgAreaName: resolveAreaText(record, 'org') || '--', tarAreaName: resolveAreaText(record, 'tar') || '--', statusText: statusMeta.text, statusType: statusMeta.type, statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool, createByText: normalizeText(record['createBy$'] || record.createByText) || '--', createTimeText: normalizeText(record['createTime$'] || record.createTimeText || record.createTime) || '--', updateByText: normalizeText(record['updateBy$'] || record.updateByText) || '--', updateTimeText: normalizeText(record['updateTime$'] || record.updateTimeText || record.updateTime) || '--', memo: normalizeText(record.memo) || '--' } } export function normalizeTransferDetailRecord(record = {}, t = $t) { return normalizeTransferRow(record, t) } export function normalizeTransferOrderRow(record = {}, t = $t) { const statusMeta = metaByValue(record.statusBool ?? record.status, getTransferStatusMetaMap(t), t('common.status.unknown')) const exceStatusMeta = metaByValue(record.exceStatus, getTransferExceStatusMetaMap(t), record.exceStatusText) return { ...record, id: record.id ?? null, code: normalizeText(record.code) || '--', poCode: normalizeText(record.poCode) || '--', typeLabel: normalizeText(record['type$'] || record.type) || '--', wkTypeLabel: normalizeText(record['wkType$'] || record.wkType) || '--', exceStatusText: normalizeText(record['exceStatus$'] || record.exceStatusText) || exceStatusMeta.text, exceStatusTagType: exceStatusMeta.type, statusText: statusMeta.text, statusType: statusMeta.type, statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool, anfme: record.anfme ?? '--', workQty: record.workQty ?? '--', qty: record.qty ?? '--', stationId: normalizeText(record.stationId) || '--', businessTimeText: normalizeText(record['businessTime$'] || record.businessTimeText || record.businessTime) || '--', createByText: normalizeText(record['createBy$'] || record.createByText) || '--', createTimeText: normalizeText(record['createTime$'] || record.createTimeText || record.createTime) || '--', updateByText: normalizeText(record['updateBy$'] || record.updateByText) || '--', updateTimeText: normalizeText(record['updateTime$'] || record.updateTimeText || record.updateTime) || '--', memo: normalizeText(record.memo) || '--' } } export function buildTransferPrintRows(records = [], t = $t) { return Array.isArray(records) ? records.map((record) => normalizeTransferRow(record, t)) : [] } export function buildTransferOrderPrintRows(records = [], t = $t) { return Array.isArray(records) ? records.map((record) => normalizeTransferOrderRow(record, t)) : [] } export function buildTransferReportMeta({ previewMeta = {}, count = 0, orientation = TRANSFER_REPORT_STYLE.orientation, t = $t } = {}) { return { reportTitle: getTransferReportTitle(t), reportDate: previewMeta.reportDate, printedAt: previewMeta.printedAt, operator: previewMeta.operator, count, reportStyle: { ...TRANSFER_REPORT_STYLE, orientation } } } export function getTransferActionList(row = {}) { const normalizedRow = normalizeTransferRow(row) const actions = [ { key: 'view', label: $t('pages.orders.transfer.actions.view'), icon: 'ri:eye-line' }, { key: 'items', label: $t('pages.orders.transfer.actions.items'), icon: 'ri:list-check-3' }, { key: 'edit', label: $t('pages.orders.transfer.actions.edit'), icon: 'ri:pencil-line' } ] if (Number(normalizedRow.exceStatus) === 0) { actions.push({ key: 'publish', label: $t('pages.orders.transfer.actions.publish'), icon: 'ri:send-plane-line' }) actions.push({ key: 'delete', label: $t('pages.orders.transfer.actions.delete'), icon: 'ri:delete-bin-5-line', color: 'var(--art-error)' }) } return actions } export function resolveTransferAreaOptions(records = []) { if (!Array.isArray(records)) return [] return records .map((item) => { if (!item || typeof item !== 'object') return null const value = normalizeNumber(item.id ?? item.value, void 0) if (value === void 0) return null return { value, label: normalizeText(item.name || item.areaName || item.code || item.warehouseId$ || item.warehouseName || `${$t('menu.warehouseAreas')} ${value}`), raw: item } }) .filter(Boolean) } export function resolveTransferTypeOptions(records = []) { if (!Array.isArray(records)) return [] return records .map((item) => { if (!item || typeof item !== 'object') return null const value = normalizeNumber(item.value ?? item.id, void 0) if (value === void 0) return null return { value, label: normalizeText(item.label || item.name || item.dictLabel || `${$t('pages.orders.transfer.dialog.type')} ${value}`) } }) .filter(Boolean) }