| | |
| | | import { $t } from '@/locales' |
| | | |
| | | export const WH_MAT_REPORT_TITLE = '物料报表' |
| | | export const WH_MAT_REPORT_STYLE = { |
| | | orientation: 'landscape', |
| | | titleAlign: 'center', |
| | | titleLevel: 'h2' |
| | | } |
| | | export const WH_MAT_DYNAMIC_FIELD_PREFIX = 'extendField__' |
| | | |
| | | function normalizeText(value) { |
| | | return String(value ?? '').trim() |
| | | } |
| | |
| | | return Number.isFinite(numericValue) ? numericValue : null |
| | | } |
| | | |
| | | function normalizeNullableInteger(value) { |
| | | const numericValue = normalizeNullableNumber(value) |
| | | return numericValue === null ? null : Math.trunc(numericValue) |
| | | } |
| | | |
| | | function normalizeBooleanLikeText(value, t = $t) { |
| | | if (value === 1 || value === '1') return t('common.status.yes') |
| | | if (value === 0 || value === '0') return t('common.status.no') |
| | | return t('common.placeholder.empty') |
| | | } |
| | | |
| | | export function createWhMatSearchState() { |
| | | return { |
| | | condition: '', |
| | | code: '', |
| | | name: '', |
| | | platCode: '', |
| | | spec: '', |
| | | model: '', |
| | | barcode: '' |
| | | color: '', |
| | | size: '', |
| | | unit: '', |
| | | purUnit: '', |
| | | stockUnit: '', |
| | | barcode: '', |
| | | describle: '', |
| | | groupId: '', |
| | | rglarId: '', |
| | | weight: null, |
| | | nromNum: null, |
| | | stockLevel: '', |
| | | flagLabelMange: '', |
| | | safeQty: null, |
| | | minQty: null, |
| | | maxQty: null, |
| | | stagn: null, |
| | | valid: null, |
| | | status: '', |
| | | flagCheck: '', |
| | | validWarn: null, |
| | | memo: '', |
| | | orderBy: 'create_time desc' |
| | | } |
| | | } |
| | | |
| | | export function createWhMatFormState() { |
| | | return { |
| | | id: void 0, |
| | | code: '', |
| | | name: '', |
| | | groupId: '', |
| | | useOrgName: '', |
| | | spec: '', |
| | | model: '', |
| | | color: '', |
| | | size: '', |
| | | weight: void 0, |
| | | unit: '', |
| | | purUnit: '', |
| | | describle: '', |
| | | safeQty: void 0, |
| | | minQty: void 0, |
| | | maxQty: void 0, |
| | | stagn: void 0, |
| | | valid: void 0, |
| | | validWarn: void 0, |
| | | flagCheck: 0, |
| | | rglarId: '' |
| | | } |
| | | } |
| | | |
| | | export function buildWhMatPageQueryParams(params = {}) { |
| | | const result = { |
| | | current: params.current || 1, |
| | | pageSize: params.pageSize || params.size || 20 |
| | | pageSize: params.pageSize || params.size || 20, |
| | | orderBy: normalizeText(params.orderBy) || 'create_time desc' |
| | | } |
| | | |
| | | ;['condition', 'code', 'name', 'spec', 'model', 'barcode'].forEach((key) => { |
| | | ;[ |
| | | 'condition', |
| | | 'code', |
| | | 'name', |
| | | 'platCode', |
| | | 'spec', |
| | | 'model', |
| | | 'color', |
| | | 'size', |
| | | 'unit', |
| | | 'purUnit', |
| | | 'stockUnit', |
| | | 'barcode', |
| | | 'describle', |
| | | 'memo' |
| | | ].forEach((key) => { |
| | | const value = normalizeText(params[key]) |
| | | if (value) { |
| | | result[key] = value |
| | | } |
| | | }) |
| | | ;[ |
| | | 'groupId', |
| | | 'rglarId', |
| | | 'weight', |
| | | 'nromNum', |
| | | 'stockLevel', |
| | | 'flagLabelMange', |
| | | 'safeQty', |
| | | 'minQty', |
| | | 'maxQty', |
| | | 'stagn', |
| | | 'valid', |
| | | 'status', |
| | | 'flagCheck', |
| | | 'validWarn' |
| | | ].forEach((key) => { |
| | | const value = params[key] |
| | | if (value !== '' && value !== null && value !== undefined) { |
| | | const numericValue = Number(value) |
| | | result[key] = Number.isFinite(numericValue) ? numericValue : value |
| | | } |
| | | }) |
| | | |
| | | if (params.groupId !== undefined && params.groupId !== null && params.groupId !== '') { |
| | | result.groupId = String(params.groupId) |
| | | } |
| | | Object.entries(params).forEach(([key, value]) => { |
| | | if (!key.startsWith(WH_MAT_DYNAMIC_FIELD_PREFIX)) { |
| | | return |
| | | } |
| | | const normalizedValue = normalizeText(value) |
| | | if (normalizedValue) { |
| | | result[key.slice(WH_MAT_DYNAMIC_FIELD_PREFIX.length)] = normalizedValue |
| | | } |
| | | }) |
| | | |
| | | return result |
| | | } |
| | |
| | | } |
| | | |
| | | return records.map((item) => { |
| | | const children = normalizeWhMatGroupTreeRows(item?.children || []) |
| | | const children = normalizeWhMatGroupTreeRows(item?.children || [], t) |
| | | const id = normalizeNullableNumber(item?.id) |
| | | const code = normalizeText(item?.code) |
| | | const name = normalizeText(item?.name) |
| | |
| | | name, |
| | | label, |
| | | displayLabel: label, |
| | | value: id, |
| | | status: normalizeNullableNumber(item?.status), |
| | | statusText: normalizeNumber(item?.status, 1) === 1 ? t('common.status.normal') : t('common.status.frozen'), |
| | | statusText: |
| | | normalizeNumber(item?.status, 1) === 1 |
| | | ? t('common.status.normal') |
| | | : t('common.status.frozen'), |
| | | statusType: normalizeNumber(item?.status, 1) === 1 ? 'success' : 'danger', |
| | | memo: normalizeText(item?.memo) || t('common.placeholder.empty'), |
| | | children |
| | |
| | | }) |
| | | } |
| | | |
| | | export function normalizeWhMatRow(record = {}, t = $t) { |
| | | const statusValue = normalizeNullableNumber(record?.status) |
| | | export function resolveWhMatGroupOptions(treeRows = []) { |
| | | if (!Array.isArray(treeRows)) { |
| | | return [] |
| | | } |
| | | |
| | | return treeRows.map((item) => ({ |
| | | id: item.id, |
| | | value: item.id, |
| | | label: |
| | | item.displayLabel || item.label || [item.name, item.code].filter(Boolean).join(' · ') || '-', |
| | | displayLabel: |
| | | item.displayLabel || item.label || [item.name, item.code].filter(Boolean).join(' · ') || '-', |
| | | children: resolveWhMatGroupOptions(item.children || []) |
| | | })) |
| | | } |
| | | |
| | | export function resolveWhMatSerialRuleOptions(records = []) { |
| | | if (!Array.isArray(records)) { |
| | | return [] |
| | | } |
| | | return records |
| | | .map((item) => ({ |
| | | value: normalizeNullableNumber(item?.id), |
| | | label: normalizeText(item?.name || item?.code || item?.description) |
| | | })) |
| | | .filter((item) => item.value !== null && item.label) |
| | | } |
| | | |
| | | export function getWhMatStatusOptions(t = $t) { |
| | | return [ |
| | | { value: 1, label: t('common.status.normal') }, |
| | | { value: 0, label: t('common.status.frozen') } |
| | | ] |
| | | } |
| | | |
| | | export function getWhMatFlagCheckOptions(t = $t) { |
| | | return [ |
| | | { value: 0, label: t('common.status.no') }, |
| | | { value: 1, label: t('common.status.yes') } |
| | | ] |
| | | } |
| | | |
| | | export function getWhMatStockLevelOptions() { |
| | | return [ |
| | | { value: 0, label: 'A' }, |
| | | { value: 1, label: 'B' }, |
| | | { value: 2, label: 'C' } |
| | | ] |
| | | } |
| | | |
| | | export function getWhMatFlagLabelManageOptions(t = $t) { |
| | | return [ |
| | | { value: 0, label: t('common.status.no') }, |
| | | { value: 1, label: t('common.status.yes') } |
| | | ] |
| | | } |
| | | |
| | | export function getWhMatDynamicFieldKey(fieldName) { |
| | | return `${WH_MAT_DYNAMIC_FIELD_PREFIX}${fieldName}` |
| | | } |
| | | |
| | | export function normalizeWhMatEnabledFields(fields = []) { |
| | | if (!Array.isArray(fields)) { |
| | | return [] |
| | | } |
| | | |
| | | return fields |
| | | .map((item) => ({ |
| | | fields: normalizeText(item?.fields), |
| | | fieldsAlise: normalizeText(item?.fieldsAlise || item?.fieldsAlias || item?.fields) |
| | | })) |
| | | .filter((item) => item.fields) |
| | | } |
| | | |
| | | export function attachWhMatDynamicFields(record = {}, enabledFields = []) { |
| | | const extendFields = |
| | | record?.extendFields && |
| | | typeof record.extendFields === 'object' && |
| | | !Array.isArray(record.extendFields) |
| | | ? record.extendFields |
| | | : {} |
| | | const dynamicValues = {} |
| | | |
| | | enabledFields.forEach((field) => { |
| | | dynamicValues[getWhMatDynamicFieldKey(field.fields)] = extendFields[field.fields] || '' |
| | | }) |
| | | |
| | | return { |
| | | ...record, |
| | | code: normalizeText(record?.code) || t('common.placeholder.empty'), |
| | | name: normalizeText(record?.name) || t('common.placeholder.empty'), |
| | | groupName: normalizeText(record?.groupId$ || record?.groupCode) || t('common.placeholder.empty'), |
| | | shipperName: normalizeText(record?.shipperId$ || record?.shipperName) || t('common.placeholder.empty'), |
| | | barcode: normalizeText(record?.barcode) || t('common.placeholder.empty'), |
| | | spec: normalizeText(record?.spec) || t('common.placeholder.empty'), |
| | | model: normalizeText(record?.model) || t('common.placeholder.empty'), |
| | | color: normalizeText(record?.color) || t('common.placeholder.empty'), |
| | | size: normalizeText(record?.size) || t('common.placeholder.empty'), |
| | | unit: normalizeText(record?.unit) || t('common.placeholder.empty'), |
| | | purUnit: normalizeText(record?.purUnit) || t('common.placeholder.empty'), |
| | | stockUnit: normalizeText(record?.stockUnit) || t('common.placeholder.empty'), |
| | | stockLevelText: normalizeText(record?.stockLeval$) || t('common.placeholder.empty'), |
| | | flagLabelManageText: normalizeText(record?.flagLabelMange$) || t('common.placeholder.empty'), |
| | | flagCheckText: |
| | | record?.flagCheck === 1 || record?.flagCheck === '1' |
| | | ? t('common.status.yes') |
| | | : record?.flagCheck === 0 || record?.flagCheck === '0' |
| | | ? t('common.status.no') |
| | | : t('common.placeholder.empty'), |
| | | statusText: |
| | | normalizeText(record?.status$) || |
| | | (statusValue === 1 |
| | | ? t('common.status.normal') |
| | | : statusValue === 0 |
| | | ? t('common.status.frozen') |
| | | : t('common.placeholder.empty')), |
| | | statusType: statusValue === 1 ? 'success' : statusValue === 0 ? 'danger' : 'info', |
| | | safeQty: record?.safeQty ?? t('common.placeholder.empty'), |
| | | minQty: record?.minQty ?? t('common.placeholder.empty'), |
| | | maxQty: record?.maxQty ?? t('common.placeholder.empty'), |
| | | valid: record?.valid ?? t('common.placeholder.empty'), |
| | | validWarn: record?.validWarn ?? t('common.placeholder.empty'), |
| | | stagn: record?.stagn ?? t('common.placeholder.empty'), |
| | | describle: normalizeText(record?.describle) || t('common.placeholder.empty'), |
| | | baseUnit: normalizeText(record?.baseUnit) || t('common.placeholder.empty'), |
| | | useOrgName: normalizeText(record?.useOrgName) || t('common.placeholder.empty'), |
| | | erpClsId: normalizeText(record?.erpClsId) || t('common.placeholder.empty'), |
| | | memo: normalizeText(record?.memo) || t('common.placeholder.empty'), |
| | | updateByText: normalizeText(record?.updateBy$) || t('common.placeholder.empty'), |
| | | createByText: normalizeText(record?.createBy$) || t('common.placeholder.empty'), |
| | | updateTimeText: normalizeText(record?.updateTime$ || record?.updateTime) || t('common.placeholder.empty'), |
| | | createTimeText: normalizeText(record?.createTime$ || record?.createTime) || t('common.placeholder.empty'), |
| | | extendFields: |
| | | record?.extendFields && typeof record.extendFields === 'object' && !Array.isArray(record.extendFields) |
| | | ? record.extendFields |
| | | : {} |
| | | ...dynamicValues, |
| | | extendFields |
| | | } |
| | | } |
| | | |
| | | export function normalizeWhMatDetail(record = {}, t = $t) { |
| | | return normalizeWhMatRow(record, t) |
| | | export function normalizeWhMatRow(record = {}, t = $t, enabledFields = []) { |
| | | const statusValue = normalizeNullableNumber(record?.status) |
| | | const validWarn = record?.validWarn ?? record?.valid_warn |
| | | const purUnit = record?.purUnit ?? record?.purchaseUnit |
| | | const stockLevelLabel = |
| | | getWhMatStockLevelOptions().find( |
| | | (item) => item.value === normalizeNullableNumber(record?.stockLevel) |
| | | )?.label || '' |
| | | const flagLabelManageLabel = |
| | | getWhMatFlagLabelManageOptions(t).find( |
| | | (item) => item.value === normalizeNullableNumber(record?.flagLabelMange) |
| | | )?.label || '' |
| | | |
| | | return attachWhMatDynamicFields( |
| | | { |
| | | ...record, |
| | | id: normalizeNullableNumber(record?.id), |
| | | code: normalizeText(record?.code) || t('common.placeholder.empty'), |
| | | name: normalizeText(record?.name) || t('common.placeholder.empty'), |
| | | groupId: normalizeNullableNumber(record?.groupId), |
| | | groupName: |
| | | normalizeText(record?.groupId$ || record?.groupCode || record?.groupName) || |
| | | t('common.placeholder.empty'), |
| | | shipperName: |
| | | normalizeText(record?.shipperId$ || record?.shipperName) || t('common.placeholder.empty'), |
| | | barcode: normalizeText(record?.barcode) || t('common.placeholder.empty'), |
| | | platCode: normalizeText(record?.platCode) || t('common.placeholder.empty'), |
| | | spec: normalizeText(record?.spec) || t('common.placeholder.empty'), |
| | | model: normalizeText(record?.model) || t('common.placeholder.empty'), |
| | | color: normalizeText(record?.color) || t('common.placeholder.empty'), |
| | | size: normalizeText(record?.size) || t('common.placeholder.empty'), |
| | | weight: record?.weight ?? t('common.placeholder.empty'), |
| | | nromNum: record?.nromNum ?? t('common.placeholder.empty'), |
| | | unit: normalizeText(record?.unit) || t('common.placeholder.empty'), |
| | | purUnit: normalizeText(purUnit) || t('common.placeholder.empty'), |
| | | stockUnit: normalizeText(record?.stockUnit) || t('common.placeholder.empty'), |
| | | stockLevelText: |
| | | normalizeText(record?.stockLeval$ || record?.stockLevel$ || stockLevelLabel) || |
| | | t('common.placeholder.empty'), |
| | | flagLabelManageText: |
| | | normalizeText(record?.flagLabelMange$ || record?.isLabelMange$ || flagLabelManageLabel) || |
| | | t('common.placeholder.empty'), |
| | | flagCheckText: normalizeBooleanLikeText(record?.flagCheck, t), |
| | | statusText: |
| | | normalizeText(record?.status$) || |
| | | (statusValue === 1 |
| | | ? t('common.status.normal') |
| | | : statusValue === 0 |
| | | ? t('common.status.frozen') |
| | | : t('common.placeholder.empty')), |
| | | statusType: statusValue === 1 ? 'success' : statusValue === 0 ? 'danger' : 'info', |
| | | safeQty: record?.safeQty ?? t('common.placeholder.empty'), |
| | | minQty: record?.minQty ?? t('common.placeholder.empty'), |
| | | maxQty: record?.maxQty ?? t('common.placeholder.empty'), |
| | | valid: record?.valid ?? t('common.placeholder.empty'), |
| | | validWarn: validWarn ?? t('common.placeholder.empty'), |
| | | stagn: record?.stagn ?? t('common.placeholder.empty'), |
| | | describle: normalizeText(record?.describle) || t('common.placeholder.empty'), |
| | | baseUnit: normalizeText(record?.baseUnit) || t('common.placeholder.empty'), |
| | | useOrgName: normalizeText(record?.useOrgName) || t('common.placeholder.empty'), |
| | | erpClsId: normalizeText(record?.erpClsId) || t('common.placeholder.empty'), |
| | | rglarId: normalizeNullableNumber(record?.rglarId), |
| | | rglarName: |
| | | normalizeText(record?.rglarId$ || record?.rglarName || record?.rglarCode) || |
| | | t('common.placeholder.empty'), |
| | | memo: normalizeText(record?.memo) || t('common.placeholder.empty'), |
| | | updateByText: normalizeText(record?.updateBy$) || t('common.placeholder.empty'), |
| | | createByText: normalizeText(record?.createBy$) || t('common.placeholder.empty'), |
| | | updateTimeText: |
| | | normalizeText(record?.updateTime$ || record?.updateTime) || t('common.placeholder.empty'), |
| | | createTimeText: |
| | | normalizeText(record?.createTime$ || record?.createTime) || t('common.placeholder.empty') |
| | | }, |
| | | enabledFields |
| | | ) |
| | | } |
| | | |
| | | export function normalizeWhMatDetail(record = {}, t = $t, enabledFields = []) { |
| | | return normalizeWhMatRow(record, t, enabledFields) |
| | | } |
| | | |
| | | export function buildWhMatDialogModel(record = {}) { |
| | | const source = normalizeWhMatRow(record) |
| | | return { |
| | | ...createWhMatFormState(), |
| | | id: source.id ?? void 0, |
| | | code: normalizeText(record?.code), |
| | | name: normalizeText(record?.name), |
| | | groupId: source.groupId ?? '', |
| | | useOrgName: normalizeText(record?.useOrgName), |
| | | spec: normalizeText(record?.spec), |
| | | model: normalizeText(record?.model), |
| | | color: normalizeText(record?.color), |
| | | size: normalizeText(record?.size), |
| | | weight: normalizeNullableNumber(record?.weight), |
| | | unit: normalizeText(record?.unit), |
| | | purUnit: normalizeText(record?.purUnit || record?.purchaseUnit), |
| | | describle: normalizeText(record?.describle), |
| | | safeQty: normalizeNullableNumber(record?.safeQty), |
| | | minQty: normalizeNullableNumber(record?.minQty), |
| | | maxQty: normalizeNullableNumber(record?.maxQty), |
| | | stagn: normalizeNullableInteger(record?.stagn), |
| | | valid: normalizeNullableInteger(record?.valid), |
| | | validWarn: normalizeNullableInteger(record?.validWarn), |
| | | flagCheck: normalizeNullableInteger(record?.flagCheck) ?? 0, |
| | | rglarId: normalizeNullableNumber(record?.rglarId) ?? '' |
| | | } |
| | | } |
| | | |
| | | export function buildWhMatSavePayload(formData = {}) { |
| | | const payload = { |
| | | ...(formData.id !== undefined && formData.id !== null ? { id: Number(formData.id) } : {}), |
| | | code: normalizeText(formData.code), |
| | | name: normalizeText(formData.name), |
| | | groupId: |
| | | formData.groupId !== undefined && formData.groupId !== null && formData.groupId !== '' |
| | | ? Number(formData.groupId) |
| | | : void 0, |
| | | useOrgName: normalizeText(formData.useOrgName), |
| | | spec: normalizeText(formData.spec), |
| | | model: normalizeText(formData.model), |
| | | color: normalizeText(formData.color), |
| | | size: normalizeText(formData.size), |
| | | weight: normalizeNullableNumber(formData.weight), |
| | | unit: normalizeText(formData.unit), |
| | | purUnit: normalizeText(formData.purUnit), |
| | | describle: normalizeText(formData.describle), |
| | | safeQty: normalizeNullableNumber(formData.safeQty), |
| | | minQty: normalizeNullableNumber(formData.minQty), |
| | | maxQty: normalizeNullableNumber(formData.maxQty), |
| | | stagn: normalizeNullableInteger(formData.stagn), |
| | | valid: normalizeNullableInteger(formData.valid), |
| | | validWarn: normalizeNullableInteger(formData.validWarn), |
| | | flagCheck: normalizeNullableInteger(formData.flagCheck), |
| | | rglarId: |
| | | formData.rglarId !== undefined && formData.rglarId !== null && formData.rglarId !== '' |
| | | ? Number(formData.rglarId) |
| | | : void 0 |
| | | } |
| | | |
| | | return Object.fromEntries(Object.entries(payload).filter(([, value]) => value !== undefined)) |
| | | } |
| | | |
| | | export function getWhMatTreeNodeLabel(node = {}) { |
| | |
| | | return [name, code].filter(Boolean).join(' · ') || $t('common.placeholder.empty') |
| | | } |
| | | |
| | | export function buildWhMatPrintRows(records = [], t = $t) { |
| | | return records.map((record) => { |
| | | const normalizedRecord = normalizeWhMatRow(record, t) |
| | | return { |
| | | 物料编码: normalizedRecord.code, |
| | | 物料名称: normalizedRecord.name, |
| | | 物料分组: normalizedRecord.groupName, |
| | | 规格: normalizedRecord.spec, |
| | | 型号: normalizedRecord.model, |
| | | 单位: normalizedRecord.unit, |
| | | 状态: normalizedRecord.statusText, |
| | | 更新时间: normalizedRecord.updateTimeText |
| | | } |
| | | }) |
| | | } |
| | | |
| | | export function buildWhMatReportMeta({ |
| | | previewMeta = {}, |
| | | count = 0, |
| | | orientation = WH_MAT_REPORT_STYLE.orientation |
| | | } = {}) { |
| | | return { |
| | | reportTitle: WH_MAT_REPORT_TITLE, |
| | | count, |
| | | ...previewMeta, |
| | | reportStyle: { |
| | | ...WH_MAT_REPORT_STYLE, |
| | | ...(previewMeta.reportStyle || {}), |
| | | orientation |
| | | } |
| | | } |
| | | } |
| | | |
| | | export const buildMatnrPageQueryParams = buildWhMatPageQueryParams |
| | | export const buildMatnrGroupTreeQueryParams = buildWhMatGroupTreeQueryParams |
| | | export const normalizeMatnrGroupTreeRows = normalizeWhMatGroupTreeRows |