Vue.config.devtools = true;
var v = new Vue({
    el:".container",
    data:{
        professional:-1,
        professionalTwo:-1,
        businessLicense:"",
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf:-1,
        selectOneData: [],
        selectTwoData: [],
        zw:[],
        id: '',
        type: '',
        attestation: null,
        post:-1,
        integralType:"医师认证成功",
        integralCount:"500",
        isNew: true
    },
    created:function (){
        if(!checkLogin()){
            // goLogin();
            return false;
        }
        if($.cookie("memToken")){
            this.memToken = $.cookie("memToken");
            this.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            this.memHeadImg = $.cookie("memHeadImg");
        }
        var myobj = getparamcommon();
        if(myobj){
            this.id = myobj.id;
            this.type = myobj.type;
        }
        this.getCataList(51,1);
        this.getCataListZw(150,1);
        this.findUserInfoWithYs();
        this.findUserIntegral();
        this.getAttestation();
    },
    mounted:function (){
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        },500)
    },
    methods:{
        getAttestation() {
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/popu/window/checkWindow",
                data : {
                    id: that.id,
                    idType: that.type
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.attestation = data.data;
                    }
                },
                error : function(data) {
                }
            });
        },
        professionalChange (type) {
            var that = this;
            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 : serverHttp+"/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=[];
                            that.selectTwoData[0] = {id: -1, name: "请选择"};
                            that.selectTwoData = that.selectTwoData.concat(res.data);
                        }
                    }
                },
                error : function(data) {

                }
            });
        },
        getCataListZw (fId,type) {
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/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 : serverHttp+"/user/findUserAttestInfo",
                data : {
                    memToken:that.memToken
                },
                success : function(data) {
                    if (data.code == 200 && data.data && data.data.physicians) {
                        that.professional = data.data.physicians.professional;
                        that.professionalTwo = data.data.physicians.professionalTwo;
                        that.businessLicense = data.data.physicians.num;
                        that.post = data.data.physicians.post;
                        that.getCataList(that.professional,5);
                        that.isNew=false;
                    }
                },
                error : function(data) {
                }
            });
        },
        findUserIntegral (){
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/findUserIntegral",
                data : {
                    memToken:that.memToken
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.userJf = data.data;
                    }
                },
                error : function(data) {
                }
            });
        },
        saveUserInfoWithYs(){
            if(!checkLogin()){
                // goLogin();
                return false;
            }
            var that = this;
            if (that.isEmptyStr(that.businessLicense)) {
                alert("请完善必填信息");
                return false;
            }
            if(!checkyishi(that.businessLicense)){
                alert("执业编码填写错误");
                return false;
            }
            $.ajax({
                type : 'POST',
                url : serverHttp+"/user/saveUserInfoWithSmAndYs",
                data : {
                    memToken:that.memToken,
                    professional:that.professional,
                    businessLicense:that.businessLicense,
                    professionalTwo: that.professionalTwo,
                    post: that.post,
                    attestType: '1'
                },
                success:function (res) {
                    if (res.code == 200) {
                        if(res.data.points != 0){
                            that.integralCount = res.data.points;
                            $(".integral-toast").show();
                            playMusic()
                            setTimeout(function (){
                                $(".integral-toast").fadeOut(200);
                            },2000);
                            sessionStorage.setItem('refresh', 'true');
                            setTimeout(function (){
                                if(that.attestation.question){
                                    window.location.href = serverHttp + "/live/liveQuestion?from=H5&memToken=&type=" + that.type + "&id=" + that.id;
                                }else{
                                    window.location.href=document.referrer;
                                }
                            },2000);
                        }else{
                            sessionStorage.setItem('refresh', 'true');
                            if(that.attestation.question){
                                window.location.href = serverHttp + "/live/liveQuestion?from=H5&memToken=&type=" + that.type + "&id=" + that.id;
                            }else{
                                window.location.href=document.referrer;
                            }
                        }
                    } else {
                        alert(res.message);
                    }
                }
            })
        },
        isEmptyStr (s) {
            if (s == null || s === '') {
                return true
            }
            return false
        },
        gotoUserCenter () {
            window.location.href = serverHttp + "/user/personalCenter?from=H5&memToken="+this.memToken;
        }
    }
})
