index.vue 40 KB
Newer Older
程智春 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<template>
    <div class="container" :style="{'padding-top':navHeight +'px'}">
        <div class="masker"></div>
        <live-pusher 
            id="pusher"
            :url="tuiStream" 
            :mode="clear" 
            bindstatechange="statechange" 
            :beauty="beauty"
            :enable-camera="enableCamera"
            :whiteness="whiteness"
            :device-position="devicePosition"
            :enable-mic="enableMic"
程智春 committed
14
            :remote-mirror="mirror"
程智春 committed
15
            :mirror="mirror"
程智春 committed
16
            :local-mirror="remoteMirror"
程智春 committed
17
            :waiting-image="liveInfo.coverUrl"
程智春 committed
18 19 20 21
            style="width: 100%; height: 100vh;position:fixed;top:0;left:0;z-index:-1" 
            @statechange="statechange"
            @error="binderror"
            @netstatus="bindnetstatus"
程智春 committed
22
            v-if="refreshLive"
程智春 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
        />
        <image class="bg-img" v-if="isBgImg" :src="liveInfo.coverUrl" mode="aspectFill" alt=""></image>
        <div class="content" :style="{'padding-top':navHeight +'px'}">
            <navBar 
                :navTop="navTop" 
                :navHeight="navHeight" 
                :isSetBeauty="isSetBeauty" 
                :isLive="isLive" 
                :type="1" 
                :id="liveId"
                :pusher="pusher"
                :liveInfo="liveInfo"
                :realStartTime="realStartTime"
                @closeSetBeauty="closeSetBeauty"
                @clearAllInterval="clearAllInterval"
程智春 committed
38
                @changeOver="changeOver"
程智春 committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            >
            </navBar>
            <div class="live-active" v-if="!isSetBeauty">
                <span>{{look}} 观看</span>
                <span>{{praise}}</span>
                <span>{{online}} 在线</span>
                  
            </div>
            
            <!-- 开播倒计时 -->
            <div class="countdown" v-show="isCountDown">
                {{liveCountDown}}
            </div>
            <!-- 还没开始直播 -->
            <div class="wait-start" v-show="noStartLive">
                <div class="title">{{liveInfo.title}}</div>
                <div class="open-live-title">{{!liveTimeStatus ? '开播倒计时' : '已超时,请尽快开始'}}</div>
                <div class="wait-time">{{liveTime}}</div>
                <div class="start-btn" @click="toSetBeauty('start')">开始直播</div>
            </div>
            <!-- 直播异常 -->
            <div class="unusual-wrap" v-show="recoverLive">
                <div class="title">{{liveInfo.title}}</div>
                <div class="unusual-text">直播异常中断</div>
                <div class="recover-btn" @click="checkLiveEnv('recover')">恢复直播</div>
            </div>
            <!-- 公告 -->
            <div class="notice" v-show="!isSetBeauty">
                公告:{{liveInfo.liveNotice}}
            </div>
            <!-- 设置 -->
            <div class="setting-wrap" @click="setBeauty" v-show="!isSetBeauty && !isCountDown">
                <img class="set-img" src="../../../static/images/shezhi.png" alt="">
            </div>
            <!-- 商品 -->
            <div class="product-wrap"  v-show="!isSetBeauty && liveInfo.liveBroadcastSales == 0" @click="showPopup">
                <div class="product-num">{{productList.length}}</div>
                <img class="product-img" src="../../../static/images/shangpin.png" alt="">
            </div>
            <!-- 商品弹窗 -->
            <product 
                :productList="productList" 
                :productDialogStatus="productDialogStatus" 
                @hideProductPopup="hideProductPopup"
                @changeProduct="changeProduct"
            >
            </product>
            <!-- 讲解商品列表 -->
            <div class="speak-product" v-show="!isSetBeauty && isLive">
            <!-- <div class="speak-product"> -->
                <div class="speak-item" v-for="(item,index) in speakProductList" :key="index">
                    <div class="item-status">
                        讲解中
                    </div>
                    <div class="item-top">
                        <img :src="item.productImgUrl" alt="">
                    </div>
                    <div class="item-bottom">
{{item.minPrice}}
                    </div>
                </div>
            </div>
            <!-- 设置 -->
            <setting 
                :pusher="pusher"
                :beauty="beauty" 
                :whiteness="whiteness"
                :clear="clear"
                :devicePosition="devicePosition"
                :enableMic="enableMic"
                :remoteMirror="remoteMirror"
                :isLive="isLive"
                :liveInfo="liveInfo"
                @updateBeauty="updateBeauty"
                @updateWhiteness="updateWhiteness"
                @updateClear="updateClear"
                @updateDevicePosition="updateDevicePosition"
                @updateRemoteMirror="updateRemoteMirror"
                @updateEnableMic="updateEnableMic"
                v-if="isSetBeauty"
