fix
13404089107
8 天以前 2e90f57e7d28d6a949247ef39b487d3e75b56683
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
<template>
  <view class="content">
    <view class="input">
      <input type="number" class="input-phone" placeholder="请输入手机号" v-model="phone" maxlength="11" />
    </view>
    <view class="input">
      <input type="number" class="input-phone" placeholder="请输入验证码" v-model="code" maxlength="4" />
      <button class="button sendCode" :class="{disabled:(verifyPhone)}" :disabled="verifyPhone" @click="getCode">{{st}}</button>
    </view>
    <button class="button submit" :loading="loading.submit" :class="{disabled:verifyCode}" :disabled="verifyCode || loading.submit" @click="submit">提交</button>
  </view>
</template>
 
<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    data() {
      return {
        phone:"",
        code:"",
        s:0,
        st:"发送验证码",
        uid:"",
        loading:{
          submit:false
        }
      }
    },
    onLoad(o) {
      if(o.uid){
        this.uid = o.uid
      }
    },
    computed: {
      verifyPhone(){
        const strictReg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/;
        return !strictReg.test(this.phone) || this.s != 0
      },
      // 验证4位纯数字验证码
      verifyCode(){
        const reg = /^\d{4}$/;
        return !reg.test(this.code) 
      },
    },
    methods: {
      ...mapMutations(['setUserInfo']),
      getCode(){
        if(this.s >= 1){
          return
        }
        this.$apis.login.getCode({phone:this.phone,type:1}).then(res=>{
          this.$toast(res.msg)
          this.s = 60
          let timer = setInterval(()=>{
            if(this.s < 1){
              this.st = '发送验证码'
              clearInterval(timer)
              return
            }
            this.s--
            this.st = this.s + 'S后重试'
          },1000)
        })
      },
      submit(){
        if(!this.phone){
          this.$toast('请输入手机号')
          return
        }
        if(!this.phone){
          this.$toast('请输入验证码')
          return
        }
        let params = {
          phone:this.phone,
          uid:this.uid,
          smsCode:this.code
        }
        this.loading.submit = true
        this.$apis.login.yaoqPhoneRegistered(params).then(res=>{
          this.loading.submit = false
          this.$toast('注册成功')
          this.setUserInfo(res.data)
          uni.reLaunch({
            url:"/pages/index/index/index"
          })
        })
      }
    }
  }
</script>
 
<style lang="scss" scoped>
.content{
  padding: 40rpx 59rpx;
  .input{
    height: 110rpx;
    border-bottom: 1rpx solid #D9D9D9;
    display: flex;
    align-items: center;
    .input-phone{
      height: 100%;
      padding-left: 4rpx;
      flex: 1;
    }
    .sendCode{
      width: 180rpx;
      background-color: #FF2729;
      color: #fff;
      border-radius: 0;
      font-size: 24rpx;
      text-align: center;
      height: 80rpx;
      border-radius: 18rpx;
      &.disabled{
        background-color: #FFD3D3;
      }
    }
  }
  .submit {
    width: 635rpx;
    height: 96rpx;
    background: #FFFFFF;
    border-radius: 58rpx;
    opacity: 0.8;
    background-color: #FF2729;
    font-weight: 700;
    font-size: 35rpx;
    color: #FFFFFF;
    line-height: 48rpx;
    margin-top: 78rpx;
    &.disabled{
      background-color: #FFD3D3;
    }
  }
}
</style>