liangjin
2021-03-25 19f91bd79fa4ce2c50dfb5b44b0ebfc4f01baeae
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!--
 * @Author: 小明丶
 * @Date: 2020-11-26 15:12:47
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-12-16 10:01:32
 * @Description: 商户收款页面
-->
<template>
  <div class="store-shsk-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="content">
      <p class="title">收款金额</p>
      <div class="input-box">
        <span>¥</span>
        <input type="text" v-model="price" placeholder="请输入收款金额" />
      </div>
      <p class="tip">本次收款渠道手续费:{{rate}}%</p>
    </div>
    <button
      class="getQrCode"
      @click="getQrCode"
      :style="{ background: $store.state.backColor, color: '#fff' }"
    >
      生成收款二维码
    </button>
    <button
      v-if="$route.query.zfbVersion != 5"
      class="toQrCode"
      @click="toQrCode"
      :style="{
        background: '#fff',
        border: `solid 1px ${$store.state.backColor}`,
        color: $store.state.backColor,
      }"
    >
      扫描用户付款码
    </button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      rate:'0.38',
      price:'',//金额
    };
  },
  created() {
    this.getWeChatConfig();
  },
  mounted(){
    this.$api.shskProdFee({
      payMethod:this.$route.query.payMethod,
      zfbVersion:this.$route.query.zfbVersion
    }).then(res=>{
      this.rate = res.body.fee
    })
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    getQrCode(){
        if(!this.price){
          this.$tool.toast('交易金额不能为空');
          return
        }
        this.$api.facepay_create({
          payAmt:this.price,
          term:0,
          payType: 1,//反扫
          zfbVersion:this.$route.query.zfbVersion,
          payMethod:this.$route.query.payMethod
        }).then(res=>{
            let url = res.body.payQrCodeUrl;
            let id = res.body.orderId;
            this.$router.push({
              path:'/getShskQRCode',
              query:{
                url:res.body.payQrCodeUrl,
                orderId:res.body.orderId
              }
            })
        })
    },
    toQrCode() {
      let that = this
      if(!this.price){
        this.$tool.toast('交易金额不能为空');
        return
      }
      this.checkIsReady().then(() => {
        wx.scanQRCode({
          needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
          scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
          success: function (res) {
            // 当needResult 为 1 时,扫码返回的结果
            // 扫码成功后调用接口
            console.log(res)
            that.$api.facepay_create({
              payAmt:that.price,
              term:0,
              payType: 2,//正扫
              zfbVersion:that.$route.query.zfbVersion,
              payMethod:that.$route.query.payMethod,
              authCode: res.resultStr,
            }).then(res=>{
                let id = res.body.orderId;
                that.$router.push({
                  path:'/shsk-payResult',
                  query:{
                    orderId:id,
                    needSearch:1
                  }
                })
            })
          },
        });
      });
    },
    // 异步准备微信环境
    checkIsReady() {
      return new Promise((resolve, reject) => {
        wx.ready(() => resolve());
        wx.error(err => reject(console.log(res + "wx.error")));
      });
    },
    // 获取微信配置
    getWeChatConfig() {
      let url = location.href.split("#")[0];
      // let url = 'http://t.finlean.com/'
      this.$api
        .getTokenInfo({
          url: url,
        })
        .then((res) => {
          // 获取微信配置
          wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印
            appId: res.body.appId, // 必填,公众号的唯一标识
            timestamp: res.body.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.body.nonceStr, // 必填,生成签名的随机串
            signature: res.body.signature, // 必填,签名
            jsApiList: ["checkJsApi", "scanQRCode"], // 必填,需要使用的JS接口列表
            openTagList: [], // 可选,需要使用的开放标签列表,例如['wx-open-launch-app']
          });
        });
    },
  },
};
</script>
<style lang="less" scoped>
.store-shsk-page {
  & {
    min-height: 100vh;
    background: #f5f5f5;
    text-align: center;
  }
  .content {
    & {
      text-align: left;
      background: #fff;
      width: 359px;
      // height: 154px;
      margin: auto;
      margin-top: 10px;
      box-sizing: border-box;
      padding: 32px 12px;
    }
    .title {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #333333;
    }
    .input-box {
      border-bottom: 1px solid #e6e6e6;
      padding: 24px 0 7px 0;
      span {
        font-size: 20px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #333333;
      }
      input {
        border: 0;
        outline: none;
        height: 30px;
        font-size: 20px;
      }
      input::placeholder {
        font-size: 20px;
      }
    }
    .tip {
      font-size: 12px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      margin-top: 16px;
    }
  }
  .getQrCode {
    width: 320px;
    height: 44px;
    outline: none;
    border-radius: 22px;
    border: 0;
    margin-top: 42px;
  }
  .toQrCode {
    width: 320px;
    height: 44px;
    outline: none;
    border-radius: 22px;
    margin-top: 16px;
  }
}
</style>