detailprintDialog.vue
4.75 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
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
165
166
167
168
<template>
<el-dialog
title="出库单铭牌打印"
:visible.sync="visible"
:showdetailprint="showdetailprint"
width="800px"
append-to-body
@close="$emit('update:showdetailprint', false)">
<div ref="print" style="padding-bottom: 30px">
<el-row>
<el-col :span="24">
<el-button size="mini"
type="info"
plain icon="el-icon-printer"
class="noprint"
@click="print()"
:class="{hide: isHide}"
style="float: right;">打印</el-button>
</el-col>
</el-row>
<el-main style="padding: 0 29%">
<el-header>长沙华恒机器人有限公司</el-header>
<el-table :data="tableData"
border
:show-header="false"
:span-method="dataSpanMethod"
size="mini"
:cell-style="tableCellStyle"
style="font-size: 13px;border: 1px solid #333">
<el-table-column prop="name1" label="第一列" width="76px"> </el-table-column>
<el-table-column prop="name2" label="第二列"> </el-table-column>
<el-table-column prop="name3" label="第三列" width="76px"></el-table-column>
</el-table>
</el-main>
<el-main style="padding: 0 29%">
<el-header>长沙华恒机器人有限公司</el-header>
<el-table :data="tableData"
border
:show-header="false"
:span-method="dataSpanMethod"
size="mini"
:cell-style="tableCellStyle"
style="font-size: 13px;border: 1px solid #333">
<el-table-column prop="name1" label="第一列" width="76px"> </el-table-column>
<el-table-column prop="name2" label="第二列"> </el-table-column>
<el-table-column prop="name3" label="第三列" width="76px"></el-table-column>
</el-table>
</el-main>
</div>
</el-dialog>
</template>
<script>
// import { importTemplate } from ''@/api/shipment/shipmentHeader'
import { listDetailprint, } from "@/api/shipment/shipmentHeader/detail";
import html2canvas from "html2canvas";
export default {
props: {
showdetailprint: {
type: Boolean,
default: false
}
},
data() {
return {
isHide:false,
tableData:[
{name1: '物料编码',name2: '10302400698',name3: '',len:1,isFirst:true},
{name1: '存货代码',name2: '-',name3: '',len:1,isFirst:true},
{name1: '存货名称',name2: '不锈钢挂钩',name3: '二维码图',len:3,isFirst:true},
{name1: '规格型号',name2: '',name3: '',len:3,},
{name1: '数 量',name2: '10',name3: '',len:3,},
{name1: ' ',name2: '',name3: '',len:1,isFirst:true},
],
visible: this.showdetailprint,
}
},
watch: {
showdetailprint() {
this.visible = this.showdetailprint
}
},
methods: {
print() {
this.isHide = true;
// 转图片打印
const timer = setTimeout(()=> {
this.isHide = false;
html2canvas(this.$refs.print, {
allowTaint: false,
taintTest: true,
useCORS: true,
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; color:#000'
},
//表格
dataSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 2) { //以0计算,第3列数据部分要合并行
console.log('row---', row);
if (row.isFirst) {
return {
rowspan: row.len,
colspan: 1
};
} else {
return {
rowspan: 0,
colspan: 0
};
}
}
}
}
}
</script>
<style lang="scss" scoped>
.el-header {
color: #000;
text-align: center;
font-size: 18px;
padding-top: 32px;
}
.el-main{
padding: 0;
font-family:'Microsoft YaHei';
}
aside{background: none;margin-bottom: 0px;}
.el-table--border, .el-table--group {
border-top: 1px solid #d7dae2;
}
.no-print {
margin-top: 15px;
}
.ad-sheet {
font-size: 22px;
}
.hide {
display: none;
}
</style>