<view class="col-gray m-left-30" bindtap="{{!is_send?'getCode':''}}">{{!is_send?'获取验证码':time+'s后尝试'}}</view>
is_send:false,//是否发送验证码
time:60,//时间
getCode(){
var reg_phone = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
if(!reg_phone.test(this.data.phone)){
//微信小程序的提示
wx.showToast({
title: '请输入正确格式的手机号',
icon:'none',
duration:2000
})
return;
}
if(!this.data.is_send){
wx.showToast({
title: '验证码发送成功',
icon: 'none'
})
this.setData({
is_send:true
})
if(this.data.time == 60){
var that = this;
var interval = setInterval(function(){
var t = that.data.time - 1;
if(t > 0){
that.setData({
time:t
})
}else{
clearInterval(interval);
that.setData({
time:60,
is_send:false
})
}
}, 1000);
}
}else{
wx.showToast({
title: '请'+this.data.time+'秒后再尝试!',
icon: 'none'
})
}
},
|