Vue.config.devtools = true;
var v = new Vue({
    el:".index-box",
    data:{
        professional:-1,
        professionalTwo:-1,
        businessLicense:"",
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf:-1,
        selectOneData: [],
        selectTwoData: [],
        zw: [],
        post: -1,
        ysrzCheck: ''
    },
    created:function (){
        console.log("yh",this.professional,this.selectOneData)
        if (!checkWebLogin()) {
            // $('.navlogorebox').trigger('click')
            return false;
        }
        // if(!checkLogin()){
        //     goLogin();
        //     return false;
        // }
        // if($.cookie("memToken")){
        //     this.memToken = $.cookie("memToken");
        //     this.isLogin=1;
        // }
        // if($.cookie("memHeadImg")){
        //     this.memHeadImg = $.cookie("memHeadImg");
        // }
        this.getUserysrz();
        this.getCataList(51,1);
        this.getCataListZw(150,1);
        this.findUserInfoWithYs();
        // this.findUserIntegral();
    },
    methods:{
        professionalChange (type) {

            var that = this;
            // console.log("yh",that.professional,that.selectOneData)
            if(type == 1){
                if(that.professional == -1){
                    that.selectTwoData=[];
                }else{
                    that.getCataList(that.professional,2);
                }
            }
        },
        getCataList (fId,type) {
            var that = this;
            $.ajax({
                type : 'POST',
                url : "/course/getCataList",
                data:{
                    fId:fId,
                    type:5,
                },
                success : function(res) {
                    if (res.code == 200) {
                        if(type == 1){
                            res.data[0].name = "请选择";
                            that.selectOneData = res.data;
                        }else{
                            that.selectTwoData = res.data;
                            that.selectTwoData.unshift({name: '请选择', id: -1});
                        }
                    }
                },
                error : function(data) {

                }
            });
        },
        getCataListZw (fId,type) {
            var that = this;
            $.ajax({
                type : 'POST',
                url : "/course/getCataList",
                data:{
                    fId:fId,
                    type:5,
                },
                success : function(res) {
                    res.data[0].name = "请选择";
                    if (res.code == 200) {
                        that.zw = res.data;
                    }
                },
                error : function(data) {

                }
            });
        },
        findUserInfoWithYs (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : "/user/findUserInfoWithYsWeb",
                // data : {
                //     memToken:that.memToken
                // },
                success : function(data) {
                    if (data.code == 200 && data.data) {
                        that.professional = data.data.professional;
                        that.professionalTwo = data.data.professionalTwo;
                        that.businessLicense = data.data.num;
                        that.post = data.data.post;
                        that.getCataList(that.professional,5);
                    }
                },
                error : function(data) {
                }
            });
        },
        findUserIntegral (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : "/user/findUserIntegral",
                data : {
                    memToken:that.memToken
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.userJf = data.data;
                    }
                },
                error : function(data) {
                }
            });
        },
        saveUserInfoWithYs(){
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            var that = this;
            if(!checkyishi(that.businessLicense)){
                layer.msg("执业编码填写错误");
                return false;
            }
            $.ajax({
                type : 'POST',
                url : "/user/saveUserInfoWithYsWeb",
                data : {
                    businessLicense:that.businessLicense,
                    professional:that.professional,
                    professionalTwo: that.professionalTwo,
                    post: that.post
                },
                success:function (res) {
                    if (res.code == 200) {
                        if(that.ysrzCheck === 0){
                            playMusic(res.message, 500)
                            that.ysrzCheck = 1
                        }else{
                            layer.msg("已完成医师认证")
                        }
                    } else if (res.code == 10014) {
                        layer.msg("已完成医师认证")
                    }else {
                        layer.msg(res.message);
                    }
                }
            })
        },
        getUserysrz () {
            var that = this;
            $.ajax({
                type: 'POST',
                url: "/user/getUserInfoWeb",
                success: function (res) {
                    if (res.code == 200) {
                        that.ysrzCheck = res.data.ysrzFlag;
                    }
                }
            })
        },
        isEmptyStr (s) {
            if (s == null || s === '') {
                return true
            }
            return false
        },
        gotoUserCenter () {
            window.location.href = "/user/personalCenter?from=H5&memToken="+this.memToken;
        }
    }
})
