import { h } from 'vue' import { ElTag } from 'element-plus' import ArtButtonMore from '@/components/core/forms/art-button-more/index.vue' import { getPurchaseStatusMeta } from './purchasePage.helpers' export function createPurchaseTableColumns({ handleView, handleEdit, handleDelete, canEdit = true, canDelete = true, canDeleteRow = () => true } = {}) { return [ { type: 'selection', width: 48, align: 'center' }, { type: 'globalIndex', label: '序号', width: 72, align: 'center' }, { prop: 'code', label: 'PO单号', minWidth: 160, showOverflowTooltip: true, formatter: (row) => row.code || '--' }, { prop: 'typeText', label: '单据类型', minWidth: 120, showOverflowTooltip: true, formatter: (row) => row.typeText || '--' }, { prop: 'wkTypeText', label: '业务类型', minWidth: 120, showOverflowTooltip: true, formatter: (row) => row.wkTypeText || '--' }, { prop: 'source', label: '来源单号', minWidth: 160, showOverflowTooltip: true, formatter: (row) => row.source || '--' }, { prop: 'anfme', label: '需求数量', width: 110, align: 'right', formatter: (row) => row.anfme ?? '--' }, { prop: 'qty', label: '已收数量', width: 110, align: 'right', formatter: (row) => row.qty ?? '--' }, { prop: 'workQty', label: '收货中数量', width: 120, align: 'right', formatter: (row) => row.workQty ?? '--' }, { prop: 'channel', label: '收货道口', minWidth: 120, showOverflowTooltip: true, formatter: (row) => row.channel || '--' }, { prop: 'platCode', label: 'ERP单号', minWidth: 150, showOverflowTooltip: true, formatter: (row) => row.platCode || '--' }, { prop: 'preArrText', label: '预计到达时间', minWidth: 170, showOverflowTooltip: true, formatter: (row) => row.preArrText || '--' }, { prop: 'startTimeText', label: '计划收货时间', minWidth: 170, showOverflowTooltip: true, formatter: (row) => row.startTimeText || '--' }, { prop: 'endTimeText', label: '计划结束时间', minWidth: 170, showOverflowTooltip: true, formatter: (row) => row.endTimeText || '--' }, { prop: 'project', label: '项目编码', minWidth: 130, showOverflowTooltip: true, formatter: (row) => row.project || '--' }, { prop: 'exceStatusText', label: '执行状态', minWidth: 120, showOverflowTooltip: true, formatter: (row) => row.exceStatusText || '--' }, { prop: 'status', label: '状态', width: 96, align: 'center', formatter: (row) => { const statusMeta = getPurchaseStatusMeta(row.statusBool ?? row.status) return h(ElTag, { type: statusMeta.type, effect: 'light' }, () => statusMeta.text) } }, { prop: 'updateByText', label: '更新人', minWidth: 120, showOverflowTooltip: true, formatter: (row) => row.updateByText || '--' }, { prop: 'updateTimeText', label: '更新时间', minWidth: 170, showOverflowTooltip: true, formatter: (row) => row.updateTimeText || '--' }, { prop: 'memo', label: '备注', minWidth: 180, showOverflowTooltip: true, formatter: (row) => row.memo || '--' }, { prop: 'operation', label: '操作', width: 120, align: 'center', fixed: 'right', formatter: (row) => { const operations = [{ key: 'view', label: '详情', icon: 'ri:eye-line' }] if (canEdit && handleEdit) { operations.push({ key: 'edit', label: '编辑', icon: 'ri:pencil-line' }) } if (canDelete && handleDelete && canDeleteRow(row)) { operations.push({ key: 'delete', label: '删除', icon: 'ri:delete-bin-5-line', color: 'var(--art-error)' }) } return h(ArtButtonMore, { list: operations, onClick: (item) => { if (item.key === 'view') handleView?.(row) if (item.key === 'edit') handleEdit?.(row) if (item.key === 'delete') handleDelete?.(row) } }) } } ] }