<template>
    <!--10.3.1.	直播详情组件1开始-->
    <div class="live_show_detail_mobile_1">
        <!--以下头部图片栏-->
        <div class="details-pic" :style="{'background-image': 'url(' + livedetail.lylPhoto + ')'}">
            <div class="appbar appbar-transparency"><!--头部标题栏-->
                <span class="goback"><a href="javascript:history.go(-1)">返回</a></span>
                <span class="appbar-moreicon">
            </span>
            </div>
            <div class="liveshow-details-title"><!--头部大小标题-->
                <span class="sp1">{{livedetail.lylName}}</span>
                <span class="sp2">{{livedetail.liveCatnamestr}}</span>
            </div>
        </div>
        <!--详情简介-->
        <div class="details-list">
            <span class="sp1">{{livedetail.lylName}}</span>
            <span class="sp5">
            <span class="spp1" v-if="livedetail.price">¥{{livedetail.price}}</span>
                <span class="spp1" v-if="!livedetail.price">免费</span>
            <span class="spp2" v-if="livedetail.price&&livedetail.crossedPrice">¥{{livedetail.crossedPrice}}</span>
            <!--<span class="spp3">限时优惠</span>-->
            <!--<span class="spp4" v-if="livedetail.price">会员折上折</span>-->
         </span>
            <span class="sp6">
            <span class="spp1">
                <!--<i>10</i>学时丨-->
                <i>{{livedetail.lylSignupNum}}</i>人已报名</span>
            <span class="spp2" v-if="livedetail.lylRealStatus=='0'">未开始</span>
            <span class="spp2" v-if="livedetail.lylRealStatus=='1'">直播中</span>
            <span class="spp2" v-if="livedetail.lylRealStatus=='2'">暂停休息中</span>
            <span class="spp2" v-if="livedetail.lylRealStatus=='3'">已结束</span>
         </span>
        </div>
        <!--主讲人-->
        <div class="myexam-mainbody">
            <!--以下tab页标题-->
            <div class="myexam-tabtitle">
                <ul>
                    <li class="active"><a href="">主讲人</a></li>
                </ul>
            </div>
            <div class="zjr-body">
                <div class="zjr-card" v-for="(item, index) in liveteacher.list" :key="index">
                    <span class="zjr-card-pic">
                        <img v-if="!item.etPhoto" src="../../theme-chalk/src/images/header.png" alt="">
                        <img v-if="item.etPhoto" :src="item.etPhoto" alt="">
                    </span>
                    <span class="zjr-card-info">
                        <span class="sp1">
                            <span class="spp1">{{item.etName}}</span>
                            <span class="spp2" v-if="item.etProfessonal">{{item.etProfessonal}}</span>
                            <!--<span class="spp2" v-if="!item.etProfessonal">特约讲师</span>-->
                        </span>
                        <span class="sp2" v-if="item.etContent">{{item.etContent}}</span>
                        <span class="sp2" v-if="!item.etContent">暂无简介</span>
                    </span>
                </div>
            </div>
        </div>
        <!--直播详情-->
        <div class="liveshow-details-body">
            <span class="sp1">直播详情</span>
            <span class="sp2"><i>直播时间</i>{{livedetail.lylStartDate | formatDate}} - {{livedetail.lylEndDate | formatDate}}</span>
            <span class="sp2"><i>直播时长</i>{{getNowTime(livedetail.lylStartDate,livedetail.lylEndDate)}}</span>
            <span class="sp3"><i>简介</i>{{livedetail.lylInfo}}</span>
        </div>
        <!--footer底部-->
        <div class="timu-footer" v-if="livedetail.payType=='1'&&!isSign">
            <span class="timu-footer-price">¥{{livedetail.price}}</span>
            <span class="timu-footer-btn">
         <!--<a href="" class="timu-footer-add" @click="addShopCar()">加入购物车</a>-->
         <a href="javascript:;" class="timu-footer-buy" @click="buyNow()">立即购买</a>
      </span>
        </div>
        <div class="timu-footer" v-if="livedetail.payType=='0' || isSign">
            <a href="javascript:;" class="liveshow-details-footerbtn" @click="whatchLive()">立即观看</a>
        </div>
    </div>
    <!--10.3.1.	直播详情组件1结束-->
</template>

