liangjin
2021-03-23 eb9443b959ad490ac735f2c04e4dee743d7365c7
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
<!--
 * @Date: 2019-08-30 13:38:35
 * @LastEditors: 小明丶
 * @LastEditTime: 2019-10-28 15:24:08
 * @Description: 
 -->
 
<template>
    <div class="hb-credit-installment h-100-g">
        <x-header title="办理分期" :left-options="{backText:''}"></x-header>
        <!--合约机分期-->
        <group v-show="activeTab === 0">
            <div class="title">
                <span class="line"></span>
                合约信息
            </div>
            <selector title='合约套餐' placeholder='请选择' v-model="selectContract" :options='contractList'
                :value-map="['contId','contName']" @on-change='handleChangeContract' direction='rtl'></selector>
            <x-input title='结算金额' v-model.trim="selectContractInfo.capitalAmt" readonly text-align='right'></x-input>
            <x-input title='月缴话费' v-model.trim="selectContractInfo.monthlyFees" readonly text-align='right'></x-input>
            <x-input title='月还款额' v-model.trim="selectContractInfo.monthlyPayments" readonly text-align='right'>
            </x-input>
            <x-input title='期数' v-model.trim="selectContractInfo.term" readonly text-align='right'></x-input>
            </x-input>
            <div style="height: 10px; background: #f5f5f5;"></div>
            <div class="title">
                <span class="line"></span>
                商品信息
            </div>
            
            <x-input title='商品品牌' v-model.trim="contractGoodsBrand" placeholder='请输入' :max='10' text-align='right'>
            </x-input>
            <x-input title='商品名称' v-model.trim="contractGoodsName" placeholder='请输入' :max='20' text-align='right'>
            </x-input>
            <div style="height: 10px; background: #f5f5f5;"></div>
            <div class="title">
                <span class="line"></span>
                用户信息
            </div>
            <x-input title='用户姓名' v-model.trim="contractUserName" placeholder='请输入' :max='10' text-align='right'>
            </x-input>
            <x-input title='用户手机号' v-model.trim="contractUserMblNo" placeholder='请输入' :max='11' text-align='right'>
            </x-input>
        </group>
        
 
        <div class="qrCode-box" v-if="dataURL">
            <div class="qrCode">
                <img :src="dataURL" alt="qrcode">
            </div>
        </div>
 
        <!--点击创建订单展示 弹窗 -->
        <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>
        <!--此次修改为 生成订单-->
        <f-space type="large"></f-space>
        <f-button fixed @on-click='contractInstallmentOrder'>生成订单</f-button>
    </div>
</template>
 
<script>
    import QRCode from 'qrcode';
    import FConfirmSimple from '@/components/old/FConfirmSimple.vue';
 
    export default {
        name: 'hb-credit-installment',
        components: {
            FConfirmSimple,
        },
        data() {
            return {
                monthMoney: '', //月还款总额
                activeTab: 0, // 处于激活状态下的tab, 最开始为合约机分期
                tabList: ['合约机分期', '商品分期'],
                selectContract: '', // 选中的合约
                contractList: [], // 合约列表
                selectContractInfo: {// 当前选中合约元素
                    capitalAmt:"",
                    monthlyFees:"",
                    monthlyPayments:"",
                    term:""
                }, 
                contractGoodsBrand: '', //商品品牌
                contractGoodsName: '', //商品名称
                contractUserMblNo: '', //用户手机号
                contractUserName: '', //用户名称
                // hb
                capitalAmt: '', //分期本金
                goodsBrand: '', //商品品牌
                goodsName: '', //商品名称
                orderNo: '', //未知参数
                term: null, //分期期数
                userMblNo: '', //用户手机号
                userName: '', //用户名称
                trial: {}, // 利率相关信息
                orderId: '', //订单id
                payQrCodeUrl: '', // 二维码
                termList: [], //分期期数列表
                dataURL: '', // QRcode
                showConfirm: false,
            };
        },
        created() {
            this.getContractList();
        },
        methods: {
            // 处理合约的修改
            handleChangeContract(val) {
                this.selectContractInfo = this.contractList.find((item) => {
                    return item.contId === val;
                })
            },
            handleHide() {
                this.showConfirm = false;
            },
            // 生成二维码
            createdQRCode() {
                this.showConfirm = false;
                let queryObj = {
                    orderId: this.orderId,
                    totalAmount: this.trial.totalAmount,
                    term: this.term,
                    typeId: this.$route.query.typeId
                }
                if(this.activeTab===0){
                    queryObj.term = this.selectContractInfo.term;
                }
                if (this.$route.query.typeId) {
                    queryObj.typeId = this.$route.query.typeId;
                }
                this.$router.push({
                    path: "/hb-getHBQRCode",
                    query: queryObj
                })
            },
            // 合约分期生成订单
            contractInstallmentOrder() {
                let v = this.$tool;
                if (v.checkValEmpty(this.selectContract)) {
                    v.toast('请选择合约套餐');
                    return false;
                }
                let reg = /^[A-Za-z0-9\u4e00-\u9fa5]+$/;
                if (v.checkValEmpty(this.contractGoodsBrand)) {
                    v.toast('请输入商品品牌');
                    return false;
                }
                if (!reg.test(this.contractGoodsBrand)) {
                    v.toast('请输入文字/字母/数字且不包含特殊字符的商品品牌');
                    return false;
                }
                if (v.checkValEmpty(this.contractGoodsName)) {
                    v.toast('请输入商品名称');
                    return false;
                }
                if (!reg.test(this.contractGoodsName)) {
                    v.toast('请输入文字/字母/数字且不包含特殊字符的商品名称');
                    return false;
                }
                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 params = {
                    contId: this.selectContract,
                    goodsName: this.contractGoodsName,
                    goodsBrand: this.contractGoodsBrand,
                    userName: this.contractUserName,
                    userMblNo: this.contractUserMblNo,
                }
                this.$api.hbhyjCreate(params).then(res => {
                    let body = res.body;
                    this.orderId = body.orderId;
                    this.payQrCodeUrl = body.payQrCodeUrl;
                    this.trial.totalAmount = body.totalAmount;
                    this.trial.repayPerMonth = body.repayPerMonth;
                    this.trial.feeRate = body.feeRate;
                    this.showConfirm = true;
                    if (body.payQrCodeUrl) {
                        sessionStorage.setItem("hbpayQrCodeUrl", body.payQrCodeUrl);
                    }
                })
                // todo 数据组装,接口的调取
            },
            // 获取当前的合约列表
            getContractList() {
                this.$api.contractList({
                    typeId: +this.$route.query.typeId
                }).then(res => {
                    this.contractList = res.body;
                }, err => err);
            }
        },
    };
 
</script>
<style lang='less' scoped >
    .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>