ann0707
2018-08-16 c9bc8ec61cff4076132f6396d99d383a2cdf5a03
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<template>
    <div class="register-page" :style="styleObject">
        <x-header :left-options="{showBack: true, backText: '', preventGoBack:true}"
                  :title="headerTitle"
                  @on-click-back="goBackPage"></x-header>
        <div class="pagebody">
            <div class="register-portrait">
                <div class="register-head-portrait">
                    <img :src="loginLogo">
                </div>
            </div>
            <group class="register-input" label-width="73px">
                <x-input title="手机号"
                         name="mobile"
                         type="tel"
                         v-model="userObj.mblNo"
                         :min="11"
                         :max="11"
                         :novalidate="true"
                         placeholder="请输入手机号码"
                         keyboard="number"></x-input>
                <x-input title="密码"
                         name="password"
                         :type="pwdType"
                         v-model="userObj.password"
                         :min="8" :max="16"
                         :novalidate="true"
                         onpaste="return false"
                         oncopy="return false"
                         placeholder="请输入8-16位数字字母组合密码">
                    <i slot="right" v-show="pwdType=='text'" class="iconfont icon-eye" @click="showPassword"></i>
                    <i slot="right" v-show="pwdType=='password'" class="iconfont icon-hide" @click="showPassword"></i>
                </x-input>
                <x-input title="验证码"
                         v-model="userObj.verificationCode"
                         name="verCode"
                         type="tel"
                         placeholder="请输入验证码"
                         keyboard="number"
                         :min="4" :max="4"
                         :novalidate="true">
                    <span slot="right" class="getverCode" @click="checkAferThreeTimes">{{codeButText}}</span>
                </x-input>
            </group>
            <div class="input-btnbox">
                <FButton :text="'注册'" @on-click-button="handleRegister"></FButton>
            </div>
            <div class="input-other">
                <span>
                     注册即视为同意
                    <span @click="handlerClickAgreement">《注册协议》</span>
                </span>
                <span @click="toLogin">登录</span>
            </div>
        </div>
        <!-- 图形验证码 -->
        <div v-transfer-dom>
            <confirm
                v-model="showImageCode"
                :title="'输入图形验证码'"
                @on-confirm="onConfirm"
                @on-hide="onHide">
                <slot>
                    <input ref="imgcode" v-model="imgCode" maxlength="4"
                           style="height: 28px;width: 90px;border:1px solid #999;"/>
                    <img style="width: 76px; position: relative;top: 10px;" :src="imgCodeUrl" @click="getImgCodeAgain"/>
                </slot>
            </confirm>
        </div>
        <!-- 倒计时 -->
        <div class="register-mask" v-if="registerTip"></div>
        <div class="register-countdown" v-if="registerTip">{{ '注册成功' + registerCountdown + 's后跳转' }}</div>
        <!-- 协议弹窗 -->
        <div class="agreement-content" v-if="isShowAgreementContent">
            <div v-html="agreementContent"></div>
        </div>
    </div>
</template>
 
