const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
const USE_STATUS_META = {
|
O: { text: '空库', type: 'success' },
|
D: { text: '空板', type: 'info' },
|
R: { text: '预约出库', type: 'warning' },
|
S: { text: '预约入库', type: 'warning' },
|
X: { text: '禁用', type: 'danger' },
|
F: { text: '在库', type: 'primary' }
|
}
|
|
const LOC_ID_FIELDS = ['id', 'version', 'warehouseId', 'areaId']
|
const LOC_SIZE_FIELDS = ['length', 'height', 'width']
|
const LOC_POSITION_FIELDS = ['row', 'col', 'lev', 'channel']
|
const LOC_CAPACITY_FIELDS = ['maxParts', 'maxPack']
|
const LOC_OPTIONAL_NUMBER_FIELDS = [...LOC_ID_FIELDS, ...LOC_SIZE_FIELDS, ...LOC_POSITION_FIELDS, ...LOC_CAPACITY_FIELDS]
|
|
export const LOC_REPORT_TITLE = '库位报表'
|
export const LOC_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong',
|
orientation: 'portrait',
|
density: 'compact',
|
showSequence: true
|
}
|
|
function normalizeText(value) {
|
return String(value ?? '').trim()
|
}
|
|
function hasValue(value) {
|
return value !== '' && value !== null && value !== undefined
|
}
|
|
function normalizeNumber(value, fallback = void 0) {
|
if (!hasValue(value)) {
|
return fallback
|
}
|
const parsed = Number(value)
|
return Number.isNaN(parsed) ? fallback : parsed
|
}
|
|
function toOptionalNumber(value) {
|
return hasValue(value) ? Number(value) : void 0
|
}
|
|
function toNumberOr(value, fallback) {
|
return hasValue(value) ? Number(value) : fallback
|
}
|
|
function buildNumberField(key, value) {
|
return hasValue(value) ? { [key]: Number(value) } : {}
|
}
|
|
function buildOptionalNumberFields(source = {}, fields = []) {
|
return Object.fromEntries(fields.map((field) => [field, toOptionalNumber(source[field])]).filter(([, value]) => hasValue(value)))
|
}
|
|
function normalizeFlagText(value) {
|
if (value === 1 || value === '1' || value === true || value === '是') {
|
return '是'
|
}
|
if (value === 0 || value === '0' || value === false || value === '否') {
|
return '否'
|
}
|
return normalizeText(value) || '--'
|
}
|
|
function normalizeTypeIds(typeIds = []) {
|
if (Array.isArray(typeIds)) {
|
return typeIds.map((item) => normalizeNumber(item, void 0)).filter(hasValue)
|
}
|
|
if (typeof typeIds === 'string' && typeIds.trim()) {
|
return typeIds.split(',').map((item) => normalizeNumber(item, void 0)).filter(hasValue)
|
}
|
|
return []
|
}
|
|
export function filterLocAreaOptionsByWarehouse(options = [], warehouseId) {
|
if (!warehouseId) {
|
return options
|
}
|
|
return options.filter((item) => {
|
if (!hasValue(item?.warehouseId)) {
|
return true
|
}
|
return Number(item.warehouseId) === Number(warehouseId)
|
})
|
}
|
|
export function createLocSearchState() {
|
return {
|
condition: '',
|
warehouseId: '',
|
areaId: '',
|
code: '',
|
useStatus: '',
|
row: '',
|
col: '',
|
lev: '',
|
channel: '',
|
status: '',
|
barcode: '',
|
memo: ''
|
}
|
}
|
|
export function createLocFormState() {
|
return {
|
id: void 0,
|
version: void 0,
|
warehouseId: void 0,
|
areaId: void 0,
|
code: '',
|
typeIds: [],
|
flagLogic: 0,
|
fucAtrrs: '',
|
barcode: '',
|
unit: '',
|
length: void 0,
|
height: void 0,
|
width: void 0,
|
row: void 0,
|
col: void 0,
|
lev: void 0,
|
channel: void 0,
|
maxParts: void 0,
|
maxPack: void 0,
|
useStatus: 'O',
|
flagLabelMange: 0,
|
locAttrs: '',
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function getLocPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getLocStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getLocUseStatusOptions() {
|
return [
|
{ label: '空库', value: 'O' },
|
{ label: '空板', value: 'D' },
|
{ label: '预约出库', value: 'R' },
|
{ label: '预约入库', value: 'S' },
|
{ label: '禁用', value: 'X' },
|
{ label: '在库', value: 'F' }
|
]
|
}
|
|
export function getLocBinaryOptions() {
|
return [
|
{ label: '否', value: 0 },
|
{ label: '是', value: 1 }
|
]
|
}
|
|
export function getLocStatusMeta(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 getLocUseStatusMeta(useStatus) {
|
if (!useStatus) {
|
return { text: '未知', type: 'info' }
|
}
|
return USE_STATUS_META[String(useStatus).trim()] || { text: String(useStatus), type: 'info' }
|
}
|
|
export function buildLocSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
warehouseId: toOptionalNumber(params.warehouseId),
|
areaId: toOptionalNumber(params.areaId),
|
code: normalizeText(params.code),
|
useStatus: normalizeText(params.useStatus),
|
row: toOptionalNumber(params.row),
|
col: toOptionalNumber(params.col),
|
lev: toOptionalNumber(params.lev),
|
channel: toOptionalNumber(params.channel),
|
status: toOptionalNumber(params.status),
|
barcode: normalizeText(params.barcode),
|
memo: normalizeText(params.memo)
|
}
|
|
return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => hasValue(value)))
|
}
|
|
export function buildLocPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildLocSearchParams(params)
|
}
|
}
|
|
export function buildLocSavePayload(formData = {}) {
|
return {
|
...buildOptionalNumberFields(formData, LOC_ID_FIELDS),
|
code: normalizeText(formData.code) || '',
|
typeIds: normalizeTypeIds(formData.typeIds),
|
...buildNumberField('flagLogic', formData.flagLogic),
|
fucAtrrs: normalizeText(formData.fucAtrrs) || '',
|
barcode: normalizeText(formData.barcode) || '',
|
unit: normalizeText(formData.unit) || '',
|
...buildOptionalNumberFields(formData, [...LOC_SIZE_FIELDS, ...LOC_POSITION_FIELDS, ...LOC_CAPACITY_FIELDS]),
|
useStatus: normalizeText(formData.useStatus) || 'O',
|
...buildNumberField('flagLabelMange', formData.flagLabelMange),
|
locAttrs: normalizeText(formData.locAttrs) || '',
|
status: toNumberOr(formData.status, 1),
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function buildLocDialogModel(record = {}) {
|
return {
|
...createLocFormState(),
|
...buildOptionalNumberFields(record, LOC_OPTIONAL_NUMBER_FIELDS),
|
code: normalizeText(record.code || ''),
|
typeIds: normalizeTypeIds(record.typeIds ?? record.type ?? ''),
|
flagLogic: toNumberOr(record.flagLogic, 0),
|
fucAtrrs: normalizeText(record.fucAtrrs || ''),
|
barcode: normalizeText(record.barcode || ''),
|
unit: normalizeText(record.unit || ''),
|
useStatus: normalizeText(record.useStatus || 'O') || 'O',
|
flagLabelMange: toNumberOr(record.flagLabelMange, 0),
|
locAttrs: normalizeText(record.locAttrs || ''),
|
status: toNumberOr(record.status, 1),
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function normalizeLocDetailRecord(record = {}) {
|
const statusMeta = getLocStatusMeta(record.statusBool ?? record.status)
|
const useStatusMeta = getLocUseStatusMeta(record.useStatus)
|
const typeIds = normalizeTypeIds(record.typeIds ?? record.type ?? '')
|
return {
|
...record,
|
...buildOptionalNumberFields(record, [...LOC_SIZE_FIELDS, ...LOC_POSITION_FIELDS, ...LOC_CAPACITY_FIELDS]),
|
warehouseName: normalizeText(record.warehouseId$ || record.warehouseName || ''),
|
areaName: normalizeText(record.areaId$ || record.areaName || ''),
|
typeIds,
|
typeIdsText: normalizeText(record.typeIds$ || record.type$ || record.typeText || record.type || ''),
|
code: normalizeText(record.code || ''),
|
barcode: normalizeText(record.barcode || ''),
|
unit: normalizeText(record.unit || ''),
|
fucAtrrs: normalizeText(record.fucAtrrs || ''),
|
locAttrs: normalizeText(record.locAttrs || ''),
|
memo: normalizeText(record.memo || ''),
|
flagLogicText: normalizeFlagText(record.flagLogic),
|
flagLabelMangeText: normalizeFlagText(record.flagLabelMange),
|
useStatusText: useStatusMeta.text,
|
useStatusType: useStatusMeta.type,
|
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 normalizeLocListRow(record = {}) {
|
return normalizeLocDetailRecord(record)
|
}
|
|
export function buildLocPrintRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeLocListRow(record))
|
}
|
|
export function buildLocReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = LOC_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: LOC_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...LOC_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|
|
export function resolveLocWarehouseOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.id ?? item.value
|
if (!hasValue(value)) {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.name || item.code || `仓库 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|
|
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 (!hasValue(value)) {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.name || item.code || `库区 ${value}`),
|
warehouseId: toOptionalNumber(item.warehouseId)
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function resolveLocTypeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.id ?? item.value
|
if (!hasValue(value)) {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.name || item.code || item.label || `类型 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|