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 hei = $(window).height()-1000 + 'px';
$(".list").css("min-height",hei)
var v = new Vue({
    el:".container",
    data:{
        productId: '',
        info: {},
        page:1,
        size:10,
        finished:false,
        loading:false,//出现了 上拉到底出发了两次请求接口的情况  加一个变量控制一下
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf:-1,
        integralType:"",
        integralCount:"",
        isUpload:'',
        wareTitle:''
    },
    created:function (){
        var that = this;
        if($.cookie("memToken")){
            this.memToken = $.cookie("memToken");
            this.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            this.memHeadImg = $.cookie("memHeadImg");
        }
        that.productId = $("#productId").val();
        that.getDetailData();
        this.findUserIntegral();
    },
    mounted: function (){
        setTimeout(() => {
            this.initFn();
        }, 1000);
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        },500)
    },
    methods:{
        goUpload(){
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            window.location.href = serverHttp + "/brand/upload?from=H5&productId=" + getQueryVariable("productId");
        },
        gotoRcmd(obj) {
            gotoRcmdPub(obj.zqFlag,obj.rcmdType,obj.rcmdObjId,obj.rcmdUrl,"H5",obj.artType,obj.artContent);
        },
        gotoProduct(obj){
            if(obj.objType == 2){
                //精品课
                // window.location.href = serverHttp + "/course/courseDetails?from=H5&id="+obj.objId;
                if (obj.ZqFlag == 0) {
                    //普通课程
                    window.location.href = serverHttp + "/course/courseDetails?from=H5&id="+obj.objId;
                } else {
                    //专区
                    window.location.href = serverHttp + "/course/coursePrefectureList?from=H5&id="+obj.objId;
                }
            }else if(obj.objType == 1){
                //直播
                window.location.href = serverHttp + "/live/detail?from=H5&liveId="+obj.objId;
            }if(obj.objType == 3){
                //资讯文章
                window.location.href = serverHttp + "/view/detail?from=H5&artId="+obj.objId;
            }if(obj.objType == 4){
                //会议
                window.location.href = serverHttp + "/meeting/details?from=H5&conferId="+obj.objId;
            }if(obj.objType == 5){
                //课件
                window.location.href = serverHttp + "/courseware/index?from=H5";
            }
        },
        getDetailData(){
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/brand/getDetailData",
                data : {
                    memToken:that.memToken,
                    productId: that.productId
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.info = data.data;
                        that.isUpload = data.data.isUpload;
                        that.wareTitle = data.data.wareTitle;
                        $("meta[name='sharetitle']").attr("content",that.info.shareTitle);
                        $("meta[name='sharedesc']").attr("content",that.info.shareDesc);
                        $("meta[name='sharepic']").attr("content",that.info.sharePic);
                        // $("meta[name='shareurl']").attr("content",that.liveInfo.shareUrl);
                    }
                },
                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) {
                }
            });
        },
        initFn(){
            var mySwiper = new Swiper('.swiper-container', {
                direction: 'horizontal', // 水平切换选项
                loop: true, // 循环模式选项
                observerParents: true,
                observer: true,
                autoplay: {
                    disableOnInteraction: false,  //触碰后自动轮播也不会停止
                    delay: 2000,
                },
                // 如果需要分页器
                pagination: {
                    el: '.swiper-pagination',
                },
                // 如果需要前进后退按钮
                navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                },
                // 如果需要滚动条
                scrollbar: {
                    el: '.swiper-scrollbar',
                },
            })
        },
        gotoRcmd(obj) {
            gotoRcmdPub(obj.zqFlag,obj.rcmdType,obj.rcmdObjId,obj.rcmdUrl,"H5",obj.artType,obj.artContent);
        }
    }
})
