| | |
| | | export const ASN_ORDER_REPORT_TITLE = '入库通知单报表' |
| | | import { $t } from '@/locales' |
| | | |
| | | export function getAsnOrderReportTitle(t = $t) { |
| | | return t('pages.orders.asnOrder.reportTitle') |
| | | } |
| | | export const ASN_ORDER_REPORT_STYLE = { |
| | | titleAlign: 'center', |
| | | titleLevel: 'strong', |
| | |
| | | showSequence: true |
| | | } |
| | | |
| | | const ASN_ORDER_STATUS_MAP = { |
| | | 0: { label: '未执行', tagType: 'info' }, |
| | | 1: { label: '执行中', tagType: 'warning' }, |
| | | 2: { label: '收货完成', tagType: 'success' }, |
| | | 3: { label: '任务执行中', tagType: 'warning' }, |
| | | 4: { label: '已完成', tagType: 'success' }, |
| | | 8: { label: '取消', tagType: 'danger' }, |
| | | 9: { label: '已关闭', tagType: 'info' } |
| | | } |
| | | |
| | | function normalizeText(value) { |
| | | return String(value ?? '').trim() |
| | | } |
| | | |
| | | function normalizeDateValue(value) { |
| | | return value ? String(value) : '' |
| | | } |
| | | |
| | | function normalizeDateTimeForApi(value) { |
| | | const normalizedValue = normalizeDateValue(value) |
| | | if (!normalizedValue) { |
| | | return '' |
| | | } |
| | | if (/^\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}$/.test(normalizedValue)) { |
| | | return new Date(normalizedValue.replace(/\s+/, 'T')).toISOString() |
| | | } |
| | | if (/^\d{4}-\d{2}-\d{2}$/.test(normalizedValue)) { |
| | | return new Date(`${normalizedValue}T00:00:00`).toISOString() |
| | | } |
| | | return normalizedValue |
| | | } |
| | | |
| | | function normalizeNumber(value) { |
| | |
| | | return Number.isFinite(numericValue) ? numericValue : '-' |
| | | } |
| | | |
| | | function getStatusConfig(status, statusText) { |
| | | function getAsnOrderStatusMap(t = $t) { |
| | | return { |
| | | 0: { label: t('pages.orders.asnOrder.status.pending'), tagType: 'info' }, |
| | | 1: { label: t('pages.orders.asnOrder.status.running'), tagType: 'warning' }, |
| | | 2: { label: t('pages.orders.asnOrder.status.receiving'), tagType: 'success' }, |
| | | 3: { label: t('pages.orders.asnOrder.status.taskRunning'), tagType: 'warning' }, |
| | | 4: { label: t('pages.orders.asnOrder.status.completed'), tagType: 'success' }, |
| | | 8: { label: t('pages.orders.asnOrder.status.cancelled'), tagType: 'danger' }, |
| | | 9: { label: t('pages.orders.asnOrder.status.closed'), tagType: 'info' } |
| | | } |
| | | } |
| | | |
| | | function getStatusConfig(status, statusText, t = $t) { |
| | | const numericStatus = Number(status) |
| | | const fallback = ASN_ORDER_STATUS_MAP[numericStatus] || { |
| | | const fallback = getAsnOrderStatusMap(t)[numericStatus] || { |
| | | label: statusText || '-', |
| | | tagType: 'info' |
| | | } |
| | |
| | | condition: '', |
| | | code: '', |
| | | poCode: '', |
| | | poId: '', |
| | | type: '', |
| | | wkType: '', |
| | | anfme: '', |
| | | qty: '', |
| | | logisNo: '', |
| | | arrTime: '', |
| | | memo: '', |
| | | exceStatus: '', |
| | | supplierName: '', |
| | | purchaseUserName: '' |
| | |
| | | |
| | | export function buildAsnOrderSearchParams(params = {}) { |
| | | const result = {} |
| | | ;['condition', 'code', 'poCode', 'wkType', 'supplierName', 'purchaseUserName'].forEach((key) => { |
| | | ;[ |
| | | 'condition', |
| | | 'code', |
| | | 'poCode', |
| | | 'type', |
| | | 'wkType', |
| | | 'logisNo', |
| | | 'arrTime', |
| | | 'memo', |
| | | 'supplierName', |
| | | 'purchaseUserName' |
| | | ].forEach((key) => { |
| | | const value = normalizeText(params[key]) |
| | | if (value) { |
| | | result[key] = value |
| | | } |
| | | }) |
| | | ;['poId', 'anfme', 'qty'].forEach((key) => { |
| | | const value = normalizeText(params[key]) |
| | | if (value) { |
| | | result[key] = Number(value) |
| | | } |
| | | }) |
| | | |
| | |
| | | return { |
| | | current: params.current || 1, |
| | | pageSize: params.pageSize || params.size || 20, |
| | | orderBy: params.orderBy || 'create_time desc', |
| | | ...buildAsnOrderSearchParams(params) |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | export function normalizeAsnOrderRow(record = {}) { |
| | | const statusConfig = getStatusConfig(record.exceStatus, record['exceStatus$']) |
| | | export function normalizeAsnOrderRow(record = {}, t = $t) { |
| | | const statusConfig = getStatusConfig(record.exceStatus, record['exceStatus$'], t) |
| | | const exceStatus = Number(record.exceStatus) |
| | | return { |
| | | ...record, |
| | | id: record.id ?? null, |
| | | code: record.code || '-', |
| | | poCode: record.poCode || '-', |
| | | poId: record.poId ?? '-', |
| | | wkTypeLabel: record['wkType$'] || record.wkType || '-', |
| | | orderTypeLabel: record['type$'] || record.type || '-', |
| | | exceStatusText: statusConfig.label, |
| | |
| | | updateTimeText: record['updateTime$'] || record.updateTime || '-', |
| | | createByText: record['createBy$'] || '-', |
| | | createTimeText: record['createTime$'] || record.createTime || '-', |
| | | logisNo: record.logisNo || '-', |
| | | arrTimeText: record['arrTime$'] || record.arrTime || '-', |
| | | memo: record.memo || '-', |
| | | canComplete: Number(record.exceStatus) === 1 |
| | | canEdit: exceStatus === 0 || exceStatus === 1, |
| | | canDelete: exceStatus === 0, |
| | | canComplete: exceStatus === 1 |
| | | } |
| | | } |
| | | |
| | |
| | | memo: record.memo || '-', |
| | | prodTimeText: record['prodTime$'] || record.prodTime || '-' |
| | | } |
| | | } |
| | | |
| | | let tempItemSeed = 0 |
| | | |
| | | function createTempRowKey(prefix = 'asn-item') { |
| | | tempItemSeed += 1 |
| | | return `${prefix}-${Date.now()}-${tempItemSeed}` |
| | | } |
| | | |
| | | export function createAsnOrderFormState() { |
| | | return { |
| | | id: undefined, |
| | | version: undefined, |
| | | code: '', |
| | | type: '', |
| | | wkType: '', |
| | | poCode: '', |
| | | logisNo: '', |
| | | arrTime: '', |
| | | memo: '' |
| | | } |
| | | } |
| | | |
| | | export function buildAsnOrderDialogModel(record = {}) { |
| | | return { |
| | | ...createAsnOrderFormState(), |
| | | ...record, |
| | | poCode: normalizeText(record.poCode), |
| | | logisNo: normalizeText(record.logisNo), |
| | | arrTime: normalizeDateValue(record.arrTime || record['arrTime$']), |
| | | memo: normalizeText(record.memo) |
| | | } |
| | | } |
| | | |
| | | export function createAsnOrderMaterialSearchState() { |
| | | return { |
| | | name: '', |
| | | code: '', |
| | | groupId: undefined |
| | | } |
| | | } |
| | | |
| | | export function buildAsnOrderMaterialSearchParams(params = {}) { |
| | | const result = {} |
| | | ;['name', 'code'].forEach((key) => { |
| | | const value = normalizeText(params[key]) |
| | | if (value) { |
| | | result[key] = value |
| | | } |
| | | }) |
| | | |
| | | const groupId = params.groupId |
| | | if (groupId !== undefined && groupId !== null && groupId !== '') { |
| | | result.groupId = groupId |
| | | } |
| | | |
| | | return result |
| | | } |
| | | |
| | | export function buildAsnOrderEditableItem(record = {}, fieldDefinitions = []) { |
| | | const dynamicFields = Object.fromEntries( |
| | | fieldDefinitions.map((item) => [ |
| | | item.fields, |
| | | record[item.fields] ?? record.extendFields?.[item.fields] ?? '' |
| | | ]) |
| | | ) |
| | | |
| | | return { |
| | | ...record, |
| | | ...dynamicFields, |
| | | __rowKey: record.__rowKey || (record.id ? `existing-${record.id}` : createTempRowKey()), |
| | | matnrId: record.matnrId ?? null, |
| | | matnrCode: record.matnrCode || '-', |
| | | maktx: record.maktx || record.matnrName || '-', |
| | | stockUnit: record.stockUnit || record.unit || '-', |
| | | purUnit: record.purUnit || record.stockUnit || record.unit || '-', |
| | | platItemId: record.platItemId || '', |
| | | splrBatch: record.splrBatch || '', |
| | | splrCode: record.splrCode || '', |
| | | splrName: record.splrName || record.supplierName || '', |
| | | memo: record.memo || '', |
| | | anfme: normalizeNumber(record.anfme), |
| | | qty: normalizeNumber(record.qty) |
| | | } |
| | | } |
| | | |
| | | export function createAsnOrderEditableItemFromMaterial(record = {}, fieldDefinitions = []) { |
| | | const dynamicFields = Object.fromEntries( |
| | | fieldDefinitions.map((item) => [ |
| | | item.fields, |
| | | record[item.fields] ?? record.extendFields?.[item.fields] ?? '' |
| | | ]) |
| | | ) |
| | | |
| | | return { |
| | | ...record, |
| | | ...dynamicFields, |
| | | __rowKey: createTempRowKey('asn-material'), |
| | | id: undefined, |
| | | matnrId: record.id ?? record.matnrId ?? null, |
| | | matnrCode: record.code || record.matnrCode || '', |
| | | maktx: record.name || record.maktx || '', |
| | | stockUnit: record.stockUnit || record.unit || '', |
| | | purUnit: record.purUnit || record.unit || '', |
| | | platItemId: '', |
| | | splrBatch: '', |
| | | splrCode: '', |
| | | splrName: '', |
| | | memo: '', |
| | | anfme: 0, |
| | | qty: 0 |
| | | } |
| | | } |
| | | |
| | | export function buildAsnOrderSavePayload({ |
| | | formData = {}, |
| | | itemRows = [], |
| | | fieldDefinitions = [] |
| | | } = {}) { |
| | | const orders = { |
| | | ...formData, |
| | | type: normalizeText(formData.type), |
| | | wkType: normalizeText(formData.wkType), |
| | | poCode: normalizeText(formData.poCode), |
| | | logisNo: normalizeText(formData.logisNo), |
| | | arrTime: normalizeDateTimeForApi(formData.arrTime), |
| | | memo: normalizeText(formData.memo) |
| | | } |
| | | |
| | | const items = itemRows.map((row) => { |
| | | const payload = { ...row } |
| | | delete payload.__rowKey |
| | | fieldDefinitions.forEach((item) => { |
| | | const value = row[item.fields] ?? row.extendFields?.[item.fields] |
| | | if (value !== undefined && value !== null && value !== '') { |
| | | payload[item.fields] = value |
| | | } |
| | | }) |
| | | return payload |
| | | }) |
| | | |
| | | return { |
| | | orders, |
| | | items |
| | | } |
| | | } |
| | | |
| | | export function resolveDictOptions(records = [], options = {}) { |
| | | const { group } = options |
| | | if (!Array.isArray(records)) { |
| | | return [] |
| | | } |
| | | |
| | | return records |
| | | .filter((item) => { |
| | | if (!item || typeof item !== 'object') { |
| | | return false |
| | | } |
| | | if (group === undefined) { |
| | | return true |
| | | } |
| | | return normalizeText(item.group) === normalizeText(group) |
| | | }) |
| | | .map((item) => { |
| | | const value = item.value ?? item.id ?? item.dictValue |
| | | if (value === undefined || value === null || value === '') { |
| | | return null |
| | | } |
| | | return { |
| | | value: normalizeText(value), |
| | | label: normalizeText(item.label || item.name || item.dictLabel || value) |
| | | } |
| | | }) |
| | | .filter(Boolean) |
| | | } |
| | | |
| | | export function normalizeTreeOptions(records = [], level = 0) { |
| | | if (!Array.isArray(records)) { |
| | | return [] |
| | | } |
| | | |
| | | return records |
| | | .map((item) => { |
| | | if (!item || typeof item !== 'object') { |
| | | return null |
| | | } |
| | | const children = normalizeTreeOptions(item.children || item.childrens || [], level + 1) |
| | | return { |
| | | value: item.id, |
| | | label: `${' '.repeat(level * 2)}${item.name || item.label || item.code || item.id}`, |
| | | children |
| | | } |
| | | }) |
| | | .filter(Boolean) |
| | | } |
| | | |
| | | export function normalizePurchaseRow(record = {}) { |
| | |
| | | } |
| | | } |
| | | |
| | | export function buildAsnOrderPrintRows(records = []) { |
| | | export function buildAsnOrderPrintRows(records = [], t = $t) { |
| | | if (!Array.isArray(records)) { |
| | | return [] |
| | | } |
| | | return records.map((record) => normalizeAsnOrderRow(record)) |
| | | return records.map((record) => normalizeAsnOrderRow(record, t)) |
| | | } |
| | | |
| | | export function buildAsnOrderReportMeta({ |
| | | previewMeta = {}, |
| | | count = 0, |
| | | orientation = ASN_ORDER_REPORT_STYLE.orientation |
| | | orientation = ASN_ORDER_REPORT_STYLE.orientation, |
| | | t = $t |
| | | } = {}) { |
| | | return { |
| | | reportTitle: ASN_ORDER_REPORT_TITLE, |
| | | reportTitle: getAsnOrderReportTitle(t), |
| | | reportDate: previewMeta.reportDate, |
| | | printedAt: previewMeta.printedAt, |
| | | operator: previewMeta.operator, |
| | |
| | | } |
| | | } |
| | | |
| | | export function getAsnOrderStatusOptions() { |
| | | return Object.entries(ASN_ORDER_STATUS_MAP).map(([value, item]) => ({ |
| | | export function getAsnOrderStatusOptions(t = $t) { |
| | | return Object.entries(getAsnOrderStatusMap(t)).map(([value, item]) => ({ |
| | | label: item.label, |
| | | value: Number(value) |
| | | })) |
| | | } |
| | | |
| | | export function getAsnOrderActionList(row = {}) { |
| | | export function getAsnOrderActionList(row = {}, options = {}) { |
| | | const normalizedRow = normalizeAsnOrderRow(row) |
| | | return [ |
| | | const actionList = [ |
| | | { |
| | | key: 'view', |
| | | label: '查看详情', |
| | | label: $t('pages.orders.asnOrder.actions.view'), |
| | | icon: 'ri:eye-line' |
| | | }, |
| | | { |
| | | key: 'items', |
| | | label: $t('pages.orders.asnOrder.actions.items'), |
| | | icon: 'ri:list-check-3' |
| | | }, |
| | | { |
| | | key: 'print', |
| | | label: '打印', |
| | | label: $t('pages.orders.asnOrder.actions.print'), |
| | | icon: 'ri:printer-line' |
| | | }, |
| | | { |
| | | key: 'complete', |
| | | label: '完成', |
| | | label: $t('pages.orders.asnOrder.actions.complete'), |
| | | icon: 'ri:check-line', |
| | | color: 'var(--el-color-success)', |
| | | disabled: !normalizedRow.canComplete |
| | | } |
| | | ] |
| | | |
| | | if (options.canEdit) { |
| | | actionList.splice(2, 0, { |
| | | key: 'edit', |
| | | label: $t('pages.orders.asnOrder.actions.edit'), |
| | | icon: 'ri:edit-line', |
| | | disabled: !normalizedRow.canEdit |
| | | }) |
| | | } |
| | | |
| | | if (options.canDelete) { |
| | | actionList.push({ |
| | | key: 'delete', |
| | | label: $t('pages.orders.asnOrder.actions.delete'), |
| | | icon: 'ri:delete-bin-line', |
| | | color: 'var(--el-color-danger)', |
| | | disabled: !normalizedRow.canDelete |
| | | }) |
| | | } |
| | | |
| | | return actionList |
| | | } |