var registerPage = new Vue({
    el: "#forGetPasswordPage",
    data: {
        title:'手机找回密码',
        loginLoading: false,
        showTabContentIndex:0,
        showClass:'',
        mobilCount:0,
        mobileCodeText:'获取验证码',
        mobilTime:null,
        isMobileDisabled:false,
        emailCount:0,
        emailCodeText:'获取验证码',
        emailTime:null,
        isEmailDisabled:false,
        isCodeModel:false,
        codeImagePath:'',
        codeImageToken:'',
        imageCode:'',
        phonePwd: {
            mobileOrEmail :'',
            activateCode : '',
            passWord : '',
            confirmPwd : '',
            status:1
        },
        emailPwd: {
            mobileOrEmail :'',
            activateCode : '',
            passWord : '',
            confirmPwd : '',
            status:2
        },
        rule:{
            name: '^[a-zA-Z\\u4e00-\\u9fa5]{2,}$',
            phone: '^\\d{6,12}$',
            code: '^\\d{6}$',
            emailCode: '^\\d{4}$',
            license: '^[a-zA-Z0-9_]{18}$',
            email: '^(([^<>()\\[\\]\\\\.,;:\\s@&quot;]+(\\.[^<>()\\[\\]\\\\.,;:\\s@&quot;]+)*)|(&quot;.+&quot;))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$',
            password: "^[^\\u4e00-\\u9fa5]{8,16}$"
        }
    },
    computed: {

    },
    methods: {
        findPhonePwd: function(){ //手机号找回密码
            var _self = this;
            var pass = verifyForm();
            if (_self.loginLoading) { return false; }
            if (!pass) {return false;}
            if(_self.phonePwd.confirmPwd!=_self.phonePwd.passWord){
                CAIMEI.dialog('两次密码输入不一致',false,function () {});
                return;
            }
            _self.loginLoading = true;
            UserApi.FindCompanyPwd(_self.phonePwd,function (response) {
                if(response.code === 0){
                    CAIMEI.Alert('成功找回密码！','去登录',true,function () {
                        _self.loginLoading = false;
                        window.location.href = '/login.html';
                    });
                } else {
                    CAIMEI.Alert(response.msg,'确定',false);
                    _self.loginLoading = false;
                }
            });
        },
        findEmailPwd: function(){ //邮箱找回密码
            var _self = this;
            var pass = verifyForm();
            if (_self.loginLoading) { return false; }
            if (!pass) {return false;}
            if(_self.emailPwd.confirmPwd!=_self.emailPwd.passWord){
                CAIMEI.dialog('两次密码输入不一致',false,function () {});
                return;
            }
            _self.loginLoading = true;
            UserApi.FindCompanyPwd(_self.emailPwd,function (response) {
                if(response.code === 0){
                    CAIMEI.Alert('成功找回密码！','去登录',true,function () {
                        _self.loginLoading = false;
                        window.location.href = '/login.html';
                    });
                } else {
                    CAIMEI.Alert(response.msg,'确定',false);
                    _self.loginLoading = false;
                }
            });
        },
        getMobileImage:function() {//获取图形验证码
            var _self = this;
            var pass = verifyCheack('.massageBtn');
            if (_self.isMobileDisabled) { return false; }
            this.$nextTick(function() {
                if (!pass) {
                    return false;
                }
                PublicApi.getImgVerifyCode({platformType: 0},function(response){
                    if(response.code == 0){
                        _self.imageCode = '';
                        _self.codeImagePath = response.data.baseImage;
                        _self.codeImageToken = response.data.token;
                        _self.isCodeModel = true;
                    }else{
                        CAIMEI.Alert(response.msg,'确定',false);
                    }
                })
            });
        },
        getMobileCodeFn:function(){//机构注册获取注册短信验证码
            var _self = this;
            var params = {
                    mobile:_self.phonePwd.mobileOrEmail,
                    imgCode:_self.imageCode,
                    token:_self.codeImageToken,
                    activateCodeType:1,
                    platformType:0
                };
            _self.isMobileDisabled = true;
            UserApi.getRegisterMobileCode(params,function (response) {
                if(response.code == 0){
                    _self.isCodeModel = false;
                    CAIMEI.dialog('验证短信已发送',false,function () {});
                    var TIME_COUNT = 60;
                    if (!_self.mobilTime) {
                        _self.mobilCount = TIME_COUNT;
                        _self.isMobileDisabled = true;
                        _self.mobilTime = setInterval(function(){
                        if (_self.mobilCount > 1 && _self.mobilCount <= TIME_COUNT) {
                            _self.mobilCount--;
                            _self.mobileCodeText = _self.mobilCount +'s重新发送';
                        } else {
                            _self.isMobileDisabled = false;
                            clearInterval(_self.mobilTime);
                            _self.mobilTime = null;
                            _self.mobileCodeText = '获取验证码';
                        }
                    },1000)
                    }
                }else{
                    CAIMEI.Alert(response.msg,'确定',false);
                    _self.isMobileDisabled = false;
                    _self.isCodeModel = false;
                }
            })
        },
        getEmailCodeFn:function(){//找回密码获取邮箱验证码
            var _self = this;
            var pass = verifyCheack('.emailMsgBtn');
            if (_self.isMobileDisabled) { return false; }
            this.$nextTick(function() {
                if (!pass) {
                    return false;
                }
                var params = {
                    email: _self.emailPwd.mobileOrEmail,
                    status: 3
                };
                _self.isEmailDisabled = true;
                PublicApi.getEmailSMScode(params, function (response) {
                    if (response.code == 0) {
                        CAIMEI.dialog('验证短信已发送', false, function () {
                        });
                        var TIME_COUNT = 60;
                        if (!_self.emailTime) {
                            _self.emailCount = TIME_COUNT;
                            _self.isEmailDisabled = true;
                            _self.emailTime = setInterval(function () {
                                if (_self.emailCount > 1 && _self.emailCount <= TIME_COUNT) {
                                    _self.emailCount--;
                                    _self.emailCodeText = _self.emailCount + 's重新发送';
                                } else {
                                    _self.isEmailDisabled = false;
                                    clearInterval(_self.emailTime);
                                    _self.emailTime = null;
                                    _self.emailCodeText = '获取验证码';
                                }
                            }, 1000)
                        }
                    } else {
                        CAIMEI.Alert(response.msg, '确定', false);
                        _self.isEmailDisabled = false;
                    }
                })
            })
        },
        refreshCodeImage:function(){
            this.getMobileImage()
        },
        closeCodeModel:function(){
            this.isCodeModel = false;
        },
        showPassword: function(event) {//密码
            var el = event.currentTarget;
            var pwdEle = $(el).siblings('input');
            if(pwdEle.attr('type') === 'password') {
                $(el).addClass('on');
                pwdEle.attr('type','text');
            } else {
                $(el).removeClass('on');
                pwdEle.attr('type','password');
            }
        },
        blurHandle: function(event) { // 失去焦点校验
            var el = event.currentTarget;
            verifyHandle(el);
        },
        checkedEmailFn:function () {
            this.title = "邮箱找回密码";
            this.showTabContentIndex = 1;
        },
        checkedPhoneFn:function () {
            this.title = "手机找回密码";
            this.showTabContentIndex = 0;
        }
    },
    created: function () {

    },
    mounted: function () {
        var _self = this;
    }
});
