liangjin
2021-03-30 13bee775e4ad2c2ea255836201c4d6a00b4888a0
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
<!--
 * @Author: 小明丶
 * @Date: 2020-11-26 16:45:20
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-12-10 09:35:07
 * @Description: 商户收款二维码页面
-->
<template>
  <div class="getShskQRCode-page">
    <van-nav-bar
      title="生成二维码"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      style="line-height: 43px"
    >
      <i
        class="iconfont iconzuojiantou"
        slot="left"
        style="font-size: 25px"
      ></i>
    </van-nav-bar>
    <div
      class="bc-box"
      :style="{ background: $store.state.defaultBgColor }"
    ></div>
    <div class="qr-box">
      <div class="border-box">
        <img :src="qrCodeBase64Url" alt="" />
      </div>
      <p>二维码失效时间为半小时</p>
      <p>请尽快提供给用户进行扫码</p>
    </div>
  </div>
</template>
<script>
import html2canvas from "html2canvas";
import QRCode from "qrcode";
 
export default {
  data() {
    return {
      qrCodeBase64Url: "",
      timeId:'',
    };
  },
  created() {
    console.log(this.$route.query.orderId)
    QRCode.toDataURL(
       this.$route.query.url,
        {
            margin: 1,
            width: 400
        },
        (err, url) => {
            if (err) console.error(err);
            this.qrCodeBase64Url = url;
            // this.search_status();
            this.timeId = setInterval(() => {
              this.search_status();
            }, 2000);
        }
    );
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    // 轮询 支付状态
    search_status() {
      this.$api.facepay_getStatus(
       this.$route.query.orderId
      ).then((res) => {
        let orderStatus = res.body.orderStatus;
        if(orderStatus !== 0){
          clearInterval(this.timeId);
          this.$router.push(
            `/shsk-payResult?orderStatus=${orderStatus}`
          );
        }
      });
    },
  },
  beforeRouteLeave(to, from, next) {
    clearInterval(this.timeId);
    next();
  },
};
</script>
<style lang="less" scoped>
.getShskQRCode-page {
  & {
    background: #f5f5f5;
    min-height: 100vh;
  }
  .bc-box {
    width: 100%;
    height: 150px;
  }
  .qr-box {
    width: 335px;
    height: 300px;
    background: #fff;
    position: absolute;
    top: 86px;
    left: 5.5%;
    box-sizing: border-box;
    padding: 29px 73px;
    .border-box {
      padding: 5px;
      border: 3px solid #dfd4ff;
      border-radius: 4px;
      margin-bottom: 22px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    p {
      text-align: center;
      font-weight: 500;
      color: #999999;
      line-height: 17px;
    }
  }
}
</style>