import { ElMessageBox } from 'element-plus' 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 } } 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 getTaskActionList(row = {}) { return [ { key: 'view', label: '查看详情', icon: 'ri:eye-line' }, ...(row.canComplete ? [ { key: 'complete', label: '完成任务', icon: 'ri:checkbox-circle-line', auth: 'update' } ] : []), ...(canCheckTask(row) ? [ { key: 'check', label: '盘点出库', icon: 'ri:file-check-line', auth: 'update' } ] : []), ...(canPickTask(row) ? [ { key: 'pick', label: '拣料出库', icon: 'ri:paint-line', auth: 'update' } ] : []), { key: 'top', label: '任务置顶', icon: 'ri:pushpin-line', auth: 'update' }, { key: 'remove', label: '取消任务', icon: 'ri:close-circle-line', color: '#f56c6c', auth: 'delete' } ] } export async function confirmTaskAction(message) { await ElMessageBox.confirm(message, '提示', { type: 'warning', confirmButtonText: '确定', cancelButtonText: '取消' }) }