define(["knockout"], function (ko) { return function (context) { var me = this; var countdown; var flag = false; me.oldMobile = ko.observable(""); me.verificationcode = ko.observable(""); me.oldMobile = userInfo.getMember().safeMobile; me.getValidateCode = function () { if (!flag) { util.sendAjax({ url: 'userCenter/sendVerificationCode/changeMobile/old', 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 < time < 60) { countdown = time; settime(); } else { countdown = 60; } } else { layer.msg("验证失败:" + json.rc + "
错误信息:" + json.msg); } } }); } function settime() { if (countdown == 0) { $("#verificationCode").removeClass(); $("#verificationCode").addClass("btn"); $("#verificationCode").attr("disabled", false); $("#verificationCode").val("重新发送验证码"); $("#oldMobile").attr("disabled", false); flag = false; } else { $("#oldMobile").attr("disabled", "disabled"); $("#verificationCode").attr("disabled", "disabled"); $("#verificationCode").addClass("time"); $("#verificationCode").val(countdown); flag = true; countdown-- setTimeout(function () { settime(); }, 1000) } } me.next = function () { if (util.isVal(me.verificationcode()) == "") { layer.msg("请填写验证码"); } else { var sendData = {}; sendData["key"] = me.verificationcode(); util.sendAjax({ url: 'userCenter/smsValidate/changeMobile/old', data: JSON.stringify(sendData), async: true, loadFlag: true, type: 'POST', cache: false, success: function (json) { if (json.rc == 0) { window.location.href = "#/accountsecurity/mobileChangeNew"; } else { layer.msg("验证码验证失败:" + json.rc + "错误信息:" + json.msg); } } }); } } $(function(){ me.getTime(); }) context.app.loading(false); } });