schangxiang@126.com
2025-05-20 cd8356ffd97d25981287d7e075cef498f7e6da58
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { defineComponent, ref, computed } from 'vue'
import BaseTable from '@/components/Table/Table'
import {
  BarcodeAnalysisColumns,
  BarcodeAnalysisType,
  BarcodeAnalysisRow,
  BarcodeAnalysisCurrent,
} from '@/widgets/BarcodeManagement/state'
import dayjs from 'dayjs'
import Search from '@/components/Search/Search'
import { ElMessage, ElTooltip } from 'element-plus'
import { _t } from '@/libs/Language/Language'
import BaseDialog from '../BaseDialog/BaseDialog'
import { useVModel } from '@vueuse/core'
import styles from './BarcodeAnalysisDialog.module.scss'
 
export default defineComponent({
  name: 'BarcodeAnalysis',
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    selections: {
      type: Array,
      default: () => [],
    },
    radio: {
      type: Boolean,
      default: false,
    },
  },
  emits: ['confirm'],
  setup(props, { emit }) {
    const tableRef = ref()
    const visible = useVModel(props, 'visible', emit)
    const dataSource = ref<BarcodeAnalysisRow[]>([])
    const searchInner = ref('')
    const checkedList = ref<BarcodeAnalysisRow[]>([])
 
    const onSearch = () => {
      tableRef.value?.getList()
      tableRef.value?.clearSelectEvent()
    }
 
    const onCheck = (records: BarcodeAnalysisRow[]) => {
      checkedList.value = records
    }
 
    const onConfirm = () => {
      if (checkedList.value.length === 0) {
        ElMessage.warning(_t('请选择解析规则'))
        return
      }
      if (checkedList.value.length > 1) {
        ElMessage.warning(_t('请选择一条解析规则'))
        return
      }
      console.log(checkedList.value[0], 'checkedList.value[0]')
      emit('confirm', checkedList.value[0])
      visible.value = false
    }
 
    const onClose = () => {
      visible.value = false
      console.log('onClose')
    }
    return () =>
      visible.value ? (
        <BaseDialog
          title={_t('条码解析规则')}
          v-model={visible.value}
          width="1200"
          height="800"
          onClose={onClose}
          onConfirm={onConfirm}
        >
          <div class={styles.barContent}>
            <div class={styles.barHeader}>
              <Search
                class={styles.search}
                onConfirm={onSearch}
                placeholder={_t('请输入解析规则名称')}
                v-model={searchInner.value}
              />
            </div>
            <div class={styles.tableContent}>
              <BaseTable
                ref={tableRef}
                url="/api/v1/barcodemanagement/barcodeanalysis"
                params={{ Filter: searchInner.value }}
                v-model:dataSource={dataSource.value}
                selections={props.selections}
                columns={BarcodeAnalysisColumns.value}
                isChecked={true}
                isFooter={false}
                radio={props.radio}
                onCheck={onCheck}
                v-slots={{
                  type: ({ row }) => BarcodeAnalysisType[row.type],
                  barcodeSegmentComposition: ({ row }) => (
                    <ElTooltip
                      effect="dark"
                      content={row.barcodeAnalysisDetails
                        .map((e: any) => e.name)
                        .join('/')}
                      placement="top"
                    >
                      {row.barcodeAnalysisDetails
                        .map((e: any) => e.name)
                        .join('/')}
                    </ElTooltip>
                  ),
                  ruleByType: ({ row }) => {
                    switch (row.type) {
                      case 0:
                        return row.symbol
                      case 1:
                        return row.startSymbol + row.endSymbol
                      case 2:
                        return row.fixedLength
                      default:
                        return '-'
                    }
                  },
                  isUsed: ({ row }) =>
                    row.isUsed ? _t('使用中') : _t('未使用'),
                  lastModificationTime: ({ row }) =>
                    row.lastModificationTime
                      ? dayjs(row.lastModificationTime).format(
                          'YYYY-MM-DD HH:mm:ss'
                        )
                      : '-',
                }}
              />
            </div>
          </div>
        </BaseDialog>
      ) : null
  },
})