代码案例1
<button :disabled="disabled" class="getCode" :style="{'color':getCodeBtnColor}" @click.stop="getCode()">{{getCodeText}}
</button>
data() {
return {
getCodeText: '获取验证码',
getCodeBtnColor: "#ffffff",
getCodeisWaiting: false,
disabled:false
}
},
Timer() {},
getCode() {
this.disabled = true
this.getCodeText = "发送中..."
this.getCodeisWaiting = true;
this.getCodeBtnColor = "rgba(255,255,255,0.5)"
setTimeout(() => {
uni.showToast({
title: '验证码已发送',
icon: "none"
});
this.setTimer();
}, 1000)
},
setTimer() {
let holdTime = 60;
this.getCodeText = "重新获取(60)"
this.Timer = setInterval(() => {
if (holdTime <= 0) {
this.disabled = false
this.getCodeisWaiting = false;
this.getCodeBtnColor = "#ffffff";
this.getCodeText = "获取验证码"
clearInterval(this.Timer);
return;
}
this.getCodeText = "重新获取(" + holdTime + ")"
holdTime--;
}, 1000)
}
代码案例2
<input type="text" class="inputCode" placeholder="请输入验证码" v-model="captcha">
<button class="getCode" @click="getCode" :disabled="disabled">{{getCodeText}}</button>
<script>
export default {
data() {
return {
inputMoney: '',
captcha: '',
getCodeText: '获取验证码',
disabled: false,
}
},
onLoad() {
},
methods: {
Timer() {},
getCode() {
this.disabled = true
this.getCodeText = "发送中..."
setTimeout(() => {
this.$common.msg('验证码已发送')
this.codeMsg()
this.setTimer();
}, 1000)
},
setTimer() {
let holdTime = 60;
this.getCodeText = "重新获取(60)"
this.Timer = setInterval(() => {
if (holdTime <= 0) {
this.disabled = false
this.getCodeText = "获取验证码"
clearInterval(this.Timer);
return;
}
this.getCodeText = "重新获取(" + holdTime + ")"
holdTime--;
}, 1000)
},
getcodeDefault(){
clearInterval(this.Timer);
this.getCodeText = '获取验证码'
this.disabled = false
},
codeMsg() {
this.$common.request('post', '/agent/login/send', {
mobile: this.infos.phone,
event: 'withdrawal'
}).then(res => {
if (res.code == 1) {
console.log(res);
}
})
},
nowWithdrawal() {
if (!uni.$u.test.amount(this.inputMoney)) {
this.$common.msg('请输入数字金额')
return;
}
if (!this.inputMoney) {
this.$common.msg('请输入提现金额')
return;
}
if (this.inputMoney <= 0) {
this.$common.msg('请输入正确的提现金额')
return;
}
if (parseFloat(this.inputMoney) > parseFloat(this.infos.balance)) {
this.$common.msg('提现金额不能大于可提现金额')
return;
}
if (uni.$u.test.isEmpty(this.captcha)) {
this.$common.msg('请输入验证码')
return;
}
this.$common.request('post', '/agent/Withdraws/withdraws', {
money: this.inputMoney,
mobile: this.infos.phone,
captcha: this.captcha,
}).then(res => {
if (res.code == 1) {
this.getData()
this.inputMoney = ''
this.captcha = ''
this.getcodeDefault()
}
})
},
}
}
</script>