<view class="apply-form">
<view class="apply-lt"> 手機號 </view>
<view class="apply-phone">
<input type="text" :value="info.telephone" name="telephone" placeholder="請輸入手機號" placeholder-style="color:#bebebe" @input="formphone" maxlength="11" />
</view>
</view>
<view class="apply-form">
<view class="apply-lt"> 驗證碼 </view>
<view class="apply-code">
<input type="number" value="" name="sms_code" placeholder="請輸入驗證碼" placeholder-style="color:#bebebe" maxlength="6" />
<view class="apply-code-btn">
<button type="default" v-if="getCode" @tap="sendMobileCode">獲取</button>
<button style="color: #969696;background-color: #eee;" type="default acv-code-btn" v-else disabled="true">{{ sec + 's' }}</button>
</view>
</view>
</view>
<script>
var tools = require('utils/tools.js');
export default {
data() {
return {
// 驗證碼
sec: '60',
getCode: true,
mobileNum:''
}
},
methods: {
// 獲取手機號
formphone(e) {
this.mobileNum = e.detail.value;
console.log(this.mobileNum)
},
//發送短信驗證碼
sendMobileCode() {
var mobileNum = this.mobileNum;
if (mobileNum.length == 0) {
uni.showToast({
title: '請輸入手機號',
icon: 'none'
});
return;
}
var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
if (!myreg.test(mobileNum) || mobileNum.length !== 11) {
uni.showToast({
title: '請輸入正確格式的手機號',
icon: 'none'
});
return;
}
tools.ajax.post(
'', {
mobile: mobileNum,
},
(err, res) => {
if (err) {
uni.showToast({
title: '接口異常',
icon: 'none'
});
return;
}
if (res.data.code == 1) {
uni.showToast({
title: res.data.msg
});
this.get_code_time();
} else {
uni.showToast({
title: res.data.msg,
icon: 'none'
});
}
}
);
},
// 發送短信驗證碼60秒倒計時
get_code_time() {
this.getCode = false;
this.get_code_interval = setInterval(() => {
--this.sec;
}, 1000);
setTimeout(() => {
clearInterval(this.get_code_interval);
this.getCode = true;
this.sec = '60';
}, 60000);
},
},
}
</script>
.apply-form {
display: flex;
justify-content: space-between;
width: calc(100% - 60rpx);
margin: auto;
padding: 25rpx 30rpx;
border-bottom: solid 0.5px #dfdfdf;
align-items: center;
}
.apply-lt {
font-size: 30rpx;
}
.apply-phone input {
text-align: right;
color: #333333;
font-size: 30rpx;
}
.apply-code {
display: flex;
justify-content: flex-end;
align-items: center;
}
.apply-code input {
text-align: right;
color: #333333;
font-size: 30rpx;
margin-right: 30rpx;
}
.apply-code-btn button {
width: 120rpx;
height: 60rpx;
line-height: 60rpx;
background: #FF7E30;
color: #FFFFFF;
font-size: 24rpx;
}