liangjin
2021-04-01 a734e1028dbc6e91a12ee03b1eeba27cdc94cd26
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
<!--
 * @Descripttion: 智享云生成二维码
 * @Author:TM丶
 * @LastEditors: 小明丶
 * @Date: 2019-3-1 15:00:00
 * @LastEditTime: 2020-11-13 17:25:14
 -->
<template>
    <div class="contract-installment-zxh">
       <van-nav-bar title="信用购">
          <i class="iconfont iconzuojiantou" slot="left" style="font-size:20px;color:#333;font-weight:blod" @click="goFrom"></i>
        </van-nav-bar>
        <div class="heyue-info">
            <p class="tit">
                <span>合约信息</span>
                <span></span>
            </p>
            <!-- <div style="margin-bottom:16px">
                <p style="margin-bottom:10px">
                    <span style="color:#999999;font-size:13px">合约套餐</span>
                    <span style="color:#FF6666;font-size:13px">*</span>
                </p>
                <el-select v-model="selectContract" placeholder="请选择">
                  <el-option
                    v-for="item in contractList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
            </div> -->
            <Ipt :type="'text'" :mustFill="true"  :tit="'合约套餐'" :readonly="true" v-model="contName"></Ipt>
            <Ipt :type="'text'" :mustFill="true"  :tit="'结算金额'" :readonly="true" v-model="selectConInfo.capitalAmt"></Ipt>
            <Ipt :type="'text'" :mustFill="true"  :tit="'月缴话费'" :readonly="true" v-model="selectConInfo.monthlyFees"></Ipt>
            <Ipt :type="'text'" :mustFill="true" :tit="'期数'" :readonly="true" v-model="selectConInfo.term"></Ipt>
        </div>
        <div class="sp-info">
            <p class="tit">
                <span>商品信息</span>
                <span></span>
            </p>
            <div style="margin-bottom:16px">
                <p style="margin-bottom:10px">
                    <span style="color:#999999;font-size:13px">商品类型</span>
                </p>
                <el-select v-model="goodsInfo.goodsType" placeholder="请选择">
                  <el-option
                    v-for="item in columns"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code"
                    @change="onConfirm">
                  </el-option>
                </el-select>
            </div>
            <Ipt :type="'text'" :tit="'品牌'" :placeholder="'请输入品牌'" :readonly="false" v-model="goodsInfo.goodsBrand"></Ipt>
            <Ipt :type="'text'" :tit="'名称'" :placeholder="'请输入名称'" :readonly="false" v-model="goodsInfo.goodsName"></Ipt>
            <Ipt :type="'text'" :tit="'型号'" :placeholder="'请输入型号'" :readonly="false" v-model="goodsInfo.goodsModel"></Ipt>
            <Ipt :type="'text'" :tit="'价格'" :placeholder="'请输入价格'" :readonly="false" v-model="goodsInfo.goodsPrice"></Ipt>
            <Ipt :type="'text'" :tit="'IMEI'" :placeholder="'请输入IMEI'" :readonly="false" v-model.trim="goodsInfo.goodsImei" v-if="goodsInfo.goodsType==1"></Ipt>
            <Ipt :type="'text'" :tit="'SN'" v-model.trim="goodsInfo.goodsSn" placeholder='请输入SN' :max='20' v-else></Ipt>
        </div>
        <van-button class="btn" round @click="submit">生成二维码</van-button>
    </div>
</template>
 
