222
schangxiang@126.com
2025-04-30 9bec4dcae002f36aa23231da11cb03a156b40110
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import Dialog from '@/components/BaseDialog/index.vue'
const BaseDialog: any = Dialog
import { defineComponent, nextTick, ref, SetupContext } from 'vue'
import styles from './PrintDialog.module.scss'
import { useRelationMaterial } from '@/hooks//Dialog'
import BaseTable from '@/components/Table/Table'
import Search from '@/components/Search/Search'
import { _t } from '@/libs/Language/Language'
import { useGlobalState } from '@/libs/Store/Store'
import { useVModel } from '@vueuse/core'
 
export default defineComponent({
  name: '打印机设置',
  props: {
    modelValue: {
      type: String,
      default: '',
    },
    visible: {
      type: Boolean,
      default: null,
    },
    title: {
      type: String,
      default: '',
    },
    // 表格数据
    dataSource: {
      type: Array,
      default: () => [],
    },
    // 当前起始坐标
    index: {
      type: Number,
      default: 0,
    },
    type: {
      type: String,
      default: 'input',
    },
    readonly: {
      type: [Boolean, Object],
    },
  },
  emits: ['update:modelValue', 'update:dataSource', 'close', 'confirm'],
  setup(props: any, ctx: SetupContext) {
    const { visible, search, tableRef, onClose, onSelect } =
      useRelationMaterial(props, ctx)
    const selection = ref([])
    const { systemConfig } = useGlobalState()
    const data = ref([])
    const modelValue = useVModel(props, 'modelValue', ctx.emit)
 
    const onOpen = () => {
      selection.value = []
      const values: string[] = props.modelValue?.split?.(',') || []
      data.value = systemConfig.state.value.PrintAgentConfig || []
 
      data.value.forEach((item) => {
        if (values.includes(`${item.printerName}_${item.printAgentIP}`)) {
          selection.value.push(item)
        }
      })
      const keys = selection.value.map((row) => row.id)
      nextTick(() => tableRef.value?.setSelectRow(keys))
    }
    const onCheck = (rows) => {
      selection.value = rows
    }
    const onConfirm = () => {
      const rows = []
      selection.value.forEach((item) => {
        rows.push(`${item.printerName}_${item.printAgentIP}`)
      })
      visible.value = false
      ctx.emit('update:modelValue', rows.join(','))
      data.value = []
      tableRef.value?.clearAll()
    }
    const onEnter = () => {
      const PrintAgentConfig = systemConfig.state.value.PrintAgentConfig || []
      data.value = PrintAgentConfig.filter((item) =>
        item.printerName.includes(search.value)
      )
      nextTick(() => tableRef.value?.setSelectRowByObj(selection.value))
    }
    const Input = () => {
      const readonly =
        typeof props.readonly?.value === 'boolean'
          ? (props.readonly?.value as boolean)
          : (props.readonly as boolean)
      return (
        <el-input
          v-model={modelValue.value}
          clearable={false}
          class={styles.selectVariable}
          placeholder={_t('请选择')}
          readonly={readonly}
          suffix-icon={
            <el-button
              link
              type="primary"
              size="small"
              style="margin-right: 10px;"
              onClick={onSelect}
            >
              {_t('选择')}
            </el-button>
          }
        ></el-input>
      )
    }
    return () => {
      return (
        <div class={styles.relationDialog}>
          <Input />
          <BaseDialog
            width="600px"
            height="400px"
            v-model={visible.value}
            title={_t('打印机选择')}
            onClose={onClose}
            onConfirm={onConfirm}
            onOpen={onOpen}
            destroy-on-close
            append-to-body
          >
            <div class={styles.header}>
              <label class={styles.key}>{_t('查询')}</label>
              <Search
                v-model={search.value}
                field="filter"
                onConfirm={onEnter}
                placeholder={_t('请输入打印机名称')}
              />
            </div>
            <div class={styles.table}>
              <BaseTable
                ref={tableRef}
                columns={[
                  {
                    title: _t('序号'),
                    field: 'seq',
                    type: 'seq',
                  },
                  {
                    title: _t('打印机'),
                    field: 'printerName',
                  },
                  {
                    title: _t('IP'),
                    field: 'printAgentIP',
                  },
                ]}
                size="mini"
                v-model:dataSource={data.value}
                isVScroll
                isSeq={true}
                isChecked={true}
                onCheck={onCheck}
                id="id"
                isHidePagination
                isStop={true}
              />
            </div>
          </BaseDialog>
        </div>
      )
    }
  },
})