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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
<!--
 * @Author: 小明丶
 * @Date: 2019-09-24 18:22:58
 * @LastEditors: 小明丶
 * @LastEditTime: 2019-09-27 15:10:45
 * @Description:
 -->
<template>
  <div class="hb-merchant-installment">
    <van-nav-bar title="办理分期" left-arrow @click-left="onClickLeft" />
    <div class="money-box">
      <div class="item-box">
        <p class="tit">商家到账金额</p>
        <p v-if="this.capitalAmt == ''" class="money">0.00</p>
        <p v-else class="money">{{this.capitalAmt}}</p>
      </div>
      <div class="item-box">
        <p class="tit">客户总还款金额</p>
        <p v-if="this.totalAmount == ''" class="money">0.00</p>
        <p v-else class="money">{{this.totalAmount}}</p>
      </div>
      <div class="item-box">
        <p class="tit">客户月还款金额</p>
        <p v-if="this.monthMoney == ''" class="money">0.00</p>
        <p v-else class="money">{{this.monthMoney}}</p>
      </div>
    </div>
    <van-field
      class="ipt"
      v-model="howMouch"
      type="number"
      label="商品金额"
      placeholder="请输入"
      input-align="right"
      border="true"
      @input="changeMoney"
      :maxlength="5"
      required
    />
    <van-field
      class="fenqi"
      readonly
      clickable
      label="分期期数"
      :value="value"
      placeholder="请选择"
      @click="showPicker = true"
      input-align="right"
      border="true"
      required
    />
 
    <van-popup v-model="showPicker" position="bottom" :style="{ height: '30%' }">
      <van-picker
        title="选择期数"
        show-toolbar
        item-height="30"
        :columns="columns"
        @cancel="showPicker = false"
        @confirm="onConfirm"
      />
    </van-popup>
    <van-field
      class="ipt"
      label="商品名称"
      placeholder="请输入"
      input-align="right"
      border="true"
      :maxlength="20"
      v-model="contractGoodsName"
      required
    />
    <van-field
      class="ipt"
      label="商品品牌"
      placeholder="请输入"
      input-align="right"
      border="true"
      :maxlength="10"
      v-model="contractGoodsBrand"
    />
    <van-field
      class="ipt"
      label="用户姓名"
      placeholder="请输入"
      input-align="right"
      border="true"
      :maxlength="10"
      v-model="contractUserName"
      required
    />
    <van-field
      class="ipt"
      type="tel"
      label="用户手机号"
      placeholder="请输入"
      input-align="right"
      border="true"
      :maxlength="11"
      v-model="contractUserMblNo"
      required
    />
    <van-button
      round
      type="info"
      class="btn"
      block="true"
      color="linear-gradient(to right, #4bb0ff, #6149f6)"
      @click="goodInstallmentOrder"
    >创建订单</van-button>
    <!--点击创建订单展示 弹窗 -->
    <FConfirmSimple
      v-model="showConfirm"
      ref="FConfirmQRCode"
      @on-hide="handleHide"
      iconClass="scene_Staging-dingdan"
      class="hb-order-confirm"
      :showIcon="true"
    >
      <div class="trial-list">
        <div>还款总额:{{trial.totalAmount}}元</div>
        <div>每月还款额:{{trial.repayPerMonth}}元</div>
        <div>费率:{{trial.feeRate}}%</div>
      </div>
      <f-button @on-click="createdQRCode">生成二维码</f-button>
    </FConfirmSimple>
  </div>
</template>
<script>
import QRCode from "qrcode";
import FConfirmSimple from "@/components/old/FConfirmSimple.vue";
import axios from "axios";
import Vue from "vue";
import { NavBar } from "vant";
import { Grid, GridItem } from "vant";
import { Field } from "vant";
import { DropdownMenu, DropdownItem } from "vant";
import { Popup } from "vant";
import { Picker } from "vant";
import { Toast } from "vant";
import { async } from "q";
 
