(function () {var position, /* 定时器定位*/ type; /* 类型 send 发送验证码*/function CatRegister(param1, param2 = '') {position = param1;type = param2;this.initialize();}CatRegister.prototype = {/** 初始化 */ initialize: function () {if (this.getTimeOut() > 0) {this.countDown();}this.sendCode();}, /** 发送验证码 */ sendCode: function () {var _this = this;$('.send-message').click(function () {var mobile = $('#mobile').val();var ali_verify = $('#verify').val(); /* 滑动验证码*/if (!mobile) {layer.msg('手机号未填写');} else {var time = _this.getTimeOut();if (time > 0) {layer.msg('请等' + time + 's后再尝试');return false;}if (!mobile) {layer.msg('手机号不能为空');return false;}if (!ali_verify) {layer.msg('请先滑动验证');return false;}$.post("sendSms", {mobile: mobile, type: type, ali_verify: ali_verify}, function (result) {if (result.code != 200) { /* 系统错误*/_this.setTimeOut(position);_this.countDown();layer.msg(result.msg);} else { /* 发送成功*/_this.setTimeOut(position);_this.countDown();}}, 'json');}});}, /** 计时器 */ countDown: function () {var time = this.getTimeOut();time = time > 0 ? time : 60;var index = setInterval(function () {if (time <= 0) { /* 倒计时结束*/$('.send-message').text('获取验证码');clearInterval(index);} else {time--;$('.send-message').text(time + 's');}}, 1000)}, /** 设置计时时间 */ setTimeOut: function () {var time = parseInt(new Date().getTime() / 1000); /* 当前时间*/window.localStorage.setItem(position, time);}, /** 获取计时时间 @returns {number} */ getTimeOut: function () {var data = window.localStorage.getItem(position); /* 设置时间*/var time = parseInt(new Date().getTime() / 1000); /* 当前时间*/var timeout = 60 - (time - data);if (data && timeout > 0 && timeout <= 60) {return timeout;} else {return 0;}}, /** 获取图形验证码 @param mobile */ get_captcha: function (mobile) {$.get('/api/mobile_verify_code_get_request/get_captcha', {device: mobile}, function (result) {if (result.code == 1) {$('#captchaImg').html('');}}, 'json');}};window.CatRegister = CatRegister;})();