1.0
zss
2023-11-15 a96e9c262ebadc2e7e731b28aa5035b0dd2a7aad
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
<template>
  <div class="previewWrap">
    <div class="flex" v-for="(x, i) in previewInfo" :key="i">
      <div class="l">{{ x.caption }}</div>
      <div class="r">
        <template v-if="x.caption === '二维码'">
          <vue-qrcode
            :value="x.defaultValue"
            :options="{ height: 150, width: 150 }"
          />
        </template>
        <template v-else-if="x.caption === '条形码'">
          <VueBarcode :value="x.defaultValue" />
        </template>
        <template v-else>
          {{ x.defaultValue }}
        </template>
      </div>
    </div>
  </div>
</template>
<script>
import { getObj } from '@/api/print/print'
import { getObj as getObjFromLog } from '@/api/print/log'
import VueQrcode from '@chenfengyuan/vue-qrcode'
import VueBarcode from 'vue-barcode'
export default {
  props: {
    rowInfo: {
      type: Object,
      default: () => {}
    },
    isLog: {
      type: Boolean,
      default: false
    }
  },
  components: {
    VueQrcode,
    VueBarcode
  },
  data() {
    return {
      previewInfo: []
    }
  },
  created() {},
  watch: {
    rowInfo(newVal) {
      if (newVal.id) {
        this.getPreviewInfo(newVal)
      }
    }
  },
  methods: {
    f(name, previewInfo) {
      const theOne = previewInfo.find((e) => {
        return e.caption === name
      })
      return theOne ? theOne.defaultValue : null
    },
    getPreviewInfo(val) {
      ;(this.isLog ? getObjFromLog : getObj)(val.id).then((res) => {
        this.previewInfo = JSON.parse(
          res.data.data.labelInfo
        ).qualityLabelPrintConfigDetail
        const lengthOne = this.previewInfo.find((e) => e.caption === '长度')
        if (lengthOne) {
          lengthOne.defaultValue = Number(lengthOne.defaultValue) * 1000 + 'm'
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
>>> .vue-barcode-element {
  width: 220px;
  height: 110px;
  margin-left: -15px;
}
>>> canvas {
  margin: -10px;
}
.flex {
  display: flex;
}
.previewWrap {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 10px 20px;
  min-height: 300px;
  > .flex {
    padding: 5px 0;
    .l {
      width: 90px;
    }
    .r {
      width: calc(100% - 90px);
    }
  }
}
</style>