var app = new Vue({ el: '#app', data: { codeTime: 60, codeStatus: false, codeSubmitStatus: false, submitStatus: false, timeId: null, formData: { mobile: '', code: '', password: '', confirmPassword: '' } }, mounted: function () { var _this = this; $(document).on('keydown', function (event) { if (event.keyCode == 13) { _this.doSubmit(); } }) }, methods: { // 获取验证码 getCode: function () { var _this = this; if (_this.codeStatus || _this.codeSubmitStatus) { return false; } if(!_this.checkForm(0)){ return false; } _this.codeSubmitStatus = true; $.post('/weixin/code/send', {mobile: _this.formData.mobile, type: 2}, function (res) { _this.codeSubmitStatus = false; if (res.code == 'success') { _this.cutdown(); _this.codeStatus = true; $.toast(res.message, 'text'); } else { $.toast(res.message, 'text'); } }, "json"); }, // 倒计时 cutdown: function () { var _this = this; clearInterval(_this.timeId); _this.timeId = setInterval(function () { _this.codeTime--; if(_this.codeTime <=0){ _this.codeStatus = false; clearInterval(_this.timeId); } }, 1000); }, // 提交处理 doSubmit: function(){ var _this = this; if(_this.submitStatus){ return false; } if(!_this.checkForm(1)){ return false; } if(confirm('确定重置登录密码?')){ _this.submitStatus = true; $.showLoading("重置密码中..."); $.post('/weixin/login/doForget', _this.formData, function (res) { _this.submitStatus = false; $.hideLoading(); if (res.code == 'success') { $.showLoading(res.message); setTimeout(function(){ location.href = '/weixin/login/index'; }, 500); } else { $.toast(res.message, 'text'); } }, "json"); } }, // 验证表单 checkForm: function(type){ if (this.formData.mobile == '' || this.formData.mobile == null) { $.toast("请输入手机号码", 'text'); return false; } var patternMobile = /1[3-9][0-9]{9}/; if (!patternMobile.test(this.formData.mobile)) { $.toast("请输入正确的手机号码", 'text'); return false; } if(type == 1){ if(this.formData.code == '' || this.formData.code == null){ $.toast("请输入手机验证码", 'text'); return false; } var codePattern = /[0-9]{4,6}/; if(!codePattern.test(this.formData.code)){ $.toast("手机验证码格式不正确", 'text'); return false; } if(this.formData.password == '' || this.formData.password == null){ $.toast("请设置登录密码", 'text'); return false; } var passwordPattern = /^[0-9a-zA-Z][0-9a-zA-Z\_\!\@\#\$\%\^\&\*\(\)]{2,19}/; if(!passwordPattern.test(this.formData.password)){ $.toast("登录密码格式不正确", 'text'); return false; } if(this.formData.password != this.formData.confirmPassword){ $.toast("确认密码不正确", 'text'); return false; } } return true; } } })