const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
export const MATNR_GROUP_REPORT_TITLE = '物料分组报表'
|
export const MATNR_GROUP_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 numberValue = Number(value)
|
return Number.isNaN(numberValue) ? fallback : numberValue
|
}
|
|
function buildLabel(name, code) {
|
return [normalizeText(name), normalizeText(code)].filter(Boolean).join(' · ') || '--'
|
}
|
|
function normalizeId(value, fallback = void 0) {
|
const numberValue = normalizeNumber(value, fallback)
|
return numberValue === void 0 ? fallback : numberValue
|
}
|
|
export function createMatnrGroupSearchState() {
|
return {
|
condition: '',
|
code: '',
|
name: '',
|
parCode: '',
|
status: '',
|
memo: '',
|
sort: '',
|
parentId: ''
|
}
|
}
|
|
export function createMatnrGroupFormState() {
|
return {
|
id: void 0,
|
parentId: 0,
|
parCode: '',
|
code: '',
|
name: '',
|
sort: 0,
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function getMatnrGroupPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getMatnrGroupStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getMatnrGroupStatusMeta(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 buildMatnrGroupPageQueryParams(params = {}) {
|
const result = {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20
|
}
|
|
;['condition', 'code', 'name', 'parCode', 'memo'].forEach((key) => {
|
const value = normalizeText(params[key])
|
if (value) {
|
result[key] = value
|
}
|
})
|
|
if (params.sort !== '' && params.sort !== null && params.sort !== undefined) {
|
result.sort = Number(params.sort)
|
}
|
|
if (params.status !== '' && params.status !== null && params.status !== undefined) {
|
result.status = Number(params.status)
|
}
|
|
if (params.parentId !== '' && params.parentId !== null && params.parentId !== undefined) {
|
result.parentId = Number(params.parentId)
|
}
|
|
return result
|
}
|
|
export function buildMatnrGroupTreeQueryParams(params = {}) {
|
return {
|
condition: normalizeText(params.condition)
|
}
|
}
|
|
export function normalizeMatnrGroupTreeRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records.map((item) => {
|
const children = normalizeMatnrGroupTreeRows(item?.children || [])
|
const id = normalizeId(item?.id)
|
const parentId = normalizeId(item?.parentId, 0)
|
const code = normalizeText(item?.code)
|
const name = normalizeText(item?.name)
|
const label = buildLabel(name, code)
|
const statusMeta = getMatnrGroupStatusMeta(item?.statusBool ?? item?.status)
|
|
return {
|
...item,
|
id,
|
parentId,
|
code,
|
name,
|
label,
|
displayLabel: label,
|
parCode: normalizeText(item?.parCode),
|
sort: normalizeId(item?.sort, 0),
|
status: normalizeId(item?.status),
|
statusText: statusMeta.text,
|
statusType: statusMeta.type,
|
memo: normalizeText(item?.memo) || '-',
|
children
|
}
|
})
|
}
|
|
export function createMatnrGroupTreeSelectOptions(records = []) {
|
const tree = normalizeMatnrGroupTreeRows(records)
|
return [
|
{
|
id: 0,
|
name: '顶级分组',
|
code: '',
|
label: '顶级分组',
|
displayLabel: '顶级分组',
|
children: tree
|
}
|
]
|
}
|
|
export function createMatnrGroupTreeLookupMap(records = []) {
|
const map = new Map()
|
|
const visit = (nodes = []) => {
|
nodes.forEach((node) => {
|
if (!node || typeof node !== 'object') {
|
return
|
}
|
const id = normalizeId(node.id)
|
if (id !== void 0) {
|
map.set(id, node)
|
}
|
if (Array.isArray(node.children) && node.children.length) {
|
visit(node.children)
|
}
|
})
|
}
|
|
visit(records)
|
map.set(0, {
|
id: 0,
|
name: '顶级分组',
|
code: '',
|
label: '顶级分组',
|
displayLabel: '顶级分组'
|
})
|
return map
|
}
|
|
export function buildMatnrGroupTreeLookupMap(records = []) {
|
return createMatnrGroupTreeLookupMap(records)
|
}
|
|
export function resolveMatnrGroupTreeNodeLabel(node = {}) {
|
return buildLabel(node?.name, node?.code)
|
}
|
|
export function buildMatnrGroupDialogModel(record = {}, options = {}) {
|
const resolveParentCode = typeof options.resolveParentCode === 'function' ? options.resolveParentCode : null
|
const parentId =
|
record.parentId !== void 0 && record.parentId !== null && record.parentId !== ''
|
? normalizeId(record.parentId, 0)
|
: normalizeId(options.parentId, 0)
|
const parentCode =
|
normalizeText(record.parCode) ||
|
normalizeText(options.parCode) ||
|
(resolveParentCode ? normalizeText(resolveParentCode(parentId)) : '')
|
|
return {
|
...createMatnrGroupFormState(),
|
...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
parentId,
|
parCode: parentCode,
|
code: normalizeText(record.code || ''),
|
name: normalizeText(record.name || ''),
|
sort:
|
record.sort !== void 0 && record.sort !== null && record.sort !== ''
|
? Number(record.sort)
|
: 0,
|
status: record.status !== void 0 && record.status !== null ? Number(record.status) : 1,
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function buildMatnrGroupSavePayload(formData = {}) {
|
return {
|
...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
parentId:
|
formData.parentId !== void 0 && formData.parentId !== null && formData.parentId !== ''
|
? Number(formData.parentId)
|
: 0,
|
parCode: normalizeText(formData.parCode) || '',
|
code: normalizeText(formData.code) || '',
|
name: normalizeText(formData.name) || '',
|
sort:
|
formData.sort !== void 0 && formData.sort !== null && formData.sort !== ''
|
? Number(formData.sort)
|
: 0,
|
status:
|
formData.status !== void 0 && formData.status !== null && formData.status !== ''
|
? Number(formData.status)
|
: 1,
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function normalizeMatnrGroupDetailRecord(record = {}, resolveParentLabel) {
|
const statusMeta = getMatnrGroupStatusMeta(record.statusBool ?? record.status)
|
const parentId = normalizeId(record.parentId, 0)
|
const parentLabel =
|
typeof resolveParentLabel === 'function'
|
? normalizeText(resolveParentLabel(parentId))
|
: normalizeText(record.parentLabel || record.parentLabelText || '')
|
|
return {
|
...record,
|
id: normalizeId(record.id),
|
parentId,
|
parentLabel: parentLabel || (parentId === 0 ? '顶级分组' : '--'),
|
code: normalizeText(record.code) || '--',
|
name: normalizeText(record.name) || '--',
|
parCode: normalizeText(record.parCode) || '--',
|
sort: normalizeId(record.sort, 0),
|
status: normalizeId(record.status),
|
statusText: statusMeta.text,
|
statusType: statusMeta.type,
|
statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
|
memo: normalizeText(record.memo) || '--',
|
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 normalizeMatnrGroupListRow(record = {}, resolveParentLabel) {
|
return normalizeMatnrGroupDetailRecord(record, resolveParentLabel)
|
}
|
|
export function buildMatnrGroupPrintRows(records = [], resolveParentLabel) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeMatnrGroupListRow(record, resolveParentLabel))
|
}
|
|
export function buildMatnrGroupReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = MATNR_GROUP_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: MATNR_GROUP_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...MATNR_GROUP_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|