Blame view

src/views/task/taskHeader/100/dialog/printDialog.vue 2.57 KB
yuanshuhui authored
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
<template>
  <el-dialog
    title="任务打印"
    :visible.sync="visible"
    :showprint="showprint"
    width="800px"
    append-to-body
    @close="$emit('update:showprint', false)"
  >
    <div ref="print">
      <el-row type="flex" class="row-bg" justify="space-between">
        <el-col :span="11"
          ><div class="date">{{ parseTime(printDate) }}</div></el-col
        >
        <el-col :span="13"><div class="ad-sheet">拣货明细</div></el-col>
      </el-row>
      <el-row :class="{hide: isHide}">
        <el-button
          size="mini"
          type="primary"
          icon="el-icon-printer"
          @click="print"
          class="pull-right"
          >打印</el-button
        >
      </el-row>

      <el-divider></el-divider>
      <el-table :data="detailList">
        <el-table-column label="库位" align="center" prop="companyCode" />
        <el-table-column label="容器" align="center" prop="locationCode" />
        <el-table-column label="物料编码" align="center" prop="materialCode" />
        <el-table-column label="物料名称" align="center" prop="materialName" />
        <el-table-column label="数量" align="center" prop="qty" />
        <el-table-column label="条码" align="center" prop="materialUnit" />
      </el-table>
    </div>
  </el-dialog>
</template>

<script>
import html2canvas from "html2canvas";
export default {
  props: {
    showprint: {
      type: Boolean,
      default: false,
    },
    printlist: {
      type: Array,
    },
  },
  data() {
    return {
      printDate: new Date(),
      visible: this.showprint,
      detailList: this.printlist,
      isHide:false,
    };
  },
  watch: {
    showprint() {
      this.visible = this.showprint;
    },
    printlist() {
      this.detailList = this.printlist;
    },
  },
  methods: {
    print() {
      this.isHide = true;
      // 转图片打印
      const timer = setTimeout(()=> {
        this.isHide = false;
        html2canvas(this.$refs.print, {
        allowTaint: false,
        taintTest: true,
        useCORS: true,
        scale: 1.5,
        windowHeight: document.body.scrollHeight,
        background: "#fff",
      }).then((canvas) => {
        const url = canvas.toDataURL("image/jpeg", 1.0);
        const myimg = document.createElement("img");
        myimg.src = url;
        this.$print(myimg);
      });
      })
      this.$once('hook:beforeDestroy',()=>{
        clearInterval(timer);
        timer = null;
      })

    },
  },
};
</script>

<style lang="scss" scoped>
.no-print {
  margin-top: 15px;
}
.ad-sheet {
  font-size: 22px;
}
.hide {
  display: none;
}
</style>