define(["knockout"],function(ko){ return function(context){ var me = this; var countdown; var flag = false; me.newMobile = ko.observable(""); me.verificationCode = ko.observable(""); me.getValidateCode = function(){ if(!util.isMobile(me.newMobile())){ $("#vaildPhone").html("手机号码不可用!"); return false; } else { if(!flag){ $("#vaildPhone").html("手机号格式正确!"); util.sendAjax({ url:'userCenter/sendVerificationCode/changeMobile/new?mobile='+me.newMobile(), async:true, loadFlag:true, type:'GET', cache:false, success:function(json){ if(json.rc==0){ countdown = 60; settime(); }else{ layer.msg("获取验证码失败:"+json.rc+"
错误信息:"+json.msg); } } }); } } } me.getTime = function(){ var time = 60; util.sendAjax({ url:'open/getCacheTime', async:false, loadFlag:true, type:'GET', cache:false, success:function(json){ if(json.rc==0){ time = json.data.time; if(0错误信息:"+json.msg); } } }); } function settime(){ if(countdown==0){ $("#verificationCodeNew").removeClass(); $("#verificationCodeNew").addClass("btn"); $("#verificationCodeNew").attr("disabled",false); $("#verificationCodeNew").val("重新发送验证码"); $("#newMobile").attr("disabled",false); flag = false; }else{ $("#newMobile").attr("disabled","disabled"); $("#verificationCodeNew").attr("disabled","disabled"); $("#verificationCodeNew").addClass("time"); $("#verificationCodeNew").val(countdown); flag = true; countdown-- setTimeout(function() { settime(); },1000) } } me.next = function(){ if(util.isVal(me.verificationCode())==""){ layer.msg("请填写验证码"); } else { var sendData = {}; sendData["mobile"] = me.newMobile(); sendData["key"] = me.verificationCode(); util.sendAjax({ url:'userCenter/smsValidate/changeMobile/new', data:JSON.stringify(sendData), async:true, loadFlag:true, type:'POST', cache:false, success:function(json){ if(json.rc==0){ layer.msg("换绑安全手机号码成功!"); setTimeout(function () { window.location.href="#/personal/index"; },1000); }else{ layer.msg("验证码验证失败:"+json.rc+"错误信息:"+json.msg); } } }); } } $(function(){ me.getTime(); }) context.app.loading(false); } });