<script>
    import {
        XButton,
        XInput,
        Group,
        cookie,
        Flexbox,
        FlexboxItem,
        XHeader,
        TransferDomDirective as TransferDom,
        Confirm
    } from 'vux';
    import FButton from '../../components/common/FButton';
    import SystApi from '../../api/api';
    import validate from '../../tool/validator';
    import IDValidator from '../../tool/IDValidator';
    import {md5} from 'vux';
    import {mapState} from 'vuex';
    import statusCodeManage from '../../api/statusCodeManage';
    /**
     * Created by z.x.q on 2018/3/22.
     * 我的--注册
     */
    export default {
        name: 'f-register',
        components: {
            XButton, XInput, Group, FButton, XHeader, Confirm, cookie
        },
        directives: {
            TransferDom
        },
        data(){
            return {
                loginLogo: '',
                headerTitle: '注册', // 头部title
                agreementContent: '', // 协议的内容
                isShowAgreementContent: false,
                styleObject: {
                    overflow: 'initial',
                    minHeight: '100%',
                    height: 'auto'
                },
                pwdType: "password",
                showImageCode: false,//显示图形验证码界面
                imgCode: '',//图形验证码对应的值
                imgCodeUrl: '',//图形验证码路径
                userObj: {
                    mblNo: '',
                    password: '',
                    confirmPwd: '',
                    verificationCode: ''
                },
                clearID: null,//获取验证码倒计时的定时器
                codeButText: '获取验证码',//倒计时显示的文字
                abledClick: true,//是否可以点击发送验证码
                registerTip: false,//自动登录的tip
                registerCountdown: 3,
            }
        },
        methods: {
            // 显示协议内容
            handlerClickAgreement() {
                let _this = this;
                this.styleObject = {
                    overflow: 'hidden',
                    minHeight: '100%',
                    height: '100%'
                };
                this.headerTitle = '注册协议';
                SystApi.getAgreementContent().then(function (response) {
                    _this.agreementContent = response;
                    _this.isShowAgreementContent = true;
                }).catch(function (error) {
                    statusCodeManage.showTipOfStatusCode(error,_this);
                });
            },
            //注册
            handleRegister() {
                let _this = this;
                if (validate.checkValEmpty(this.userObj.mblNo)) {
                    this.$vux.toast.text('请输入手机号', 'middle');
                    return;
                }
                if (validate.checkValEmpty(this.userObj.verificationCode)) {
                    this.$vux.toast.text('请输入验证码', 'middle');
                    return;
                }
                if (validate.checkValEmpty(this.userObj.password)) {
                    this.$vux.toast.text('请设置密码', 'middle');
                    return;
                }
                if (!validate.checkPhone(this.userObj.mblNo)) {
                    this.$vux.toast.text('请输入正确的手机号', 'middle');
                    return;
                }
                if (!validate.checkDynamicCode(this.userObj.verificationCode)) {
                    this.$vux.toast.text('请输入正确的验证码', 'middle');
                    return;
                }
                if (!validate.checkPassword(this.userObj.password)) {
                    this.$vux.toast.text('请设置8-16位字母数字组合密码', 'middle');
                    return;
                }
                let tmpPassword = md5(this.userObj.mblNo + this.userObj.password);
                SystApi.register({
                    mblNo: this.userObj.mblNo,
                    password: tmpPassword,
                    confirmPwd: tmpPassword,
                    verificationCode: this.userObj.verificationCode,
//          referralCode: this.invitationCode
                }).then(response => {
                    if (response.errorCode === 0) {
                        this.registerTip = true;
                        this.autoLogin(tmpPassword);
                        // 登录倒计时3 秒
                        function registerCountdown() {
                            let timeId = setTimeout(function () {
                                // 1秒的时候,就倒计时停止,进行跳转
                                if (_this.registerCountdown === 1) {
                                    _this.registerTip = false;
                                    // /prodInfo?id=50000095&cn=dRbq8m
                                    let _url = window.sessionStorage.getItem('newBackPage');
                                    try {
                                        clearInterval(_this.clearID);
                                        _this.codeButText = '获取验证码';
                                    } catch (e) {
 
                                    }
                                    // 在产品详情页 ,信用卡详情页  首页的值往回跳转
                                    let _path = window.sessionStorage.getItem('newGoBackPage');
                                    if (_path) {
                                        window.location.href = window.location.pathname +'#'+_path;
                                    }
                                    clearTimeout(timeId);
                                    return false;
                                } else {
                                    _this.registerCountdown--;
                                    registerCountdown();
                                }
                            }, 1000);
                        }
                        registerCountdown();
                    }
                }, err => {
                    statusCodeManage.showTipOfStatusCode(err, _this);
                });
            },
            //自动登录
            autoLogin: function (tmpPassword) {
                let _this = this;
                SystApi.userLogin({mblNo: this.userObj.mblNo, password: tmpPassword}).then(response => {
                    window.sessionStorage.setItem('newSid', response.body.sessionId);
                    window.sessionStorage.setItem('newPhoneNum', response.body.account);
                    window.sessionStorage.setItem('newClientState', response.body.isClient);
                    this.$store.commit('UPDATE_SESSION_ID', {sid: response.body.sessionId});  // 更新sid
                }, err => {
                    statusCodeManage.showTipOfStatusCode(err,_this);
                })
            },
            checkUserName() {
                if (validate.checkValEmpty(this.userObj.mblNo)) {
                    this.$vux.toast.text('请输入手机号', 'middle');
                    return false;
                } else if (!validate.checkPhone(this.userObj.mblNo)) {
                    this.$vux.toast.text('请输入正确的手机号', 'middle');
                    return false;
                } else {
                    return true;
                }
            },
            //获取验证码
            checkAferThreeTimes () {
                let _this = this;
                const _userNameState = this.checkUserName();
                if (!_userNameState) {
                    return false;
                }
                let _times = cookie.get('ecImageCodeNum');
                _times = parseInt(_times);
                if (_times <= 0) {
                    _this.imgCodeUrl = '/commerce/user/imageCode?mblNo=' + _this.userObj.mblNo + '&' + new Date();
                    _this.showImageCode = true;
                } else {
                    cookie.set('ecImageCodeNum', _times -= 1);
                    this.sendCode();
                }
            },
            //点击图形验证码再次获取验证码
            getImgCodeAgain () { //       发送图形验证码
                this.imgCodeUrl = '/commerce/user/imageCode?mblNo=' + this.userObj.mblNo + '&' + new Date();
            },
            //提交图形验证码
            onConfirm(){
                let _this = this;
                if (validate.checkValEmpty(_this.imgCode)) {
                    this.$vux.toast.text('请输入图片验证码', 'middle');
                    return;
                }
                if (_this.imgCode.length !== 4) {
                    this.$vux.toast.text('验证码错误', 'middle');
                    return;
                }
                SystApi.checkImageCode({imageCode: _this.imgCode, mblNo: _this.userObj.mblNo}).then(function (res) {
                    if (res.errorCode === 0) {
                        _this.sendCode();
                    }
                }, function (error) {
                    if (error.response) {
                        statusCodeManage.showTipOfStatusCode(error,_this);
                    }
                });
            },
            //发送验证码
            sendCode () {   // 发送验证码
                if (!this.abledClick) {
                    return;
                }
                let _this = this;
                this.abledClick = false;
                // 防止快速点击,事件触发多次,倒计时出现错误
                let countDown = 60;
                _this.codeButText = countDown + 's后重发';
                this.clearID = setInterval(function () {
                    countDown--;
                    _this.codeButText = countDown + 's后重发';
                    if (countDown === 0) {
                        clearInterval(_this.clearID);
                        _this.codeButText = '重新获取';
                        _this.abledClick = true;
                    }
                }, 1000);
                let _par = {mblNo: this.userObj.mblNo, verCodeType: 0};
                SystApi.getVerCode(_par).then(function (res) {
                    if (res.errorCode === 0) {
                    }
                }, function (error) {
                    if (error.response) {
                        clearInterval(_this.clearID);
                        _this.codeButText = '重新发送验证码';
                        _this.abledClick = true;
                    }
                    statusCodeManage.showTipOfStatusCode(error,_this);
                });
            },
            //隐藏图形验证码弹窗
            onHide(){
                this.imgCode = '';
            },
            //切换为登录
            toLogin(){
                clearInterval(this.clearID);
                this.codeButText = '获取验证码';
                this.$router.push({name: 'f-login'})
            },
            //显示-隐藏密码
            showPassword(){
                if (this.pwdType == "password") {
                    this.pwdType = "text";
                }
                else {
                    this.pwdType = "password";
                }
            },
            goBackPage: function () {
                try {
                    clearInterval(this.clearID);
                    this.codeButText = '获取验证码';
                } catch (e) {
 
                }
                // 点击返回,使注册协议消失
                if (this.isShowAgreementContent) {
                    // 协议弹窗内容点击返回时
                    this.isShowAgreementContent = false;
                    this.headerTitle = '注册';
                    this.styleObject = {
                        overflow: 'initial',
                        minHeight: '100%',
                        height: 'auto'
                    };
                } else {
                    this.$router.back();
                }
            },
        },
        computed: {
            ...mapState({
                cn: state => state.vux.cn
            })
        },
        activated(){
            this.$store.commit('UPDATE_DIRECTION', {direction: 'in'});
            this.headerTitle = '注册';
            this.agreementContent = '';
            this.isShowAgreementContent = false;
            this.styleObject = {
                overflow: 'initial',
                minHeight: '100%',
                height: 'auto'
            };
            this.pwdType =  "password";
            this.showImageCode = false;
            this.imgCode = '';
            this.imgCodeUrl = '';
            this.userObj.mblNo = '';
            this.userObj.password = '';
            this.userObj.confirmPwd = '';
            this.userObj.verificationCode = '';
            this.clearID = null;
            this.codeButText = '获取验证码';
            this.abledClick = true;
            this.registerTip =  false;
            this.registerCountdown = 3;
            let prodConfig = JSON.parse(window.localStorage.getItem('newProdConfig'));
            this.loginLogo = prodConfig.logoPath;
        },
        deactivated () {
            this.$store.commit('UPDATE_DIRECTION', {direction: 'none'});
        }
 
    }
