<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> 
 |