zhou zhou
14 小时以前 a49845f424ae5b1e43e391837a55c43ce07ea62d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { h } from 'vue'
import { ElTag } from 'element-plus'
import ArtButtonMore from '@/components/core/forms/art-button-more/index.vue'
import { getLocStatusMeta, getLocUseStatusMeta } from './locPage.helpers'
 
function createTextColumn(prop, label, minWidth, formatter) {
  return {
    prop,
    label,
    minWidth,
    showOverflowTooltip: true,
    formatter: formatter || ((row) => row[prop] || '--')
  }
}
 
function createNumberColumn(prop, label, width) {
  return {
    prop,
    label,
    width,
    align: 'center',
    formatter: (row) => row[prop] ?? '--'
  }
}
 
function createTagColumn(prop, label, width, resolveMeta) {
  return {
    prop,
    label,
    width,
    align: 'center',
    formatter: (row) => {
      const statusMeta = resolveMeta(row)
      return h(ElTag, { type: statusMeta.type, effect: 'light' }, () => statusMeta.text)
    }
  }
}
 
export function createLocTableColumns({
  handleView,
  handleEdit,
  handleDelete,
  canEdit = true,
  canDelete = true
} = {}) {
  const operations = [{ key: 'view', label: '详情', icon: 'ri:eye-line' }]
 
  if (canEdit && handleEdit) {
    operations.push({ key: 'edit', label: '编辑', icon: 'ri:pencil-line' })
  }
 
  if (canDelete && handleDelete) {
    operations.push({ key: 'delete', label: '删除', icon: 'ri:delete-bin-5-line', color: 'var(--art-error)' })
  }
 
  return [
    { type: 'selection', width: 48, align: 'center' },
    { type: 'globalIndex', label: '序号', width: 72, align: 'center' },
    createTextColumn('code', '库位号', 160),
    createTextColumn('warehouseName', '仓库', 150, (row) => row.warehouseName || row.warehouseId$ || '--'),
    createTextColumn('areaName', '库区', 150, (row) => row.areaName || row.areaId$ || '--'),
    createTextColumn('typeIdsText', '库位类型', 180),
    createNumberColumn('row', '排', 80),
    createNumberColumn('col', '列', 80),
    createNumberColumn('lev', '层', 80),
    createNumberColumn('channel', '巷道', 90),
    createTagColumn('useStatus', '使用状态', 110, (row) => getLocUseStatusMeta(row.useStatus)),
    createTextColumn('flagLogicText', '虚拟库位', 110),
    createTextColumn('flagLabelMangeText', '标签管理', 110),
    createTextColumn('barcode', '容器编码', 150),
    createTagColumn('status', '状态', 100, (row) => getLocStatusMeta(row.statusBool ?? row.status)),
    createTextColumn('updateTimeText', '更新时间', 170, (row) => row.updateTimeText || row.updateTime$ || '--'),
    createTextColumn('memo', '备注', 180),
    {
      prop: 'operation',
      label: '操作',
      width: 120,
      align: 'center',
      fixed: 'right',
      formatter: (row) =>
        h(ArtButtonMore, {
          list: operations,
          onClick: (item) => {
            if (item.key === 'view') handleView?.(row)
            if (item.key === 'edit') handleEdit?.(row)
            if (item.key === 'delete') handleDelete?.(row)
          }
        })
    }
  ]
}