const TRANSFER_SOURCE_META = {
|
1: { text: 'ERP系统', type: 'info' },
|
2: { text: 'WMS系统生成', type: 'primary' },
|
3: { text: 'EXCEL导入', type: 'warning' },
|
4: { text: 'QMS系统', type: 'success' }
|
}
|
|
const TRANSFER_EXCE_STATUS_META = {
|
0: { text: '未执行', type: 'info' },
|
1: { text: '执行中', type: 'warning' },
|
2: { text: '执行完成', type: 'success' }
|
}
|
|
const TRANSFER_STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
export const TRANSFER_REPORT_TITLE = '调拨单报表'
|
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: 'ERP系统', value: 1 },
|
{ label: 'WMS系统生成', value: 2 },
|
{ label: 'EXCEL导入', value: 3 },
|
{ label: 'QMS系统', value: 4 }
|
]
|
}
|
|
export function getTransferStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getTransferExceStatusOptions() {
|
return [
|
{ label: '未执行', value: 0 },
|
{ label: '执行中', value: 1 },
|
{ label: '执行完成', 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 = {}) {
|
const statusMeta = metaByValue(record.statusBool ?? record.status, TRANSFER_STATUS_META, '未知')
|
const exceStatusMeta = metaByValue(record.exceStatus, TRANSFER_EXCE_STATUS_META, record.exceStatusText)
|
const sourceMeta = metaByValue(record.source, TRANSFER_SOURCE_META, 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 = {}) {
|
return normalizeTransferRow(record)
|
}
|
|
export function normalizeTransferOrderRow(record = {}) {
|
const statusMeta = metaByValue(record.statusBool ?? record.status, TRANSFER_STATUS_META, '未知')
|
const exceStatusMeta = metaByValue(record.exceStatus, TRANSFER_EXCE_STATUS_META, 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 = []) {
|
return Array.isArray(records) ? records.map((record) => normalizeTransferRow(record)) : []
|
}
|
|
export function buildTransferOrderPrintRows(records = []) {
|
return Array.isArray(records) ? records.map((record) => normalizeTransferOrderRow(record)) : []
|
}
|
|
export function buildTransferReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = TRANSFER_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: TRANSFER_REPORT_TITLE,
|
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: '查看详情', icon: 'ri:eye-line' },
|
{ key: 'edit', label: '编辑', icon: 'ri:pencil-line' }
|
]
|
if (Number(normalizedRow.exceStatus) === 0) {
|
actions.push({ key: 'publish', label: '下发执行', icon: 'ri:send-plane-line' })
|
actions.push({ key: 'delete', label: '删除', 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 || `库区 ${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 || `类型 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|