;
var informationPage = new Vue({
    el: "#informationPage",
    data: {
        isRequset:true,
        loginLoading: false,
        showTabContentIndex:1,
        showSupplierConfirm:true,
        advisoryStatus: false,
        userId:0,
        showClass:'',
        mobilCount:0,
        mobileCodeText:'获取验证码',
        mobilTime:null,
        isMobileDisabled:false,
        isCodeModel:false,
        codeImagePath:'https://dss2.bdstatic.com/8_V1bjqh_Q23odCf/pacific/1819816496.jpg',
        codeImageToken:'',
        imageCode:'',
        bindMobile:'',
        userIdentity:'',
        clubUpgradeUser: {
            userID:0,
            clubID:0,					//会所ID
            name:'',                    //机构名称
            linkMan1:'',                //联系人
            contractEmail1:'',          //邮箱
            sname:'',                   //机构简称
            provinceID:0,               //省ID
            cityID:0,                   //市ID
            townID:0,                   //区ID
            address:'',                 //地址
            socialCreditCode:'',        //营业执照编号
            businessLicenseImage:'',    //营业执照图片
            headpic:'',                 //门头照
            firstClubType:'', //机构类型分类 医美:0和生美:1
            secondClubType:'',		//机构类型二级分类 诊所:1,门诊:2,医院:3
            department:'',			//科室
            medicalPracticeLicenseImg:'',//资质图片
            isAgreed:0,				//是否勾选协议
            mainpro:[],             //主营内容
            fax:'',                 //传真
            contractPhone:'',       //固定电话
            info : ''               //公司简介
        },
        userMainPros:[],
        formData:new FormData(),
        isAgreed:0,
        isAgree:false,
        isShowAgree:false,
        mentuzCampNullList:[
            {value:'1',name:'整形'},
            {value:'2',name:'轻医美'},
            {value:'3',name:'皮肤科'},
        ],
        medicaCampNullList: [
            {name:'美容'},
            {name:'美体'},
            {name:'美发'},
            {name:'皮肤管理'},
            {name:'光电'},
            {name:'综合类'},
            {name:'中医养生'},
            {name:'spa'},
        ],
        mainPros: ['产品','仪器','服务','整形'],
        mainProEdit: '',
        ProvinceList:[],
        cityArray:[],
        townArray:[],
        addressfrom: {
            provinceID: '',//省id
            cityID: '',//市ID
            townID: '',//地区ID
            name:'请选择'
        },
        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: {
        infoInformationData:function(){
            var _self = this;
            UserApi.GetApplicationData({userID:_self.userId},function (response) {
                if(response.code == 0){
                    var data = response.data;
                    _self.isRequset = false;
                    _self.clubUpgradeUser = data.club;
                    _self.bindMobile = data.user.bindMobile;
                    _self.userIdentity = data.user.userIdentity;
                    _self.addressfrom.clubID = data.user.clubID;
                    _self.addressfrom.userID = data.user.userID;
                    _self.addressfrom.contractEmail1 = data.user.contractEmail1;
                    _self.addressfrom.provinceID = data.club.provinceID;
                    _self.addressfrom.cityID = data.club.cityID;
                    _self.addressfrom.townID = data.club.townID;
                    _self.userMainPros = _self.setNewMainpro(data.club.mainpro);
                    console.log(_self.userMainPros);
                    _self.GetProvinceFn();
                    _self.GetCtiyFn();
                    _self.GetTownFn();
                }else{
                    CAIMEI.Alert(response.msg,'确定',false);
                }
            })
        },
        clunConfirmFn:function() {//保存提交
            var _self = this;
            var params ={};
            var pass = verifyForm();
            if (_self.loginLoading) { return false; }
            this.$nextTick(function() {
                if (!pass) {return false;}
                if(_self.clubUpgradeUser.businessLicenseImage == ''){
                    $('#formbusinessLicenseImage').parent().addClass("error").find('.checked').removeClass("show");
                    $('#formbusinessLicenseImage').siblings('.errTips').text('请上传营业执照图片').addClass("show");
                    return  false;
                }
                if(_self.clubUpgradeUser.firstClubType === 0){
                    $('#firstClubType').parent().addClass("error");
                    $('#firstClubType').siblings('.errTips').text('请选择机构类型').addClass("show");
                    return  false;
                }else{
                    $('#firstClubType').parent().removeClass("error");
                    $('#firstClubType').siblings('.errTips').removeClass("show");
                }
                _self.clubUpgradeUser.mainPros = _self.userMainPros.join("/");
                if(_self.userIdentity === 4){
                    params = {
                        userID:_self.clubUpgradeUser.userID,
                        clubID:_self.clubUpgradeUser.clubID,					//会所ID
                        linkMan1:_self.clubUpgradeUser.linkMan1,
                        fax:_self.clubUpgradeUser.fax,
                        contractPhone:_self.clubUpgradeUser.contractPhone,
                        info : _self.clubUpgradeUser.info,
                    }
                }else{
                    params 	= {
                        userID:_self.clubUpgradeUser.userID,
                        clubID:_self.clubUpgradeUser.clubID,				//会所ID
                        name:_self.clubUpgradeUser.name,
                        linkMan1:_self.clubUpgradeUser.linkMan1,
                        sname:_self.clubUpgradeUser.sname,
                        contractEmail1:_self.clubUpgradeUser.contractEmail1,
                        provinceID:_self.clubUpgradeUser.provinceID,
                        cityID:_self.clubUpgradeUser.cityID,
                        townID:_self.clubUpgradeUser.townID,
                        address:_self.clubUpgradeUser.address,
                        socialCreditCode:_self.clubUpgradeUser.socialCreditCode,
                        businessLicenseImage:_self.clubUpgradeUser.businessLicenseImage,
                        headpic:_self.clubUpgradeUser.headpic,
                        firstClubType:_self.clubUpgradeUser.firstClubType, //机构类型分类 医美:0和生美:1
                        secondClubType:_self.clubUpgradeUser.secondClubType,	//机构类型二级分类 诊所:1,门诊:2,医院:3
                        department:_self.clubUpgradeUser.department,				//科室
                        medicalPracticeLicenseImg:_self.clubUpgradeUser.medicalPracticeLicenseImg,//资质图片
                        mainpro:_self.clubUpgradeUser.mainpro,
                        fax:_self.clubUpgradeUser.fax,
                        contractPhone:_self.clubUpgradeUser.contractPhone,
                        info : _self.clubUpgradeUser.info,
                    }
                }
                _self.loginLoading = true;
                UserApi.UpdateModifiedData(params,function (response) {
                    if(response.code === 0){
                        CAIMEI.dialog('修改成功',true,function () {
                            window.location.href='/user/dashboard.html';
                            _self.loginLoading = false;
                        });
                    } else {
                        CAIMEI.Alert(response.msg,'确定',false);
                        _self.loginLoading = false;
                    }
                });
            });
        },
        setNewMainpro:function(arr){//回显处理主营内容
            var newArr = [];
            arr.split('/').forEach(function(item){
                newArr.push(item);
            });
            return newArr
        },
        mainProAdd: function(){//添加主营
            var _self = this;
            if (_self.mainProEdit.length>0) {
                if (_self.mainPros.indexOf(_self.mainProEdit)<0){
                    var obj = {name:_self.mainProEdit};
                    if(_self.clubUpgradeUser.firstClubType === '0'){
                        if(_self.checkedArray(_self.mainProEdit,_self.mentuzCampNullList)){
                            CAIMEI.dialog('主营内容已存在!',false);
                        }else {
                            _self.mentuzCampNullList.push(obj);
                        }
                    }else{
                        if(_self.checkedArray(_self.mainProEdit,_self.medicaCampNullList)){
                            CAIMEI.dialog('主营内容已存在!',false);
                        }else {
                            _self.medicaCampNullList.push(obj);
                        }
                    }
                }
            }
        },
        checkedArray:function(content,arr){//判断主营内容是否已存在
            for(var i in arr){
                if(arr[i].name == content){
                    return true;
                }
            }
            return false;
        },
        blurHandle: function(event) { // 失去焦点校验
            var el = event.currentTarget;
            verifyHandle(el);
        },
        uploadBusinessLicenseImageFn: function(event){//上传营业执照
            var _self = this;
            var inputDOM = _self.$refs.businessLicenseImage;
            var file = inputDOM.files;
            _self.formData.append('file', file[0]);
            PublicApi.uploadimg(_self.formData,function(response){
                _self.clubUpgradeUser.businessLicenseImage = response.data;
                event.target.value = '';
            });
        },
        uploadMentuzImageFn: function(event){//上传营业执照
            var _self = this;
            var inputDOM = _self.$refs.businessMentuImage;
            var file = inputDOM.files;
            _self.formData.append('file', file[0]);
            PublicApi.uploadimg(_self.formData,function(response){
                _self.clubUpgradeUser.headpic = response.data;
                event.target.value = '';
            });
        },
        uploadMedicaImageFn: function(event){//上传资质证书
            var _self = this;
            var inputDOM = _self.$refs.businessMedicaImage;
            var file = inputDOM.files;
            _self.formData.append('file', file[0]);
            PublicApi.uploadimg(_self.formData,function(response){
                _self.clubUpgradeUser.medicalPracticeLicenseImg = response.data;
                event.target.value = '';
            });
        },
        deleteBusinessImage:function(){//清楚营业执照图片
            this.clubUpgradeUser.businessLicenseImage = '';
        },
        deleteMentuzImage:function(){//清楚门头照图片
            this.clubUpgradeUser.headpic = '';
        },
        deleteMedicalImage:function(){//清楚资质照图片
            this.clubUpgradeUser.medicalPracticeLicenseImg = '';
        },
        checkedIsAgreeFn:function () {
            var _self = this;
            _self.isAgree = !_self.isAgree;
            if (_self.isAgree){
                _self.isShowAgree = false;
                _self.isAgreed = 1;
            }else{
                _self.isShowAgree = true;
                _self.isAgreed = 0;
            }
        },
        GetProvinceFn: function(){//获取全部省份
            var _self = this;
            PublicApi.GetProvince({},function(response){
                if(response.code == 0){
                    _self.ProvinceList =response.data;
                }else{
                    CAIMEI.Alert(response.msg,'确定',false);
                }
            })
        },
        ChangeProvince:function () {//选择省份
            var _self = this;
            _self.addressfrom.provinceID = event.target.value;
            _self.clubUpgradeUser.provinceID = event.target.value;
            if(_self.addressfrom.provinceID==''){//省为请选择时市区初始化
                _self.cityArray=[];
                _self.townArray=[];
                _self.clubUpgradeUser.townID=''
            }else {
                _self.GetCtiyFn();
            }
        },
        ChangeGetcity:function(event){//加载市
            var _self = this;
            _self.addressfrom.cityID = event.target.value;
            _self.clubUpgradeUser.cityID = event.target.value;
            if(_self.addressfrom.cityID==''){
                _self.townArray=[];
            }else {
                _self.GetTownFn();
            }
        },
        ChangeGetcTown:function(event){//选择地区
            var _self = this;
            _self.clubUpgradeUser.townID = event.target.value;
        },
        GetProvinceFn: function(){//获取全部省份
            var _self = this;
            PublicApi.GetProvince({},function(response){
                if(response.code == 0){
                    _self.ProvinceList =response.data;
                }else{
                    CAIMEI.Alert(response.msg,'确定',false);
                }
            })
        },
        GetCtiyFn: function(){//获取市
            var _self = this;
            PublicApi.GetCity({ provinceId: _self.addressfrom.provinceID },function(response){
                if(response.code == 0 ){
                    _self.cityArray = response.data;
                }else{
                    CAIMEI.Alert(response.msg,'确定',false);
                }
            })
        },
        GetTownFn: function(){//获取区
            var _self = this;
            PublicApi.GetTown({ cityId: _self.addressfrom.cityID },function(response){
                if(response.code == 0 ){
                    _self.townArray = response.data;
                }else{
                    CAIMEI.Alert(response.msg,'确定',false);
                }
            })
        },
        showViewerImageFn:function(){//预览营业执照图片
            var viewer = new Viewer(document.getElementById('businessLicenseImage'));
        },
        showViewerImageFn1:function(){//预览门头照图片
            var viewer = new Viewer(document.getElementById('uploadMentuzImage'));
        },
        showViewerImageFn2:function(){//预览资质图片
            var viewer = new Viewer(document.getElementById('medicalPracticeLicenseImg'));
        },
    },
    created: function () {

    },
    mounted: function () {
        var _self = this;
        if(globalUserData){
            _self.userId = globalUserData.userId;
            _self.infoInformationData();
        }
        _self.GetProvinceFn();
        $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
        $('.navLayout').find('.navList').eq(1).addClass("on").find('.con').show().find('a').eq(0).addClass("on");
    }
});
