<div class="forgetPwdBox" style="display:none">
<div class="forTit">
<p>忘记密码</p>
<span id="closeBtn">x</span>
</div>
<div class="textPwd">
<div class="inputTel">
<input id="phone" name="phone" placeholder="请输入手机号" type="text"/>
</div>
<div class="inputverifity">
<input id="verifity" name="verifity" placeholder="请输入短信验证码" type="text"/>
</div>
<div id="curBtn">
<input type="button" id="btn" value="获取验证码">
</div>
<div class="errorInfo"></div>
<button id="check-btn" class="layui-btn">确定</button>
</div>
</div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.cookie.js"></script>
<script>
$(function(){
var verifityCode = "";
if($.cookie("total")!=undefined&&$.cookie("total")!='NaN'&&$.cookie("total")!='null'){//cookie存在倒计时
timekeeping();
}else{//cookie 没有倒计时
$('#btn').attr("disabled", false);
}
function timekeeping(){
//把按钮设置为不可以点击
$('#btn').attr("disabled", true);
var interval=setInterval(function(){//每秒读取一次cookie
//从cookie 中读取剩余倒计时
total=$.cookie("total");
//在发送按钮显示剩余倒计时
$('#btn').val('请等待'+total+'秒');
//把剩余总倒计时减掉1
total--;
if(total==0){//剩余倒计时为零,则显示 重新发送,可点击
//清除定时器
clearInterval(interval);
//删除cookie
total=$.cookie("total",total, { expires: -1 });
//显示重新发送
$('#btn').val('重新发送');
//把发送按钮设置为可点击
$('#btn').attr("disabled", false);
}else{//剩余倒计时不为零
//重新写入总倒计时
$.cookie("total",total);
}
},1000);
}
//绑定发送按钮
$('#btn').click(function(event) {
/* Act on the event */
// alert($("#btn").val());
//校验手机号码
var phone=$('#phone').val();
var pre=/^[1][358][0-9]{9}$/;
if(phone==''){
$(".errorInfo").html("手机号不能为空!");
$('#phone').focus();
return this;
}else{
var pre=/^[1][358][0-9]{9}$/;
if(!pre.test(phone)){
$(".errorInfo").html("手机号格式错误!");
$('#phone').focus();
return this;
}
}
$.ajax({
url: '/user/sendSms?mob=' + phone,
type: 'GET',
success:function(data){
if(data.code){
verifityCode = data.code;
}
}
})
.done(function(re) {
var str="发送短信验证码成功,请注意查看您的手机";
if(re.code == 404)
{
str="输入的手机账户不存在!";
}
// console.log(re);
if(re){
if(re.code == 404)
{
str="输入的手机账户不存在!";
}
else{
$.cookie("total",60);
timekeeping();
}
}else{
switch (re.result) {
case '-1':
str="没有该用户账户";
break;
case '-2':
str="接口密码不正确";
break;
case '-3':
str="短信数量不足";
break;
case '-11':
str="该用户被禁用";
break;
case '-14':
str="短信内出现非法字符";
break;
case '-4':
str="手机号格式不正确";
break;
case '-41':
str="手机号码为空";
break;
default:
str="发送验证码失败";
break;
}
}
$(".errorInfo").html(str);
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
$("#check-btn").click(function(){
var curVerifity = $("#verifity").val();
var phone = $('#phone').val();
if(curVerifity == "" || verifityCode == ""){
$(".errorInfo").html("请填写手机验证码!");
$('#verifity').focus();
return;
}
if(curVerifity == verifityCode){
$.ajax({
url: '/user/resetPassword?mob=' + phone,
type: 'GET',
success:function(data){
if(data.code == 200){
$(".errorInfo").html("密码初始化成功,请用初始密码进行登录!");
window.setTimeout(function(){
window.location.href = "/lougout"
}, 1500);
}
else{
$(".errorInfo").html("密码初始化失败!");
}
}
})
}
else{
$(".errorInfo").html("您填写的手机验证码有误!");
$('#verifity').focus();
}
})
$("#forgetPwd").click(function(){
$(".forgetPwdBox").fadeIn(500);
});
$("#closeBtn").click(function(){
$(".forgetPwdBox").fadeOut("fast");
});
})
</script>