Vue.config.devtools = true;

function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(false);
}

var v = new Vue({
    el: ".container",
    data: {
        list: [],
        finished: false,
        loading: false,//出现了 上拉到底出发了两次请求接口的情况  加一个变量控制一下
        ad: [],//广告信息
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf: -1,
        pageLoaded: false,
        isUpload: '',
        wareTitle:''
    },
    created: function () {
        if ($.cookie("memToken")) {
            this.memToken = $.cookie("memToken");
            this.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            this.memHeadImg = $.cookie("memHeadImg");
        }
        this.getData();
        this.findUserIntegral();

    },
    mounted: function () {
        //认证信息公共部分
        window.getId = getQueryVariable("productId");
        window.getMemToken = this.memToken;
        window.getRzType = '2';
    },
    methods: {
        goUpload(){
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            window.location.href = serverHttp + "/brand/upload?from=web&productId=" + getQueryVariable("productId");
        },
        gotoProduct(obj){
            if(obj.objType == 2){
                //精品课
                // window.location.href = serverHttp + "/course/courseDetails?from=web&id="+obj.objId;
                if (obj.ZqFlag == 0) {
                    //普通课程
                    window.location.href = serverHttp + "/course/courseDetails?from=web&id="+obj.objId;
                } else {
                    //专区
                    window.location.href = serverHttp + "/course/coursePrefectureList?from=web&id="+obj.objId;
                }
            }else if(obj.objType == 1){
                //直播
                window.location.href = serverHttp + "/live/detail?from=web&liveId="+obj.objId;
            }if(obj.objType == 3){
                //资讯文章
                window.location.href = serverHttp + "/view/detail?from=web&artId="+obj.objId;
            }if(obj.objType == 4){
                //会议
                window.location.href = serverHttp + "/meeting/details?from=web&conferId="+obj.objId;
            }if(obj.objType == 5){
                //课件
                window.location.href = serverHttp + "/courseware/index?from=web";
            }
        },
        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) {
                }
            });
        },
        getData(id) {
            var that = this;
            id = getQueryVariable("productId");
            console.log(id);
            $.ajax({
                type: 'POST',
                url: serverHttp + "/brand/getDetailData",
                data: {
                    productId: id,
                    memToken: that.memToken,
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.ad = data.data.ads;
                        that.list = data.data.productList;
                        that.isUpload = data.data.isUpload;
                        that.wareTitle = data.data.wareTitle;
                        that.loading = false;
                        that.pageLoaded = true;
                    }
                },
                error: function (data) {

                }
            });
        }
    }
})
