Vue.config.devtools = true;
var v = new Vue({
    el:".container",
    data:{
        id: '',
        list:[],
        title: '',
        cover: '',
        finished: false,
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        start:1,
        size:20,
        loading:false,
        swiperHide: false,
        indexPic: 0,
        isHide: true
    },
    created:function (){
        if($.cookie("memToken")){
            this.memToken = $.cookie("memToken");
            this.isLogin=1;
        }
        if($.cookie("memHeadImg")){
            this.memHeadImg = $.cookie("memHeadImg");
        }
        if(!checkLogin()){
            return false;
        }
        this.id = $("#id").val()
        this.getIndexData();
        window.addEventListener("scroll", this.scrollBottom, true);
    },
    mounted:function (){
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        },500)

    },
    methods:{
        getIndexData() {
            var that = this;
            if (that.loading) {
                return ;
            }
            that.loading = true;
            if(that.start == 1){
                that.list = []
            }
            $.ajax({
                type : 'get',
                url : serverHttp+"/meeting/getPhotoWall",
                data : {
                    id: that.id,
                    type: 3,
                    page: that.start,
                    size: that.size,
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.title = data.data.ConferenceTitle
                        that.cover = data.data.ConferenceCoverImg
                        that.list = that.list.concat(data.data.results);
                        // 请求的数据未加载完成时
                        that.start = that.start + 1;
                        that.loading = false;
                        if(data.data.results.length == 0){
                            that.finished = true;
                        }
                    } else if (data.code == 10005) {
                        that.finished = true;
                    }

                },
                error : function(data) {

                }
            });
        },
        getIndexPic(index) {
            this.indexPic = index
            var that = this;
            $("body").addClass("hideActive")
            var mySwiper = new Swiper('.swiper-container', {
                direction: 'horizontal', // 水平切换选项
                observerParents: true,
                observer: true,
                initialSlide :that.indexPic,//默认第三页
                slidesPerView: 1,//可见页面3
                centeredSlides: true,//居中
                onTouchStart: function(swiper,even){
                    if(swiper.activeIndex == that.list.length-2 && !that.finished){
                        that.getIndexData();
                    }
                }
            })
            $(".swiper-cover").css('visibility','visible');
        },
        getClosePic(){
            $(".swiper-cover").css('visibility','hidden');
            $("body").removeClass("hideActive")
        },
        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();
            }
        }
    }
})
