gx
queenwuli
2021-01-15 4b80c98ef5fda8d6358778f2efe8bb35cb20ccf9
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
<template>
    <!-- 忘记密码 -->
    <view>
        <view class="input-box">
            <input type="text" v-model="phone" placeholder="请输入手机号码" placeholder-class="placeholder" class="input-group-row"/>
            <view class="flex mt-10 ">
                <input type="text" v-model="code" value="" placeholder="请输入验证码" placeholder-class="placeholder" class="input-group-row flex-1 mr-10"/>
                <view url="" hover-class="none" class="btn-box">
                    <button class="btn blue-btn" :disabled="btnDisabled" @click="sendCode">{{btnTxt}}</button>
                </view>
            </view>
        </view>
        <button class="blue-btn sticky-footer" @click="next">下一步</button>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                phone:'',
                code: '',
                btnTxt: '获取验证码',
                btnDisabled: false
            }
        },
        methods: {
            sendCode(){
                if (!this.$utils.checkPhone(this.phone)){
                    this.$toast.info('请输入正确的手机号');
                    return false;
                }
                this.btnDisabled = true;
                let second = 120;
                this.$httpUtils.request('/api/common/sendSmsCode',{
                    telphone: this.phone.trim()
                },'POST').then((res)=>{
                    if(res.status==200){
                        this.btnTxt = second + 's';
                        this.timer = setInterval(() => {
                            if(second<=1){
                                this._reset()
                            }else{
                                second--;
                                this.btnTxt = second + 's';
                            }
                        }, 1000);
                        this.$toast.info(res.info);
                    } else {
                        this.$toast.info(res.info);
                        this.btnDisabled = false;
                    }
                }).catch((err) => {
                    this.$toast.info('发送失败');
                    this._reset()
                })
            },
            _reset(){
                this.timer && clearInterval(this.timer);
                this.timer = null;
                this.btnTxt = '发送验证码';
                this.btnDisabled = false;
            },
            valid(){
                if(!this.phone.trim()){
                    this.$toast.info('请输入手机号');
                    return false;
                }
                if(!this.code.trim()){
                    this.$toast.info('请输入验证码');
                    return false;
                }
            },
            next(){
                if(this.valid() === false){
                    return;
                }else{
                    uni.navigateTo({
                        url:'./newPassword?code='+this.code+'&phone='+this.phone
                    })
                }
            }
        }
    }
</script>
 
<style>
    .input-box{
        margin: 20px 15px;
    }
    .btn-box{
        display: flex;
        align-items: flex-end;
    }
    .btn{
        margin: 0;
        font-size: 12px;
        line-height: 36px;
    }
</style>