<script>
    import {
        XAddress
    } from 'vux';
    import QRCode from 'qrcode';
    import IDValidator from '@/utils/IDValidator';
    import Vue from 'vue';
    import { Picker } from 'vant';
    import Ipt from '../../../../components/common/h-ipt'
    Vue.use(Picker);
    export default {
        name: 'xyg_createcode',
        components: {
            XAddress,Ipt
        },
        data() {
            return {
                value:'',
                showPicker: false,//弹出层
               
                cityList: [],
                selectContract: '', // 选中的合约
                contName:'',//合约名称
                // 合约信息
                selectConInfo: {
                    capitalAmt: '', // 结算金额
                    monthlyFees: '', // 月缴话费
                    term: '', // 期数
                },
                // 商品信息
                goodsInfo: {
                    //selectContract: '', // 选中的合约
                    goodsBrand: '', //商品品牌
                    goodsName: '', //商品名称
                    goodsModel: '', // 商品型号
                    goodsPrice: '', // 价格
                    goodsImei: '', // IMEI
                    goodsSn: '', // SN
                    goodsType:'',//设备类型,1-手机(IMEI)2-电子商品、3-智能家电、4-其他(SN)
                },
                contractList: [], // 合约列表
                columns: [],//设备下拉表
            }
        },
        created() {
            if(sessionStorage.hb_session_info){
                this.goodsInfo = JSON.parse(sessionStorage.hb_session_info)
            }
            this.contName = this.$route.query.prodName;
            this.selectContract = this.$route.query.prodId
            this.selectConInfo.capitalAmt = this.$route.query.prodAmt
            this.selectConInfo.monthlyFees = this.$route.query.monthlyFees //月缴话费
            this.selectConInfo.term = this.$route.query.term
            
            this.initWXToken(location.origin + location.pathname);
            this.$api.getGoodsTypeList().then(res=>{
                this.columns = res.body.prodTypes
            })
            this.$api.getArea().then(res => {
                this.cityList = res.body.provList;
            });
        },
        watch: {
        },
        methods: {
            // 返回上一页
            goFrom(){
                this.$router.go(-1)
            },
            onConfirm() {
                console.log(this.goodsInfo.goodsType)
            //   this.value = value
            //   this.goodsInfo.goodsType = index+1;
              //this.showPicker = false;
              if(this.goodsInfo.goodsType==1||this.goodsInfo.goodsType==''){
                  this.goodsInfo.goodsSn = ''
              }else{
                  this.goodsInfo.goodsImei = ''
              }
            },
            initWXToken(parUrl) {
                this.$api.getTokenInfo({
                    url: parUrl
                }).then(
                    function (res) {
                        if (res.errorCode === 0) {
                            // 第二步骤   只需要首页地址分享 ,需要在每次变化时调用
                            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, // 必填,签名,见附录1
                                jsApiList: [
                                    'checkJsApi',
                                    'scanQRCode',
                                    'getLocation'
                                ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
                            });
                        }
                    },
                    function (error) {
                        if (error.response) {
                            console.log(error.response);
                        }
                    }
                );
            },
            getLocation(){
                console.log('getLocation');
                let _this = this;
                wx.getLocation({
                    type: 'wgs84',
                    success: function (res) {
                        console.log(JSON.stringify(res));
                        let longitude = res.longitude
                        let latitude = res.latitude
                        _this.$api.gpsAddr({
                            gpsAddrLongitude: longitude,
                            gpsAddrLatitude: latitude
                        }).then(res => {
                            console.log('gpsSucess');
                        }, err => err);
                    },
                    cancel: function (res) {
                        console.log('用户拒绝授权获取地理位置');
                        _this.$api.gpsAddr({
                            gpsAddrLongitude: '',
                            gpsAddrLatitude: ''
                        }).then(res => {
                            console.log('gpsfail');
                        }, err => err);
                    }
                })
            },
            // 处理合约的修改
            contractChange(val) {
                if (!val) {
                    return;
                }
                this.selectConInfo = this.contractList.find((item) => {
                    return item.contId === val;
                })
            },
            // 生成二维码
            submit() {
                this.getLocation();
                let v = this.$tool;
                if (v.checkValEmpty(this.selectContract)) {
                    v.toast('请选择合约套餐');
                    return false;
                }
                if (v.checkValEmpty(this.goodsInfo.goodsBrand)) {
                    v.toast('请输入商品品牌');
                    return false;
                }
                if (!/^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(this.goodsInfo.goodsBrand)) {
                    v.toast('请输入文字/字母/数字且不包含特殊字符的商品品牌');
                    return false;
                }
                if (v.checkValEmpty(this.goodsInfo.goodsName)) {
                    v.toast('请输入商品名称');
                    return false;
                }
                if (!/^[A-Za-z0-9\u4e00-\u9fa5]+$/.test(this.goodsInfo.goodsName)) {
 
                    v.toast('请输入文字/字母/数字且不包含特殊字符的商品名称');
                    return false;
                }
                if (v.checkValEmpty(this.goodsInfo.goodsModel)) {
                    v.toast('请输入商品型号');
                    return false;
                }
                if (v.checkValEmpty(this.goodsInfo.goodsPrice)) {
                    v.toast('请输入商品价格');
                    return false;
                }
                if (!/^[1-9]\d{0,4}/.test(this.goodsInfo.goodsPrice)) {
                    v.toast('请输入商品正确的价格');
                    return false;
                }
                if(this.goodsInfo.goodsType == 1){
                    if (v.checkValEmpty(this.goodsInfo.goodsImei)) {
                        v.toast('请输入商品IMEI');
                        return false;
                    }
                }else{
                    if (v.checkValEmpty(this.goodsInfo.goodsSn)) {
                        v.toast('请输入商品SN');
                        return false;
                    }
                }
                if (v.checkValEmpty(this.goodsInfo.goodsType)) {
                    v.toast('请选择设备类型');
                    return false;
                }
                 // 用来整体存储缓存数据
                let hb_session_info = {
                  ...this.goodsInfo
                }
                sessionStorage.hb_session_info = JSON.stringify(hb_session_info)
 
                let queryObj = {
                    ...this.selectConInfo,
                    ...this.goodsInfo,
                    mgrId: sessionStorage.sid, // 办单员id
                    contId: this.selectContract, // 合约id
                    contName: this.contName,
                    typeId: this.$route.query.typeId,
                    seq:this.$route.query.seq
                };
 
                this.$router.push({
                    path: "/contract-qrcode",
                    query: queryObj
                })
            },
            // 根据城市code 获取拼接的字符串
            getAddrText(arr) {
                let str = '';
                this.cityList.forEach(item => {
                    if (arr.indexOf(item.value) > -1) {
                        str += item.name
                    }
                })
                return str;
            }
        }
    };