</script>
 
<style lang="less">
    @import "../../style/mixin.less";
    .register-page{
        .vux-header{
            .color-linear-gradient(@color-primary-light,@color-primary,90deg);
            .vux-header-title{
               font-size: 18px;
            }
            .vux-header-left {
                .left-arrow:before {
                    border: solid 1px @color-white;
                    border-width: 2px 0 0 2px;
                }
 
            }
        }
        .pagebody {
            padding: 0 12px 0 12px;
            .register-portrait {
                height: 150px;
                .flexLayout(center, center, column);
                .register-head-portrait {
                    width: 84px;
                    height: 84px;
                    border-radius: @border-radius-normal-size;
                    overflow: hidden;
                    img {
                        width: 100%;
                        height: 100%;
                    }
                }
            }
            .register-input {
                .weui-cells {
                    margin: 0;
                    .weui-cell {
                        height: 23px;
                        border: 1px solid @color-disabled;
                        border-radius: @border-radius-normal-size;
                        margin-bottom: 10px;
                        font-size: @font-size-base;
                        .weui-cell__ft {
                            .getverCode {
                                padding-left: 10px;
                                display: inline-block;
                                color: @color-primary;
                                border-left: 1px solid @color-divider-regular;
                            }
                        }
                    }
                    .weui-cell:before {
                        display: none;
                    }
 
                }
                .weui-cells:before {
                    display: none;
                }
                .weui-cells:after {
                    display: none;
                }
            }
            .f-button {
              width: 100%;
            }
            .input-other {
                font-size: @font-size-medium;
                .flexLayout(space-between, center, row);
                span {
                    &:first-child {
                        color: @color-text-third;
                        span {
                            color: @color-primary;
                        }
                    }
                    &:nth-child(2) {
                        color: @color-primary;
                    }
                }
            }
        }
        .register-mask {
            position: fixed;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            width: 100%;
            height: 100%;
            background: rgba(17, 17, 17, 0.4);
        }
        .register-countdown {
            position: fixed;
            bottom: 50px;
            left: 50%;
            top: 50%;
            padding: 8px 20px;
            line-height: 20px;
            height: 20px;
            color: #fff;
            text-align: center;
            border-radius: 5px;
            transform: translateY(-50%);
            transform: translateX(-50%);
            background: rgba(17, 17, 17, 0.7);
            z-index: 100;
        }
        /*协议弹窗*/
        .agreement-content {
            position: fixed;
            left: 0;
            top: 46px;
            bottom: 0;
            right: 0;
            z-index: 10;
            width: 100%;
            height: 100%;
            overflow-y: scroll;
            padding: 20px 20px 66px;
            box-sizing: border-box;
            background: #fff;
        }
    }
 
</style>