<script>
    import {logout} from '../../../src/utils/utils';
    import formMixin from '../../../src/mixins/formMixin';
    import lenye_base from 'lenye_base';
    import $ from "fy-kit";
    import { Toast } from "vant";
    export default {
        name: 'ElLiveShowDetailMobile1',
        mixins: [formMixin],
        model: {},
        data() {
            return {
                lylId: '',
                userData: '',
                livedetail:'',
                liveteacher:'',
                isCollect:'',
                isSign:false,
                lylLiveStatus:''
            }
        },
        // 过滤
        filters: {
            formatDate: function (value) {
                // var datavalue = value.replace(/\-/g, "/");
                let date = new Date(value);
                // let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? ('0' + MM) : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                // let s = date.getSeconds();
                // s = s < 10 ? ('0' + s) : s;
                return MM + '月' + d + '日' + h + ':' + m;
            }
        },
        mounted() {
            // console.log(httpPost);
            // console.log(lenye_base);
            this.lylId = lenye_base.getUrlParam('id');//'8fbb8997aa65430f801a4c0aac463ada';
            this.lylLiveStatus = lenye_base.getUrlParam('lylLiveStatus');
            this.userData = lenye_base.user_data.getuserData();
            console.log(this.userData);
            this.detail();
        },
        computed: {
            [Toast.name]: Toast,
        },
        methods: {
            // 时间格式转换
            getNowTime(startdata,enddata){
                var start = new Date(startdata);
                var end = new Date(enddata);
                var value = (end - start)/1000;
                var secondTime = parseInt(value); // 秒
                var minuteTime = 0 // 分
                var hourTime = 0 // 小时
                var dayTime = 0 // 天
                var result = ''
                if (value < 60) {
                    result = secondTime + '秒'
                } else {
                    if (secondTime >= 60) { // 如果秒数大于60，将秒数转换成整数
                        // 获取分钟，除以60取整数，得到整数分钟
                        minuteTime = parseInt(secondTime / 60)
                        // 获取秒数，秒数取佘，得到整数秒数
                        secondTime = parseInt(secondTime % 60)
                        // 如果分钟大于60，将分钟转换成小时
                        if (minuteTime >= 60) {
                            // 获取小时，获取分钟除以60，得到整数小时
                            hourTime = parseInt(minuteTime / 60)
                            // 获取小时后取佘的分，获取分钟除以60取佘的分
                            minuteTime = parseInt(minuteTime % 60)
                            if (hourTime >= 24) {
                                // 获取天数， 获取小时除以24，得到整数天
                                dayTime = parseInt(hourTime / 24)
                                // 获取小时后取余小时，获取分钟除以24取余的分；
                                hourTime = parseInt(hourTime % 24)
                            }
                        }
                    }
                    if (secondTime > 0) {
                        secondTime = parseInt(secondTime) >= 10 ? secondTime : secondTime
                        result = '' + secondTime + '秒'
                    }
                    if (minuteTime > 0) {
                        minuteTime = parseInt(minuteTime) >= 10 ? minuteTime : minuteTime;
                        result = '' + minuteTime + '分钟' + result
                    }
                    if (hourTime > 0) {
                        result = '' + parseInt(hourTime) + '小时' + result
                    }
                    if (dayTime > 0) {
                        result = '' + parseInt(dayTime) + '天' + result
                    }
                }
                return result
            },
            detail(){
                $.util.ajax(
                    lenye_base.base_data.getapiUrl() + "/learnyeai-live-service/common/lylLive/queryById.do", lenye_base.base_data.getformatting({
                        lylId: this.lylId,
                    })
                ).then(res=>{
                    if(res.success=='1'){
                        this.livedetail = res.data;
                        this.isSigndata();
                    }else{
                        Toast.fail(res.message);
                    }
                })
            },

            //判断用户是否已经登录
            hasLogin() {
                if (this.userData && this.userData.custId) {
                    return true;
                } else {
                    logout();
                    Toast.fail('未登录');
                    return false;
                }
            },
            // 立即购买
            buyNow() {
                if (this.hasLogin()) {
                    $.util.ajax(
                        lenye_base.base_data.getapiUrl() + "/orderform-service/api2/ordShoppingCart/signup.do", lenye_base.base_data.getformatting({
                            objId:this.lylId,
                            objType:5,
                            shoppingNum:1,
                            spcId:this.lylId,
                            custId:this.userData.custId,
                            siteId:this.userData.siteId
                        })
                    ).then(res=>{
                        if(res.success=='1'){
                            window.location.href='/classreging?fp='+res.data.orderId+'&id='+res.data.orderId+'&orderId='+res.data.orderId;
                            // this.$router.push({name: "orderBuy", query: {lylId: this.lylId}});
                        }else{
                            Toast.fail(res.message);
                        }
                    })

                }
            },
            whatchLive() {
                var that = this;
                if (this.hasLogin()) {
                    if (!this.isSign) {
                        $.util.ajax(
                            lenye_base.base_data.getapiUrl() + "/orderform-service/api2/ordShoppingCart/signup.do", lenye_base.base_data.getformatting({
                                objId:that.lylId,
                                objType:5,
                                shoppingNum:1,
                                spcId:that.lylId,
                                custId:that.userData.custId,
                                siteId:that.userData.siteId
                            })
                        ).then(res=>{
                            if(res.success=='1'){
                                window.location.href = '/livestudio?id=' + that.lylId +'&lylLiveStatus='+that.lylLiveStatus;
                            }else{
                                Toast.fail(res.message);
                            }
                        })
                    }else{
                        window.location.href = '/livestudio?id=' + that.lylId +'&lylLiveStatus='+that.lylLiveStatus;
                    }

                }

            },
            isSigndata() {
                if (this.userData.custId){
                    $.util.ajax(lenye_base.base_data.getapiUrl() + "/learnyeai-live-service/api2/lylLive/queryUserLivePage.do", lenye_base.base_data.getformatting({
                        lylId:this.lylId,
                        custId:this.userData.custId
                    })
                    ).then(res=>{
                        if(res.success=='1' && res.data.length>0){
                            console.log('有数据');
                            this.isSign = true;
                        }
                    })
                }
            }
        },
    };
</script>
