Vue.config.devtools = true;
// 获取当前屏幕高度
var screenHeight = $(window).height() + 'px';
$("body").css("height",screenHeight)
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: ".container",
    data: {
        isVip: 0,
        cata: [
            {name: "会议日程", active: 1, id: 1, disable: true},
            {name: "互动", active: 0, id: 2, disable: true},
            {name: "项目支持", active: 0, id: 3, disable: false},
            {name: "分享榜单", active: 0, id: 4, disable: true}
        ],
        websock: null,
        memToken: '',
        memCard: '',
        liveId: '',
        fromMemCard:'',
        source: '0',
        liveInfo: {sysRecommendDTOs: []},
        endTime: {day: 0, hour: 0, minute: 0, second: 0},
        content: '',
        loading: false,
        cid: -1,
        finished: false,
        contentList: [],
        yzt: [],
        liveLlayer: null,
        memberInfo: {
            isPurchased: 0,
            isRemind: 0,
            joinMembers: 0,
            remindMemberNum: 0
        },
        memNicknames: [],
        isLogin: 0,
        memHeadImg: '',
        userJf: -1,
        rank: [],
        objType: 2,
        subing: 0,
        learnTime: 1,
        currentTime: 1,
        timer: null,
        toast: false,
        url: "https://www.qkyxzx.com/live/detail?from=web",
        integralType: "",
        integralCount: "",
        bofangFlag: 0,
        showTabContentIndex: 1,
        numberTimer: null, // 人数定时器
        joinMembers: 0,
        attestation: {},
        finishTimer: null,//定时结束
        retryInterval: null,
        hlsError: false,
        dplayer: null,
        count:0,
        isAudit:false,
        shareData: null
    },
    created: function () {
        var that = this;
        if ($.cookie("memToken")) {
            that.memToken = $.cookie("memToken");
            that.isLogin = 1;
        }
        if ($.cookie("memHeadImg")) {
            that.memHeadImg = $.cookie("memHeadImg");
        }
        if ($.cookie("memCard")) {
            that.memCard = $.cookie("memCard");
        }
        that.liveId = $("#liveId").val();
        that.fromMemCard = $("#fromMemCard").val();
        if(getQueryVariable("source") == 1){
            that.source = getQueryVariable("source");
        }else{
            that.source = '0';
        }
        that.getDetailData();
        that.findUserBaseInfo();
        that.commentList();
        that.findUserIntegral();
        that.rankingList();
        this.getAttestation();
        if (typeof (fromlogin) != "undefined" && fromlogin == "1") {
            jifen();
        }

        this.posterData();
    },
    mounted: function () {
        window.addEventListener('resize', function () {

        })
        var that = this;
        window.addEventListener('pageshow', function (event) {
            if (event.persisted) { // ios 有效, android 和 pc 每次都是 false
                that.findUserBaseInfo();
            } else { // ios 除外
                if (sessionStorage.getItem('refresh') === 'true') {
                    that.findUserBaseInfo();
                }
            }
            sessionStorage.removeItem('refresh');
        });
        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);
        window.addEventListener("scroll", this.debounce(this.scrollBottom,10), true);
        this.initWebSocket();
        window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
        setTimeout(() => {
            $(".loading-item").fadeOut(200);
            // this.initFn();
        }, 500)
        // this.getcounter()
        // this.numberTimer = setInterval(this.getcounter, 10000);
    },
    destroy() {
        clearInterval(this.numberTimer)
    },
    watch: {
        liveInfo(val) {
            if (val.colorSwatches) {
                const len = val.colorSwatches.split(',').length;
                if (len <= 1) {
                    this.$refs.make.style.background = val.colorSwatches || '#000';
                } else {
                    this.$refs.make.style.background = 'linear-gradient(to bottom,' + val.colorSwatches + ')'
                }
            }
            if (val.colorTextSwatches) {
                this.$refs.make.style.color = val.colorTextSwatches || '#fff';
            }

            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: {
        posterData(){
            var that = this;
            $.ajax({
                type: 'get',
                url: serverHttp + "/live/getUserInfoByLiveId",
                async: false,
                data: {
                    liveId: that.liveId
                },
                success: function (res) {
                    console.log(res)
                    that.shareData = res.data
                },
                error: function (data) {
                }
            })
        },
        scrollCont(){
            $(".textCont")[0].scrollTop = $(".textCont")[0].scrollHeight;
        },
        getAttestation() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/popu/window/checkWindow",
                async: false,
                data: {
                    id: that.liveId,
                    idType: 1,  // 0 课程 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
                    }
                }
            })
        },
        initFn() {
            var mySwiper = new Swiper('.swiper-container', {
                direction: 'horizontal', // 水平切换选项
                loop: this.ad.length > 1, // 循环模式选项
                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',
                },

            })
        },
        copy() {
            var aux = document.createElement("input");
            aux.setAttribute('readonly', 'readonly');
            aux.value = this.url + "&liveId=" + this.liveId;
            document.body.appendChild(aux);
            aux.setSelectionRange(0, 9999);
            aux.select();
            document.execCommand("copy");
            document.body.removeChild(aux);
            this.toast = false;
        },
        showTast() {
            this.toast = true;
        },
        closeToast() {
            this.toast = false;
        },
        startTiming() {
            var that = this;
            that.timer = setInterval(function () {
                that.learnTime = that.learnTime + 1;
                // if (that.learnTime >= 5) {
                //     that.addVideoPlayRecorde();
                //     that.learnTime = 0;
                // }
                if (that.learnTime % 30 == 0) {
                    //30秒的倍数
                    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){
                        goLogin();
                    }else if(data.code == 10029){
                        //在另一设备登录，重新登录
                        $(".userConfirmBox").show();
                    }
                },
            });
        },
        rankingList() {
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/rankList",
                data: {
                    objType: that.objType,
                    objId: that.liveId,
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.rank = data.data.rankList;
                    }
                }
            });
        },
        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() {
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            var that = this;
            if (!that.parseRule()) {
                return false;
            }
            var check = true;
            that.liveInfo.questions.forEach((item, index) => {
                if (!item.answerContent || item.answerContent.trim() == "") {
                    check = false;
                }
            });
            // if (!check) {
            //     alert("请完善相关信息");
            //     return false;
            // }
            toPay(2, that.liveInfo.lvId, 1, '');
        },
        addFreeBuyApi() {
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            var that = this;
            if (!that.parseRule()) {
                return false;
            }
            $.ajax({
                type: 'POST',
                url: serverHttp + "/pay/addFreeBuyApi",
                data: {
                    memToken: that.memToken,
                    orderType: 2,
                    objId: that.liveId,
                    ispackage: 1,
                    paySource: 3,
                    fromMemCard: $.cookie("fromMemCard")
                },
                success: function (data) {
                    if (data.code == 200) {
                        that.getDetailData();
                        // that.addVideoPlayRecorde();
                        that.liveInfo.isPurchased = 1;
                        //that.toPlay();
                        that.integralType = "领取直播";
                        that.integralCount = 10;
                        $(".integral-toast").show();
                        playMusic()
                        setTimeout(function () {
                            $(".integral-toast").fadeOut(200);
                        }, 2000);
                    } else if (data.code == 10008) {
                        //去登录
                        goLogin();
                    } else {
                        alert(data.message);
                    }
                },
                error: function (data) {
                }
            });
        },
        parseRule() {
            var that = this;
            this.getAttestation();
            if (that.attestation.attestType == 2) {
                window.location.href = serverHttp + "/user/certificationSm?from=H5&memToken=&type=1&id=" + that.liveId;
                return false;
            } else if (that.attestation.attestType == 1) {
                window.location.href = serverHttp + "/user/certificationYs?from=H5&memToken=&type=1&id=" + that.liveId;
                return false;
            } else if (that.attestation.attestType == 4) {
                window.location.href = serverHttp + "/user/certificationSmojl?from=H5&memToken=&type=1&id=" + that.liveId + '&source=' + that.source;
                return false;
            } else if (that.attestation.attestType == 3) {
                window.location.href = serverHttp + "/user/certificationYsojl?from=H5&memToken=&type=1&id=" + that.liveId + '&source=' + that.source;
                return false;
            } else if (that.attestation.attestType == 5 && that.attestation.question) {
                window.location.href = serverHttp + "/live/liveQuestion?from=H5&memToken=&type=1&id=" + that.liveId;
                return false;
            }else if (that.attestation.attestType == 5 && !that.attestation.question && that.attestation.needAuditing == 1) {
                if(that.attestation.auditingStatus == 1){
                    that.isAudit = true
                }else if(that.attestation.auditingStatus == 3){
                    window.location.href = serverHttp + "/live/liveQuestion?from=H5&memToken=&type=1&id=" + that.liveId;
                }else{
                    return true;
                }
                return false;
            }
            return true;
        },
        closeAudit(){
            this.isAudit = false
        },
        inputChange(e, obj) {
            obj.answerContent = e.target.value;
        },
        gotoRcmd(obj) {
            gotoRcmdPub(obj.zqFlag, obj.rcmdType, obj.rcmdObjId, obj.rcmdUrl, "H5", obj.artType, obj.artContent);
        },
        saveQuestionAnswer() {
            var that = this;
            var check = true;
            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: {
                    memToken: that.memToken,
                    questions: JSON.stringify(that.liveInfo.questions)
                },
                success: function (data) {
                    if (data.code == 200) {
                        $(".info-collect").hide();
                        that.liveInfo.isQuestionAnswer = 1;
                    }
                },
                error: function (data) {
                }
            });
        },
        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) {
                }
            });
        },
        findUserBaseInfo() {
            if (!checkLogin()) {
                return false;
            }
            var that = this;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/user/findUserBaseInfo",
                data: {
                    memToken: that.memToken
                },
                success: function (data) {
                    that.memberInfo = data.data;
                    that.isVip = that.memberInfo.isVip;
                },
                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)
            }
            if(isLive == false){
                var memoryPlay = [{
                    name: 'MemoryPlayComponent',
                    type: AliPlayerComponent.MemoryPlayComponent,
                    args:[false,getTime,saveTime]
                }]
            }else{
                var memoryPlay = []
            }

            var that = this;
            let autoPlay = that.liveInfo.isPurchased > 0 ? true : false;
            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": 6
                            },
                            {
                                "name": "timeDisplay",
                                "align": "tl",
                                "x": 10,
                                "y": 7
                            },
                            {
                                "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;
            // if (that.cata[1].active == 1) {
            //     // 滚动到页面顶部时
            //     const scrollTop = document.getElementById('contentList').scrollTop
            //     if (scrollTop == 0 && !that.finished) {
            //         that.commentList();
            //     }
            // }
            const that = this;
            if (that.cata[1].active == 1) {
            // 滚动到页面底部时
                const el = document.getElementsByClassName('commentList')[0];
                const elHeight = $(".commentList").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.commentList();
                }
            }
        }
        ,
        commentList() {
            var that = this;
            if (that.loading) {
                return;
            }
            that.loading = true;
            if (that.start == 1) {
                that.contentList = []
            }
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/commentList",
                data: {
                    cId: that.cid,
                    liveId: that.liveId
                },
                success: function (res) {
                    that.loading = false;
                    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;
                        if (that.cata[1].active == 1) {
                            document.getElementById('contentList').scrollTop = 2;
                        }
                    } else if (res.code == 10005) {
                        that.finished = true;
                    }
                }
            });
        }
        ,
        addLiveComment() {
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            var that = this;
            var content = AnalyticEmotion($(".textCont").val());
            if (!content.trim()) {
                alert("请输入您的观点");
                return false;
            }
            if(content.length>2000){
                alert("超过最大字符限制，请重新输入");
                return false;
            }
            if (that.subing == 1) {
                return false;
            }
            that.subing = 1;
            $.ajax({
                type: 'POST',
                url: serverHttp + "/live/addLiveComment",
                data: {
                    memToken: that.memToken,
                    liveId: that.liveId,
                    content: content
                },
                success: function (data) {
                    that.subing = 0;
                    if (data.code == 200) {
                        that.websocketsend(content);
                        $(".commentList")[0].scrollTop = 0;
                        // $(".commentList").animate( { scrollTop: 0 } );
                        $(".textCont").val("");
                    } else if (data.code == 10008) {
                        //去登录
                        goLogin();
                    } else {
                        alert(data.data.message);
                    }
                },
                error: function (data) {
                }
            });
        }
        ,
        addRemind() {
            if (!checkLogin()) {
                // goLogin();
                return false;
            }
            var that = this;
            //距离播放时间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 + "/live/addRemind",
                data: {
                    memToken: that.memToken,
                    liveId: that.liveId
                },
                success: function (data) {
                    if (data.code == 200) {
                        if (data.data.code != -1) {
                            that.getDetailData()
                            // that.infoByMember()
                            //过万以 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) {
                            $("#gzfwh").show();
                        }
                        if (that.liveInfo.price == 0 && that.liveInfo.point == 0) {
                            //如果是免费课程，订阅成功后添加购买记录
                            //that.addFreeBuyApi();
                        }
                    } else if (data.code == 10008) {
                        //去登录
                        goLogin();
                    } else {

                    }
                },
                error: function (data) {
                }
            });
        }
        ,
        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;
        },

        getDetailData() {
            var that = this;
            $.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=H5'
                            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);
                        }

                        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) {
                }
            });
        },
        updateTime(e) {
            var video = document.getElementById('dplayer');
            // this.currentTime = Math.floor(video.currentTime) * 1000;
            this.currentTime = Math.floor(video.getCurrentTime());
        },
        videoPlay() {
            this.startTiming();
        },
        videoPause() {
            clearInterval(this.timer)
        },
        initWebSocket() { //初始化weosocket
            var that = this;
            if (!that.memCard) {
                return false;
            }
            var wsUrl = serverHttpWss + "/live/oneToMany/" + $("#liveId").val() + "/" + this.memCard;
            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);
        }
        ,
        websocketonopen() { //连接建立之后执行send方法发送数据

        }
        ,
        websocketonerror() {//连接建立失败重连

            this.initWebSocket();
        }
        ,
        websocketonmessage(e) { //数据接收

            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.dplayer = that.newPlayer(that.liveInfo.livePlayUrl, that.liveInfo.liveCoverImg,true)
                        //that.toPlay();
                    }, 500)
                } else {
                    if (that.dplayer) {
                        document.getElementById('dplayer').style.display = "none"
                        // that.dplayer.destroy();
                        that.dplayer.dispose();
                    }
                    $('.load').hide(500);
                    $(".load-live-ing").hide(500);
                }
            } 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();
            }
        }
        ,
        websocketsend(Data) {//数据发送
            // if (!isOpen(socket)) return;
            // socket.send(JSON.stringify(data));
            this.websock.send(Data);
        }
        ,

        websocketclose(e) {  //关闭
            if(this.count<3){
                this.count = this.count + 1;
                setTimeout(function () {
                    console.info("尝试重连..." + new Date().format("yyyy-MM-dd hh:mm:ss"));
                    this.initWebSocket();
                }, 3000);
            }

        }
        ,
        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);
        }
        ,
        inserComment(data) {
            data.mem.oprTime = "刚刚";
            data.mem.content = data.mem.msg;
            this.contentList.unshift(data.mem);
        }
        ,
        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);
            }
        }
        ,
    }
})
