1
zhaoxiaoqiang
2022-11-28 912aeddb56e0514dd9fd0b0db10319b81d9976fc
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<!--
 * @Author: 小明丶
 * @Date: 2020-05-13 17:26:17
 * @LastEditors: zxq
 * @LastEditTime: 2022-06-15 17:53:43
 * @Description: 还款试算-订单详情还款计划表
 -->
<template>
    <div class="repayment-plan-page">
        <v-navbar :title="isPlan?'还款计划表':'还款试算'" fixed></v-navbar>
        <div class='repayment_box'>
            <!-- <div class='repayment_small_box'> -->
                <!-- <div style="height:10px"></div> -->
                 <div v-if='isAllReplay' class="primary_btn"  @click="checkAll" >
                        <van-checkbox icon-size='14px' v-model="checkedAll">全选</van-checkbox>
                </div>
                <div class='repayment_small_box'>
                    <van-collapse v-model="activeNames" accordion style='padding-bottom:50px;' >
                        <van-checkbox-group v-model="result" ref="checkboxGroup" @change='changeRadion'>
                            <div v-for="(item,index) in tremList" :key="index" class='chckout'>
                                <van-checkbox  v-if='isAllReplay&&item.canRepay==1' @click.stop='changeRad' :name="item.seqNo" icon-size='14px'> </van-checkbox>
                                <van-collapse-item  :name="index">
                                    <template #title>
                                        <div>
                                            <span>{{'第'+(index+1)+'期'}}</span>
                                        </div> 
                                    </template>
                                    <div class="detail-box">
                                        <div class="text-box">
                                            <span>应还日期:</span>
                                            <span>{{item.rpyDay}}</span>
                                        </div>
                                        <div class="text-box">
                                            <span>{{isPlan?'应还本金:':'应还总额:'}}</span>
                                            <span v-if="isPlan">¥{{item.rpyAmt}}</span>
                                            <span v-else>¥{{item.totalAmt}}</span>
                                        </div>
                                        <div v-if="isPlan" class="text-box">
                                            <span>应还服务费:</span>
                                            <span>¥{{item.rpySerFee}}</span>
                                        </div>
                                        <div v-if="isPlan" class="text-box">
                                            <span>应还滞纳金:</span>
                                            <span>¥{{item.rpyLateFee}}</span>
                                        </div>
                                        <div v-if="isPlan" class="text-box">
                                            <span>实还日期:</span>
                                            <span>{{item.realRpyTime}}</span>
                                        </div>
                                        <div v-if="isPlan" class="text-box">
                                            <span>实还本金:</span>
                                            <span>¥{{item.realAmt}}</span>
                                        </div>
                                        <div v-if="isPlan" class="text-box">
                                            <span>实还服务费:</span>
                                            <span>¥{{item.realSerFee}}</span>
                                        </div>
                                        <div v-if="isPlan" class="text-box">
                                            <span>实还滞纳金:</span>
                                            <span>¥{{item.realLateFee}}</span>
                                        </div>
                                    </div>
                                </van-collapse-item>
                            </div>
                        </van-checkbox-group>
                    </van-collapse>
                    <!-- <div class='btn_class' v-if='!isAllReplay&&showReplayArr.length>0'>
                        <van-button size='normal' block type="info" @click="goPay">立即还款</van-button>
                    </div>
                    <div class='btn_replay primary_btn' v-else>
                        <div class='payment_money' v-if='totalAmt'>
                            <span>本次共计需还</span>
                            <span>{{totalAmt}}</span>
                        </div>
                        <div v-if="totalAmt&&havaRadion" >
                            <van-button  size="small" type="info" @click="yzmShow=true">确认还款</van-button>
                            <van-button  size="small" type="default" @click="canelReplay">取消</van-button>
                        </div>
                    </div> -->
                </div>
        </div>
         <!-- 短信验证码弹窗 -->
        <van-popup v-model="yzmShow">
            <div class="yzmbox">
                <van-icon  name="cross"  size="18"  class="yzmbox-close" @click="yzmShow = false" />
                <p style="font-size:16px;color:#000;">请输入短信验证码</p>
                <div class="yzmbox-contnet">
                    <div class="yzmbox-contnet-yzm">
                        <span>将发送到手机号:</span>
                        <span>{{userinfo.mblNo.replace(/(\d{3})\d*(\d{4})/,'$1****$2')}}</span>   
                    </div>
                </div>
                <div class="yzmbox-contnet-get">
                    <input type="text"  v-model="yzmVal" placeholder="请输入验证码"/>
                    <span class="yzmbox-contnet-get-yzm" @click="getYzm">{{yzmText}}</span>    
                </div>
                <van-button class="showbtn" block round @click="yzmYes">确认</van-button> 
            </div>
        </van-popup>
    </div>