</script>
<style lang='less' >
    .contract-installment-zxh {
        min-height: 100vh;
        background-color: #f1f1f1;
        padding-bottom: 80px;
        //overflow-y: scroll;
        input::-webkit-input-placeholder{color:#333333;}
        .van-cell {
            padding: 0.22rem 0.32rem 0.22rem 8px;
            border: 1px solid #CDD3F6;
            border-radius: 4px;
            background-color: #F9FAFF;
            margin-bottom: 16px;
        }
        .van-cell:after {
            content: " ";
            position: absolute;
            left: 0.3rem;
            top: 0;
            right: 0;
            height: 0.02rem;
            width: 98%;
            border-top: 0.02rem solid #D9D9D9;
            color: #D9D9D9;
            transform-origin: 0 100%;
            transform: scaleY(0.5);
        }
        .van-nav-bar__title {
            max-width: 60%;
            margin: 0 auto;
            color: #333;
            font-weight: bold;
            font-size: 16px;
        }
        .el-input__inner{
            background-color: #F9FAFF;
            padding-left: 8px;
        }
        .el-select{
            width: 100%;
            height: 40px;
        }
        .heyue-info{
            width:100%;
            height:385px;
            background:rgba(255,255,255,1);
            box-shadow:1px 5px 13px 0px rgba(0, 0, 0, 0.08);
            margin-top: 12px;
            box-sizing: border-box;
            padding: 17px 20px 0 20px;
            .tit{
                margin-bottom: 19px;
                color: #6C4AD5;
                font-size: 16px;
                position: relative;
                span:nth-of-type(1){
                    display: inline-block;
                    font-weight: bold;
                }
                span:nth-of-type(2){
                    display: inline-block;
                    width:64px;
                    height:7px;
                    background:rgba(255,236,190,0.5);
                    position: absolute;
                    left: 0;
                    bottom: 0;
                }
            }
        }
        .sp-info{
            width:375px;
            height:560px;
            background:rgba(255,255,255,1);
            box-shadow:1px 5px 13px 0px rgba(0, 0, 0, 0.08);
            border-radius:3px;
            margin-top: 15px;
            box-sizing: border-box;
            padding: 17px 20px 0 20px;
            .tit{
                margin-bottom: 19px;
                color: #6C4AD5;
                font-size: 16px;
                position: relative;
                span:nth-of-type(1){
                    display: inline-block;
                    font-weight: bold;
                }
                span:nth-of-type(2){
                    display: inline-block;
                    width:64px;
                    height:7px;
                    background:rgba(255,236,190,0.5);
                    position: absolute;
                    left: 0;
                    bottom: 0;
                }
            }
        }
        .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;
            }
        }
    }
    .btn {
        width: 84%;
        margin: 0 8%;
        background: @c-default;
        color: @c-text-fff;
        display: block;
        margin-top: 24px;
        }
</style>