程智春 committed
119
                @setBeautyStart="checkLiveEnv"
程智春 committed
120 121 122
            >
            </setting>
            <!-- 评论 -->
程智春 committed
123
            <comments v-if="!isSetBeauty" :updateVal="updateVal" :id="liveId" :commentsList="commentsList"></comments>
程智春 committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
            <!-- 用户进入通知 -->
            <div class="userComing userComingAni" v-if="userComing && !isSetBeauty">
                <span>{{entryNoticeText}}</span>
                <span>来了</span>
            </div>
            
        </div>  
    </div>
</template>

<script>
import navBar from '@/components/common/navbar.vue'
import product from '@/components/product'
import setting from '@/components/setting'
import comments from '@/components/comments'
import { getNavbarInfo,DFSImg } from '../../utils/common.js'

import liveApi from '@/api/liveing'
export default {
    data(){
        return{
            navTop : '',
            navHeight : '',

            isSetBeauty : false, //是否点击了设置
            isUsual : false, //直播异常
            productDialogStatus : false, //商品弹出框状态
            isLive : false, //是否在直播
            enableCamera : false, //是否开启摄像头

            isPruductUp : false,

            speakProductList : [],

            pusher:null,
            beauty:5, //美颜
            whiteness:5,//美白
            clear:'HD',
            devicePosition : 'front', //前置或者后置 back => 后置
            enableMic: true, //麦克风是否开启
程智春 committed
164
            remoteMirror:'enable', //镜像
程智春 committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213

            userInfo : null,

            liveInfo : {}, //直播信息

            liveTime :'', //开播时间
            liveTimeStatus : false , //是否超时

            liveCountDown : 3, //开播倒计时
            isCountDown : false, //是否显示倒计时

            liveId : '', //直播间id

            userComing: false,
            entryNoticeText : '', //进入通知

            online : 0, //在线
            look : 0, //观看
            praise:0, //点赞

            commentsList : [], //评论

            
            noStartLive : false,//还没开始直播,
            recoverLive : false,//恢复直播

            openLiveTimer : null, //开播时间定时器

            tuiStream : '', //推流
            
            productList : [], //商品列表

            realStartTime : 0, //直播时间

            liveDetailTimer : null, //获取直播评论等数据的定时器

            getProductTimer : null, //刷新商品定时器

            isBgImg : true,  //是否展示背景图片

            openRecordSet : false, //控制录音授权

            openCameraSet : false, //控制相机授权

            isChangeProduct : true, //是否可以上下屏,防止多次点击上下屏

            isTimeLock : true, //时间锁

            isTimeFirstReq : true, //第一次数据请求
程智春 committed
214

程智春 committed
215 216
            isDetailLock : true, //查看详情锁

程智春 committed
217 218 219
            updateVal : 0,

            overOrStop : 1, //是暂停还是结束
程智春 committed
220 221

            isDetailControlLock : true,
程智春 committed
222

程智春 committed
223 224 225 226 227
            mirror : true,


            refreshLive : true

程智春 committed
228 229
        }
    },
程智春 committed
230 231 232 233 234
    filter(){
        formatNum : (val) => {
            return val - 0 > 10000 ? Math.floor(val / 10000)+ "w" : val
        }
    },
程智春 committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    watch:{
        //用户通知
        entryNoticeText(){
            if(this.entryNoticeText){
                this.userComing=true;
                setTimeout(() => {
                    this.userComing=false;
                }, 4600);
            }else{
                this.userComing=false;
            }
        },
        //开关摄像头
        enableCamera(){
            
            if(this.isLive){
                this.enableCamera = true
                this.isBgImg = false;
            }
            
        },
    },
    components:{
        navBar,
        product,
        setting,
        comments
    },
    created(){
        //获取导航栏信息
        getNavbarInfo((res) => {
            this.navTop = res.navTop
            this.navHeight = res.navHeight
        })
    },
    onLoad(options){

        this.isLive = false;
        this.enableCamera = false;
        this.isSetBeauty = false; 
        this.noStartLive = false;
        this.recoverLive = false;
        this.realStartTime = 0;
        this.isBgImg = true;
        this.isTimeLock = true;
        this.isTimeFirstReq = true;
程智春 committed
281
        this.overOrStop = 1;
程智春 committed
282
        this.isDetailLock = true;
程智春 committed
283
        this.refreshLive = true;
程智春 committed
284 285 286 287 288 289 290 291 292

        this.online = 0 //在线
        this.look = 0 //观看
        this.praise = 0 //点赞
        this.liveInfo = {}

        this.liveTime = '';

        this.liveId = options.id;
程智春 committed
293 294 295 296
        this.getLiveDetail(options.id);
        this.openLiveTimer = setInterval(() => {
            this.getLiveDetail(options.id); //传入直播间id
        },5000)
程智春 committed
297 298 299 300 301 302 303 304 305 306 307 308


        this.getServerTimeNow(); //获取服务器时间戳

        
    },
    onReady(){
        this.userInfo = this.$store.state.userInfo;
        this.pusher = wx.createLivePusherContext('pusher')
        
    },
    onShow(){
程智春 committed
309

程智春 committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
        wx.setKeepScreenOn({
            keepScreenOn: true
        })  

        if(this.openRecordSet){
            this.openRecordSet = false;
            this.getAuthSet('record')
        }

        if(this.openCameraSet){
            this.openCameraSet = false;
            this.getAuthSet('camera');
        }

        
    },
    onHide(){
        this.commentsList = []
        this.clearAllInterval()
程智春 committed
329 330 331

        console.log('onHide',this.overOrStop)

程智春 committed
332 333
        this.pusher.stop();

程智春 committed
334 335 336
        if(this.overOrStop){
            if(this.liveInfo.liveBroadcastState == 1){
                this.changeLiveStatus(3)
程智春 committed
337
                
程智春 committed
338 339
                this.isSetBeauty = false;
            }
程智春 committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
        }
       
    },
    onUnload(){
        this.commentsList = []
        this.clearAllInterval()
        this.changeLiveStatus(3)
    },
    methods:{
        getAuthSet(type){
            wx.getSetting({
                success :(res) => {

                    if(type == 'record'){
                        if (!res.authSetting["scope.record"]) {
程智春 committed
355
                            this.refreshLive = false;
程智春 committed
356
                            this.openConfirm(type);
程智春 committed
357 358 359 360
                        }else{
                            this.refreshLive = true;
                            this.pusher = wx.createLivePusherContext('pusher');
                            this.pusher.startPreview()
程智春 committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
                        }
                    }else if(type == 'camera'){
                        if (!res.authSetting["scope.camera"]) {
                            this.openConfirm(type);
                        }else{
                            this.enableCamera = true;
                        }
                    }
                    
                },
                fail(res) {
                    console.log("调用失败");
                }
            });
        },
        openConfirm(type){

            let contentText = '';

            if(type == 'record'){
                contentText = '检测到您没打开麦克风的权限,是否去设置打开?'
            }else if(type == 'camera'){
                this.enableCamera = false;
                contentText = '检测到您没打开摄像头的权限,是否去设置打开?'
            }
            wx.showModal({
                content: contentText,
                confirmText : '确认',
                confirmColor : '#07c160',
                success : (res) => {
                    if (res.confirm) {
                        wx.openSetting({
                            success : (res1) => {

                                if(type == 'record'){
                                    this.openRecordSet = true;
                                }else if(type == 'camera'){
                                    this.openCameraSet = true;
                                }
                                
                            }
                        });
                    } else if (res.cancel) {
                        wx.reLaunch({url:`../liveList/main`})
                    }
                }
            })
        },
        //点击设置美颜
        setBeauty(){
            this.enableCamera = true;
            this.noStartLive = false;
            this.recoverLive = false
            this.isBgImg = false;
            this.isSetBeauty = true;
程智春 committed
416
            this.isDetailControlLock = false;
程智春 committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
            this.pusher.startPreview()
        },
        showPopup(){
            this.productDialogStatus = true
            this.getProductList()
        },
        hideProductPopup(){
            this.productDialogStatus = false
        },
        //设置美颜
        updateBeauty(val){
            this.beauty = val;
        },
        //设置美白
        updateWhiteness(val){
            this.whiteness = val;
        },
        //设置清晰度
        updateClear(val){
            this.clear = val
        },
        //镜像
        updateRemoteMirror(val){
            this.remoteMirror = val;
程智春 committed
441
            this.mirror = val == 'enable' ? true : false
程智春 committed
442 443 444 445 446 447 448 449
        },
        //麦克风
        updateEnableMic(val){
            this.enableMic = val;
        },
        //获取直播间详情
        getLiveDetail(id){

程智春 committed
450 451 452 453 454 455 456
            if(this.isDetailLock && this.isDetailControlLock){
                this.isDetailLock = false;
                liveApi.queryLiveDetail({id}).then(res => {
                    this.isDetailLock = true;
                    if(res.data.code == '200'){
                        
                        let result = res.data.data
程智春 committed
457

程智春 committed
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
                        if(result){
                            result.coverUrl = DFSImg(result.coverUrl)
                            result.logoUrl = DFSImg(result.logoUrl)
                            this.liveInfo = result;
                            this.tuiStream = result.tuiStream
                            if(result.liveBroadcastState == 0){
                                this.isLive = false
                                this.isBgImg = true;
                                this.noStartLive = true;
                            }else if(result.liveBroadcastState == 1){
                                this.enableCamera = true
                                this.isLive = true
                                this.isBgImg = false;
                            }else if(result.liveBroadcastState == 3){
                                console.log('llll')
                                this.recoverLive = true;
                                this.isUsual = true;
                                this.isBgImg = true;
                            }
程智春 committed
477

程智春 committed
478 479
                            if(result.realStartTime){
                                this.realStartTime = Math.floor((new Date().getTime() - new Date(result.realStartTime.replace(/-/g, '/').replace(/-/g, '/')).getTime())/1000)
程智春 committed
480

程智春 committed
481 482 483
                            }else{
                                this.realStartTime = 0
                            }
程智春 committed
484 485
                            this.getLiveTimeHandler(result.startTime)
                            this.getProductList(); //获取商品列表
程智春 committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511

                        }else{
                            wx.showModal({
                                title: '提示',
                                content: '直播已关闭',
                                success (res3) {
                                    if (res3.confirm) {
                                        wx.reLaunch({url:`../liveList/main`})
                                    } else if (res3.cancel) {
                                        console.log('用户点击取消')
                                    }
                                }
                            })
                        }
                    }else if(res.data.code == '-1'){
                        wx.showModal({
                            title: '提示',
                            content: '直播已关闭',
                            success (res3) {
                                if (res3.confirm) {
                                    wx.reLaunch({url:`../liveList/main`})
                                } else if (res3.cancel) {
                                    console.log('用户点击取消')
                                }
                            }
                        })
程智春 committed
512 513 514
                    }
                })
            }
程智春 committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
        },
        //获取开播时间
        getLiveTimeHandler(time){
            let getTime = new Date(time.replace(/-/g, '/')).getTime() - new Date().getTime();

            let getTimeAbs = Math.abs(getTime)

            let hours = '';
            let minute = '';
            let day = '';
            if(getTime > 0){
                this.liveTimeStatus = false 

            }else{
                this.liveTimeStatus = true
            }

            day = Math.floor(getTimeAbs / (3600*1000*24))
            hours = Math.floor((getTimeAbs%(24*3600*1000))/(3600*1000));
程智春 committed
534
            minute = Math.floor((getTimeAbs%(24*3600*1000)%(3600*1000) )/(60*1000))     
程智春 committed
535 536
            if(getTime > 0){
                if(day > 0){
程智春 committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
                    let showHours = "";
                    let showMinute = "";
                    if(hours > 0){  
                        if(hours >= 10){
                            showHours = hours + '小时'
                        }else{
                            showHours = '0' + hours + '小时'
                        } 
                    } 
                    if(minute >= 10){
                        showMinute = minute + '分'
                    }else{
                        showMinute = '0' + minute + '分'
                    }       
                    this.liveTime = `${day >= 10 ? day : '0' + day}${showHours}${showMinute}`
程智春 committed
552
                }else if(day <= 0 && hours > 0){
程智春 committed
553 554 555 556 557 558 559
                    let showMinute = "";
                    if(minute >= 10){
                        showMinute = minute + '分'
                    }else{
                        showMinute = '0' + minute + '分'
                    }   
                    this.liveTime = `${hours >= 10 ? hours : '0' + hours}小时${showMinute}`
程智春 committed
560
                }else if(day <= 0 && hours <= 0 && minute >= 0){
程智春 committed
561 562 563 564 565 566 567 568 569 570 571 572 573
                     this.liveTime = `${minute >= 10 ? minute : '0' + minute}分`
                }

            }else{
                this.liveTime = `${15 - minute}分钟后关闭`
            }
            
        },
        //开始直播去设置美颜
        toSetBeauty(type){
            this.noStartLive = false;
            this.isSetBeauty = true;
            this.enableCamera = true;
程智春 committed
574
            this.isDetailControlLock = false;
程智春 committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
            this.isBgImg = false;
            this.pusher.startPreview()
        },
        //检测直播环境
        checkLiveEnv(type){
            wx.getNetworkType({
                success :(res) => {
                  if(res.errMsg == 'getNetworkType:ok'){
                        if(res.networkType != 'wifi'){
                            wx.showModal({
                                title: '流量提醒',
                                content: '你目前处于非WIFI环境,是否继续',
                                confirmText : '继续',
                                confirmColor : '#07c160',
                                success :(res1) => {
                                    if (res1.confirm) {
                                        liveApi.queryLiveDetail({id : this.liveId}).then(res2 => {

                                            if(res2.data.code == '200'){
                                                
                                                if(res2.data.data.liveBroadcastState == 4 || res2.data.data.liveBroadcastState == 2){
                                                    wx.showModal({
                                                        title: '提示',
程智春 committed
598
                                                        content: '直播已关闭',
程智春 committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
                                                        success (res3) {
                                                            if (res3.confirm) {
                                                                wx.reLaunch({url:`../liveList/main`})
                                                            } else if (res3.cancel) {
                                                                console.log('用户点击取消')
                                                            }
                                                        }
                                                    })
                                                }else{
                                                    this.startLive(type);
                                                }
                                            }
                                        })
                                    } else if (res1.cancel) {
                                        // console.log('用户点击取消')
                                    }
                                }
                            })
                        }else{
程智春 committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
                            liveApi.queryLiveDetail({id : this.liveId}).then(res2 => {

                                if(res2.data.code == '200'){

                                    if(res2.data.data == null || res2.data.data.liveBroadcastState == 4 || res2.data.data.liveBroadcastState == 2){
                                        wx.showModal({
                                            title: '提示',
                                            content: '直播已关闭',
                                            success (res3) {
                                                if (res3.confirm) {
                                                    wx.reLaunch({url:`../liveList/main`})
                                                } else if (res3.cancel) {
                                                    console.log('用户点击取消')
                                                }
                                            }
                                        })
                                    }else{
                                        this.startLive(type);
                                    }
                                }
                            })
程智春 committed
639 640 641 642 643 644 645
                        }
                  }
                }
            })
        },
        //开始直播
        startLive(type){
程智春 committed
646
            this.isDetailControlLock = false;
程智春 committed
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
            if(type == 'recover'){
                this.recoverLive = false;
                this.isUsual = false;
            }else if(type == 'start'){
                this.noStartLive = false;
            }
            
            this.isPruductUp = true;
            this.liveCountDown = 3;
            this.isCountDown = true;
            let timer = setInterval(() => {
                --this.liveCountDown;
                if(this.liveCountDown == 0){
                    console.log('开始直播')
                    this.pusher.start(); //开始推流
程智春 committed
662
                    
程智春 committed
663
                    this.isCountDown = false;
程智春 committed
664
                    
程智春 committed
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
                    this.isSetBeauty = false;
                    clearInterval(timer)
                    this.changeLiveStatus(1);
                }
            },1000)
        },
        //改变直播状态
        changeLiveStatus(val){
            liveApi.updateLiveStatus({
                id : this.liveId,
                liveBroadcastState : val
            }).then(res => {
                if(res.data.code == '200'){
                    if(val == 1){
                        this.isLive = true;
                        this.enableCamera = true;
                        this.isBgImg = false;
                        this.pusher.resume();
                    }else if(val == 3){
                        this.isLive = false;
程智春 committed
685
                        console.log('222222')
程智春 committed
686 687 688 689 690
                        this.recoverLive = true;
                        this.isBgImg = true;
                        this.enableCamera = false;
                        this.pusher.pause();
                    }
程智春 committed
691
                    this.isDetailControlLock = true;
程智春 committed
692 693 694 695 696 697 698 699 700 701 702
                    
                    this.$set(this.liveInfo,'liveBroadcastState',val)
                    // this.pusher.resume();
                }
            })
        },
        //设置点击右上角返回
        closeSetBeauty(val){
            this.isSetBeauty = val;
            this.isBgImg = true;
            this.enableCamera = false;
程智春 committed
703
            this.isDetailControlLock = true;
程智春 committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717
            if(this.liveInfo.liveBroadcastState == 0){
                this.noStartLive = true;
            }else if(this.liveInfo.liveBroadcastState == 1){
                this.noStartLive = false;
                this.recoverLive = false;
            }else if(this.liveInfo.liveBroadcastState ==3){
                this.recoverLive = true;
            }
            
            
        },
        //定时查询数据
        timeGetInfo(serverTime){
            let newCommentsTime = serverTime
程智春 committed
718
            let userActivebeginTime = serverTime
程智春 committed
719 720 721 722 723 724 725 726
            clearInterval(this.liveDetailTimer)
            this.liveDetailTimer = setInterval(() => {
                
                if(this.isTimeLock){

                    //第一次请求用服务器的时间减去2秒
                    this.isTimeLock = false;
                    let dataTime = this.isTimeFirstReq ? serverTime - 2000 : newCommentsTime
程智春 committed
727
                    let userTime = this.isTimeFirstReq ? serverTime - 2000 : userActivebeginTime
程智春 committed
728 729
                    liveApi.queryLiveComments({
                        id: Number(this.liveId),
程智春 committed
730 731
                        beginTime: dataTime, //评论时间
                        userActivebeginTime : userTime, //用户进入时间
程智春 committed
732
                    }).then(res => {
程智春 committed
733
                        this.isTimeLock = true;
程智春 committed
734 735 736
                        if(res.data.code == '200'){
                            this.isTimeFirstReq = false;
                            let result = res.data.data;
程智春 committed
737
                            // if(result.liveState == 'IN_LIVE' || result.liveState == 'SUSPEND_LIVE' || result.liveState == 'NO_LIVE' || result.liveState == 'PAUSE_LIVE'){
程智春 committed
738 739 740 741 742 743 744 745 746 747 748 749
                                //用户通知
                                this.entryNoticeText = "";
                                if (result.entryNoticeList.length > 0) {
                                    if (result.entryNoticeList.length == 1) {
                                        this.entryNoticeText = `${result.entryNoticeList[0].userName}`;//用户进入
                                    } else {
                                        this.entryNoticeText = `${
                                        result.entryNoticeList[0].userName
                                        }${result.entryNoticeList.length}人`;//用户进入
                                    }
                                }
                                //观看
程智春 committed
750
                                this.look = result.historyWatchNum - 0 >= 10000 ? ((result.historyWatchNum - 0) / 10000).toFixed(1)+ "w" : result.historyWatchNum
程智春 committed
751
                                //在线
程智春 committed
752
                                this.online = result.watchNum - 0 >= 10000 ?((result.watchNum - 0) / 10000).toFixed(1)+ "w" : result.watchNum 
程智春 committed
753
                                //点赞
程智春 committed
754
                                this.praise = result.likeInfo.likeNum - 0 >= 10000 ? ((result.likeInfo.likeNum - 0) / 10000).toFixed(1)+ "w" : result.likeInfo.likeNum
程智春 committed
755 756 757 758 759 760 761
                                //评论
                                result.guestBookList.forEach(item => {
                                    this.commentsList.push(item)
                                })
                                if(result.guestBookList && result.guestBookList.length){
                                    newCommentsTime = result.guestBookList[result.guestBookList.length - 1].createTimeStamp
                                }
程智春 committed
762

程智春 committed
763 764 765 766
                                if(result.entryNoticeList && result.entryNoticeList.length){
                                    userActivebeginTime = result.entryNoticeList[result.entryNoticeList.length - 1].createTimeStamp
                                }

程智春 committed
767
                                this.updateVal = new Date().getTime(); //监听使用数据
程智春 committed
768
                            // }
程智春 committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
                        }
                    })  
                }else{
                    console.log('上次请求未结束,进行了下一次请求')
                }
                
            },2000)
        },
        //服务器时间戳
        getServerTimeNow(){
            liveApi.queryServerTimeNow().then(res => {
                if(res.data.code == 200){
                    //定时查询数据
                    this.timeGetInfo(res.data.data);
                }
            })
        },
        //推流状态
        statechange(e){
            console.log('statechange',e.mp.detail)

            if(e.mp.detail.code == -1307){
                this.isLive = false;
                this.clearAllInterval()
                wx.showToast({ title: e.mp.detail.message, icon: "none" });
            }
        },
        binderror(e){
            console.log('binderror',e.mp.detail)

            if(e.mp.detail.errCode == 10002){ //禁用麦克风
                this.getAuthSet('record')
            }

            if(e.mp.detail.errCode == 10001){ //禁用摄像头
                this.getAuthSet('camera')
            }
        },
        bindnetstatus(e){
            console.log('binderror',e.mp.detail)
        },
        //获取商品列表
        getProductList(){      
程智春 committed
812
            liveApi.queryProductList({id : this.liveId,pageNum : 0,pageSize:0}).then(res => {
程智春 committed
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
                if(res.data.code == '200'){

                    let productIdArr = []
                    let productIdArr1 = []
                    
                    this.productList.forEach(item2 => {
                        productIdArr.push(item2.productId)
                    })

                    res.data.data.forEach(item1 => {
                        productIdArr1.push(item1.productId)
                    })

                    if(JSON.stringify(productIdArr) != JSON.stringify(productIdArr1)){
                        this.speakProductList = [];

                        res.data.data.forEach(item => {
                            item.productImgUrl = DFSImg(item.productImgUrl)
                            item.minPrice = Number(item.minPrice).toFixed(2)
                            
                                if(item.upperScreenState == '1'){
                                    this.speakProductList.push(item)
                                }
                            
                        })

                        this.productList = res.data.data
                    }

                    
                }
            })
        },
        //商品上下屏
        changeProduct(type,id,item){
            if(this.isChangeProduct){
                this.isChangeProduct = false;
            
                liveApi.queryProductUpDown({
                    productId : id,
                    liveBroadcastId : this.liveId,
                    upperScreenState : type
                }).then(res => {
程智春 committed
856
                    
程智春 committed
857
                    if(res.data.code == '200'){
程智春 committed
858
                        this.isChangeProduct = true;
程智春 committed
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
                        console.log('上下屏')
                        
                        if(type == 1){
                            if(this.speakProductList.length == 1){
                                if(Number(item.number) < Number(this.speakProductList[0].number)){
                                    this.speakProductList.unshift(item)
                                }else{
                                    this.speakProductList.push(item)
                                }
                            }else{
                                this.speakProductList.push(item)
                            }
                            
                            this.productList.forEach((productItem,productIndex) => {
                                if(productItem.productId == id){
                                    
                                    this.$set(this.productList[productIndex],'upperScreenState',1)
                                }
                            })
                        }else{
                            this.speakProductList.forEach((i,index) => {
                                if(i.productId == id){
                                    this.speakProductList.splice(index,1)
                                }
                            })
                            this.productList.forEach((productItem,productIndex) => {
                                if(productItem.productId == id){
                                    this.$set(this.productList[productIndex],'upperScreenState',0)
                                }
                            })
                        }
程智春 committed
890
                        console.log(this.speakProductList, '上下屏商品')
程智春 committed
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
                    }else{
                        
                        wx.showModal({
                            title: '提示',
                            content: res.data.msg,
                            success (res) {
                                if (res.confirm) {
                                console.log('用户点击确定')
                                } else if (res.cancel) {
                                console.log('用户点击取消')
                                }
                            }
                        })
                    }
                })
            }
        },
        //结束直播清除相关定时器
        clearAllInterval(){
            clearInterval(this.openLiveTimer)
            clearInterval(this.getProductTimer)
            clearInterval(this.liveDetailTimer)
程智春 committed
913 914 915
        },
        changeOver(val){
            this.overOrStop = 0;
程智春 committed
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
        }
    }
}
</script>

