Vue.config.devtools = true;
function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
    }
    return(false);
}
var v = new Vue({
    el: ".index-box",
    data: {
        isVip: localStorage.getItem('isVip') == 1,
        websock: null,
        showTabContentIndex: 1,
        cata: [
            {name: "会议日程", active: 1, id: 1, disable: true},
            {name: "互动", active: 0, id: 2, disable: false},
            {name: "云展厅", active: 0, id: 3, disable: false},
            {name: "分享榜单", active: 0, id: 4, disable: true}
        ],
        liveId: '',
        fromMemCard:'',
        liveInfo: {
            sysRecommendDTOs: [],
        },
        endTime: {day: 0, hour: 0, minute: 0, second: 0},
        memberInfo: {
            isPurchased: 0,
            isRemind: 0,
            joinMembers: 0,
            remindMemberNum: 0
        },
        source: '0',
        page: 1,
        size: 10,
        loading: false, //出现了 上拉到底出发了两次请求接口的情况  加一个变量控制一下
        isLogin: 0,
        memToken: '',
        memHeadImg: '',
        userJf: -1,
        cid: -1,
        yzt: [],
        contentList: [],
        content: '',
        objType: 2,
        rankList: [],
        queryQrCode: {},
        consulting: {},
        rankInfo: '',
        finished: false,
        userName: "",
        card: "",
        unitName: "",
        address: "",
        addressXx: "",
        sex: "1",
        experience: "-1",
        experiences: [
            {id: 1, name: "1-3年"},
            {id: 2, name: "3-5年"},
            {id: 3, name: "5-10年"},
            {id: 4, name: "10年以上"}
        ],
        learnTime: 1,
        currentTime: 1,
        timer: null,
        collect: false,
        collectImgSrc: '/web/img/collect.png',
        liveTab: [],
        tabActive: '1',
        numberTimer: null, // 人数定时器
        joinMembers: 0,
        attestation: null,
        commenCD: false
    },
    created: function () {
        var that = this;
        if ($.cookie("memToken")) {
            that.memToken = $.cookie("memToken");
            that.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            that.memHeadImg = $.cookie("memHeadImg");
        }
        that.liveId = $("#liveId").val();
        that.fromMemCard = $("#fromMemCard").val();
        if(getQueryVariable("source") != false || getQueryVariable("source") != null || getQueryVariable("source") != ''){
            that.source = getQueryVariable("source");
        }else{
            that.source = '0';
        }
        that.getDetailData();
        this.findUserIntegral();
        that.findUserBaseInfo()
        that.commentList();
        this.getQueryQrCode()
        this.getConsulting()
        this.findUserInfoWithSm()
        that.rankingList();
    },
    mounted: function () {
        // setTimeout(() => {
        //     this.initFn();
        // }, 1000);

        document.getElementById("contentList").addEventListener("scroll", this.debounce(this.scrollBottom,100), true);
        this.initWebSocket();
        // this.getcounter()
        // this.numberTimer = setInterval(this.getcounter, 30000)
        setTimeout(() => {
            var mySwiper = new Swiper('.swiper-container', {
                direction: 'horizontal', // 水平切换选项
                loop: this.liveInfo.sysRecommendDTOs.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);
    },
    destroy() {
        clearInterval(this.numberTimer)
    },
    watch: {
        liveInfo(val) {
            var arrStr = '1:详情,2:互动,3:云展厅,4:榜单';
            var tabList = []
            if(val.liveTab){
                arrStr = val.liveTab;
            }


            if (val.liveTab) {
                var arr = val.liveTab.split(',')
                var tabList = []
                arr.forEach(_i => {
                    var type = _i.split(':')[0]
                    var name = _i.split(':')[1]
                    var tab = this.cata.find(_i => _i.id == type)
                    if (tab.id == 3 && val.showHall) {
                        tab.name = name
                        tab.disable = true
                        tabList.push(tab)
                    } else {
                        tab.name = name
                        tabList.push(tab)
                    }
                })
                var index = tabList.findIndex(item => item.id == 1)
                if (index !== -1 && index !== 0) {
                    tabList[index].active = false
                }
                tabList[0].active = true
                this.showTabContentIndex = tabList[0].id
                this.cata = tabList
            }

            if(val.agoQuestionnaire){
                this.cata[0].active = 0;
                this.cata.unshift({
                    name: "会前问卷",
                    active: 1,
                    id: 5,
                    disable: true
                })
                this.showTabContentIndex = this.cata[0].id
            }
            if(val.cookQuestionnaire){
                this.cata.push({
                    name: "会后问卷",
                    active: 0,
                    id: 6,
                    disable: true
                })
                this.showTabContentIndex = this.cata[0].id
            }
        }
    },
    methods: {
        getAttestation() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/popu/window/checkWindow",
                data: {
                    id: that.liveId,
                    idType: 1,
                    memToken: that.memToken
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.attestation = data.data;
                    }
                },
                error: function (data) {
                }
            });
        },
        // 获取人数
        getcounter() {
            $.ajax({
                type: 'GET',
                url: `${serverHttp}/livecounter/getcounter?liveId=${this.liveId}`,
                success: (res) => {
                    if (res.code == 200) {
                        this.joinMembers = res.data.count
                    }
                    // else if (res.code == 10008) {
                    //     $('.navlogorebox').click();
                    // }
                }
            })
        },
        changeTabActive(type) {
            this.tabActive = type
        },
        collectFn() {
            var that = this;
            $.ajax({
                type: 'post',
                data: {typeId: that.liveId, type: 2, isDel: that.collect ? 1 : 2},
                url: '/user/saveCollectionWeb',
                success: function (res) {
                    if (res.code == 200) {
                        that.collect = !that.collect;
                        if (that.collect) {
                            that.collectImgSrc = '/web/img/collected.png';
                            layer.msg('已收藏，可在我的收藏中查看');
                        } else {
                            that.collectImgSrc = '/web/img/collect.png';
                            layer.msg('已取消收藏');
                        }
                    } else if (res.code == 10008) {
                        $('.navlogorebox').click();
                    } else {
                        layer.msg('添加收藏失败，请重试');
                    }
                }
            })
        },
        startTiming() {
            var that = this;
            that.timer = setInterval(function () {
                that.learnTime = that.learnTime + 1;
                if (that.learnTime % 30 == 0) {
                    //1分钟的倍数
                    that.addVideoPlayRecorde();
                }
            }, 1000)
        },
        beforeunloadHandler() {
            this.addVideoPlayRecorde();
        },
        addVideoPlayRecorde() {
            var that = this;
            let playTime = that.currentTime ? that.currentTime : -1;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/course/addVideoPlayRecorde",
                async: false,
                data: {
                    playTime: playTime,
                    totalLearnTime: that.learnTime * 1000,
                    objType: 2,
                    objId: that.liveId,
                    memToken: that.memToken
                },
                success: function (data) {
                    if (data.code == 200) {
                        // that.currentTime = 0;
                        // that.learnTime = 0;
                    }else if(data.code == 10008){
                        $('.navlogorebox').trigger('click');
                    }else if(data.code == 10029){
                        //在另一设备登录，重新登录
                        layer.open({
                            title:"提示",//标题信息
                            content: '您的账号在另一台设备登录，如需继续使用，请重新登录',//内容区域
                            shift: 0,
                            offset: ['calc(50% - 80px)', 'calc(50% - 200px)'],
                            shadeClose: true,
                            btn: ['登录'],
                            btn1: function(index){
                                layer.close(index)
                                $('.navlogorebox').trigger('click');
                            },
                            // 右上角关闭按钮的点击事件
                            cancel: function(index){
                                layer.close(index)
                                // $('.navlogorebox').trigger('click');
                                window.location.href = serverHttp + '/index/index?from=web'
                            }
                        });
                    }
                },
            });
        },
        rankingList() {
            var that = this;
            if (that.start == 1) {
                that.list = []
            }
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/rankList",
                data: {
                    objType: that.objType,
                    objId: that.liveId,
                    page: that.page,
                    size: that.size
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.rankList = that.rankList.concat(data.data.rankList);
                        that.rankInfo = data.data.info;
                        // 请求的数据未加载完成时
                        that.start = that.start + 1;
                    } else if (data.code == 10005) {
                        that.finished = true;
                    }
                }
            });
        },
        addRemind() {
            var that = this;
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            //距离播放时间10分钟，不允许预约
            if (that.endTime.day == 0 && that.endTime.hour == 0 && that.endTime.minute < 10) {
                $("#tipsyuyue").show();
                setTimeout(() => {
                    $("#tipsyuyue").hide();
                }, 3000);
                return false;
            }
            // $.ajax({
            //     type: 'post',
            //     url: serverHttp + "/index/isLogin",
            //     async: false,
            //     success: function (res) {
            //         if (res.code == 200) {
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/addRemind",
                data: {
                    memToken: that.memToken,
                    liveId: that.liveId
                },
                success: function (data) {
                    if (data.code == 200) {
                        if (data.data.code != -1) {
                            that.getDetailData()
                            //过万以 W 为单位展示
                            // var total = data.data.remindMemberNum + data.data.vremindMemberNum;
                            // if (total > 9999) {
                            //     that.liveInfo.remindMemberNum = (Math.floor(total / 1000) / 10) + "W";
                            // }
                        } else {
                            alert(data.data.errMsg);
                        }
                        if (that.memberInfo.subscribe != 1) {
                            layer.open({
                                type: 1,
                                area: ['300px', '400px'],
                                skin: 'layui-layer-molv',
                                shift: 0,
                                title: false,
                                offset: ['20%', 'calc(50% - 150px)'],
                                closeBtn: 1,
                                shadeClose: true,
                                content: $('.ma-live')
                            });
                        }
                        if (that.liveInfo.price == 0 && that.liveInfo.point == 0) {
                            //如果是免费课程，订阅成功后添加购买记录
                            // that.addFreeBuyApi();
                        }
                    } else if (data.code == 10008) {
                        //去登录
                        // goLogin();
                    } else {

                    }
                },
                error: function (data) {
                }
            });
        },
        findUserBaseInfo() {
            var that = this;

            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            $.ajax({
                type: 'POST',
                url: serverHttp + "/user/findUserBaseInfo",
                data: {
                    memToken: that.memToken
                },
                success: function (data) {
                    that.memberInfo = data.data;
                },
                error: function (data) {
                }
            });
        },


        newPlayer(url,pic,isLive){
            var saveTime = function (memoryVideo,currentTime) {
                localStorage.setItem(memoryVideo, currentTime);
            }
            var getTime = function (memoryVideo) {
                //return返回的是自定义起播时间
                return localStorage.getItem(memoryVideo)
            }
            var that = this;
            let autoPlay = that.liveInfo.isPurchased > 0 ? true : false;
            if(isLive == false){
                var memoryPlay = [{
                    name: 'MemoryPlayComponent',
                    type: AliPlayerComponent.MemoryPlayComponent,
                    args:[false,getTime,saveTime]
                }]
            }else{
                var memoryPlay = []
            }
            const dp = new Aliplayer({
                    "id": 'dplayer',
                    "source": url,
                    "width": "100%",
                    "height": "500px",
                    "autoplay": autoPlay,
                    "isLive": isLive,
                    "cover": pic,
                    "rePlay": false,
                    "playsinline": true,
                    "preload": true,
                    "controlBarVisibility": "hover",
                    "useH5Prism": true,
                    "skinLayout": [
                        {
                            "name": "bigPlayButton",
                            "align": "blabs",
                            "x": 30,
                            "y": 80
                        },
                        {
                            "name": "errorDisplay",
                            "align": "tlabs",
                            "x": 0,
                            "y": 0
                        },
                        {
                            "name": "infoDisplay"
                        },
                        {
                            "name": "controlBar",
                            "align": "blabs",
                            "x": 0,
                            "y": 0,
                            "children": [
                                //进度条
                                {
                                    "name": "progress",
                                    "align": "blabs",
                                    "x": 0,
                                    "y": 44
                                },
                                //播放按钮
                                {
                                    "name": "playButton",
                                    "align": "tl",
                                    "x": 15,
                                    "y": 8
                                },
                                //显示时间
                                {
                                    "name": "timeDisplay",
                                    "align": "tl",
                                    "x": 10,
                                    "y": 7
                                },
                                //播放器调节音量
                                {
                                    "name": "volume",
                                    "align": "tr",
                                    "x": 5,
                                    "y": 10
                                },
                                //全屏
                                {
                                    "name": "fullScreenButton",
                                    "align": "tr",
                                    "x": 10,
                                    "y": 10
                                },

                            ]
                        }
                    ],
                    "components": memoryPlay
                }, function (player) {
                    $(".load").hide();
                    $("#dplayer").show();
                    //console.log("The player is created");
                    player.on("timeupdate", () => {
                        //alert("timeupdate222");
                        if (that.liveInfo.liveStatus == 3 && that.liveInfo.isPurchased == 1) {
                            that.currentTime = Math.floor(player.getCurrentTime());
                        }
                    });
                    player.on("play", () => {
                        //alert("play");
                        that.videoPlay()
                    });
                    player.on("pause", () => {
                        // player.play();
                        //document.getElementById('dplayer').appendChild("<div class=\"prism-big-play-btn pause\" id=\"player-con_component_21894B02-33D2-4FC6-A4F4-2FCC05929BEE\" style=\"position: absolute; left: 30px; bottom: 80px; display: block;\"><div class=\"outter\"></div></div>")
                        //
                        that.videoPause()
                    });
                    player.on('onM3u8Retry',function(){
                        $(".load").show();
                        $(".prism-player .prism-ErrorMessage").css("background-color","unset");
                    });
                }

            );
            return dp;
        },

        debounce(fn, wait) { //节流方法
            var timeout = null;  // 初始化定时器
            return function() {
                if(timeout !== null)   clearTimeout(timeout);  // 如果scroll方法反复触发，则清空定时器
                timeout = setTimeout(fn, wait);  // 如果方法没有反复触发，那么就调用我们判断滚动的方法，然后去调用数据，他就只会请求一次了
            }
        },
        scrollBottom() {
            const that = this;
            // 滚动到页面顶部时
            const scrollTop = document.getElementById('contentList').scrollTop
            if (scrollTop == 0 && !that.finished) {
                that.commentList();
            }
        },

        commentList() {
            var that = this;
            if (that.start == 1) {
                that.contentList = []
            }
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/commentList",
                data: {
                    cId: that.cid,
                    liveId: that.liveId
                },
                success: function (res) {
                    if (res.code == 200) {
                        if (that.cid == -1) {
                            that.contentList = res.data;
                        } else {
                            that.contentList =that.contentList.concat(res.data);
                        }
                        that.cid = that.contentList[that.contentList.length-1].cid;
                    } else if (res.code == 10005) {
                        that.finished = true;
                    }
                }
            });
        },
        commentListTab() {
            document.getElementById("commentlist").setAttribute("class", "nowclcik")
            document.getElementById("sharelist").removeAttribute("class")
            document.getElementById("liveDetail").removeAttribute("class")
            document.getElementById("yztList").removeAttribute("class")

            document.getElementsByClassName("kechudong")[0].style.display = ""
            document.getElementsByClassName("bangdan")[0].style.display = "none"
            document.getElementsByClassName("xqtabbox")[0].style.display = "none"
            document.getElementsByClassName("yzt")[0].style.display = "none"
        },
        detailTab() {
            document.getElementById("liveDetail").setAttribute("class", "nowclcik")
            // document.getElementById("commentlist").removeAttribute("class")
            document.getElementById("sharelist").removeAttribute("class")
            document.getElementById("yztList").removeAttribute("class")

            document.getElementsByClassName("xqtabbox")[0].style.display = ""
            // document.getElementsByClassName("kechudong")[0].style.display = "none"
            document.getElementsByClassName("bangdan")[0].style.display = "none"
            document.getElementsByClassName("yzt")[0].style.display = "none"
        },
        shareList() {
            document.getElementById("sharelist").setAttribute("class", "nowclcik")
            // document.getElementById("commentlist").removeAttribute("class")
            document.getElementById("liveDetail").removeAttribute("class")
            document.getElementById("yztList").removeAttribute("class")

            // document.getElementsByClassName("kechudong")[0].style.display = "none"
            document.getElementsByClassName("xqtabbox")[0].style.display = "none"
            document.getElementsByClassName("yzt")[0].style.display = "none"
            document.getElementsByClassName("bangdan")[0].style.display = ""
        },

        yztTab() {
            document.getElementById("yztList").setAttribute("class", "nowclcik")
            document.getElementById("sharelist").removeAttribute("class")
            // document.getElementById("commentlist").removeAttribute("class")
            document.getElementById("liveDetail").removeAttribute("class")

            // document.getElementsByClassName("kechudong")[0].style.display = "none"
            document.getElementsByClassName("xqtabbox")[0].style.display = "none"
            document.getElementsByClassName("bangdan")[0].style.display = "none"
            document.getElementsByClassName("yzt")[0].style.display = ""
        },

        addLiveComment() {
            var that = this;
            var content = AnalyticEmotion($("textarea[name='commtent_content']").val());

            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            if (!content.trim()) {
                alert("请输入您的观点");
                return false;
            }
            if(content.length>2000){
                alert("超过最大字符限制，请重新输入");
                return false;
            }
            if (this.commenCD) return;
            this.commenCD = true;
            // $.ajax({
            //     type: 'post',
            //     url: serverHttp + "/index/isLogin",
            //     async: false,
            //     success: function (res) {
            //         if (res.code == 200) {
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/addLiveComment",
                data: {
                    memToken: that.memToken,
                    liveId: that.liveId,
                    content: content
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.websocketsend(content);
                        $(".pinglun")[0].scrollTop = 0;
                        $("textarea[name='commtent_content']").val("");
                    } else if (data.code == 10008) {
                        //去登录
                        // goLogin();
                    } else {
                        alert(data.data.message);
                    }
                    that.commenCD = false;
                },
                error: function (data) {
                    that.commenCD = false;
                }
            });
        },
        initWebSocket() { //初始化weosocket
            var that = this;

            $.ajax({
                type: 'post',
                url: serverHttp + "/index/isLogin",
                async: false,
                success: function (res) {
                    if (res.code == 200) {
                        var wsUrl = serverHttpWss + "/live/oneToMany/" + $("#liveId").val() + "/" + res.data;
                        that.websock = new WebSocket(wsUrl);
                        that.websock.onmessage = that.websocketonmessage;
                        that.websock.onopen = that.websocketonopen;
                        that.websock.onerror = that.websocketonerror;
                        that.websock.onclose = that.websocketclose;
                        setTimeout(function () {
                            // that.showName();
                        }, 1000);
                    } else {
                        return false;
                    }
                },
                error: function (data) {
                    return false;
                }
            });
        },
        showName() {
            var that = this;
            if (that.liveInfo.liveStatus > 1) {
                return false;
            }
            if (that.memNicknames.length > 0) {
                var name = that.memNicknames[that.memNicknames.length - 1];
                that.memNicknames.pop();
                $(".comeIn").html("<span>" + name + "</span>" + " 来了");
                $(".comeIn").stop();
                $(".comeIn").fadeIn(500);
                setTimeout(function () {
                    $(".comeIn").fadeOut(400);
                    setTimeout(function () {
                        that.showName();
                    }, 1000);
                }, 500)
            } else {
                setTimeout(function () {
                    that.showName();
                }, 1000);
            }
        },
        websocketonopen() { //连接建立之后执行send方法发送数据
            console.log('websocket开启');
        },
        websocketonerror() {//连接建立失败重连
            console.log('websocketonerror');
            this.initWebSocket();
        },
        websocketonmessage(e) { //数据接收
            console.log('websocketonmessage');
            var that = this;
            const jx = JSON.parse(e.data);
            if (jx.type == 0) {
                //谁来了
                that.memNicknames.unshift(jx.memNickname);
            } else if (jx.type == 1) {
                //评论
                that.inserComment(jx);
            } else if (jx.type == 2) {
                //更改直播状态
                that.liveInfo.liveStatus = jx.liveStatus;
                if (that.liveInfo.liveStatus == 1) {
                    $(".vcp-player").show();
                    setTimeout(() => {
                        that.toPlay();
                    }, 500)
                } else {
                    $(".vcp-player").hide();
                }
            } else if (jx.type == 3) {
                changeJoinMembers(jx.joinMembers);
            } else if (jx.type == 4) {
                buildHtml(jx.awardWinnerList, 1);
            } else if (jx.type == 5) {
                barrage(jx.barrage);
            } else if (jx.type == 6) {
                sendDrawALotteryActivity();
            } else if (jx.type == 7) {
                for (var item of jx.users) {
                    that.memNicknames.unshift(item);
                }
            } else if (jx.type == 8) {
                $("#tuisongQrpath").find(".wjs").attr("src", jx.imgPath);
                $("#tuisongQrpath").show();
            }
        },
        inserComment(data) {
            data.mem.oprTime = "刚刚";
            data.mem.content = data.mem.msg;
            this.contentList.unshift(data.mem);
        },
        websocketsend(Data) {//数据发送
            console.log("websocketsend");
            this.websock.send(Data);
        },
        websocketclose(e) {  //关闭
            console.log('断开连接', e);
        },
        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) {
                }
            });
        },
        toPay() {
            var that = this
            if (!checkWebLogin()) {
                // $('.navlogorebox').trigger('click')
                return false;
            }
            if (!parseRule(that.liveId,that.memToken,'1',that.source)) {
                return false;
            }

            toPayWeb(2, that.liveInfo.lvId, 1, '');
        },
        addFreeBuyApi() {
            var that = this;
            // $.ajax({
            //     type: 'post',
            //     url: serverHttp + "/index/isLogin",
            //     async: false,
            //     success: function (res) {
            //         if (res.code == 200) {
                        if (!checkWebLogin()) {
                            // $('.navlogorebox').trigger('click')
                            return false;
                        }
                        if (!parseRule(that.liveId,that.memToken,'1',that.source)) {
                            return false;
                        }
                        $.ajax({
                            type: 'POST',
                            url: serverHttp + "/pay/addFreeBuyApi",
                            data: {
                                memToken: that.memToken,
                                orderType: 2,
                                objId: that.liveId,
                                ispackage: 1,
                                paySource: 3,
                                fromMemCard: ''
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    that.liveInfo.isPurchased = 1;
                                    playMusic("积分兑换成功", 10);
                                    that.getDetailData()
                                } else if (data.code == 10008) {
                                    //去登录
                                    $('.navlogorebox').trigger('click')
                                } else {
                                    alert(data.data.message);
                                }
                            },
                            error: function (data) {
                            }
                        });
            //         } else {
            //             $('.navlogorebox').trigger('click')
            //             return false;
            //         }
            //     }
            // })


            // if (!checkLogin()) {
            //     $('.navlogorebox').trigger('click')
            //     return false;
            // }
            // if (!that.parseRule()) {
            //     return false;
            // }

            //         } else {
            //             layer.open({
            //                 type: 1,
            //                 area: ['640px', '400px'],
            //                 skin: 'layui-layer-molv',
            //                 shift: 0,
            //                 title: false,
            //                 offset: ['20%', ' calc(50% - 260px)'],
            //                 closeBtn: 0,
            //                 shadeClose: true,
            //                 content: '<div id="loginbox" class="loginbox">\n' +
            //                     '    <div class="loginboxleft">\n' +
            //                     '        <h1>验证码登录</h1>\n' +
            //                     '        <p><label>+86</label><input name="Text1" type="text" class="tel" autocomplete="off" placeholder="请输入手机号码" /></p>\n' +
            //                     '        <p><input name="Text1" autocomplete="off" type="text" class="yzm" placeholder="请输入验证码" /><button name="Abutton1"\n' +
            //                     '                                                                                      type="button" id="verification">获取验证码</button><span id="djstime" style="display: none;">重新发送(<em id="waittime">60</em>&nbsp;)</span></p>\n' +
            //                     '        <button name="Abutton1" type="button" id="loginBtn">登录</button>\n' +
            //                     '        <div>点击按钮即表示您同意并愿意遵守</div>\n' +
            //                     '        <div><a href="/user/registration?from=web">《用户协议》</a>和<a href="/user/privacy?from=web">《隐私政策》</a></div>\n' +
            //                     '    </div>\n' +
            //                     // '    <div class="loginboxright"></div>\n' +
            //                     '</div>',
            //                 success: function () {
            //                     // 验证
            //                     $('#verification').click(function () {
            //                         var mobile = $(".tel").val();
            //                         if (mobile == "") {
            //                             layer.msg("请填写手机号");
            //                             return;
            //                         }
            //                         if (!isMobile(mobile)) {
            //                             layer.msg("请填写正确的手机号码");
            //                             return;
            //                         }
            //                         sendYzm(mobile);
            //                     })
            //
            //                     $('#loginBtn').click(function () {
            //                         login();
            //                         $.ajax({
            //                             type: 'POST',
            //                             url: serverHttp + "/pay/addFreeBuyApi",
            //                             data: {
            //                                 memToken: that.memToken,
            //                                 orderType: 2,
            //                                 objId: that.liveId,
            //                                 ispackage: 1,
            //                                 paySource: 3,
            //                                 fromMemCard: ''
            //                             },
            //                             success: function (data) {
            //                                 if (data.code == 200) {
            //                                     that.liveInfo.isPurchased = 1;
            //                                 } else if (data.code == 10008) {
            //                                     //去登录
            //                                     // goLogin();
            //                                 } else {
            //                                     alert(data.data.message);
            //                                 }
            //                             },
            //                             error: function (data) {
            //                             }
            //                         });
            //                     })
            //                 }
            //             });
            //         }
            //     },
            //     error: function (data) {
            //         return false;
            //     }
            // });


        },
        findUserInfoWithSm() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: "/user/findUserInfoWithSmWeb",
                success: function (data) {
                    if (data.code == 200 && data.data) {
                        that.userName = data.data.memRealName;
                        that.card = data.data.memIdentityId;
                        that.unitName = data.data.unitName;
                        that.address = data.data.memAddr;
                        that.addressXx = data.data.detailedAddress;
                        that.sex = data.data.memSex;
                        that.experience = data.data.memExp;
                    }
                },
                error: function (data) {
                }
            });
        }
        ,
        // parseRule(){
        //     authentication();
        //     return true;
        // },
        // parseRule() {
        //     var that = this;
        //     $("#submitInfo").unbind("click");
        //     $("#submitQuestion").unbind("click");
        //     $("#professional").unbind("click");
        //     $("#submitInformation").unbind("click");
        //     if (that.attestation.realName) {
        //         var index = layer.open({
        //             type: 1,
        //             area: ['600px', '600px'],
        //             skin: 'layui-layer-molv',
        //             shift: 0,
        //             title: false,
        //             offset: ['8%', 'calc(50% - 260px)'],
        //             closeBtn: 0,
        //             shadeClose: true,
        //             content: $('#smrz'),
        //             success: function () {
        //                 $("#submitInfo").click(function () {
        //
        //                     var userName = $("#userName").val()
        //                     var card = $("#card").val()
        //                     var unitName = $("#unitName").val()
        //                     var address = $("#address").val()
        //                     var sex = $("input[type='radio']:checked").val();
        //                     var experience = $("#experience").val()
        //                     var department = $("#department").val()
        //
        //                     if (!userName || !card || !unitName || !address || !sex || !experience || !department) {
        //                         alert("请完善相关信息");
        //                         return
        //                     }
        //                     $.ajax({
        //                         type: 'POST',
        //                         url: "/user/saveUserInfoWithSmWeb",
        //                         data: {
        //                             userName: userName,
        //                             card: card,
        //                             unitName: unitName,
        //                             address: address,
        //                             sex: sex,
        //                             experience: experience,
        //                             department: department
        //                         },
        //                         success: function (res) {
        //                             if (res.code == 200) {
        //                                 // layer.msg(res.message)
        //                                 $.ajax({
        //                                     type: 'POST',
        //                                     url: serverHttp + "/user/findUserBaseInfo",
        //                                     data: {
        //                                         memToken: that.memToken
        //                                     },
        //                                     success: function (data) {
        //                                         that.memberInfo = data.data;
        //                                         that.attestation.realName = false;
        //                                         layer.close(index)
        //                                         playMusic('实名认证成功', 200);
        //                                         if (that.attestation.physician || that.attestation.question) {
        //                                             setTimeout(that.parseRule, 1500)
        //                                         }
        //                                     },
        //                                     error: function (data) {
        //                                     }
        //                                 });
        //                             } else if (res.code == 10014) {
        //                                 layer.msg("已实名认证")
        //                             } else {
        //                                 layer.msg(res.message);
        //                             }
        //                         }
        //                     })
        //                 })
        //             }
        //         });
        //         return false;
        //     } else if (that.attestation.physician) {
        //         var index = layer.open({
        //             type: 1,
        //             area: ['600px', '600px'],
        //             skin: 'layui-layer-molv',
        //             shift: 0,
        //             title: false,
        //             offset: ['8%', 'calc(50% - 260px)'],
        //             closeBtn: 0,
        //             shadeClose: true,
        //             content: $('#ysrz'),
        //             success: function () {
        //
        //                 getCataList(51, 1);
        //                 getCataListZw(150, 1);
        //
        //                 $("#submitInformation").click(function () {
        //                     var professional = $("#professional").val()
        //                     var professionalTwo = $("#professionalTwo").val()
        //                     var businessLicense = $("#businessLicense").val()
        //                     var post = $("#post").val()
        //                     if (!professional || !professionalTwo || !businessLicense || post == -1 || !post) {
        //                         layer.msg("请完善相关信息");
        //                         return;
        //                     }
        //                     if (!checkyishi(businessLicense)) {
        //                         layer.msg("执业编码填写错误");
        //                         return false;
        //                     }
        //                     $.ajax({
        //                         type: 'POST',
        //                         url: serverHttp + "/user/saveUserInfoWithYsWeb",
        //                         data: {
        //                             professional: professional,
        //                             businessLicense: businessLicense,
        //                             professionalTwo: professionalTwo,
        //                             post: post
        //                         },
        //                         success: function (res) {
        //                             console.log(res);
        //                             if (res.code == 200) {
        //                                 // layer.msg(res.message)
        //                                 $.ajax({
        //                                     type: 'POST',
        //                                     url: serverHttp + "/user/findUserBaseInfo",
        //                                     data: {
        //                                         memToken: ''
        //                                     },
        //                                     success: function (data) {
        //                                         that.memberInfo = data.data;
        //                                         that.attestation.physician = false;
        //                                         layer.close(index)
        //                                         playMusic('医师认证成功', 500);
        //                                         if (that.attestation.question) {
        //                                             setTimeout(that.parseRule, 1500)
        //                                         }
        //                                     },
        //                                     error: function (data) {
        //                                     }
        //                                 });
        //                             } else if (res.code == 10014) {
        //                                 alert("已完成医师认证")
        //                             } else {
        //                                 alert(res.message);
        //                             }
        //                         }
        //                     })
        //                 })
        //
        //                 $("#professional").click(function () {
        //                     professionalChange(1)
        //                 })
        //
        //                 // $("#professionalTwo").click(function () {
        //                 //     professionalChange(1)
        //                 // })
        //
        //                 function professionalChange(type) {
        //                     if (type == 1) {
        //                         var professional = $("#professional").val()
        //                         if (professional == -1) {
        //                             // that.selectTwoData = [];
        //                         } else {
        //                             getCataList(professional, 2);
        //                         }
        //                     }
        //                 }
        //
        //                 function getCataList(fId, type) {
        //                     $.ajax({
        //                         type: 'POST',
        //                         url: serverHttp + "/course/getCataList",
        //                         data: {
        //                             fId: fId,
        //                             type: 5,
        //                         },
        //                         success: function (res) {
        //                             if (res.code == 200) {
        //                                 if (type == 1) {
        //                                     $("#professional").empty()
        //                                     res.data[0].name = "请选择"
        //                                     var selectOneData = res.data;
        //                                     for (let i = 0; i < selectOneData.length; i++) {
        //                                         $("#professional").append("<option value='" + selectOneData[i].id + "'>" + selectOneData[i].name + "</option>")
        //                                     }
        //                                 } else {
        //                                     $("#professionalTwo").empty()
        //                                     var selectTwoData = res.data;
        //                                     for (let i = 0; i < selectTwoData.length; i++) {
        //                                         $("#professionalTwo").append("<option value='" + selectTwoData[i].id + "'>" + selectTwoData[i].name + "</option>")
        //                                     }
        //                                 }
        //                             }
        //                         },
        //                         error: function (data) {
        //
        //                         }
        //                     });
        //                 }
        //
        //                 function getCataListZw(fId, type) {
        //                     $.ajax({
        //                         type: 'POST',
        //                         url: serverHttp + "/course/getCataList",
        //                         data: {
        //                             fId: fId,
        //                             type: 5,
        //                         },
        //                         success: function (res) {
        //                             res.data[0].name = "请选择";
        //                             if (res.code == 200) {
        //                                 var zw = res.data;
        //                                 for (let i = 0; i < zw.length; i++) {
        //                                     $("#post").append("<option value='" + zw[i].id + "'>" + zw[i].name + "</option>")
        //                                 }
        //                             }
        //                         },
        //                         error: function (data) {
        //
        //                         }
        //                     });
        //                 }
        //             }
        //         });
        //         return false;
        //     } else if (that.attestation.question) {
        //         var size = 0;
        //         for (var item of that.liveInfo.questions) {
        //             if (item.answerContent == undefined || item.answerContent == null || item.answerContent === '') {
        //                 size++;
        //             }
        //         }
        //         if (size == 0) {
        //             return true;
        //         }
        //         // $(".info-collect").show();
        //         var layerIndex = layer.open({
        //             type: 1,
        //             area: ['700px', '430px'],
        //             skin: 'layui-layer-molv',
        //             shift: 0,
        //             title: false,
        //             offset: ['8%', 'calc(50% - 380px)'],
        //             closeBtn: 0,
        //             shadeClose: true,
        //             content: $('#wjdc'),
        //             success: function () {
        //                 $("#writeform").empty()
        //                 var index = 0;
        //                 for (var item of that.liveInfo.questions) {
        //                     if (item.answerContent == undefined || item.answerContent == null || item.answerContent === '') {
        //                         $("#writeform").append("<div><label>" + item.quTitle + "：</label><span><input data-index='" + index + "' type=\"text\" placeholder=\"请输入\"/></span></div>");
        //                     }
        //                     index++;
        //                 }
        //                 $("#writeform").append("<div class=\"layerbtnbox\"><button id='submitQuestion' type=\"button\" class=\"btn\">提交信息</button></div>")
        //                 $("#submitQuestion").click(function () {
        //                     var check = true;
        //                     var inputs = $("#writeform input");
        //
        //                     for (let i = 0; i < inputs.length; i++) {
        //                         that.liveInfo.questions[$(inputs[i]).data("index")].answerContent = $(inputs[i]).val()
        //                     }
        //
        //                     for (var item of that.liveInfo.questions) {
        //                         if (item.answerContent == undefined || item.answerContent == null || item.answerContent === '') {
        //                             check = false;
        //                             break;
        //                         }
        //                     }
        //                     if (!check) {
        //                         alert("请完善相关信息");
        //                         return false;
        //                     }
        //                     $.ajax({
        //                         type: 'POST',
        //                         url: serverHttp + "/live/saveQuestionAnswer",
        //                         data: {
        //                             liveId: that.liveId,
        //                             memToken: that.memToken,
        //                             questions: JSON.stringify(that.liveInfo.questions)
        //                         },
        //                         success: function (data) {
        //                             if (data.code == 200) {
        //                                 that.liveInfo.isQuestionAnswer = 1;
        //                                 that.attestation.question = false;
        //                                 layer.close(layerIndex)
        //                                 // that.addFreeBuyApi();
        //                             }
        //                         },
        //                         error: function (data) {
        //                         }
        //                     });
        //                 })
        //             }
        //         });
        //
        //         return false;
        //     }
        //     return true;
        // }

        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;
            //var fromMemCard = '';
            // if(getQueryVariable("fromMemCard") != false){
            //     fromMemCard = getQueryVariable("fromMemCard")
            // }
            $.ajax({
                type : 'POST',
                url : serverHttp+"/live/getDetailData",
                data : {
                    memToken:that.memToken,
                    liveId: that.liveId,
                    fromMemCard:that.fromMemCard
                },
                success : function(data) {
                    if (data.code == 200) {
                        that.liveInfo = data.data;
                        //公众号链接进入的隐藏直播
                        if(that.liveInfo.isVisiable == 0){
                            alert("直播已取消");
                            window.location.href = serverHttp + '/live/index?from=web'
                            return false;
                        }

                        if (that.liveInfo.liveStatus == 3 && that.liveInfo.isPurchased == 1) {
                            setTimeout(() => {
                                that.dplayer = that.newPlayer(that.liveInfo.backviewUrl, that.liveInfo.liveCoverImg,false);
                            }, 500);
                        }
                        $("meta[name='sharetitle']").attr("content",that.liveInfo.shareTitle);
                        $("meta[name='sharedesc']").attr("content",that.liveInfo.shareDesc);
                        $("meta[name='sharepic']").attr("content",that.liveInfo.sharePic);
                        //$("meta[name='shareurl']").attr("content",that.liveInfo.shareUrl);


                        document.title = that.liveInfo.liveTitle;
                        if (that.liveInfo.liveStatus == 0) {
                            that.countDown();
                        } else if (that.liveInfo.liveStatus == 1 && that.liveInfo.isPurchased == 1) {

                            setTimeout(() => {
                                that.dplayer = that.newPlayer(that.liveInfo.livePlayUrl, that.liveInfo.liveCoverImg,true);
                            }, 500);
                            //this.addplayevent(that.dplayer);
                            //document.getElementById('dplayer').appendChild("<div class=\"prism-big-play-btn pause\" id=\"player-con_component_21894B02-33D2-4FC6-A4F4-2FCC05929BEE\" style=\"position: absolute; left: 30px; bottom: 80px; display: block;\"><div class=\"outter\">111</div>222</div>")

                        }
                        if (that.liveInfo.showHall == null || that.liveInfo.showHall == '' || that.liveInfo.showHall == undefined) {
                            that.cata[1].disable = false;
                        }
                        that.infoByMember();
                        that.numberTimer = setInterval(that.infoByMember, 60000);
                        if(that.liveInfo.isPurchased == 1){
                            // if(that.liveInfo.pointFlag==1 && that.liveInfo.point>0 || that.liveInfo.price>0){
                                that.addVideoPlayRecorde();
                            // }
                        }
                    }
                },
                error : function(data) {
                }
            });


            // $.ajax({
            //     type: 'POST',
            //     url: serverHttp + "/live/getDetailData",
            //     data: {
            //         memToken: that.memToken,
            //         liveId: that.liveId
            //     },
            //     success: function (data) {
            //         if (data.code == 200) {
            //             that.liveInfo = data.data;
            //             if (that.liveInfo.liveStatus == 3 && that.liveInfo.isPurchased == 1) {
            //                 document.getElementById('dplayer').style.display = ""
            //                 const dp = new DPlayer({
            //                     container: document.getElementById('dplayer'),
            //                     video: {
            //                         url: that.liveInfo.backviewUrl,
            //                         pic: that.liveInfo.liveCoverImg
            //                     },
            //                     autoplay: true,
            //                     hotkey: true
            //                 });
            //                 dp.on("timeupdate", () => {
            //                     that.currentTime = Math.floor(dp.video.currentTime) * 1000;
            //                 });
            //                 dp.on("play", () => {
            //                     that.videoPlay()
            //                 });
            //                 dp.on("pause", () => {
            //                     that.videoPause()
            //                 });
            //                 document.getElementById('dplayer').oncontextmenu = function (event) {
            //                     event.preventDefault();
            //                     return false;
            //                 }
            //             }
            //
            //             $("meta[name='sharetitle']").attr("content", that.liveInfo.shareTitle);
            //             $("meta[name='sharedesc']").attr("content", that.liveInfo.shareDesc);
            //             $("meta[name='sharepic']").attr("content", that.liveInfo.sharePic);
            //             // $("meta[name='shareurl']").attr("content",that.liveInfo.shareUrl);
            //             that.collect = data.data.isController > 0 ? false : true;
            //             that.collectImgSrc = data.data.isController > 0 ? '/web/img/collect.png' : '/web/img/collected.png';
            //             // (that.liveInfo.price==0 &&that.liveInfo.pointFlag==0 && that.liveInfo.isPurchased == 0) || (that.liveInfo.price==0 &&that.liveInfo.pointFlag==1 && that.liveInfo.point==0 && that.liveInfo.isPurchased == 0)?that.addFreeBuyApi():''
            //
            //             if (that.liveInfo.liveStatus == 0) {
            //                 that.countDown();
            //             } else if (that.liveInfo.liveStatus == 1 || that.liveInfo.liveStatus == 3) {
            //                 timer = setTimeout(() => {
            //                     that.toPlay();
            //                 }, 1000);
            //             }
            //             that.infoByMember();
            //         }
            //     },
            //     error: function (data) {
            //     }
            // });
        }
        ,
        updateTime(e) {
            var video = document.getElementById('dplayer');
            this.currentTime = Math.floor(video.currentTime) * 1000;
        },
        videoPlay() {
            this.startTiming();
        },
        videoPause() {
            clearInterval(this.timer)
        },
        infoByMember() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/infoByMember",
                data: {
                    memToken: that.memToken,
                    liveId: that.liveId
                },
                success: function (data) {
                    if (data.code == 200) {
                        // that.liveInfo.joinMembers = data.data.joinMembers;
                        // that.liveInfo.isPurchased = data.data.isPurchased;
                        // that.liveInfo.isRemind = data.data.isRemind;
                        //过万以 W 为单位展示
                        //+ data.data.vremindMemberNum
                        var total = data.data.remindMemberNum;
                        if (total > 9999) {
                            var numCount =(total / 10000).toFixed(2)
                            that.liveInfo.remindMemberNum = numCount + "万";
                        }else{
                            that.liveInfo.remindMemberNum = total;
                        }
                        that.liveInfo.liveManTime = data.data.liveManTime
                        that.liveInfo.isQuestionAnswer = data.data.isQuestionAnswer;
                    }
                },
                error: function (data) {
                }
            });
        }
        ,
        countDown() {
            var that = this;
            var timer = setInterval(function () {
                if (that.liveInfo.liveBeginSySecond > 0) {
                    var sys_second = that.liveInfo.liveBeginSySecond - 1;
                    that.liveInfo.liveBeginSySecond = sys_second;
                    that.endTime.day = Math.floor((sys_second / 3600) / 24);
                    that.endTime.hour = Math.floor((sys_second / 3600) % 24);
                    that.endTime.minute = Math.floor((sys_second / 60) % 60);
                    that.endTime.second = Math.floor(sys_second % 60);
                    //倒计时结束打开播放器并播放
                    if(sys_second > 172800){
                        sys_second = 172800
                    }
                    setTimeout(() => {
                        that.liveInfo.liveStatus = 1;
                        $(".vcp-player").show();
                        that.newPlayer();
                    }, sys_second * 1000)
                } else {
                    clearInterval(timer);
                }
            }, 1000);
        }
        ,
        chooseTab(i, item) {
            this.showTabContentIndex = item.id
            const that = this;
            for (var item of that.cata) {
                if (item.active == 1) {
                    item.active = 0
                }
            }
            that.cata[i].active = 1;
        }
        ,
        gotoDetail(obj) {
            window.location.href = serverHttp + '/live/detail?from=H5&liveId=' + obj.lvId;
        }
        ,
        gotoRcmd(obj) {
            gotoRcmdPub(obj.zqFlag, obj.rcmdType, obj.rcmdObjId, obj.rcmdUrl);
        }
        ,

        // 查询社群二维码
        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) {
                }
            });
        }
        ,

        // 咨询推荐
        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[1].rcmdData
                    }
                },
                error: function (data) {
                }
            });
        }

    }
})
