jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
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
<template>
  <GlobalWindow
    :title="title"
    width="527px"
    :visible.sync="visible"
  >
    <div v-show="needSelect">
 
      <div class="print-title">选择打印样式:</div>
      <div style="margin: 5px 0 20px 0; display: flex;">
        <div :class="type==0 ? 'btn-select' : 'btn-normal'" @click="type=0">
          <div class="btn">横版样式</div>
        </div>
        <div style="width:10px"></div>
        <div :class="type==1 ? 'btn-select' : 'btn-normal'" @click="type=1">
          <div class="btn">竖版样式</div>
        </div>
      </div>
    </div>
    <div class="print-title">打印样式预览:</div>
    <div class="tip">当前标签尺寸为{{ type==0 ? '70mm x 35mm,' : '30mm x 30mm,编码最大支持8个字符,' }}打印时请根据需要自行缩放</div>
    <div v-if="type==0" id="qr1" style="width:100%;">
      <div
        v-for="(item, index) in qrList" 
        :key="index" 
      >
        <div style="margin: 0 2mm 0; height: 35mm; width: 74mm;border: 1px solid #000;display: flex;">
          <div style="height: 35mm;width: 35mm;">
            <vue-qr style="margin:4.5mm 3.87mm" :text="qrStr(item.code)" :size="98" :margin="0"/>
          </div>
          <div
            style="margin: 4.5mm 0;display: flex;flex-direction: column;justify-content: space-between; flex: 1"
          >
            <div style="font-size: 12px;font-weight: Bold;color: #010101;">{{ item.department }}</div>
            <div style="font-size: 14px;color: #010101;">{{item.title}}</div>
            <div style="font-size: 14px;color: #010101;">{{ item.code }}</div>
            <div style="font-size: 10px;color: #010101;">{{ item.content }}</div>
          </div>
        </div>
        <div v-if="index != qrList.length-1" style="height: 6mm;background-color: #fff;"></div>
      </div>
    </div>
    <div v-else id="qr2" style="width: 100%; display:flex; flex-flow: wrap;justify-content: space-between;">
        <div v-for="(item, index) in qrList" :key="index" style="height: 30mm;width: 30mm;border: 1px solid #ccc;" :style="index<4?'margin: 0;':'margin: 1.2mm 0 0; padding: 1mm 0mm'">
        <!-- <div v-for="(item, index) in qrList" :key="index" style="height: 32mm;width: 30mm;border: 1px solid #ccc;" :style="index<4?'margin: 0;':'margin: 16.5mm 0 0; padding: 1mm 0mm'"> -->
          <div style="height: 22mm;width: 22mm; margin: 1.5mm 2mm 0mm;" >
            <vue-qr style="margin: 2mm 4mm 0mm 3mm;" :text="qrStr(item.code)" :size="70" :margin="0"/>
          </div>
          <div style="text-align: center; font-size: 14px; height:4mm; font-weight: 700; line-height:5mm ">{{ item.code }}</div>
          <!-- <div style="text-align: center; font-size: 12px; height:5mm; line-height:5mm ">XS123458</div> -->
        </div>
    </div>
    <div slot="footer" class="window__header">
      <el-button type="primary" @click="cancel" plain>返回</el-button>
      <el-button type="primary" @click="submit">去打印</el-button>
    </div>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import VueQr from 'vue-qr'
import printJS from 'print-js'
export default {
  name: 'QrCodeLabel',
  extends: BaseOpera,
  components: { GlobalWindow, VueQr },
  data () {
    return {
      // 表单数据
      type: 0, // 0 横版 1、竖版
      qrList: [],
      prefix: '',
      needSelect: false,
      userInfo: {}
    }
  },
  created () {
    this.config({
      api: '/ext/materialExt',
      'field.id': 'id'
    })
    this.userInfo = this.$store.state.userInfo
  },
  methods: {
    open (title, qrList, prefix, needSelect=false) {
      this.type = 0
      this.title = title
      this.qrList = qrList
      this.prefix = prefix
      this.needSelect = needSelect
      this.visible = true
    },
    qrStr (code) {
      return this.prefix + code
    },
    cancel () {
      this.visible = false
    },
    submit () {
      
      printJS(
        {
          printable: this.type === 0 ? "qr1" : 'qr2',
          type:'html',
          header:null,
          targetStyles:['*'],
          style:"@page {margin: 6mm}",
          onPrintDialogClose: () => {
            this.visible = false
          }
        }
      )
      
    }
  }
}
</script>
 
<style lang="scss" scoped>
.print-title {
  width: 100px;
  text-align: right;
  height: 14px;
  line-height: 14px;
  font-size: 14px;
  font-weight: 500;
  color: #222222;
  padding: 10px 0;
  
}
.tip {
  color: #999;
  font-size: 12px;
}
.btn {
  margin: 0 16px;
  height: 38px;
  line-height: 38px;
  font-size: 14px;
  border-radius: 2px;
  cursor: pointer;
}
.btn-select {
  border-radius: 2px;
  background-color: #305ED5;
  color: #fff;
}
.btn-normal {
  border-radius: 2px;
  background-color: #F4F5FA;
  color: #305ED5;
}
 
.ss {
  font-size: 16px;
  font-weight: Bold;
  color: #010101;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
</style>