qRcodeDialog.vue
3.91 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
169
170
171
<!-- 下载对账单 -->
<template>
<d2-dialog title="收款二维码"
:isVisible="qRcodeVisible"
class="qRcodeDailog"
width="40%"
btnOkLabel="下载二维码"
@closeDialog="handleClose"
@confirmDialog="handleAddConfirm">
<div class="codeDiv"
id="view">
<img style="width:100%;height:100%"
src="./images/code3.png">
<div class="imgDiv">
<img style="width:100%;height:100%"
:src="qrCodeURL?qrCodeURL:defaultImg">
</div>
<div class="merchantNameDiv">{{info.yqMerchantName}}</div>
</div>
</d2-dialog>
</template>
<script>
import { createWeappQrcode } from '@api/serviceManage'
import html2canvas from 'html2canvas'
export default {
name: 'qRcodeDialog',
data() {
return {
infoForm: {
merchantType: '',
merchant: [],
payStartDate: '',
payEndDate: '',
reportType: '1'
},
// 基本数据
baseData: {
merchantList: []
},
qrCodeURL: '',
defaultImg: require('./images/defaultImg.png')
}
},
props: {
qRcodeVisible: {
type: Boolean,
default: false
},
info: {
type: Object,
default: null
},
},
watch: {
},
created() {
},
components: {},
mounted() {
this.createQrcodeImage()
},
methods: {
createQrcodeImage() {
let oParams = {}
oParams.channelType = 1
oParams.appId = 'wx06d1198e751435d1'
oParams.qrcodeType = 'QR_WXA_UNLIMIT'
// oParams.path = 'packagesPayment/pages/QRPayment/QRPayment'
oParams.path = 'packagesPayment/pages/payment/index'
oParams.scene = `merchantId=${this.info.yqMerchantId}&merchantName=${this.info.yqMerchantName}`
createWeappQrcode(oParams).then(res => {
this.qrCodeURL = res
})
},
//下载保存图片
takeScreenshot() {
html2canvas(document.getElementById('view')).then(canvas => {
this.convertCanvasToImg(canvas)
});
},
//转换图片格式
convertCanvasToImg(canvas) {
// canvas base64 转 blob
var myBlob = this.dataURLtoBlob(canvas.toDataURL('img/png', 0.92))
// blob转URL对象
let myUrl = URL.createObjectURL(myBlob)
// 创建a标签,下载图片
this.downImg(myUrl)
},
//base64 转 blob
dataURLtoBlob(dataurl) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
},
//下载图片 filename是图片名称
downImg(url) {
// 创建a标签 并设置其相关属性,最后触发其点击事件
let a = document.createElement("a")
let clickEvent = document.createEvent("MouseEvents");
a.setAttribute("href", url)
a.setAttribute("download", "filename")
a.setAttribute("target", '_blank')
clickEvent.initEvent('click', true, true)
a.dispatchEvent(clickEvent);
},
handleAddConfirm() {
this.takeScreenshot()
},
handleClose() {
this.$emit('dialogClose', true)
}
}
}
</script>
<style>
.dateItem {
display: flex;
}
.dateItem .el-form-item__content {
display: flex;
margin-left: 0 !important;
}
.codeDiv {
width: 345px;
height: 468px;
margin: 0px auto;
position: relative;
/* background-image: url('./images/code3.png'); */
}
.imgDiv {
width: 150px;
height: 150px;
position: absolute;
left: 50%;
top: 42%;
transform: translate(-50%, -50%);
background-color: #d8d8d8;
}
.merchantNameDiv {
width: 150px;
height: 20px;
position: absolute;
left: 50%;
top: 63%;
transform: translate(-50%, -50%);
text-align: center;
font-size: 14px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #333333;
line-height: 17px;
}
</style>