Vue.config.devtools = true;
var hei = $(window).height()-770 + 'px';
$("#list").css("min-height",hei)
var v = new Vue({
    el:".container",
    data:{
        list:[],
        cata:[],
        isLogin: 0,
        ad:[],
        memToken: '',
        memHeadImg: '',
        userJf:-1,
        chooseItem:false,
        start:1,
        size:10,
        loading:false,
        integralType:"",
        integralCount:""
    },
    created:function (){
        if($.cookie("memToken")){
            this.memToken = $.cookie("memToken");
            this.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            this.memHeadImg = $.cookie("memHeadImg");
        }
        if(!againLogin()){
            // goLogin();
            return false;
        }
        this.findUserIntegral();
        this.getAdInfo();
        this.getIndexData();
        window.addEventListener("scroll", this.scrollBottom, true);
    },
    mounted:function (){
        setTimeout(() => {
            var mySwiper = new Swiper('.swiper-container', {
                direction: 'horizontal', // 水平切换选项
                loop: this.ad.length > 1, // 循环模式选项
                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',
                },

            })
        }, 1000);
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        },500)
    },
    methods:{

        meetingDetails(id){
            window.location.href=serverHttp+"/meeting/details?from=H5&conferId="+id;
        },
        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) {
                }
            });
        },
        getIndexData () {
            //id：分类id id = -1 是全部分类
            var that = this;
            if (that.loading) {
                return ;
            }
            that.loading = true;
            if(that.start == 1){
                that.list = []
            }
            $.ajax({
                type : 'POST',
                url : serverHttp+"/meeting/getConferList",
                data : {
                    page: that.start,
                    size: that.size,
                    memToken:that.memToken
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.list = that.list.concat(data.data);
                        // 请求的数据未加载完成时
                        that.start = that.start + 1;
                        that.loading = false;
                    } else if (data.code == 10005) {
                        that.finished = true;
                    }

                },
                error : function(data) {

                }
            });
        },
        scrollBottom() {
            const that = this;
            // 滚动到页面底部时
            const el = document.getElementById("list");
            const elHeight = $("#list").offset()['top'];//元素距离顶部距离 该计算可能会有一些偏差
            const windowHeight = window.screen.height*750/window.screen.width;
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop;
            const contentHeight = el.clientHeight;
            //316为
            const toBottom = contentHeight - windowHeight - scrollTop-elHeight;
            if (toBottom < 10 && !that.finished) {
                that.getIndexData();
            }
        },
        getAdInfo () {
            var that = this;
            $.ajax({
                type : 'POST',
                url : serverHttp+"/meeting/getAdInfo",
                success : function(res) {
                    if (res.code == 200) {
                        that.ad = res.data;
                    }
                },
                error : function(data) {
                }
            });
        },

        gotoAdHtml (url){
            window.location.href = url;
        },
    }
})
