const OUT_BOUND_STATUS_META = {
|
0: { label: '冻结', tagType: 'danger' },
|
1: { label: '正常', tagType: 'success' }
|
}
|
|
function normalizeText(value) {
|
return String(value ?? '').trim()
|
}
|
|
function normalizeOptionalText(value) {
|
const text = normalizeText(value)
|
return text === '-' ? '' : text
|
}
|
|
function normalizeNumber(value) {
|
if (value === '' || value === null || value === undefined) {
|
return 0
|
}
|
const numericValue = Number(value)
|
return Number.isFinite(numericValue) ? numericValue : 0
|
}
|
|
function getStatusMeta(status, statusText) {
|
const fallback = OUT_BOUND_STATUS_META[Number(status)] || {
|
label: statusText || '-',
|
tagType: 'info'
|
}
|
return {
|
label: statusText || fallback.label,
|
tagType: fallback.tagType
|
}
|
}
|
|
function toNumberOrOriginal(value) {
|
if (value === '' || value === null || value === undefined) {
|
return value
|
}
|
const numericValue = Number(value)
|
return Number.isFinite(numericValue) ? numericValue : value
|
}
|
|
function normalizeItemOutQty(row = {}) {
|
const outQty = row.outQty !== undefined && row.outQty !== null && row.outQty !== ''
|
? normalizeNumber(row.outQty)
|
: normalizeNumber(row.anfme)
|
return outQty < 0 ? 0 : outQty
|
}
|
|
function compactDefinedFields(record = {}) {
|
return Object.fromEntries(
|
Object.entries(record).filter(([, value]) => value !== undefined && value !== null && value !== '')
|
)
|
}
|
|
export function createOutBoundSearchState() {
|
return {
|
condition: '',
|
locCode: '',
|
matnrCode: '',
|
maktx: '',
|
batch: '',
|
splrBatch: '',
|
trackCode: '',
|
status: '',
|
memo: ''
|
}
|
}
|
|
export function createOutBoundTaskState() {
|
return {
|
siteNo: '',
|
memo: ''
|
}
|
}
|
|
export function buildOutBoundSearchParams(params = {}) {
|
const result = {}
|
;['condition', 'locCode', 'matnrCode', 'maktx', 'batch', 'splrBatch', 'trackCode', 'memo'].forEach((key) => {
|
const value = normalizeText(params[key])
|
if (value) {
|
result[key] = value
|
}
|
})
|
|
if (params.status !== '' && params.status !== undefined && params.status !== null) {
|
result.status = Number(params.status)
|
}
|
|
return result
|
}
|
|
export function buildOutBoundPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildOutBoundSearchParams(params)
|
}
|
}
|
|
export function normalizeOutBoundRow(record = {}) {
|
const statusMeta = getStatusMeta(record.status, record['status$'])
|
return {
|
...record,
|
locCode: normalizeText(record.locCode) || '-',
|
matnrCode: normalizeText(record.matnrCode) || '-',
|
maktx: normalizeText(record.maktx) || '-',
|
trackCode: normalizeText(record.trackCode) || '-',
|
batch: normalizeText(record.batch) || '-',
|
splrBatch: normalizeText(record.splrBatch) || '-',
|
unit: normalizeText(record.unit) || '-',
|
anfme: normalizeNumber(record.anfme),
|
workQty: normalizeNumber(record.workQty),
|
qty: normalizeNumber(record.qty),
|
outQty: normalizeNumber(record.outQty),
|
statusText: statusMeta.label,
|
statusTagType: statusMeta.tagType,
|
createTimeText: normalizeText(record['createTime$'] || record.createTime) || '-',
|
updateTimeText: normalizeText(record['updateTime$'] || record.updateTime) || '-',
|
splrCode: normalizeText(record.splrCode) || '-',
|
splrName: normalizeText(record.splrName) || '-',
|
siteNo: normalizeText(record.siteNo) || '-',
|
memo: normalizeText(record.memo) || '-'
|
}
|
}
|
|
export function normalizeOutBoundBasketRows(rows = []) {
|
if (!Array.isArray(rows)) {
|
return []
|
}
|
|
const seen = new Set()
|
return rows
|
.map((row) => ({
|
...normalizeOutBoundRow(row),
|
outQty: normalizeItemOutQty(row)
|
}))
|
.filter((row) => {
|
const key = row.id ?? `${row.locId || ''}-${row.matnrCode || ''}-${row.batch || ''}`
|
if (seen.has(key)) {
|
return false
|
}
|
seen.add(key)
|
return true
|
})
|
}
|
|
export function mergeOutBoundBasketRows(currentRows = [], incomingRows = []) {
|
const basket = new Map()
|
|
normalizeOutBoundBasketRows(currentRows).forEach((row) => {
|
const key = row.id ?? `${row.locId || ''}-${row.matnrCode || ''}-${row.batch || ''}`
|
basket.set(key, row)
|
})
|
|
normalizeOutBoundBasketRows(incomingRows).forEach((row) => {
|
const key = row.id ?? `${row.locId || ''}-${row.matnrCode || ''}-${row.batch || ''}`
|
if (!basket.has(key)) {
|
basket.set(key, row)
|
return
|
}
|
basket.set(key, {
|
...basket.get(key),
|
...row,
|
outQty: basket.get(key).outQty > 0 ? basket.get(key).outQty : row.outQty
|
})
|
})
|
|
return Array.from(basket.values())
|
}
|
|
export function buildOutBoundGenerateTaskPayload({ siteNo, memo = '', items = [] } = {}) {
|
return {
|
siteNo: normalizeOptionalText(siteNo),
|
memo: normalizeText(memo),
|
items: Array.isArray(items)
|
? items.map((row) =>
|
compactDefinedFields({
|
...row,
|
id: toNumberOrOriginal(row.id),
|
locId: toNumberOrOriginal(row.locId),
|
orderId: toNumberOrOriginal(row.orderId),
|
orderItemId: toNumberOrOriginal(row.orderItemId),
|
wkType: toNumberOrOriginal(row.wkType),
|
matnrId: toNumberOrOriginal(row.matnrId),
|
channel: toNumberOrOriginal(row.channel),
|
status: toNumberOrOriginal(row.status),
|
outQty: normalizeItemOutQty(row),
|
anfme: normalizeNumber(row.anfme),
|
workQty: normalizeNumber(row.workQty),
|
qty: normalizeNumber(row.qty),
|
siteNo: normalizeOptionalText(row.siteNo),
|
memo: normalizeOptionalText(row.memo)
|
})
|
)
|
: []
|
}
|
}
|
|
export function normalizeOutBoundSiteOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
const seen = new Set()
|
return records
|
.map((record) => normalizeText(record.site))
|
.filter((site) => {
|
if (!site || seen.has(site)) {
|
return false
|
}
|
seen.add(site)
|
return true
|
})
|
.map((site) => ({
|
label: site,
|
value: site
|
}))
|
}
|
|
export function getOutBoundValidationMessage({ siteNo, items = [] } = {}) {
|
if (!normalizeText(siteNo)) {
|
return '请选择出库站点'
|
}
|
if (!Array.isArray(items) || items.length === 0) {
|
return '请先选择库存明细'
|
}
|
|
const invalidRow = items.find((row) => normalizeItemOutQty(row) <= 0)
|
if (invalidRow) {
|
return `库存明细 ${invalidRow.locCode || invalidRow.matnrCode || invalidRow.id || ''} 的出库数量必须大于 0`
|
}
|
|
const overflowRow = items.find((row) => normalizeItemOutQty(row) + normalizeNumber(row.workQty) > normalizeNumber(row.anfme))
|
if (overflowRow) {
|
return `库存明细 ${overflowRow.locCode || overflowRow.matnrCode || overflowRow.id || ''} 的出库数量不能超过可用数量`
|
}
|
|
return ''
|
}
|