var $url="/register",$urlCaptcha="/register/captcha",$urlCaptchaCheck="/register/captcha/actions/check",$urlSendSms="/register/actions/sendSms",$urlVerifyMobile="/register/actions/verifyMobile",data=utils.init({returnUrl:decodeURIComponent(utils.getQueryString("returnUrl")),isSmsEnabled:null,isUserVerifyMobile:null,isUserRegistrationMobile:null,isUserRegistrationEmail:null,isUserRegistrationGroup:null,isHomeAgreement:null,homeAgreementHtml:null,styles:null,groups:null,isAgreement:!1,captchaToken:null,captchaUrl:null,countdown:0,form:{mobile:"",code:"",captchaValue:"",groupId:0}}),methods={insertText:function(t,i,e){this.form[utils.getCountName(t)]<i&&(this.form[utils.getCountName(t)]=i),this.form[utils.getExtendName(t,i)]=e,this.form=_.assign({},this.form)},apiGet:function(){var t=this;utils.loading(this,!0),$api.get($url).then(function(i){var e=i.data;t.isSmsEnabled=e.isSmsEnabled,t.isUserVerifyMobile=e.isUserVerifyMobile,t.isUserRegistrationMobile=e.isUserRegistrationMobile,t.isUserRegistrationEmail=e.isUserRegistrationEmail,t.isUserRegistrationGroup=e.isUserRegistrationGroup,t.isHomeAgreement=e.isHomeAgreement,t.homeAgreementHtml=e.homeAgreementHtml,t.styles=e.styles;for(var o=0;o<e.styles.length;o++){var n=e.styles[o];t.form[utils.toCamelCase(n.attributeName)]=n.defaultValue}t.form=_.assign({},t.form),t.groups=e.groups,t.apiCaptchaReload()}).catch(function(t){utils.notifyError(t,{redirect:!0})}).then(function(){utils.loading(t,!1)})},apiSendSms:function(){var t=this;utils.loading(this,!0),$api.post($urlSendSms,{mobile:this.form.mobile}).then(function(i){i.data;utils.notifySuccess("验证码发送成功，10分钟内有效"),t.countdown=60;var e=setInterval(function(){t.countdown-=1,t.countdown<=0&&clearInterval(e)},1e3)}).catch(function(t){utils.notifyError(t)}).then(function(){utils.loading(t,!1)})},btnExtendAddClick:function(t){var i=this.form[utils.getCountName(t.attributeName)]+1;this.form[utils.getCountName(t.attributeName)]=i,this.form[utils.getExtendName(t.attributeName,i)]=""},btnExtendRemoveClick:function(t){var i=this.form[utils.getCountName(t.attributeName)]-1;this.form[utils.getCountName(t.attributeName)]=i,this.form[utils.getExtendName(t.attributeName,i)]=""},btnPreviewClick:function(t,i){var e=i?this.form[utils.getExtendName(t,i)]:this.form[t];window.open(e)},apiCaptchaReload:function(){var t=this;utils.loading(this,!0),$api.post($urlCaptcha).then(function(i){var e=i.data;t.captchaToken=e.value,t.form.captchaValue="",t.captchaUrl=$apiUrl+$urlCaptcha+"?token="+t.captchaToken}).catch(function(t){utils.notifyError(t)}).then(function(){utils.loading(t,!1)})},apiCheckCaptcha:function(){var t=this;utils.loading(this,!0),$api.post($urlCaptchaCheck,{token:this.captchaToken,value:this.form.captchaValue}).then(function(i){t.apiSubmit()}).catch(function(i){t.apiCaptchaReload(),utils.loading(t,!1),utils.notifyError(i)})},apiVerifyMobile:function(){var t=this;utils.loading(this,!0),$api.post($urlVerifyMobile,{mobile:this.form.mobile,code:this.form.code}).then(function(i){t.apiSubmit()}).catch(function(i){utils.loading(t,!1),utils.notifyError(i)})},apiSubmit:function(){var t=this;utils.loading(this,!0);var i=_.assign({},this.form);delete i.captchaValue,delete i.confirmPassword,$api.post($url,i).then(function(i){i.data.value?utils.alertSuccess({title:"恭喜，账号注册成功",button:"进入登录页",callback:function(){location.href=utils.getRootUrl("login",{returnUrl:t.returnUrl})}}):utils.alertSuccess({title:"账号注册成功，请等待管理员审核",button:"进入登录页",callback:function(){location.href=utils.getRootUrl("login",{returnUrl:t.returnUrl})}})}).catch(function(i){t.apiCaptchaReload(),utils.loading(t,!1),utils.notifyError(i)})},isMobile:function(t){return/^1[3|4|5|7|8][0-9]\d{8}$/.test(t)},btnSendSmsClick:function(){this.countdown>0||(this.form.mobile?this.isMobile(this.form.mobile)?this.apiSendSms():utils.notifyError("请输入有效的手机号码"):utils.notifyError("手机号码不能为空"))},btnRegisterClick:function(){var t=this;this.$refs.form.validate(function(i){i&&(t.isMobileCode?t.apiVerifyMobile():t.apiCheckCaptcha())})},btnLoginClick:function(){location.href=utils.getRootUrl("login")},validatePass:function(t,i,e){""===i?e(new Error("请再次输入密码")):i!==this.form.password?e(new Error("两次输入密码不一致!")):e()}},$vue=new Vue({el:"#main",data:data,methods:methods,computed:{isMobile:function(){return this.isUserVerifyMobile||this.isUserRegistrationMobile},isMobileCode:function(){return this.isUserVerifyMobile||this.isSmsEnabled&&this.isUserRegistrationMobile}},created:function(){this.apiGet()}});