headerprintDialog.vue
4.02 KB
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
<template>
<el-dialog
title="入库单打印"
:visible.sync="visible"
:showheaderprint="showheaderprint"
width="800px"
append-to-body
@close="$emit('update:showheaderprint', false)">
<div ref="print">
<el-main>
<el-header>
<el-row :gutter="24" style="border-bottom: 1px solid #333">
<el-col :span="8" style="text-align: left;font-size: 13px">{{ parseTime(printDate) }}</el-col>
<el-col :span="8" style="font-size: 24px">入库单</el-col>
<el-col :span="8" style="text-align: right;">二维码图</el-col>
</el-row>
<el-row :gutter="24">
<el-col :span="12" style="text-align: right;font-size: 13px;">
<span>明细条数:1</span>
<span style="padding-left: 20px">明细总数:100</span>
<el-button size="mini"
type="info" plain
icon="el-icon-printer"
@click="print()"
:class="{hide: isHide}"
style="margin-left: 10px">打印</el-button>
</el-col>
</el-row>
</el-header>
<el-table :data="DetailList" border :cell-style="tableCellStyle" :header-cell-style="tableHeaderCellStyle">
<el-table-column prop="materialCode" label="物料编码"></el-table-column>
<el-table-column prop="materialName" label="物料名称"></el-table-column>
<el-table-column prop="batch" label="批次"></el-table-column>
<el-table-column prop="lot" label="批号"></el-table-column>
<el-table-column prop="projectNo" label="项目号"></el-table-column>
<el-table-column prop="shipQty" label="数量"></el-table-column>
<el-table-column prop="materialCodepic" label="条码"></el-table-column>
</el-table>
</el-main>
</div>
</el-dialog>
</template>
<script>
import html2canvas from "html2canvas";
export default {
props: {
showheaderprint: {
type: Boolean,
default: false
},
printlist: {
type: Array,
},
},
data() {
return {
// DetailList:[
// {materialCode:'10302400695',materialName:'绘图纸,A0/880MM*50M/80G',batch:'',lot:'',projectNo:'',shipQty:'100',materialCodepic:'二维码',},
// {materialCode:'10302400695',materialName:'不锈钢挂钩,A0/880MM*50M/80G',batch:'',lot:'',projectNo:'',shipQty:'100',materialCodepic:'二维码',}
// ],
printDate: new Date(),
visible: this.showheaderprint,
DetailList: this.printlist,
isHide:false,
};
},
watch: {
showheaderprint() {
this.visible = this.showheaderprint;
},
printlist() {
this.DetailList = this.printlist;
},
/* 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;
})
},
// 修改 table cell边框的背景色...
tableCellStyle () {
return 'border-color: #868686;'
},
// 修改 table header cell的背景色、边框背景色...
tableHeaderCellStyle () {
return 'border-color: #868686; color: #606266; background:#fff;font-size:14px'
},
},
};
</script>
<style>
</style>