var registerPage = new Vue({
    el: "#registerPage",
    data: {
        advisoryStatus: false,
        advisory:{
            name: '',
            phone: ''
        },
        clubUser: {
            name:'',
            phone:'',
            code:'',
            password:'',
            password2:''
        },
        supplierUser: {
            phone:'',
            code:'',
            password:'',
            password2:'',
            shopName:'',
            name:'',
            email:'',
            shopAbbr:'',
            firstShopType:'2',
            secondShopType: '',
            mainPros: [],
            businessLicense:'',
            businessLicenseImage:''
        },
        mainPros: ['产品','仪器','服务','整形'],
        mainProEdit: '',
        rule:{
            name: '^[a-zA-Z\\u4e00-\\u9fa5]{2,}$',
            phone: '^\\d{6,12}$',
            code: '^\\d{6}$',
            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: {
        mainProAdd: function(){
            if (this.mainProEdit.length>0) {
                if (this.mainPros.indexOf(this.mainProEdit)<0){
                    this.mainPros.push(this.mainProEdit)
                }
            }
        },
        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);
        },
        /**
         * 机构入驻咨询提交
         */
        postAdvisory: function(){
            var _self = this;
            $('.advisoryInfo').find("[needverify]:visible").each(function (index, ele) {
                if (!$(ele).siblings('.checked').hasClass("show")) {
                    verifyHandle(ele);
                }
            });
            var pass = ($('.errTips.show:visible').length === 0);
            if (this.advisoryStatus) { return false; }
            this.$nextTick(function(){
                if (!pass) { return false; }
                _self.advisoryStatus = true;
                $.post(spiServer + '/club/advisory',{
                    name: _self.advisory.name,
                    mobile: _self.advisory.phone
                }).done(function(res){
                    _self.advisoryStatus = false;
                    if(res.code === 0){
                        alertInfo("您的信息已提交成功,采美工作人员会第一时间联系您");
                    } else {
                        alertInfo(res.msg);
                    }
                }).fail(function(err){
                    console.log(err);
                    alertInfo('提交失败，请稍后重试！');
                    _self.advisoryStatus = false;
                });
            });
        },
        /**
         * 机构注册提交
         */
        clubRegister: function(){
            alertInfo('机构注册');
            console.log(JSON.stringify(this.clubUser));
        },
        /**
         * 供应商注册提交
         */
        supplierRegister: function(){
            alertInfo('供应商注册');
            console.log(JSON.stringify(this.supplierUser));
        }

    },
    created: function () {

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