Vue.config.devtools = true;
var v = new Vue({
    el: "#main",
    data: {
        indexData: {
            integralDetailCount: 0,
            seriesRecommends: {
                children: [],
            }
        },
        homData: ['会议推荐', '课程推荐', '资讯推荐', '课件推荐'],
        brandData: [], // 品牌专区
        livedData: [], // 直播
        meetingData: [], // 会议
        courseData: [], // 课程
        courseWareData: [], // 课件
        viewData: [], // 咨询
        photoWall: [],//照片墙
        isLogin: 0,
        homIndex: 0,
        memToken: '',
        memHeadImg: '',
        loading: true,
        integralType: "",
        integralCount: "",
        img: "",
        attestation: {},
        regCount:0,
        lineCount:0,
    },
    created() {
        if ($.cookie("memToken")) {
            this.memToken = $.cookie("memToken");
            this.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            this.memHeadImg = $.cookie("memHeadImg");
        }
        if(!againLogin()){
            // goLogin();
            return false;
        }
        this.getIndexData();
        if (typeof (fromlogin) != "undefined" && fromlogin == "1") {
            jifen();
        }
    },
    mounted() {
        setTimeout(() => {
            this.initFn();
            this.regCountData();
            this.getPeople();
        }, 2000);
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        }, 1000)
    },
    methods: {
        regCountData(){
            var that = this;
            setInterval(function () {
                that.getPeople();
            }, 10000)
        },
        getPeople(){
            var that = this;
            //注册人数
            $.ajax({
                type: 'get',
                url: serverHttp + "/index/peopleCoun",
                data: {
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.regCount = data.data.registerPerson;
                        that.lineCount = data.data.onlinePerson;
                    }else {

                    }
                },
                error: function (data) {
                }
            });
        },
        remove(){
            sessionStorage.removeItem('searchTitle')
        },
        initFn() {
            var swiper1 = new Swiper('#zbtj .swiper-container', {
                direction: 'horizontal', // 水平切换选项
                slidesPerView: this.livedData.length < 3 ? this.livedData.length : 3, // 能够同时显示的数量
                spaceBetween: 5,
                autoplay: {
                    delay: 3000,
                    stopOnLastSlide: false,
                    disableOnInteraction: true,
                },
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true,
                },
            });

            var swiper2 = new Swiper('#photoList .swiper-container', {
                direction: 'horizontal', // 水平切换选项
                slidesPerView: 2,
                observerParents: true,
                observer: true,
                autoplay: {
                    delay: 3000,
                    stopOnLastSlide: false,
                    disableOnInteraction: true,
                },
                pagination: {
                    el: ".swiper-pagination",

                },
            });

            var swiper = new Swiper(".mySwiper", {
                loop: this.indexData.swriperRecommends.length > 1, // 循环模式选项
                direction: 'horizontal', // 水平切换选项
                observerParents: true,
                observer: true,
                autoplay: {
                    delay: 3000,
                    stopOnLastSlide: false,
                    disableOnInteraction: true,
                },
                pagination: {
                    el: ".swiper-pagination",

                },
            });
            // var mySwiper3 = new Swiper('.ad .swiper-container', {
            //     direction: 'vertical', // 水平切换选项
            //     loop: true, //循环
            //     observer: true,//修改swiper自己或子元素时，自动初始化swiper
            //     observeParents: true,//修改swiper的父元素时，自动初始化swiper
            //     autoplay: {
            //         disableOnInteraction: false,  //触碰后自动轮播也不会停止
            //         delay: 2000,
            //     }
            // });
        },
        getIndexData() {
            $.ajax({
                type: 'POST',
                url: serverHttp + "/index/homeData",
                data: {
                    memToken: this.memToken
                },
                success: (data) => {
                    if (data.code == 200) {
                        this.indexData = data.data;
                        let brandData = data.data.seriesRecommends.children.filter(item => {
                            return item.posName == '品牌专区'
                        }); // 品牌专区
                        this.brandData = brandData.length === 0 ? [] : brandData[0].rcmdData

                        // let livedData = data.data.seriesRecommends.children.filter(item => {
                        //     return item.posName == '近期直播'
                        // }); // 直播
                        // this.livedData = livedData.length === 0 ? [] : livedData[0].rcmdData

                        let meetingData = data.data.seriesRecommends.children.filter(item => {
                            return item.posName == '会议推荐'
                        }); // 会议
                        this.meetingData = meetingData.length === 0 ? [] : meetingData[0].rcmdData

                        let courseData = data.data.seriesRecommends.children.filter(item => {
                            return item.posName == '课程推荐'
                        }); // 课程
                        this.courseData = courseData.length === 0 ? [] : courseData[0].rcmdData

                        let courseWareData = data.data.seriesRecommends.children.filter(item => {
                            return item.posName == '课件推荐'
                        }); // 课件
                        this.courseWareData = courseWareData.length === 0 ? [] : courseWareData[0].rcmdData

                        let viewData = data.data.seriesRecommends.children.filter(item => {
                            return item.posName == '资讯推荐'
                        }); // 咨询
                        this.viewData = viewData.length === 0 ? [] : viewData[0].rcmdData

                        let photoWall = data.data.seriesRecommends.children.filter(item => {
                            return item.posName == '会议照片墙'
                        }); // 咨询
                        this.photoWall = photoWall.length === 0 ? [] : photoWall[0].rcmdData

                        this.img = this.livedData.length === 0 ? '' : this.livedData[0].rcmdImgpath;

                    }
                },
                error: function (data) {
                }
            });
        },
        gotoRcmd(obj) {
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            if(obj.rcmdType == 6){
                if (!this.parseRule(obj.rcmdObjId)) {
                    return false;
                }
            }
            gotoRcmdPub(obj.zqFlag, obj.rcmdType, obj.rcmdObjId, obj.rcmdUrl, "H5", obj.artType, obj.artContent);
        },
        parseRule(id) {
            var that = this;
            var flag = false;
            $.ajax({
                type : 'POST',
                async: false,
                url : serverHttp+"/popu/window/checkWindow",
                data : {
                    id: id,
                    idType: 2,  //
                    memToken: that.memToken
                },
                success : function(data) {
                    if (data.code == 200) {
                        let attestation = data.data;
                        console.log(attestation)
                        if (attestation.attestType == 2) {
                            window.location.href = serverHttp + "/user/certificationSm?from=H5&memToken=&type=2&id=" + id;
                            return false;
                        } else if (attestation.attestType == 1) {
                            window.location.href = serverHttp + "/user/certificationYs?from=H5&memToken=&type=2&id=" + id;
                            return false;
                        } else if (attestation.attestType == 4) {
                            window.location.href = serverHttp + "/user/certificationSmojl?from=H5&memToken=&type=2&id=" + id;
                            return false;
                        } else if (attestation.attestType == 3) {
                            window.location.href = serverHttp + "/user/certificationYsojl?from=H5&memToken=&type=2&id=" + id;
                            return false;
                        } else if (attestation.attestType == 5) {
                            flag = true
                        }
                        flag = true
                    }
                }
            });
            return flag
        },
        // 切换tab
        chooseHom(index) {
            this.homIndex = index

        },
        // gotoPay(item) {
        //     if ((item.isPurchased == 0 && item.pointFlag == 0 && item.price > 0) || (item.isPurchased == 0 && item.pointFlag == 1 && item.point > 0)) {
        //         this.toPay(item.id);
        //     } else if ((item.isPurchased == 0 && item.pointFlag == 0 && item.price == 0) || (item.isPurchased == 0 && item.pointFlag == 1 && item.point == 0)) {
        //         this.addFreeBuyApi(item.id);
        //     } else if (item.isPurchased == 1) {
        //         this.downFile(item.id)
        //     }
        // },
        // downFile (id) {
        //     window.location.href = serverHttp+"/courseware/downFile?id="+id+"&memToken="+$.cookie("memToken");
        // },
    }
})
