Vue.config.devtools = true;
var v = new Vue({
    el: ".index-box",
    data: {
        list: [],
        cata: [],
        isLogin: 0,
        ad: [],
        memToken: '',
        memHeadImg: '',
        userJf: -1,
        chooseItem: false,
        currentPage: 1, // 当前页
        total: 0, // 总数
        pageSizes: [10, 20, 50, 100],
        pageSize: 12, // 每页数量
        queryQrCode: {},
        consulting: {},
    },
    created: function () {
        if ($.cookie("memToken")) {
            this.memToken = $.cookie("memToken");
            this.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            this.memHeadImg = $.cookie("memHeadImg");
        }
        if (!againWebLogin()) {
            return false;
        }
        this.findUserIntegral();
        this.getIndexData();
        this.getAdInfo()
        // window.addEventListener("scroll", this.scrollBottom, true);
    },
    mounted() {

        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);

    },
    methods: {
        /**
         * 分页功能 - 检测当前页变化
         */
        currentPageChange(val) {
            this.currentPage = val
            this.getIndexData()
        },
        /**
         * 分页功能 - 检测PageSize变化
         */
        pageSizeChange(val) {
            this.pageSize = val
            this.getIndexData()
        },
        meetingDetails(id) {
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            window.location.href = serverHttp + "/meeting/details?from=web&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 是全部分类

            $.ajax({
                type: 'POST',
                url: serverHttp + "/meeting/getPageData",
                data: {
                    page: this.currentPage,
                    size: this.pageSize,
                    memToken: this.memToken
                },
                success: (data) => {
                    if (data.code == 200) {
                        this.list = data.data;
                        this.list.map(item => {
                            item.endTime = tsFormatTime(item.endTime, 'M.D')
                            item.bigenTime = tsFormatTime(item.bigenTime, 'Y.M.D')
                        })
                        this.total = data.totalCount
                    } else if (data.code == 10005) {
                        this.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;
        },
    }
})