Vue.use(Toast);
Vue.use(Picker);
Vue.use(Popup);
Vue.use(DropdownMenu).use(DropdownItem);
Vue.use(Field);
Vue.use(Grid).use(GridItem);
Vue.use(NavBar);
export default {
  components: {
    FConfirmSimple
  },
  data() {
    return {
      showConfirm: false,
      capitalAmt: "0.00", //商家到账金额
      monthMoney: "0.00", //客户月还款总额
      contractGoodsBrand: "", //商品品牌
      contractGoodsName: "", //商品名称
      contractUserMblNo: "", //用户手机号
      contractUserName: "", //用户名称
      totalAmount: "0.00",
      orderNo: "", //未知参数
      term: null, //分期期数
      userMblNo: "", //用户手机号
      userName: "", //用户名称
      trial: {}, // 利率相关信息
      orderId: "", //订单id
      typeId: "",
      payQrCodeUrl: "", // 二维码
      termList: [], //分期期数列表
      showConfirm: false,
      howMouch: "", //商品金额
      value: "", //期数选择值
      showPicker: false, //期数选择弹出层控制
      columns: [] //分期期数列表
    };
  },
  created() {
    this.$api.shtxOrderInit().then(
      res => {
        console.log(res);
        var arr = res.body.terms;
        arr.forEach((ele, i) => {
          this.columns.push(`${ele.code}期`);
        });
        console.log(this.columns);
      },
      err => err
    );
  },
  methods: {
    handleHide() {
      this.showConfirm = false;
    },
    //返回上一级按钮
    onClickLeft() {
      this.$router.go(-1);
    },
    //弹出层显示
    showPopup() {
      this.show = true;
    },
    // 弹出层期数选项控制
    onConfirm(value) {
      this.value = value;
      //console.log(value.slice(0, -1));
      this.showPicker = false;
      this.term = value.slice(0, -1)
      //得到月还款额
      this.$api
        .getMonthMoney({
          totalAmount: this.howMouch,
          term: value.slice(0, -1)
        })
        .then(res => {
          console.log(res);
          this.capitalAmt = res.body.capitalAmt;
          this.monthMoney = res.body.repayPerMonth;
          this.totalAmount = res.body.totalAmount;
        });
    },
    changeMoney(){
      if(this.howMouch != this.totalAmount && this.term!= null && this.howMouch !=''){
        //得到月还款额
      this.$api
        .getMonthMoney({
          totalAmount: this.howMouch,
          term: this.value.slice(0, -1)
        })
        .then(res => {
          this.capitalAmt = res.body.capitalAmt;
          this.monthMoney = res.body.repayPerMonth;
          this.totalAmount = res.body.totalAmount;
        });
      } else if(this.howMouch == ''){
          this.capitalAmt = 0.00;
          this.monthMoney = 0.00
          this.totalAmount = 0.00
      }
    },
    //订单生成
    goodInstallmentOrder() {
      this.totalAmount = this.howMouch
      if(this.totalAmount != ''){
        this.$api
        .getMonthMoney({
          totalAmount: this.howMouch,
          term: this.value.slice(0, -1)
        })
        .then(res => {
          console.log(res);
          this.capitalAmt = res.body.capitalAmt;
          this.monthMoney = res.body.repayPerMonth;
          this.totalAmount = res.body.totalAmount;
        });
      }
      let v = this.$tool;
      if (v.checkValEmpty(this.totalAmount)) {
        v.toast("请输入商品金额");
        return ;
      }
      // if (!Number(this.totalAmount)) {
      //   v.toast("请输入正确的结算金额");
      //   return false;
      // }
      //临时调整价格
      if (Number(this.totalAmount) <= 0 ) {
        v.toast("商品金额不能为0");
        return false;
      }
      let res = /^[A-Za-z0-9\u4e00-\u9fa5]+$/;
      if (v.checkValEmpty(this.contractGoodsName)) {
        v.toast("请输入商品名称");
        return ;
      }
      if (!res.test(this.contractGoodsName)) {
        v.toast("请输入文字/字母/数字且不包含特殊字符的商品名称");
        return ;
      }
      if (v.checkValEmpty(this.term)) {
        v.toast("请输入分期期数");
        return ;
      }
        if (v.checkValEmpty(this.contractUserName)) {
            v.toast('请输入用户姓名');
            return false;
        }
        if (v.checkValEmpty(this.contractUserMblNo)) {
            v.toast('请输入用户手机号');
            return false;
        }
        if (!v.checkPhone(this.contractUserMblNo)) {
            v.toast('请输入正确的用户手机号');
            return false;
        }
      let queryObj = {
        goodsBrand: this.contractGoodsBrand, //商品品牌
        goodsName: this.contractGoodsName, //商品名称
        prodId: 30000010, //产品id
        term: this.value.slice(0, -1), //分期期数
        totalAmount: this.totalAmount, //商品总价
        userMblNo: this.contractUserMblNo, //用户电话号
        userName: this.contractUserName // 用户名称
      };
      this.$api.shtxOrderCreate(queryObj).then(res => {
        console.log(res);
        this.orderId = res.body.orderId;
        this.payQrCodeUrl = res.body.payQrCodeUrl;
        this.trial.totalAmount = res.body.totalAmount;
        this.trial.repayPerMonth = res.body.repayPerMonth;
        this.trial.feeRate = res.body.feeRate;
        this.showConfirm = true;
      });
    },
    //生成二维码
    createdQRCode() {
      this.showConfirm = false;
      var queryObj = {
        term: this.value.slice(0, -1), //分期期数
        payQrCodeUrl: this.payQrCodeUrl, //二维码
        totalAmount: this.totalAmount //还款总额,本金
      };
      if (this.$route.query.typeId) {
        queryObj.typeId = this.$route.query.typeId;
      }
      this.$router.push({
        path: "/shtx-getShtxQRCode",
        query: {
          orderId: this.orderId,
          ...queryObj
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.hb-merchant-installment {
  & {
    background-color: #e0e1e6;
    width: 100%;
    height: 100vh;
  }
  .money-box {
    & {
      width: 100%;
      height: 13vh;
      background-color: #e0e1e6;
      display: flex;
      justify-content: space-between;
      text-align: center;
    }
    .item-box {
      & {
        display: flex;
        flex-wrap: wrap;
        align-content: center;
      }
      .tit {
        font-size: 14px;
        font-weight: 700;
        display: inline-block;
        vertical-align: middle;
        width: 100%;
      }
      .money {
        margin: 15px 0 0 0;
        width: 100%;
      }
    }
  }
  .ipt,
  .fenqi {
    & {
      border-bottom: 1px solid #e0e1e6;
    }
  }
  .btn {
    width: 80vw;
    height: 6vh;
    line-height: 6vh;
    margin: auto;
    position: fixed;
    bottom: 3vh;
    right: 10vw;
  }
  .hb-order-confirm {
    .trial-list {
      padding-left: 20px;
    }
 
    .f-button-component .f-button {
      margin-top: 12px;
    }
  }
 
  .hb-credit-installment {
    background-color: #f1f1f1;
    padding-top: 54px;
    .title {
      padding: 14px 12px;
      font-size: 15px;
      color: #333;
      .line {
        display: inline-block;
        width: 2px;
        height: 16px;
        margin-right: 8px;
        background: @color-text-three;
        vertical-align: middle;
        margin-top: -1px;
      }
    }
 
    .qrCode-box {
      padding-top: 0;
      .flexLayout(center, center, row);
 
      .qrCode {
        width: 200px;
        height: 200px;
        box-sizing: border-box;
        background-color: #fff;
        border: 5px solid @color-border-theme;
        padding: 5px;
 
        img {
          width: 100%;
          height: 100%;
          vertical-align: middle;
          display: block;
        }
      }
    }
  }
}
</style>