import { ElMessageBox } from 'element-plus' import { $t } from '@/locales' function normalizeText(value) { return String(value ?? '').trim() } function normalizeNumber(value) { if (value === '' || value === null || value === undefined) { return 0 } const numericValue = Number(value) return Number.isFinite(numericValue) ? numericValue : 0 } export function createTaskSearchState() { return { condition: '', taskCode: '', orgLoc: '', targLoc: '', barcode: '' } } export function buildTaskPageQueryParams(params = {}) { const result = { current: params.current || 1, pageSize: params.pageSize || params.size || 20 } ;['condition', 'taskCode', 'orgLoc', 'targLoc', 'barcode'].forEach((key) => { const value = normalizeText(params[key]) if (value) { result[key] = value } }) return result } export function normalizeTaskRow(record = {}) { return { ...record, taskCode: record.taskCode || '-', taskStatusLabel: record['taskStatus$'] || '-', taskTypeLabel: record['taskType$'] || '-', warehTypeLabel: record['warehType$'] || '-', orgLoc: record.orgLoc || '-', orgSiteLabel: record['orgSite$'] || record.orgSite || '-', targLoc: record.targLoc || '-', targSiteLabel: record['targSite$'] || record.targSite || '-', barcode: record.barcode || '-', robotCode: record.robotCode || '-', sort: normalizeNumber(record.sort), statusText: record['status$'] || '-', updateTimeText: record['updateTime$'] || record.updateTime || '-', createTimeText: record['createTime$'] || record.createTime || '-', canComplete: record.canComplete === true, canCancel: record.canCancel === true } } export function normalizeTaskItemRow(record = {}) { return { ...record, orderTypeLabel: record['orderType$'] || '-', wkTypeLabel: record['wkType$'] || '-', platWorkCode: record.platWorkCode || '-', platItemId: record.platItemId || '-', matnrCode: record.matnrCode || '-', maktx: record.maktx || '-', batch: record.batch || '-', unit: record.unit || '-', anfme: normalizeNumber(record.anfme), updateByText: record['updateBy$'] || '-', updateTimeText: record['updateTime$'] || record.updateTime || '-' } } export function canCheckTask(row = {}) { return Number(row.taskStatus) === 199 && Number(row.taskType) === 107 } export function canPickTask(row = {}) { return Number(row.taskStatus) === 199 && Number(row.taskType) === 103 } export function canTopTask(row = {}) { const taskStatus = Number(row.taskStatus) const taskType = Number(row.taskType) const allowedStatuses = [1, 101] const allowedTypes = [1, 101, 10, 103, 11] return allowedStatuses.includes(taskStatus) && allowedTypes.includes(taskType) } export function getTaskActionList(row = {}) { return [ { key: 'view', label: $t('pages.task.actions.view'), icon: 'ri:eye-line' }, { key: 'flowStep', label: $t('pages.task.actions.flowStep'), icon: 'ri:node-tree' }, ...(row.canComplete ? [ { key: 'complete', label: $t('pages.task.actions.complete'), icon: 'ri:checkbox-circle-line', auth: 'update' } ] : []), ...(canCheckTask(row) ? [ { key: 'check', label: $t('pages.task.actions.check'), icon: 'ri:file-check-line', auth: 'update' } ] : []), ...(canPickTask(row) ? [ { key: 'pick', label: $t('pages.task.actions.pick'), icon: 'ri:paint-line', auth: 'update' } ] : []), ...(canTopTask(row) ? [ { key: 'top', label: $t('pages.task.actions.top'), icon: 'ri:pushpin-line', auth: 'update' } ] : []), ...(row.canCancel ? [ { key: 'remove', label: $t('pages.task.actions.remove'), icon: 'ri:close-circle-line', color: '#f56c6c', auth: 'delete' } ] : []) ] } export async function confirmTaskAction(message) { await ElMessageBox.confirm(message, $t('crud.confirm.deleteTitle'), { type: 'warning', confirmButtonText: $t('common.confirm'), cancelButtonText: $t('common.cancel') }) }