</template>
<script>
import Vue from 'vue';
import { mapState } from 'vuex';
import { Collapse, CollapseItem ,Button,Checkbox, CheckboxGroup,Popup,Icon,Dialog } from 'vant';
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Button);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Popup);
Vue.use(Icon);
export default {
    components: {[Dialog.Component.name]: Dialog.Component},
    data(){
        return{
            activeNames: ['1'],
            tremList:[],
            result: [],
            checkedAll:false,
            isAllReplay:false,//是否是可还款状态
            yzmShow:false,
            yzmVal:"",
            Open: true, //倒计时开关
            yzmText: '获取验证码',
            showReplayArr:[],
            totalAmt:'',
            orderId:'',
            timer:null,
            havaRadion:true,
            getStatusTime:null,
            repayId:'',
            repayPStatus:1,
        }
    },
    computed: {
        ...mapState(['userinfo']),
        isPlan(){
            if(this.$route.query.id){
                return true
            }else{
                return false
            }
        }
    },
    methods:{
       init() {
            this.$api.initRepay({orderId:this.$route.query.id}).then(res => {
                this.tremList  = (res.body.repayPlans || []).map((val,index)=>{
                        return {
                            ...val,
                            id:val.orderId+index,
                            checked:false
                        }
                });
                let arr = [];
                res.body.repayPlans.forEach(val=>{
                    if(val.canRepay==1){
                        arr.push(val.canRepay);
                    }
                });
                this.showReplayArr = arr;
            });
      },
      checkAll() {
        if(!this.checkedAll){
          this.$refs.checkboxGroup.toggleAll(true);
        }else{
          this.result=[];
        }
      },
      goPay(index) {
        this.isAllReplay =!this.isAllReplay;
      },
      getYzm(){
         let sendParams = {mblNo: this.userinfo.mblNo, verCodeType: 20};
            if (this.Open) {
                this.$api.getVerCode(sendParams).then((res) => {
                    this.Open = false;
                    let num = 60;
                    this.yzmText = num + '秒后重发';
                    let _this = this;
                    _this.timer = setInterval(() => {
                        num--;
                        if (num === 0) {
                            clearInterval( _this.timer);
                            _this.Open = true;
                            _this.yzmText = '重新发送';
                        } else {
                            _this.yzmText = num + '秒后重发';
                        }
                    }, 1000);
                }).catch(() => {
                    this.Open = true;
                });
            }  
      },
      yzmYes() {
        if (this.yzmVal == "" || this.yzmVal == null) {
            this.$notify({ type: "danger", message: "验证码为空!" });
        } else {
            this.$api.repay({orderId: parseInt(this.$route.query.id),repayAmt:this.totalAmt, repayTerms:this.result,verCode:this.yzmVal}).then(({body}) => {
                this.yzmShow = false;
                clearInterval(this.timer);
                this.yzmVal = "";
                this.yzmText ='获取验证码';
                this.isAllReplay =false;
                this.Open = true;
                this.totalAmt ='';
                this.result=[];
                this.repayId = body.repayId;//还款还款行为ID
                this.checkReolayStatus();
            });
            
        }
      },
      checkReolayStatus(){
            this.$api.findRepayResult({repayId:this.repayId}).then(({body})=>{
                if(this.getStatusTime!==null){
                clearInterval(this.getStatusTime);
                }
                // 0-支付中,1-支付成功,2-支付失败
                // failMsg: "支付金额为0,不需要调用授权支付接口流程"
                // repaySts: 1
                // repayStsName: "支付成功"
                // this.repayPStatus = body.repaySts;
                if(body.repaySts==1){
                Dialog.alert({
                    title: '提示',
                    message:body.repayStsName? body.repayStsName:'还款成功',
                }).then(res=>{
                    clearInterval(this.getStatusTime);
                })
                }else if(body.repaySts==2){
                Dialog.alert({
                    title: '提示',
                    message:body.repayStsName? body.repayStsName:'还款失败',
                }).then(res=>{
                    clearInterval(this.getStatusTime);
                })
                }else{
                    // 状态为还款中时不许操作其他未还款的
                Dialog.alert({
                    title: '提示',
                    message:body.repayStsName? body.failMsg:'还款中',
                }).then(() => {
                        this.getStatusTime = setInterval(() => {
                            this.checkReolayStatus();
                        }, 2000);
                });
                }
                this.init();
            });
      },
        changeRadion(e){
            this.havaRadion = this.result.length>0;
            if(this.result==0){
            this.totalAmt =''; 
            }
            if(this.showReplayArr.length!==e.length){
                this.checkedAll =false;
            }else{
                this.checkedAll =true;
            }
            if(e.length>0){
                let  max;
           //遍历数组,默认arr中的某一个元素为最大值,进行逐一比较
                for(let i=0; i<e.length; i++){
              //外层循环一次,就拿arr[i] 和 内层循环arr.legend次的 arr[j] 做对比
                    for(var j=i; j<e.length; j++){
                        if(e[i]>e[j]){
                            //如果arr[j]大就把此时的值赋值给最大值变量max
                 max=e[j];
                            e[j]=e[i];
                            e[i]=max;
                        }
                    }
                }
                this.$api.repayTrial({orderId:this.$route.query.id,repayTerms:e}).then(res => {   
                    this.totalAmt =   res.body.totalAmt;     
                }).catch(err=>{
                    this.totalAmt = 0;
                });
            }
        
        },
        canelReplay(){
            this.isAllReplay=false;
            this.result=[];
            this.checkedAll=false;
            this.totalAmt=0;
        },
        changeRad(){
            
        }
    },
    created(){
        let tremList = JSON.parse(window.sessionStorage.getItem('order-repayPlans'));
        if(tremList){
          this.tremList = (JSON.parse(window.sessionStorage.getItem('order-repayPlans')) || []).map((val,index)=>{
            return {
                ...val,
                id:val.orderId+index
            }
          });
        }else{
          this.init();
        }
    },
    beforeDestroy(){
       clearInterval(this.getStatusTime);
       clearInterval(this.timer);
       sessionStorage.removeItem('order-repayPlans');
    }
}
</script>
<style lang="less" scoped>
    .repayment-plan-page{
        padding-top: 44px;
        &{
            min-height: 100vh;
            background-color:#fff;
            padding-bottom: 24px;
            box-sizing: border-box;
        }
        .repayment_box{
            height:calc(100vh - 44px);
            overflow: hidden;
        }
        .repayment_small_box{
            height:calc(100vh - 44px);
            overflow: scroll;
            padding-bottom: 50px;
            // box-sizing: border-box;
        }
        .detail-box{
            background: @c-back;
            display: flex;
            flex-wrap: wrap;
            .text-box{
                display: inline-block;
                width: 50%;
                color:rgba(153,153,153,1);
                font-weight:500;
                margin: 6px 0;
                span:nth-of-type(2){
                    color:rgba(51,51,51,1);
                }
            }
        }
        .btn_class{
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin-top: 20px;
        }
        .van-button--block{
            width: 90%;
        }
        .primary_btn{
            box-sizing: border-box;
            width: 100%;
            padding: 0.2rem 0.32rem;
            overflow: hidden;
            color: #323233;
            font-size: 0.28rem;
            line-height: 0.48rem;
            background-color: #fff;
        }
        .btn_replay{
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 40px;
            position: absolute;
            bottom: 0;
            left: 0;
        }
        .payment_money{
            color: #666;
            span{
                &:last-child{
                    font-size: 18px;
                    color: #333;
                    font-weight: bold;
                }
            }
        }
        .yzmbox {
                box-sizing: border-box;
                width: 280px;
                height: 225px;
                position: relative;
                overflow: hidden;
                .flex("", center, center, column);
                text-align: center;
                border-radius: 6px;
                background: #fff;
                padding-top: 30px;
                .van-button--block{
                    width: 90%;
                    margin-top: 15px;
                }
                &-close {
                    color: #999;
                    font-size: 16px;
                    position: absolute;
                    right: 8px;
                    top: 8px;
                }
                &-contnet {
                    margin-top: 11px;
                    color: #999;
                    font-size: 14px;
                    &-yzm {
                    .flex(center, center);
                    span {
                        font-size: 14px;
                    }
                    }
                    &-get {
                        width: 80%;
                        margin: 0 10%;
                        margin-top: 15px;
                        .flex(space-between, center);
                        input {
                            border: none;
                            width: 45%;
                            background: #fff;
                            height: 30px;
                        }
                        &-yzm {
                            color: @c-default;
                        }
                    }
                }
        }
        .chckout{
            display: flex;
            justify-content: flex-start;
            align-items: flex-start;
            padding: 0 0.32rem;
            overflow: hidden;
            color: #323233;
            box-sizing: border-box;
            .van-checkbox{
                width: 20px;
                height: 44px;
                overflow: hidden;
                color: #323233;
                font-size: 0.28rem;
                line-height: 44px;
                background-color: #fff;
                box-sizing: border-box;
                display: flex;
                justify-content:center;
                align-items: center;
            }
           
        }
        .van-collapse-item{
            width: 100%;
            
        }
        /deep/.van-cell--clickable{
            padding-left: 0 !important; 
            padding-left: 0.16rem;
        }
        /deep/.van-collapse-item__title{
            padding-left: 0 !important; 
            padding-left: 0.16rem;
        }
        /deep/.van-collapse-item__content {
            padding: 0.32rem;
            color: #969799;
            font-size: 0.26rem;
            line-height: 1.5;
            background-color: @c-back;
        }
    }
</style>