function normalizeText(value) {
|
return String(value ?? '').trim()
|
}
|
|
function normalizeNumber(value, fallback = 0) {
|
if (value === '' || value === null || value === undefined) {
|
return fallback
|
}
|
const numericValue = Number(value)
|
return Number.isFinite(numericValue) ? numericValue : fallback
|
}
|
|
function normalizeNullableNumber(value) {
|
if (value === '' || value === null || value === undefined) {
|
return null
|
}
|
const numericValue = Number(value)
|
return Number.isFinite(numericValue) ? numericValue : null
|
}
|
|
export function createWhMatSearchState() {
|
return {
|
condition: '',
|
code: '',
|
name: '',
|
spec: '',
|
model: '',
|
barcode: ''
|
}
|
}
|
|
export function buildWhMatPageQueryParams(params = {}) {
|
const result = {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20
|
}
|
|
;['condition', 'code', 'name', 'spec', 'model', 'barcode'].forEach((key) => {
|
const value = normalizeText(params[key])
|
if (value) {
|
result[key] = value
|
}
|
})
|
|
if (params.groupId !== undefined && params.groupId !== null && params.groupId !== '') {
|
result.groupId = String(params.groupId)
|
}
|
|
return result
|
}
|
|
export function buildWhMatGroupTreeQueryParams(params = {}) {
|
return {
|
condition: normalizeText(params.condition)
|
}
|
}
|
|
export function normalizeWhMatGroupTreeRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records.map((item) => {
|
const children = normalizeWhMatGroupTreeRows(item?.children || [])
|
const id = normalizeNullableNumber(item?.id)
|
const code = normalizeText(item?.code)
|
const name = normalizeText(item?.name)
|
const label = [name, code].filter(Boolean).join(' · ') || '-'
|
|
return {
|
...item,
|
id,
|
parentId: normalizeNumber(item?.parentId, 0),
|
code,
|
name,
|
label,
|
displayLabel: label,
|
status: normalizeNullableNumber(item?.status),
|
statusText: normalizeNumber(item?.status, 1) === 1 ? '正常' : '冻结',
|
statusType: normalizeNumber(item?.status, 1) === 1 ? 'success' : 'danger',
|
memo: normalizeText(item?.memo) || '-',
|
children
|
}
|
})
|
}
|
|
export function normalizeWhMatRow(record = {}) {
|
const statusValue = normalizeNullableNumber(record?.status)
|
return {
|
...record,
|
code: normalizeText(record?.code) || '-',
|
name: normalizeText(record?.name) || '-',
|
groupName: normalizeText(record?.groupId$ || record?.groupCode) || '-',
|
shipperName: normalizeText(record?.shipperId$ || record?.shipperName) || '-',
|
barcode: normalizeText(record?.barcode) || '-',
|
spec: normalizeText(record?.spec) || '-',
|
model: normalizeText(record?.model) || '-',
|
color: normalizeText(record?.color) || '-',
|
size: normalizeText(record?.size) || '-',
|
unit: normalizeText(record?.unit) || '-',
|
purUnit: normalizeText(record?.purUnit) || '-',
|
stockUnit: normalizeText(record?.stockUnit) || '-',
|
stockLevelText: normalizeText(record?.stockLeval$) || '-',
|
flagLabelManageText: normalizeText(record?.flagLabelMange$) || '-',
|
flagCheckText:
|
record?.flagCheck === 1 || record?.flagCheck === '1'
|
? '是'
|
: record?.flagCheck === 0 || record?.flagCheck === '0'
|
? '否'
|
: '-',
|
statusText: normalizeText(record?.status$) || (statusValue === 1 ? '正常' : statusValue === 0 ? '冻结' : '-'),
|
statusType: statusValue === 1 ? 'success' : statusValue === 0 ? 'danger' : 'info',
|
safeQty: record?.safeQty ?? '-',
|
minQty: record?.minQty ?? '-',
|
maxQty: record?.maxQty ?? '-',
|
valid: record?.valid ?? '-',
|
validWarn: record?.validWarn ?? '-',
|
stagn: record?.stagn ?? '-',
|
describle: normalizeText(record?.describle) || '-',
|
baseUnit: normalizeText(record?.baseUnit) || '-',
|
useOrgName: normalizeText(record?.useOrgName) || '-',
|
erpClsId: normalizeText(record?.erpClsId) || '-',
|
memo: normalizeText(record?.memo) || '-',
|
updateByText: normalizeText(record?.updateBy$) || '-',
|
createByText: normalizeText(record?.createBy$) || '-',
|
updateTimeText: normalizeText(record?.updateTime$ || record?.updateTime) || '-',
|
createTimeText: normalizeText(record?.createTime$ || record?.createTime) || '-',
|
extendFields:
|
record?.extendFields && typeof record.extendFields === 'object' && !Array.isArray(record.extendFields)
|
? record.extendFields
|
: {}
|
}
|
}
|
|
export function normalizeWhMatDetail(record = {}) {
|
return normalizeWhMatRow(record)
|
}
|
|
export function getWhMatTreeNodeLabel(node = {}) {
|
const name = normalizeText(node?.name)
|
const code = normalizeText(node?.code)
|
return [name, code].filter(Boolean).join(' · ') || '-'
|
}
|
|
export const buildMatnrPageQueryParams = buildWhMatPageQueryParams
|
export const buildMatnrGroupTreeQueryParams = buildWhMatGroupTreeQueryParams
|
export const normalizeMatnrGroupTreeRows = normalizeWhMatGroupTreeRows
|
export const normalizeMatnrRow = normalizeWhMatRow
|
export const normalizeMatnrDetail = normalizeWhMatDetail
|
export const createMatnrSearchState = createWhMatSearchState
|
export const getMatnrTreeNodeLabel = getWhMatTreeNodeLabel
|