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
<template>
    <div class="forget-page">
        <x-header :left-options="{backText: ''}">忘记密码</x-header>
        <div class="pagebody">
            <group class="forget-input" label-width="73px">
                <x-input title="手机号码"
                         name="mobile"
                         v-model="userObj.mblNo"
                         type="tel"
                         :min="11" :max="11"
                         :novalidate="true"
                         placeholder="请输入手机号码"
                         keyboard="number"></x-input>
                <x-input title="新密码"
                         name="password"
                         v-model="userObj.password"
                         :type="pwdType"
                         :novalidate="true"
                         onpaste="return false"
                         oncopy="return false"
                         :min="8" :max="16"
                         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="验证码"
                         name="verCode"
                         v-model="userObj.verCode"
                         type="tel"
                         :min="4" :max="4"
                         :novalidate="true"
                         placeholder="请输入验证码"
                         keyboard="number">
                    <span slot="right" class="getverCode" @click="sendCode">{{codeButText}}</span>
                </x-input>
            </group>
            <div class="input-btnbox">
                <FButton :text="'重置密码'" @click.native="updatePd"></FButton>
            </div>
        </div>
    </div>
</template>
 
<script>
    import { XButton,XInput,Group,Flexbox,FlexboxItem,XHeader} from 'vux';
    import FButton from '../../components/common/FButton';
    import SystApi from '../../api/api';
    import { md5 } from 'vux';
    import validate from '../../tool/validator';
    import statusCodeManage from '../../api/statusCodeManage'
    import { mapState } from 'vuex'
    /**
     * Created by z.x.q on 2018/3/27.
     * 我的--注册
     */
    export default {
        name: 'f-forget-password',
        components: {
            XButton,XInput,Group,Flexbox,FlexboxItem,FButton,XHeader,FButton
        },
        data(){
            return {
                pwdType:'password',
                codeButText:'获取验证码',
                abledClick:true,
                clearID:null,
                userObj:{
                    mblNo:'',
                    password:'',
                    verCode:''
                }
            }
        },
        computed: {
            ...mapState({
                cn: state => state.vux.cn
            })
        },
        methods:{
            showPassword(){
                if(this.pwdType==='password'){
                    this.pwdType='text';
                }else{
                    this.pwdType='password';
                }
            },
            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;
                }
            },
            sendCode() {   // 发送验证码
                if(!this.abledClick){
                    return;
                }
                let _this = this;
                const _userNameState = this.checkUserName();
                if (!_userNameState) {
                    return false;
                }
                _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: 1
                };
                SystApi.getVerCode(_par).then(function (res) {
                    if (res.errorCode === 0) { }
                }, function (error) {
                    if (error.response) {
                        clearInterval(_this.clearID);
                        _this.codeButText = '重新获取验证码';
                        _this.abledClick = true;
                        // The request was made and the server responded with a status code
                        // that falls out of the range of 2xx
 
                    }
                    statusCodeManage.showTipOfStatusCode(error, _this);
                })
            },
            updatePd() {   // 修改密码
                let _this = this;
                if (validate.checkValEmpty(this.userObj.mblNo)) {
                    this.$vux.toast.text('请输入手机号', 'middle');
                    return;
                }
                if (validate.checkValEmpty(this.userObj.password)) {
                    this.$vux.toast.text('请输入密码', 'middle');
                    return;
                }
                if (validate.checkValEmpty(this.userObj.verCode)) {
                    this.$vux.toast.text('请输入验证码', 'middle');
                    return;
                }
                if (!validate.checkPhone(this.userObj.mblNo)) {
                    this.$vux.toast.text('请输入正确的手机号', 'middle');
                    return;
                }
                if (!validate.checkDynamicCode(this.userObj.verCode)) {
                    this.$vux.toast.text('请输入正确的验证码', 'middle');
                    return;
                }
                if (!validate.checkPassword(this.userObj.password)) {
                    this.$vux.toast.text('请输入正确的密码', 'middle');
                    return;
                }
                let tmpPassword = md5(this.userObj.mblNo + this.userObj.password);
                let _par = {
                    mblNo: this.userObj.mblNo,
                    password: tmpPassword,
                    confirmPwd: tmpPassword,
                    verCode: this.userObj.verCode
                };
                SystApi.forgetPwd(_par).then(response => {
                    if (response.errorCode === 0) {
                        _this.$vux.toast.show({
                            width: '80%',
                            type: 'text',
                            text: '密码修改成功,请重新登录',
                            time: 2000,
                            position: 'middle',
                            onHide: function () {
                                try {
                                    clearInterval(_this.clearID);
                                    _this.codeButText = '获取验证码';
                                } catch (e) {
 
                                }
                                _this.$router.push({name: 'f-login'});
                            }
                        })
                    }
                }, err => {
                    statusCodeManage.showTipOfStatusCode(err, _this);
                })
            },
        },
        activated(){
            this.$store.commit('UPDATE_DIRECTION', {direction: 'in'});
            this.codeButText = '获取验证码';
            this.abledClick = true;
            this.userObj.mblNo = '';
            this.userObj.password = '';
            this.userObj.verCode = '';
        },
        deactivated () {
            this.$store.commit('UPDATE_DIRECTION', {direction: 'none'});
        }
    }
</script>
<style lang="less">
    @import "../../style/mixin.less";
    .forget-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 ;
            .forget-input{
                .weui-cells{
                    .weui-cell{
                        height:23px;
                        border:1px solid @color-disabled;
                        border-radius: @border-radius-normal-size;
                        margin-top: 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%;
            }
 
        }
    }
 
</style>