import { h } from 'vue' import { ElTag } from 'element-plus' import { $t } from '@/locales' import ArtButtonMore from '@/components/core/forms/art-button-more/index.vue' import { getWhMatDynamicFieldKey } from './whMatPage.helpers' export function createWhMatTableColumns({ handleViewDetail, handleEdit, handleDelete, handlePrint, enabledFields = [], canEdit = true, canDelete = true, t = $t } = {}) { const operations = [{ key: 'view', label: t('common.actions.detail'), icon: 'ri:eye-line' }] if (canEdit && handleEdit) { operations.push({ key: 'edit', label: t('common.actions.edit'), icon: 'ri:pencil-line' }) } if (handlePrint) { operations.push({ key: 'print', label: t('common.actions.print'), icon: 'ri:printer-line' }) } if (canDelete && handleDelete) { operations.push({ key: 'delete', label: t('common.actions.delete'), icon: 'ri:delete-bin-5-line', color: 'var(--art-error)' }) } const dynamicColumns = Array.isArray(enabledFields) ? enabledFields.map((field) => ({ prop: getWhMatDynamicFieldKey(field.fields), label: field.fieldsAlise, minWidth: 140, showOverflowTooltip: true, formatter: (row) => row[getWhMatDynamicFieldKey(field.fields)] || '--' })) : [] return [ { type: 'selection', width: 48, align: 'center' }, { type: 'globalIndex', label: t('table.index'), width: 72, align: 'center' }, { prop: 'id', label: t('table.id'), width: 90, align: 'center', formatter: (row) => row.id ?? '--' }, { prop: 'code', label: t('pages.basicInfo.whMat.table.code'), minWidth: 150, showOverflowTooltip: true }, { prop: 'name', label: t('pages.basicInfo.whMat.table.name'), minWidth: 220, showOverflowTooltip: true }, { prop: 'groupName', label: t('pages.basicInfo.whMat.table.groupName'), minWidth: 180, showOverflowTooltip: true }, { prop: 'barcode', label: t('pages.basicInfo.whMat.table.barcode'), minWidth: 160, showOverflowTooltip: true }, { prop: 'spec', label: t('pages.basicInfo.whMat.table.spec'), minWidth: 160, showOverflowTooltip: true }, { prop: 'model', label: t('pages.basicInfo.whMat.table.model'), minWidth: 160, showOverflowTooltip: true }, ...dynamicColumns, { prop: 'unit', label: t('table.unit'), width: 100 }, { prop: 'status', label: t('table.status'), width: 100, align: 'center', formatter: (row) => h( ElTag, { type: row.statusType || 'info', effect: 'light' }, () => row.statusText || t('common.placeholder.empty') ) }, { prop: 'updateByText', label: t('table.updateBy'), minWidth: 120, showOverflowTooltip: true }, { prop: 'updateTimeText', label: t('table.updateTime'), minWidth: 180, showOverflowTooltip: true }, { prop: 'createByText', label: t('table.createBy'), minWidth: 120, showOverflowTooltip: true }, { prop: 'createTimeText', label: t('table.createTime'), minWidth: 180, showOverflowTooltip: true }, { prop: 'memo', label: t('table.memo'), minWidth: 160, showOverflowTooltip: true }, { prop: 'operation', label: t('table.operation'), width: 120, align: 'center', fixed: 'right', formatter: (row) => h( 'div', { class: 'flex justify-center' }, h(ArtButtonMore, { list: operations, onClick: (item) => { if (item.key === 'view') handleViewDetail?.(row) if (item.key === 'edit') handleEdit?.(row) if (item.key === 'print') handlePrint?.(row) if (item.key === 'delete') handleDelete?.(row) } }) ) } ] }