const CHECK_OUT_BOUND_REPORT_TITLE = '盘点出库任务生成'
|
|
function normalizeText(value) {
|
return typeof value === 'string' ? value.trim() : value
|
}
|
|
function normalizeNumber(value) {
|
if (value === '' || value === null || value === undefined) {
|
return 0
|
}
|
const numericValue = Number(value)
|
return Number.isFinite(numericValue) ? numericValue : 0
|
}
|
|
function filterParams(params = {}, ignoredKeys = []) {
|
return Object.fromEntries(
|
Object.entries(params)
|
.filter(([key, value]) => {
|
if (ignoredKeys.includes(key)) return false
|
if (value === undefined || value === null) return false
|
if (typeof value === 'string' && value.trim() === '') return false
|
return true
|
})
|
.map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])
|
)
|
}
|
|
function getCheckOutBoundStatusMeta(status) {
|
const normalized = Number(status)
|
if (normalized === 1) {
|
return { text: '正常', type: 'success' }
|
}
|
if (normalized === 0) {
|
return { text: '冻结', type: 'danger' }
|
}
|
return { text: '--', type: 'info' }
|
}
|
|
export function createCheckOutBoundSearchState() {
|
return {
|
condition: '',
|
locCode: '',
|
matnrCode: '',
|
maktx: '',
|
batch: '',
|
trackCode: ''
|
}
|
}
|
|
export function buildCheckOutBoundSearchParams(params = {}) {
|
return filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
|
export function buildCheckOutBoundPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
function normalizeTaskItemRow(row = {}) {
|
const {
|
statusText,
|
statusTagType,
|
createTimeText,
|
updateTimeText,
|
actionList,
|
operation,
|
...rest
|
} = row
|
return {
|
...rest
|
}
|
}
|
|
export function buildCheckOutBoundTaskPayload({ siteNo = '', items = [], memo = '' } = {}) {
|
const payload = {
|
siteNo: normalizeText(siteNo),
|
items: Array.isArray(items) ? items.map((item) => normalizeTaskItemRow(item)) : []
|
}
|
|
const normalizedMemo = normalizeText(memo)
|
if (normalizedMemo) {
|
payload.memo = normalizedMemo
|
}
|
|
return payload
|
}
|
|
export function normalizeCheckOutBoundRow(row = {}) {
|
const statusMeta = getCheckOutBoundStatusMeta(row.status ?? row.status$)
|
return {
|
...row,
|
locCode: normalizeText(row.locCode || row.locCode$ || row.locId || '--') || '--',
|
matnrCode: normalizeText(row.matnrCode || row.matnrCode$ || '--') || '--',
|
maktx: normalizeText(row.maktx || row.maktx$ || '--') || '--',
|
batch: normalizeText(row.batch || row.batch$ || '--') || '--',
|
splrBatch: normalizeText(row.splrBatch || row.splrBatch$ || '--') || '--',
|
unit: normalizeText(row.unit || row.unit$ || '--') || '--',
|
trackCode: normalizeText(row.trackCode || row.trackCode$ || '--') || '--',
|
siteNo: normalizeText(row.siteNo || row.siteNo$ || '--') || '--',
|
memo: normalizeText(row.memo || row.memo$ || '--') || '--',
|
anfme: normalizeNumber(row.anfme),
|
workQty: normalizeNumber(row.workQty),
|
qty: normalizeNumber(row.qty),
|
statusText: row.statusText || row.status$ || statusMeta.text,
|
statusTagType: row.statusTagType || statusMeta.type,
|
createTimeText: row.createTimeText || row.createTime$ || row.createTime || '--',
|
updateTimeText: row.updateTimeText || row.updateTime$ || row.updateTime || '--'
|
}
|
}
|
|
export function resolveCheckOutBoundSiteOptions(source = []) {
|
const records = Array.isArray(source)
|
? source
|
: Array.isArray(source?.records)
|
? source.records
|
: Array.isArray(source?.list)
|
? source.list
|
: Array.isArray(source?.data)
|
? source.data
|
: Array.isArray(source?.data?.records)
|
? source.data.records
|
: Array.isArray(source?.data?.list)
|
? source.data.list
|
: Array.isArray(source?.data?.data)
|
? source.data.data
|
: []
|
const seen = new Set()
|
|
return records
|
.map((item) => {
|
if (typeof item === 'string' || typeof item === 'number') {
|
const value = String(item).trim()
|
return value ? { value, label: value } : null
|
}
|
|
const value = normalizeText(item?.siteNo ?? item?.site ?? item?.code ?? item?.value ?? item?.id)
|
if (!value) return null
|
|
return {
|
value,
|
label: normalizeText(item?.name ?? item?.siteName ?? item?.label ?? item?.code ?? value)
|
}
|
})
|
.filter(Boolean)
|
.filter((item) => {
|
if (seen.has(item.value)) return false
|
seen.add(item.value)
|
return true
|
})
|
}
|
|
export function getCheckOutBoundActionList() {
|
return [
|
{
|
key: 'view',
|
label: '查看明细',
|
icon: 'ri:eye-line'
|
}
|
]
|
}
|
|
export function buildCheckOutBoundReportMeta(rows = []) {
|
return {
|
reportTitle: CHECK_OUT_BOUND_REPORT_TITLE,
|
reportDate: new Date().toLocaleDateString('zh-CN'),
|
printedAt: new Date().toLocaleString('zh-CN', { hour12: false }),
|
count: Array.isArray(rows) ? rows.length : 0
|
}
|
}
|
|
export function buildCheckOutBoundPrintRows(records = []) {
|
return Array.isArray(records) ? records.map((item) => normalizeCheckOutBoundRow(item)) : []
|
}
|
|
export { CHECK_OUT_BOUND_REPORT_TITLE, getCheckOutBoundStatusMeta }
|