var func = { wait:60, timeFlag:true, statusFlag:true, //1.获取验证码 getRandCode:function(){ $(document).on('click','#get_code',function(){ var mobileVal = $('#bind_mobile').val(); if(/^1[34578]\d{9}$/.test(mobileVal)){ if(func.timeFlag){ func.time($(this)); }else{ return false; } //发送验证码 func.sendRandCode(mobileVal); }else{ $.toptip('亲!手机号不正确', 3000, 'error'); //设置显示时间 } }); }, //2.倒计时 time:function(o){ if (func.wait == 0) { o.attr("disabled",false); o.html("获取验证码"); func.timeFlag = true; func.wait = 60; } else { func.wait--; func.timeFlag = false; o.attr("disabled", true); o.html("已发送" + func.wait + "S"); setTimeout(function() { func.time(o) }, 1000) } }, //3.发送验证码 sendRandCode:function(phone){ $.ajax({ url:mUrl.sendRandCode, async:false, type:'POST', dataType:'json', data:{"phone_number":phone}, success:function(data){ //alert(dataObj.user); } }); }, //绑定用户手机号 bindingPhone:function(){ $(document).on('click','#binging_btn',function(){ var mobileVal = $('#bind_mobile').val(); var appid = $("#appid").val(); var randCode = $('#verification_code').val(); if(appid == null || appid == ""){ $.alert("亲!绑定失败,请重新尝试绑定"); return false; } if(mobileVal == null || mobileVal ==''){ $.toptip('亲!请输入手机号', 3000, 'error'); //设置显示时间 return false; } if(!(/^1[34578]\d{9}$/.test(mobileVal))){ $.toptip('亲!手机号不正确', 3000, 'error'); //设置显示时间 return false; } if(randCode == null || randCode ==""){ $.toptip('亲!请输入验证码', 3000, 'error'); //设置显示时间 return false; } var jsonInfo={}; jsonInfo.phone=mobileVal; jsonInfo.appid=appid; jsonInfo.randCode=randCode; if(/^1[34578]\d{9}$/.test(mobileVal)){ jsutil.defaultReq( mUrl.bindingPhone, jsonInfo, function(data){ if("1004" ==data.code ){ $.alert("亲!验证码错误,重新验证!"); return false; }else if("8888" !=data.code){ $.alert("亲!绑定失败,请重新尝试绑定"); return false; }else{ //$.toptip('绑定成功', 1000, 'success'); //设置显示时间 $.alert('亲,您已绑定成功!','成功', function() { targetUrl=$("#targetUrl").val(); if(targetUrl == null ||targetUrl.length<3){ //如果为空,默认跳转到月卡、年卡界面 targetUrl = mUrl.toParkInfoListView; } window.location.href=targetUrl; }); } } ); }else{ $.toptip('亲!手机号不正确', 3000, 'error'); //设置显示时间 } }); } }; $(function(){ func.getRandCode(); func.bindingPhone(); });