const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
export const LOC_AREA_MAT_REPORT_TITLE = '库区物料报表'
|
export const LOC_AREA_MAT_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
|
}
|
|
export function createLocAreaMatSearchState() {
|
return {
|
condition: '',
|
code: '',
|
warehouseId: '',
|
areaId: '',
|
depict: '',
|
status: '',
|
memo: '',
|
timeStart: '',
|
timeEnd: ''
|
}
|
}
|
|
export function createLocAreaMatFormState() {
|
return {
|
id: void 0,
|
code: '',
|
warehouseId: '',
|
areaId: '',
|
depict: '',
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function createLocAreaMatRelationBindMatnrState(areaMatId = void 0) {
|
return {
|
areaMatId,
|
warehouseId: '',
|
areaId: '',
|
groupId: '',
|
matnrId: [],
|
typeId: []
|
}
|
}
|
|
export function createLocAreaMatRelationBindLocState(areaMatId = void 0) {
|
return {
|
areaMatId,
|
warehouseId: '',
|
areaId: '',
|
groupId: '',
|
locId: [],
|
typeId: []
|
}
|
}
|
|
export function buildLocAreaMatRelationBindLocState(areaMatId = void 0) {
|
return createLocAreaMatRelationBindLocState(areaMatId)
|
}
|
|
export function buildLocAreaMatRelationBindMatnrModel(record = {}) {
|
return {
|
...createLocAreaMatRelationBindMatnrState(record.areaMatId),
|
...(record.areaMatId !== void 0 && record.areaMatId !== null && record.areaMatId !== ''
|
? { areaMatId: normalizeNumber(record.areaMatId) }
|
: {}),
|
warehouseId:
|
record.warehouseId !== undefined && record.warehouseId !== null && record.warehouseId !== ''
|
? normalizeNumber(record.warehouseId)
|
: '',
|
areaId:
|
record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
|
? normalizeNumber(record.areaId)
|
: '',
|
groupId:
|
record.groupId !== undefined && record.groupId !== null && record.groupId !== ''
|
? normalizeNumber(record.groupId)
|
: '',
|
matnrId: Array.isArray(record.matnrId) ? record.matnrId.map((item) => normalizeNumber(item)).filter(Boolean) : [],
|
typeId: Array.isArray(record.typeId) ? record.typeId.map((item) => normalizeNumber(item)).filter(Boolean) : []
|
}
|
}
|
|
export function buildLocAreaMatRelationBindLocModel(record = {}) {
|
return {
|
...createLocAreaMatRelationBindLocState(record.areaMatId),
|
...(record.areaMatId !== void 0 && record.areaMatId !== null && record.areaMatId !== ''
|
? { areaMatId: normalizeNumber(record.areaMatId) }
|
: {}),
|
warehouseId:
|
record.warehouseId !== undefined && record.warehouseId !== null && record.warehouseId !== ''
|
? normalizeNumber(record.warehouseId)
|
: '',
|
areaId:
|
record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
|
? normalizeNumber(record.areaId)
|
: '',
|
groupId:
|
record.groupId !== undefined && record.groupId !== null && record.groupId !== ''
|
? normalizeNumber(record.groupId)
|
: '',
|
locId: Array.isArray(record.locId) ? record.locId.map((item) => normalizeNumber(item)).filter(Boolean) : [],
|
typeId: Array.isArray(record.typeId) ? record.typeId.map((item) => normalizeNumber(item)).filter(Boolean) : []
|
}
|
}
|
|
export function getLocAreaMatStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getLocAreaMatPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getLocAreaMatStatusMeta(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 buildLocAreaMatSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
code: normalizeText(params.code),
|
warehouseId:
|
params.warehouseId !== undefined && params.warehouseId !== null && params.warehouseId !== ''
|
? normalizeNumber(params.warehouseId)
|
: void 0,
|
areaId:
|
params.areaId !== undefined && params.areaId !== null && params.areaId !== ''
|
? normalizeNumber(params.areaId)
|
: void 0,
|
depict: normalizeText(params.depict),
|
status:
|
params.status !== undefined && params.status !== null && params.status !== ''
|
? normalizeNumber(params.status)
|
: void 0,
|
memo: normalizeText(params.memo),
|
timeStart: normalizeText(params.timeStart),
|
timeEnd: normalizeText(params.timeEnd)
|
}
|
|
return Object.fromEntries(
|
Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
|
)
|
}
|
|
export function buildLocAreaMatPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildLocAreaMatSearchParams(params)
|
}
|
}
|
|
export function buildLocAreaMatSavePayload(formData = {}) {
|
return {
|
...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
|
? { id: normalizeNumber(formData.id) }
|
: {}),
|
code: normalizeText(formData.code) || '',
|
warehouseId:
|
formData.warehouseId !== undefined && formData.warehouseId !== null && formData.warehouseId !== ''
|
? normalizeNumber(formData.warehouseId)
|
: void 0,
|
areaId:
|
formData.areaId !== undefined && formData.areaId !== null && formData.areaId !== ''
|
? normalizeNumber(formData.areaId)
|
: void 0,
|
depict: normalizeText(formData.depict) || '',
|
status:
|
formData.status !== undefined && formData.status !== null && formData.status !== ''
|
? normalizeNumber(formData.status)
|
: 1,
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function buildLocAreaMatDialogModel(record = {}) {
|
return {
|
...createLocAreaMatFormState(),
|
...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: normalizeNumber(record.id) } : {}),
|
code: normalizeText(record.code || ''),
|
warehouseId:
|
record.warehouseId !== undefined && record.warehouseId !== null && record.warehouseId !== ''
|
? normalizeNumber(record.warehouseId)
|
: '',
|
areaId:
|
record.areaId !== undefined && record.areaId !== null && record.areaId !== ''
|
? normalizeNumber(record.areaId)
|
: '',
|
depict: normalizeText(record.depict || ''),
|
status: record.status !== void 0 && record.status !== null ? normalizeNumber(record.status, 1) : 1,
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function normalizeLocAreaMatListRow(record = {}) {
|
const statusMeta = getLocAreaMatStatusMeta(record.statusBool ?? record.status)
|
return {
|
...record,
|
code: normalizeText(record.code || ''),
|
depict: normalizeText(record.depict || ''),
|
warehouseName: normalizeText(record.warehouseId$ || record.warehouseName || ''),
|
areaName: normalizeText(record.areaId$ || record.areaName || ''),
|
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 || ''),
|
updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
|
createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
|
updateTimeText: normalizeText(record.updateTime$ || record.updateTime || ''),
|
warehouseIdText: normalizeText(record.warehouseId$ || record.warehouseIdText || ''),
|
areaIdText: normalizeText(record.areaId$ || record.areaIdText || '')
|
}
|
}
|
|
export function normalizeLocAreaMatDetailRecord(record = {}) {
|
return normalizeLocAreaMatListRow(record)
|
}
|
|
export function normalizeLocAreaMatRelationRow(record = {}) {
|
const relationTypeText =
|
record.matnrId !== void 0 ||
|
record.matnrId$ !== void 0 ||
|
record.typeId !== void 0 ||
|
record.typeId$ !== void 0
|
? '物料绑定'
|
: '库位绑定'
|
|
return {
|
...record,
|
warehouseIdText: normalizeText(record.warehouseId$ || record.warehouseIdText || ''),
|
areaIdText: normalizeText(record.areaId$ || record.areaIdText || ''),
|
matnrIdText: normalizeText(record.matnrId$ || record.matnrIdText || record.matnrCode || record.matnrName || ''),
|
groupIdText: normalizeText(record.groupId$ || record.groupIdText || record.groupName || ''),
|
locTypeIdText: normalizeText(record.locTypeId$ || record.locTypeIdText || record.typeName || record.typeText || ''),
|
locIdText: normalizeText(record.locId$ || record.locIdText || record.locCode || record.code || ''),
|
relationTypeText,
|
statusText: getLocAreaMatStatusMeta(record.statusBool ?? record.status).text,
|
createByText: normalizeText(record.createBy$ || record.createByText || ''),
|
updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
|
createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
|
updateTimeText: normalizeText(record.updateTime$ || record.updateTime || ''),
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function buildLocAreaMatPrintRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeLocAreaMatListRow(record))
|
}
|
|
export function buildLocAreaMatReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = LOC_AREA_MAT_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: LOC_AREA_MAT_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...LOC_AREA_MAT_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|
|
function normalizeOptionText(item = {}, fallbackPrefix = '') {
|
return normalizeText(item.name || item.code || item.label || item.codeText || `${fallbackPrefix}${item.id ?? item.value ?? ''}`) || '--'
|
}
|
|
function normalizeOptionId(item = {}) {
|
const value = item.id ?? item.value
|
if (value === void 0 || value === null || value === '') {
|
return void 0
|
}
|
return normalizeNumber(value)
|
}
|
|
export function resolveLocAreaMatWarehouseOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records
|
.map((item) => {
|
const value = normalizeOptionId(item)
|
if (value === void 0) return null
|
return {
|
value,
|
label: normalizeOptionText(item, '仓库 ')
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function resolveLocAreaMatAreaOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records
|
.map((item) => {
|
const value = normalizeOptionId(item)
|
if (value === void 0) return null
|
return {
|
value,
|
label: normalizeOptionText(item, '库区 '),
|
warehouseId:
|
item.warehouseId !== undefined && item.warehouseId !== null && item.warehouseId !== ''
|
? normalizeNumber(item.warehouseId)
|
: void 0
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function resolveLocAreaMatLocTypeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records
|
.map((item) => {
|
const value = normalizeOptionId(item)
|
if (value === void 0) return null
|
return {
|
value,
|
label: normalizeOptionText(item, '类型 ')
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function resolveLocAreaMatMatnrOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records
|
.map((item) => {
|
const value = normalizeOptionId(item)
|
if (value === void 0) return null
|
const label = normalizeText(item.name || item.code || item.maktx || item.barcode || `物料 ${value}`)
|
return {
|
value,
|
label: label || `物料 ${value}`,
|
groupId:
|
item.groupId !== undefined && item.groupId !== null && item.groupId !== ''
|
? normalizeNumber(item.groupId)
|
: void 0
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function resolveLocAreaMatLocOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records
|
.map((item) => {
|
const value = normalizeOptionId(item)
|
if (value === void 0) return null
|
const code = normalizeText(item.code || item.locCode || '')
|
const label = [code, normalizeText(item.warehouseName || item.areaName || '')].filter(Boolean).join(' · ') || `库位 ${value}`
|
return {
|
value,
|
label,
|
warehouseId:
|
item.warehouseId !== undefined && item.warehouseId !== null && item.warehouseId !== ''
|
? normalizeNumber(item.warehouseId)
|
: void 0,
|
areaId:
|
item.areaId !== undefined && item.areaId !== null && item.areaId !== ''
|
? normalizeNumber(item.areaId)
|
: void 0
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function normalizeLocAreaMatGroupTreeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
const walk = (nodes = []) =>
|
nodes
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = normalizeOptionId(item)
|
const children = walk(item.children || [])
|
if (value === void 0 && children.length === 0) {
|
return null
|
}
|
return {
|
id: value ?? 0,
|
name: normalizeText(item.name || '顶级分组'),
|
code: normalizeText(item.code || ''),
|
displayLabel: [normalizeText(item.name || '顶级分组'), normalizeText(item.code || '')].filter(Boolean).join(' · ') || '顶级分组',
|
children
|
}
|
})
|
.filter(Boolean)
|
|
return [
|
{
|
id: 0,
|
name: '顶级分组',
|
code: '',
|
displayLabel: '顶级分组',
|
children: walk(records)
|
}
|
]
|
}
|