const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
export const LOC_TYPE_REPORT_TITLE = '库位类型报表'
|
export const LOC_TYPE_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong',
|
orientation: 'portrait',
|
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
|
}
|
|
export function createLocTypeSearchState() {
|
return {
|
condition: '',
|
uuid: '',
|
code: '',
|
name: '',
|
regex: '',
|
status: '',
|
memo: ''
|
}
|
}
|
|
export function createLocTypeFormState() {
|
return {
|
id: void 0,
|
code: '',
|
name: '',
|
regex: '',
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function getLocTypePaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getLocTypeStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getLocTypeStatusMeta(status) {
|
if (status === true || Number(status) === 1) {
|
return STATUS_META[1]
|
}
|
if (status === false || Number(status) === 0) {
|
return STATUS_META[0]
|
}
|
return { text: '未知', type: 'info', bool: false }
|
}
|
|
export function buildLocTypeSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
uuid: normalizeText(params.uuid),
|
code: normalizeText(params.code),
|
name: normalizeText(params.name),
|
regex: normalizeText(params.regex),
|
status:
|
params.status !== undefined && params.status !== null && params.status !== ''
|
? Number(params.status)
|
: void 0,
|
memo: normalizeText(params.memo)
|
}
|
|
return Object.fromEntries(
|
Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
|
)
|
}
|
|
export function buildLocTypePageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildLocTypeSearchParams(params)
|
}
|
}
|
|
export function buildLocTypeSavePayload(formData = {}) {
|
return {
|
...(formData.id !== undefined && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
code: normalizeText(formData.code) || '',
|
name: normalizeText(formData.name) || '',
|
regex: normalizeText(formData.regex) || '',
|
status:
|
formData.status !== undefined && formData.status !== null && formData.status !== ''
|
? Number(formData.status)
|
: 1,
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function buildLocTypeDialogModel(record = {}) {
|
return {
|
...createLocTypeFormState(),
|
...(record.id !== undefined && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
code: normalizeText(record.code || ''),
|
name: normalizeText(record.name || ''),
|
regex: normalizeText(record.regex || ''),
|
status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function normalizeLocTypeDetailRecord(record = {}) {
|
const statusMeta = getLocTypeStatusMeta(record.statusBool ?? record.status)
|
return {
|
...record,
|
uuid: normalizeText(record.uuid || ''),
|
code: normalizeText(record.code || ''),
|
name: normalizeText(record.name || ''),
|
regex: normalizeText(record.regex || ''),
|
memo: normalizeText(record.memo || ''),
|
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.createTime || ''),
|
updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
|
updateTimeText: normalizeText(record.updateTime$ || record.updateTime || '')
|
}
|
}
|
|
export function normalizeLocTypeListRow(record = {}) {
|
return normalizeLocTypeDetailRecord(record)
|
}
|
|
export function buildLocTypePrintRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeLocTypeListRow(record))
|
}
|
|
export function buildLocTypeReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = LOC_TYPE_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: LOC_TYPE_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...LOC_TYPE_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|