<style scoped lang="scss">

    @mixin btn {
        width: 148px;
        height: 40px;
        text-align: center;
        line-height: 40px;
        font-size: 16px;
        color: white;
        border-radius: 8px;
        background-image:-webkit-linear-gradient(to right,#FF877D, #FB566D);
        background-image:-moz-linear-gradient(to right,#FF877D, #FB566D);
        background-image:-o-linear-gradient(to right,#FF877D, #FB566D);
        background-image: linear-gradient(to right,#FF877D, #FB566D);
    }

    .container{
        width: 100%;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        box-sizing: border-box;
    }
    .masker{
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background-color: rgba(102,102,102,0.38);
    }
    .bg-img{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: -1;
    }
    .content{  
        width: 100%;
        height: 100vh;
        z-index: 10;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 10;

    }
    .live-active{
        width: 155px;
        height: 17px;
        background-color: rgba(0,0,0,.6);
        margin-left: 36px;
        border-radius: 17px;
        font-size: 10px;
        color: white;
        display: flex;
        align-items: center;
        justify-content: space-around;
    }
    .wait-start{
        text-align: center;
        margin-top: 20vh;
        .title{
            font-size: 18px;
            color: white;
            font-weight: bold;
        }
        .open-live-title{
            font-size: 15px;
            color: #EEEEED;
            line-height: 50px;
        }
        .wait-time{
            font-size: 36px;
            color: white;
            font-weight: bold;
        }
        .start-btn{
            @include btn;
            margin: 23px auto 0;
        }
    }
    .countdown{
        width: 100%;
        height: 100vh;
        position: absolute;
        top: 0;
        left: 0;
        background-color: rgba(0,0,0,.38);
        padding-top: 35vh;
        color: white;
        font-size: 40px;
        text-align: center;
        z-index: 120;
    }
    .unusual-wrap{
        text-align: center;
        margin-top: 20vh;
        color: white;
        .title{
            font-size: 18px;
            font-weight: bold;
        }
        .unusual-text{
            font-size: 36px;
            line-height: 80px;
            font-weight: bold;
        }
        .recover-btn{
            @include btn;
            margin: 20px auto 0;
        }
    }
    .notice{
        position: fixed;
        left: 16px;
        bottom: 60px;
        width: 195px;
        background-color: rgba(0,0,0,.4);
        border-radius: 14px;
        box-sizing: border-box;
        padding: 10px 7px 7px 10px;
        font-size: 12px;
        color: white;
        line-height: 18px;
    }
    .product-wrap{
        position: fixed;
        left: 19px;
        bottom: 14px;
        width: 31px;
        height: 29px;
        .product-num{
            font-size:12px;
            color: white;
            width: 100%;
            text-align: center;
            position: absolute;
            bottom: 4px;
        }
        .product-img{
            width: 100%;
            height: 100%;
        }
    }
    .setting-wrap{
        position: fixed;
        right: 13px;
        bottom: 14px;
        width: 37px;
        height: 37px;
        .set-img{
            width: 100%;
            height: 100%;
        } 
    }
    .speak-product{
        position: fixed;
        left: 8px;
        top:20vh;       
        .speak-item{
            width: 78px;
            margin-bottom: 15px;
            border-radius: 2px;
            overflow: hidden;
            position: relative;
            .item-status{
                position: absolute;
                top: 0;
                left: 0;
                width: 39px;
程智春 committed
1095
                height: 16px;
程智春 committed
1096 1097 1098 1099 1100
                color: white;
                background-color: #FF4240;
                border-bottom-right-radius: 2px;
                font-size: 11px;
                text-align: center;
程智春 committed
1101
                line-height: 16px;
程智春 committed
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
            }
            .item-top{
                height: 78px;
                background-color: #B1B1B1;
                img{
                    width: 100%;
                    height: 100%;
                }
            }
            .item-bottom{
                height: 23px;
                background-color: white;
                text-align: center;
                line-height: 23px;
                font-size: 14px;
                color: #FA7018;
            }
        }  
    }
    .userComing {
        margin-bottom: 10px;
        background: rgba(#000, 0.4);
        color: #fff;
        font-size: 16px;
        height: 26px;
        line-height: 26px;
        border-radius: 26px;
        padding: 0 8px;
        display: inline-block;
        position: fixed;
        bottom: 30vh;
    }
    .userComingAni {
        animation: userComingAni 4.7s linear;
    }

     @keyframes userComingAni {
        0% {
            transform: translateX(150vw);
            opacity: 0.3;
        }
        30% {
            transform: translateX(24px);
            opacity: 1;
        }
        80% {
            transform: translateX(24px);
            opacity: 1;
        }
        100% {
            transform: translateX(-150vw);
            opacity: 0;
        }
    }

</style>