| | |
| | | return String(value ?? '').trim() |
| | | } |
| | | |
| | | function normalizeDateValue(value) { |
| | | return value ? String(value) : '' |
| | | } |
| | | |
| | | function normalizeNumber(value) { |
| | | if (value === '' || value === null || value === undefined) { |
| | | return 0 |
| | |
| | | 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 = {}, 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: normalizeDateValue(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 getAsnOrderActionList(row = {}) { |
| | | export function getAsnOrderActionList(row = {}, options = {}) { |
| | | const normalizedRow = normalizeAsnOrderRow(row) |
| | | return [ |
| | | const actionList = [ |
| | | { |
| | | key: 'view', |
| | | label: $t('pages.orders.asnOrder.actions.view'), |
| | |
| | | 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 |
| | | } |