liangjin
2021-04-01 a734e1028dbc6e91a12ee03b1eeba27cdc94cd26
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
<!--
 * @Date: 2019-08-30 14:37:51
 * @LastEditors: 小明丶
 * @LastEditTime: 2019-09-02 11:07:46
 * @Description: 
 -->
<template>
    <div class="contract-qrcode-page h-100-g">
        <x-header title="扫码办理" :left-options="{backText:''}"></x-header>
        <div class="order-info">
            <div v-if="qrCodeBase64Url" class='canvasImg'>
                <img :src="qrCodeBase64Url" alt="qrcode">
            </div>
            <div id="QRCode" v-else class='qr-code'>
                <div class='qeimg'>
                    <img :src="dataUrl" alt="">
                </div>
            </div>
            <p class="notice">请向用户展示二维码,扫码后开始办理分期。</p>
        </div>
    </div>
</template>
<script>
    import html2canvas from 'html2canvas';
    import QRCode from 'qrcode';
 
    export default {
        name: 'contract-qrcode',
        data() {
            return {
                dataUrl: '',
                qrCodeBase64Url: '',
                params: ''
            }
        },
        created(){
            this.params = {
                ...this.$route.query
            };
            QRCode.toDataURL(
                JSON.stringify(this.params), {
                    margin: 0,
                    width: 400
                },
                (err, url) => {
                    if (err) console.error(err);
                    this.dataUrl = url;
                    setTimeout(() => {
                        html2canvas(document.getElementById('QRCode')).then(
                            canvas => {
                                this.qrCodeBase64Url = canvas.toDataURL(
                                    'image/jpeg'
                                );
                            }
                        );
                    }, 100);
                }
            );
        }
    }
 
</script>
<style lang="less" scoped>
    .contract-qrcode-page {
        background-color: #f1f1f1;
        padding-top: 54px;
        .order-info {
            padding-top: 46px;
 
            .canvasImg {
                margin: 0 auto;
                width: 220px;
                height: 220px;
 
                img {
                    width: 100%;
                }
            }
 
            .notice {
                padding-top: 40px;
                text-align: center;
                color: #666;
            }
 
            .qr-code {
                background: #fff;
                width: 220px;
                height: 220px;
                margin: 0 auto;
                display: flex;
                justify-content: center;
                align-items: center;
                flex-direction: column;
                border: 4px solid @color-text-three;
                color: @color-text-three;
 
                .qeimg {
                    width: 200px;
                    height: 200px;
                    padding: 5px;
 
                    img {
                        width: 100%;
                        height: 100%;
                    }
                }
            }
 
        }
    }
 
</style>