Vue.config.devtools = true;
var v = new Vue({
    el: ".container",
    data: {
        artId: '',
        artInfo: {
            sysRecommendDTOs: [],
        },
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf: -1,
        queryQrCode: {},
        courseware: {},
        consulting: {}
    },
    created: function () {
        // if(!checkWebLogin()){
        //     $('.navlogorebox').trigger('click')
        //     return false;
        // }
        if ($.cookie("memToken")) {
            this.memToken = $.cookie("memToken");
            this.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            this.memHeadImg = $.cookie("memHeadImg");
        }
        this.artId = $("#artId").val();
        this.getDetailData();
        this.findUserIntegral();
        this.getQueryQrCode()
        this.getCourseware()
        this.getConsulting()
    },
    mounted: function () {
        setTimeout(() => {
            this.initFn();
        }, 1000);
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
        }, 500)
    },
    methods: {
        // 查询社群二维码
        getQueryQrCode() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: "/user/getQrImg",
                data: {
                    queryQrCode: that.queryQrCode
                },
                success: function (data) {
                    if (data.code == 200) {
                        // that.queryQrCode = data.data
                        that.queryQrCode = [
                            {
                                "id": 1,
                                "name": "赋能全科医生交流群",
                                "qrImg": "/web/img/fnqkysjl.png",
                                "stauts": 0
                            }
                        ]
                    }
                },
                error: function (data) {
                }
            });
        },
        // 课件下载
        getCourseware() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: "/courseware/getPageData?cataId=-1",
                data: {
                    courseware: that.courseware
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.courseware = data.data

                    }
                },
                error: function (data) {
                }
            });
        },

        // 咨询推荐
        getConsulting() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: "/web/index/information",
                data: {
                    consulting: that.consulting
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.consulting = data.data
                    }
                },
                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,
                }, autoplay: true,
                // 如果需要分页器
                pagination: {
                    el: '.swiper-pagination',
                },
                // 如果需要前进后退按钮
                navigation: {
                    nextEl: '.swiper-button-next',
                    prevEl: '.swiper-button-prev',
                },
                // 如果需要滚动条
                scrollbar: {
                    el: '.swiper-scrollbar',
                },

            })
        },
        getDetailData() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/view/getDetailData",
                data: {
                    memToken: that.memToken,
                    artId: that.artId
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.artInfo = data.data;
                        $("meta[name='sharetitle']").attr("content", that.artInfo.shareTitle);
                        $("meta[name='sharedesc']").attr("content", that.artInfo.shareDesc);
                        $("meta[name='sharepic']").attr("content", that.artInfo.sharePic);
                        // $("meta[name='shareurl']").attr("content",that.artInfo.shareUrl);
                        document.title = that.artInfo.info.title;
                    }
                },
                error: function (data) {
                }
            });
        },
        gotoRcmd(obj) {
            gotoRcmdPub(obj.zqFlag, obj.rcmdType, obj.rcmdObjId, obj.rcmdUrl);
        },


        // 右侧功能
        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) {
                return;
            }
        },
        toPay(id) {
            console.log(111, checkWebLogin());
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            // var that = this;
            toPayWeb(4, id, 1, '');
        },
        addFreeBuyApi(id) {
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/pay/addFreeBuyApi",
                data: {
                    memToken: that.memToken,
                    memCard: that.memCard,
                    orderType: 4,
                    objId: id,
                    ispackage: 1,
                    paySource: 2,
                    fromMemCard: ''
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.courseware.forEach((item, index) => {
                            if (item.id == id) {
                                item.isPurchased = 1;
                            }
                        });
                    } else if (data.code == 10008) {
                        //去登录
                        $('.navlogorebox').trigger('click')

                    } else {
                        alert(data.data.message);
                    }
                },
                error: function (data) {
                }
            });
        },
        downFile(id) {
            window.location.href = serverHttp + "/courseware/downFilebyWeb?id=" + id
        },
        jumpTo(url) {
            window.open(url)
        },
        jumpToLive(obj) {
            gotoRcmdPub(obj.zqFlag, obj.rcmdType, obj.rcmdObjId, obj.rcmdUrl, "web")
        },
    }
})
