zhouhao
2021-11-04 43f8bdca58733c2cf9be0653fa25e2c801645567
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
<template>
    <!-- 商户收款:扫描二维码页面 -->
    <div class="contract-qrcode-page">
        <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>
        </div>
    </div>
</template>
<script>
    import html2canvas from 'html2canvas';
    import QRCode from 'qrcode';
 
    export default {
        name: 'facepay_code',
        data() {
            return {
                dataUrl: '',
                qrCodeBase64Url: '',
                params: '',
                timeId: null
            }
        },
        computed: {
            orderId() {
                let id = this.$route.query.id;
                return id;
            }
        },
        beforeRouteLeave(to, from, next) {
            clearInterval(this.timeId);
            next()
        },
        methods: {
            // 轮询 支付状态
            search_status() {
                this.$api.facepay_getStatus(this.orderId).then(res => {
                    let orderStatus = res.body.orderStatus;
                    if (orderStatus !== 0) {
                        if (orderStatus === 1) {
                            // 成功
                            this.$router.replace(
                                `/facepay/details?orderStatus=1&page=facepay_code&orderId=${this.orderId}`)
                        } else if (orderStatus === 2) {
                            // 失败
                            this.$router.replace(
                                `/facepay/details?orderStatus=2&page=facepay_code&orderId=${this.orderId}`)
                        }
                    }
                })
            }
        },
        created() {
            QRCode.toDataURL(this.$route.query.url, {
                    margin: 0,
                    width: 400
                },
                (err, url) => {
                    this.dataUrl = url;
                    setTimeout(() => {
                        html2canvas(document.getElementById('QRCode')).then(
                            canvas => {
                                this.qrCodeBase64Url = canvas.toDataURL(
                                    'image/jpeg'
                                );
                                this.timeId = setInterval(() => {
                                    this.search_status();
                                }, 2000);
                            }
                        );
                    }, 100);
                }
            );
        }
    }
 
</script>
<style lang="less" scoped>
 
 
 
    .contract-qrcode-page {
        .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>