const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
export const LOC_AREA_REPORT_TITLE = '库区报表'
|
export const LOC_AREA_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 createLocAreaSearchState() {
|
return {
|
condition: '',
|
areaId: '',
|
name: '',
|
code: '',
|
status: '',
|
memo: ''
|
}
|
}
|
|
export function createLocAreaFormState() {
|
return {
|
id: void 0,
|
areaId: void 0,
|
name: '',
|
code: '',
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function getLocAreaPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getLocAreaStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getLocAreaStatusMeta(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 buildLocAreaSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
areaId:
|
params.areaId !== undefined && params.areaId !== null && params.areaId !== ''
|
? Number(params.areaId)
|
: void 0,
|
name: normalizeText(params.name),
|
code: normalizeText(params.code),
|
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 buildLocAreaPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildLocAreaSearchParams(params)
|
}
|
}
|
|
export function buildLocAreaSavePayload(formData = {}) {
|
return {
|
...(formData.id !== undefined && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
...(formData.areaId !== undefined && formData.areaId !== null && formData.areaId !== ''
|
? { areaId: Number(formData.areaId) }
|
: {}),
|
name: normalizeText(formData.name) || '',
|
code: normalizeText(formData.code) || '',
|
status:
|
formData.status !== undefined && formData.status !== null && formData.status !== ''
|
? Number(formData.status)
|
: 1,
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function buildLocAreaDialogModel(record = {}) {
|
return {
|
...createLocAreaFormState(),
|
...(record.id !== undefined && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
areaId:
|
record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
|
? Number(record.areaId)
|
: void 0,
|
name: normalizeText(record.name || ''),
|
code: normalizeText(record.code || ''),
|
status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function resolveLocAreaOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.id ?? item.value
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.name || item.code || `库区 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function normalizeLocAreaDetailRecord(record = {}) {
|
const statusMeta = getLocAreaStatusMeta(record.statusBool ?? record.status)
|
return {
|
...record,
|
areaName: normalizeText(record.areaId$ || record.areaName || ''),
|
name: normalizeText(record.name || ''),
|
code: normalizeText(record.code || ''),
|
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 normalizeLocAreaListRow(record = {}) {
|
return normalizeLocAreaDetailRecord(record)
|
}
|
|
export function buildLocAreaPrintRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeLocAreaListRow(record))
|
}
|
|
export function buildLocAreaReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = LOC_AREA_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: LOC_AREA_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...LOC_AREA_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|