<template>
    <div class="courseplay">
        <div class="vp-body">
            <!--课程播放页头部-->
            <div class="vp-top clearfix">
                <div class="vp-top-left vp-top-left-phone">
                    <a class="vp-goback" href="javascript:history.go(-1)">返回课程</a>
                    <span class="vp-title">{{courseName}}({{cptnametitle}})</span>
                </div>

            </div>
            <div  class="playbox">
                <div id="player_video" class="video-js"></div>
            </div>
            <!--<video id="my-video" class="video-js" controls preload="auto" width="100%" height="100%" data-setup="{}">-->
                <!--<source src="mp4/video.mp4" type="video/mp4">-->
            <!--</video>-->
            <div class="vp-bottom">
                <div class="vp-top-left">
                    <a class="vp-top-prev" v-if="prebtn" @click="prevcourse()">上一课时</a>
                    <a class="vp-top-next" v-if="nextbtn" @click="nextcourse()">下一课时</a>
                </div>
                <!--<div class="vp-top-right">-->
                    <!--<span class="vp-learn-yet"><a>学过了</a></span>-->
                <!--</div>-->
            </div>
            <div class="vp-sidebar">
                <div class="vp-sidebar-title">
                    <!--<a class="vp-sidebar-btn">收起</a>-->
                    <ul>
                        <li :class="videotab==0?'on':''"><a class="sidebar-icon1"  @click="videotab=0">目录</a></li>
                        <li :class="videotab==1?'on':''"><a class="sidebar-icon2" @click="videotab=1">问答</a></li>
                        <!--<li><a class="sidebar-icon3">笔记</a></li>-->
                        <!--<li><a class="sidebar-icon4">讨论</a></li>-->
                        <!--<li><a class="sidebar-icon5">资料</a></li>-->
                        <!--<li><a class="sidebar-icon6">扫一扫</a></li>-->
                    </ul>
                </div>
                <div class="vp-sidebar-main">
                    <div class="et4-class-mulu" v-if="videotab==0">
                        <div class="nLi" v-for="(item, index) in coursetreelist" :key="index">
                            <div class="et4-class-mulu-title">
                                    {{item.cptName}}
                                <span class="nLi-icon"></span>
                            </div>
                            <ul class="et4-class-mulu-ul">
                                <li v-for="(cptitem, cptindex) in item.childs" :key="cptindex" :class="cptitem.cptId==cptidvalue?'':''">
                                    <div class="mulu-pie" :id="mulu-pie"></div>
                                    <a class="cptresult_a" :id="cptitem.cptId" :data-name="cptitem.cptId" @click="playvideo(cptitem.cp[0].resId,cptitem.cptName,cptitem.cptId)" href="javascript:;">{{cptitem.cptName}}
                                        <!--<br>要求{{cptitem.cptInfo}}-->
                                    </a>
                                    <span class="mulu-time">{{cptitem.cp[0].fileTimeLen | getNowTime}}</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="vp-ques" v-if="videotab==1">
                        <div class="vp-ques-inp">
                            <textarea cols="30" v-model="question" rows="10" placeholder="我要提问"></textarea>
                            <p class="vp-ques-sub"><a href="javascript:;" @click="subque()">提交</a></p>
                        </div>
                        <p class="vp-ques-title">全部问答（{{questionslist.data?questionslactiveist.data.length:0}}）</p>
                        <div v-if="questionslist.data" class="vp-ask" v-for="(item, index) in questionslist.data" :key="index" >
                            <p>{{item.topicContent}}</p>
                            <p class="vp-ask-p2">
                                <span>{{item.custName}}<i>{{item.topicDate}}</i></span>
                                <span class="vp-ask-p2-right">
                                    {{item.replayNum?item.replayNum:0}}
                                    回答</span>
                            </p>
                            <p v-if="item.anserList" class="vp-ask-answer" v-for="(acsitem, acsindex) in item.anserList" :key="acsindex">
                                <span>{{acsitem.itemUserId}}<i>回答：</i></span>
                                {{acsitem.itemContent}}
                            </p>
                        </div>
                    </div>
                    <div class="vp-biji" style="display: none">
                        <div class="vp-biji-fuwenben">
                            <textarea name="" cols="30" rows="10" id="editor_id" placeholder="输入笔记内容，便于日后复习"></textarea>
                            <p class="vp-biji-btn clearfix">
                                <span class="vp-biji-jietu"><a>截图</a></span>
                                <span class="vp-biji-time"><a href=""></a>00:00:00</span>
                                <span class="vp-biji-save"><a href="">保存</a></span>
                            </p>
                        </div>
                        <div class="vp-biji-explain">
                            <p class="vp-biji-title">笔记攻略</p>
                            <p class="vp-biji-cont clearfix"><span><img src="images/vp-biji-pic1.png" alt=""></span><i>输入框中输入文字，点击保存即可保存到您的课程笔记中</i>
                            </p>
                            <p class="vp-biji-cont clearfix"><span><img src="images/vp-biji-pic2.png" alt=""></span><i>点击任意视频时间点立即跳转到显示的时间点</i>
                            </p>
                            <p class="vp-biji-cont clearfix"><span><img src="images/vp-biji-pic3.png" alt=""></span><i>开启笔记截图输入笔记文字后，系统将自动截图视频画面</i>
                            </p>
                        </div>
                        <div class="vp-biji-explain">
                            <p class="vp-biji-title">温馨提示</p>
                            <p class="vp-biji-cont">学习过程中，添加对课程的记录、想法、感悟、理解等，在日后的复习回顾中将会有很大的帮助</p>
                        </div>
                    </div>
                    <div class="vp-discuss" style="display: none">
                        <div class="vp-discuss-issue">
                            <input type="text">
                            <a href="">发布</a>
                        </div>
                        <div class="vp-topic">
                            <p class="vp-topic-p1"><span>话题：</span>课程中提到的关键点，考试都会考吗？</p>
                            <p class="vp-topic-p2">
                                <span class="vp-topic-p2-name"><i>发布人</i>钱海洋</span>2020-02-07
                                <span class="vp-topic-p2-num"><i>60</i>人关注 · <i>120</i>次浏览</span>
                            </p>
                            <div class="vp-topic-p3">
                                <span class="vp-topic-p3-all"><a>查看全部回答(24)</a></span>
                                <span class="vp-topic-p3-pl"><a>写评论</a></span>
                                <div class="vp-topic-inp" style="display: none;">
                                    <textarea name="" cols="30" rows="10" placeholder="这里写下您的回答"></textarea>
                                    <a href="">发布</a>
                                </div>
                                <div class="vp-topic-pllist" style="display: none;">
                                    <ul>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="vp-topic">
                            <p class="vp-topic-p1"><span>话题：</span>课程中提到的关键点，考试都会考吗？</p>
                            <p class="vp-topic-p2">
                                <span class="vp-topic-p2-name"><i>发布人</i>钱海洋</span>2020-02-07
                                <span class="vp-topic-p2-num"><i>60</i>人关注 · <i>120</i>次浏览</span>
                            </p>
                            <div class="vp-topic-p3">
                                <span class="vp-topic-p3-all"><a>查看全部回答(24)</a></span>
                                <span class="vp-topic-p3-pl"><a>写评论</a></span>
                                <div class="vp-topic-inp" style="display: none;">
                                    <textarea name="" cols="30" rows="10" placeholder="这里写下您的回答"></textarea>
                                    <a href="">发布</a>
                                </div>
                                <div class="vp-topic-pllist" style="display: none;">
                                    <ul>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="vp-topic">
                            <p class="vp-topic-p1"><span>话题：</span>课程中提到的关键点，考试都会考吗？</p>
                            <p class="vp-topic-p2">
                                <span class="vp-topic-p2-name"><i>发布人</i>钱海洋</span>2020-02-07
                                <span class="vp-topic-p2-num"><i>60</i>人关注 · <i>120</i>次浏览</span>
                            </p>
                            <div class="vp-topic-p3">
                                <span class="vp-topic-p3-all"><a>查看全部回答(24)</a></span>
                                <span class="vp-topic-p3-pl"><a>写评论</a></span>
                                <div class="vp-topic-inp" style="display: none;">
                                    <textarea name="" cols="30" rows="10" placeholder="这里写下您的回答"></textarea>
                                    <a href="">发布</a>
                                </div>
                                <div class="vp-topic-pllist" style="display: none;">
                                    <ul>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="vp-topic">
                            <p class="vp-topic-p1"><span>话题：</span>课程中提到的关键点，考试都会考吗？</p>
                            <p class="vp-topic-p2">
                                <span class="vp-topic-p2-name"><i>发布人</i>钱海洋</span>2020-02-07
                                <span class="vp-topic-p2-num"><i>60</i>人关注 · <i>120</i>次浏览</span>
                            </p>
                            <div class="vp-topic-p3">
                                <span class="vp-topic-p3-all"><a>查看全部回答(24)</a></span>
                                <span class="vp-topic-p3-pl"><a>写评论</a></span>
                                <div class="vp-topic-inp" style="display: none;">
                                    <textarea name="" id="" cols="30" rows="10" placeholder="这里写下您的回答"></textarea>
                                    <a href="">发布</a>
                                </div>
                                <div class="vp-topic-pllist" style="display: none;">
                                    <ul>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘虎强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                        <li><span>刘大强</span>不管考不考，好好学准是没错的，毕竟这些专业知识和技能都是难得的，学到就是赚到！</li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="vp-data" style="display: none">
                        <div class="vp-data-title">课时简介</div>
                        <div class="vp-data-cont">电工类作业取证培训要求电工类作业取证培训要求电工类作业取证培训要求电工类作业取证培训要求电工类作业取证培训要求电工类作业取证培训要求
                        </div>
                        <div class="vp-data-title">课时资料</div>
                        <div class="vp-data-list">
                            <ul>
                                <li class="data-icon01"><a href="">演示文档</a></li>
                                <li class="data-icon02"><a href="">演示文档</a></li>
                                <li class="data-icon03"><a href="">演示文档</a></li>
                                <li class="data-icon04"><a href="">演示文档</a></li>
                                <li class="data-icon05"><a href="">演示文档</a></li>
                            </ul>
                        </div>
                    </div>
                    <div class="vp-code" style="display: none">
                        <p class="vp-code-p1"><img src="images/vp-code.png" alt=""></p>
                        <p class="vp-code-p2">手机扫一扫，随时随地学习</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script type="module">
    import formMixin from '../../../src/mixins/formMixin';
    import lenye_base from 'lenye_base';
    import Player from 'xgplayer';
    import {httpPost} from "../../../src/utils/utils";
    // import HlsJsPlayer from 'xgplayer-hls.js';

    export default {
        name: 'ElCourseplay',
        mixins: [formMixin],
        model: {},
        data() {
            return {
                courseName:'',
                videotab:0,
                userdata:'',
                csId:'',
                playVideoList:[],
                playList:{},
                fileresList:[],
                coursetreelist:[],
                studyTime: {
                    time: 0,
                    type: 'nologin',
                    learClockTime: 0,
                },
                learClockTime: 0,
                newPlay: '',
                isplay: true,
                islearsave: true,
                studyBreakpoint:'',
                cptnametitle: '',
                cptidvalue:'',
                questionslist:[],
                question:'',
                coursetab: 0,
                nextbtn:true,
                prebtn:true,
                newplayer:'',
            };
        },
        // 过滤
        filters: {
            formatDate: function (value) {
                var datavalue = value.replace(/\-/g, "/");
                let date = new Date(datavalue);
                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 y + '/' + MM + '/' + d + ' ' + h + ':' + m;
            },
            getNowTime: function(value) {
                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
            }
        },
        mounted() {
            this.csId = lenye_base.getUrlParam('id')? lenye_base.getUrlParam('id'):'855e5554c80b4888abbe764dacaac6e0';
            this.userdata = lenye_base.user_data.getuserData();
            this.courseinfo();
            this.coursegettreelist();
            this.islogin();
            let script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = 'http://dsw.jsou.cn/assets/sdk/play-sdk/dist/e3c-play.js';
            document.getElementsByTagName('head')[0].appendChild(script);
        },
        watch: {
            'videotab'(newvalue) {
                if (newvalue === 0) {
                    this.coursegettreelist();
                } else if (newvalue === 1) {
                    this.questions();
                }
            }
        },
        methods: {
            courseinfo() {
                const that = this;
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/course-service/common/crsCourse/queryById.do', lenye_base.base_data.getformatting({
                    csId: that.csId
                }), function(e) {
                    if (e.success === '1') {
                        that.courseName = e.data.csName;
                    }
                });
            },
            /*获取资源播放列表*/
            videoList(resids) {
                const that = this;
                console.log(1111, resids.toString());
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/resource-service/common/resResource/detail.do', lenye_base.base_data.getformatting({
                    resId: resids.toString()
                }), function(e) {
                    if (e.success === '1' && e.data.length) {
                        for (let i = 0; i < e.data.length; i++) {
                            that.playList[e.data[i].resId] = {
                                resid: e.data[i].resId,
                                thirdResource: e.data[i].thirdResource,
                                thirdSource: e.data[i].thirdSource,
                                thirdResId: e.data[i].thirdResId,
                                file: e.data[i].resFiles.length ? e.data[i].resFiles[0].fileId : '',
                                resPhoto: e.data[i].resPhoto,
                            };
                            console.log(that.playList);
                        }
                    }
                });
            },
            /*课程章节树目录*/
            coursegettreelist() {
                const that = this;
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.course.treeList, lenye_base.base_data.getformatting({
                    csId: this.csId
                }), function(e) {
                    if (e.success === '1'){
                        if (e.data.length) {
                            // 先获取到章节列表
                            for (let i = 0; i < e.data.length; i++) {
                                // 通过章节列表绑定章节小节的小节资源
                                for (let j = 0; j < e.data[i].childs.length; j++) {
                                    lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.course.queryResources, lenye_base.base_data.getformatting({
                                        cptId: e.data[i].childs[j].cptId,
                                        sorts: '1',
                                    }), function(res) {
                                        e.data[i].childs[j].cp = res.data;
                                        // console.log('cp1111' + JSON.stringify(e.data[i].childs[j].cp));
                                        /*获取资源url*/
                                        if (e.data[i].childs[j].cp && e.data[i].childs[j].cp.length) {
                                            for (let n = 0; n < e.data[i].childs[j].cp.length; n++) {
                                                that.fileresList.push(e.data[i].childs[j].cp[0].resId);
                                                // console.log('fileList1111' + JSON.stringify(that.fileresList));
                                            }
                                        }
                                    });
                                }
                            }
                            setTimeout(function () {
                                that.coursetreelist = e.data;
                                console.log('coursetreelist' + JSON.stringify(that.coursetreelist));
                                if (that.fileresList) {
                                    // console.log('fileList1111' + JSON.stringify(that.fileresList));
                                    that.videoList(that.fileresList);
                                };
                            },1000);
                        }
                    }
                });
            },
            /*播放视频*/
            playvideo(resId,cptname,cptid) {
                const that = this;
                // pagepara.resId = resId;
                that.cptnametitle = cptname?cptname:'';
                that.cptidvalue = cptid?cptid:'';
                that.playlists(resId);
                console.log(that.playVideoList)
                if (that.playVideoList[0].thirdResource) {
                    httpPost(lenye_base.base_data.getapiUrl() + '/resource-service/common/resResource/gainPlayUrlFromDSW.do', lenye_base.base_data.getformatting({
                            dswResId: that.playVideoList[0].thirdResId
                        }),
                        function (res) {
                            if (res.success === '1') {
                                if (!that.newplayer) {
                                    that.newplayer = new E3CPlayer({
                                        id: 'player_video',
                                        type: res.data.type,
                                        playbackRates: {
                                            enable: false, //true 默认优先H5，false 优先Flash方式
                                            source: 'hls',
                                            src: res.data.playUrl
                                        },
                                        //playlist: $("#hls_playlist").val(),
                                        //disableControlBar:flag,  // 此处禁用整个菜单栏
                                        // disableProgressBar: flag,   // 此处是禁用进度条，防止第一次观看视频时用户进行拖拽快进
                                        controlBar: {}
                                    })
                                } else {
                                    document.getElementById('player_video').innerHTML = '';
                                    that.newplayer = new E3CPlayer({
                                        id: 'player_video',
                                        type: res.data.type,
                                        playbackRates: {
                                            enable: false, //true 默认优先H5，false 优先Flash方式
                                            source: 'hls',
                                            src: res.data.playUrl
                                        },
                                        //playlist: $("#hls_playlist").val(),
                                        //disableControlBar:flag,  // 此处禁用整个菜单栏
                                        // disableProgressBar: flag,   // 此处是禁用进度条，防止第一次观看视频时用户进行拖拽快进
                                        controlBar: {}
                                    })
                                } ;
                            };
                        }
                    );


                } else {
                    setInterval(() => {
                        that.learClockTime++
                    },1000);
                    if (!that.newPlay) {
                        that.newPlay = new Player({
                                id: 'player_video',
                                autoplay: true,
                                url: that.playVideoList[0] && that.playVideoList[0].file,
                                height: '100%',
                                width: '100%',
                                lang: 'zh-cn',
                                videoInit: true,
                                playbackRate: [0.5, 0.75, 1, 1.5, 2],
                                defaultPlaybackRate: 1,
                            });
                        that.newPlay.on('play', function() {
                            that.newPlay.currentTime = that.isplay ? that.studyBreakpoint : 0;
                            that.isplay = false;
                        }).on('pause', function() {
                            /*暂停*/
                            that.saveTime(resId, that.newPlay.currentTime, that.learClockTime);
                            that.learClockTime = 0;
                        }).on('ended', function() {
                            /*结束*/
                            that.saveTime(resId, that.newPlay.currentTime, that.learClockTime);
                            that.learClockTime = 0;
                            that.nextcourse();
                        }).on('timeupdate', function() {
                            console.log('timeupdate', that.learClockTime, resId);
                            if (that.learClockTime > 30 && that.islearsave) {
                                that.islearsave = false;
                                that.saveTime(resId, that.newPlay.currentTime, that.learClockTime);
                                that.learClockTime = 0;
                            }
                        });
                    } else {
                        that.newPlay.src = that.playVideoList[0] && that.playVideoList[0].file;
                    }
                    that.changebtn();
                }
            },
            /*上次资源播放进度*/
            getLastBreakPosition(resId) {
                const that = this;
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.resource.queryResources, lenye_base.base_data.getformatting({
                    resId: resId,
                    studyUserId: this.userdata.custId,
                    resinfo: '0',
                }), function(e) {
                    if (e.success === '1') {
                        that.studyBreakpoint = e.data[0].studyBreakpoint?e.data[0].studyBreakpoint:0;
                    } ;
                });
            },
            /*播放列表*/
            playlists(id) {
                const that = this;
                let ist = false;
                that.playVideoList = [];
                // console.log(that.playList)
                if (id) {
                    for (let i in that.playList) {
                        if (that.playList[i].file || that.playList[i].thirdResource) {
                            if (i === id || ist) {
                                ist = true;
                                that.playVideoList.push({
                                    'image': that.playList[i].resPhoto,
                                    'id': i,
                                    'file': that.playList[i].file,
                                    'thirdResource': that.playList[i].thirdResource,
                                    'thirdSource': that.playList[i].thirdSource,
                                    'thirdResId': that.playList[i].thirdResId
                                });
                            }
                        }
                    }
                }
            },
            /*资源学习提交计时*/
            saveTime(id, point, time) {
                // if (!libs.getUserData()) {
                //     return false;
                // }
                const that = this;
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.resource.learnSave, lenye_base.base_data.getformatting({
                    'studyUserId': this.userdata.custId,
                    'resId': id,
                    'studyBreakpoint': parseInt(point) + '',
                    'studyTime': time + '',
                }), function(e) {
                    if (e.success === '1') {
                        that.learClockTime = 0;
                        that.islearsave = true;
                    } ;
                });
            },
            // 问答列表
            questions() {
                const that = this;
                let aswIds = '';
                let listobj = [];
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/forum-service/common/itaForum/topicsVisible.do', lenye_base.base_data.getformatting({
                    objType: 'course',
                    objId: this.csId,
                }), function(e) {
                    for (let i = 0; i < e.data.length; i++) {
                        aswIds += e.data[i].aswId + ',';
                        listobj.push({
                            objId: e.data[i].aswId,
                            type: 'asw',
                        });
                        lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/forum-service/common/itaForum/queryAllByTopicId.do', lenye_base.base_data.getformatting({
                            topicId: e.data[i].topicId
                        }), function(res) {
                            e.data[i].anserList = res.data.itaForumItems;
                        });
                        // lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.interact.addReadTimes, lenye_base.base_data.getformatting({
                        //     objId: e.data[i].aswId,
                        //     type: 'asw'
                        // }), function(res) {
                        //     e.data[i].anserList = res.data;
                        // });
                    }
                    console.log(aswIds);
                    setTimeout(function () {
                        that.questionslist = e;
                    },1000)
                });
            },
            subque() {
                const that = this;
                if (!that.question) {
                    that.$message({
                        showClose: true,
                        message: '提问内容不能为空！',
                        type: 'warning'
                    });
                    return false;
                }
                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/forum-service/api2/itaForum/addTopic.do', lenye_base.base_data.getformatting({
                    objName: this.courseName,
                    topicContent: this.question,
                    topicHide: '0',
                    objId: this.csId,
                    objType: 'course',
                }), function(e) {
                    if (e.success === '1') {
                        that.$message({
                            showClose: true,
                            message: '已提问',
                            type: 'success'
                        });
                        that.question = '';
                        // 重新渲染一次列表
                        that.questions();
                    } else {
                        that.$message({
                            showClose: true,
                            message: e.message,
                            type: 'warning'
                        });
                    }
                });
            },
            changebtn() {
                let cptlist = document.querySelectorAll('.cptresult_a');
                console.log(cptlist);
                for (var i=0; i<cptlist.length; i++) {
                    if (cptlist[i].dataset.name === this.cptidvalue) {
                        var num = i+1;
                        if (num >= cptlist.length) {
                            this.nextbtn = false;
                        } else {
                            this.nextbtn = true
                        }
                        var pre = i-1;
                        if (pre >= 0) {
                            this.prebtn = true;
                        } else {
                            this.prebtn = false;
                        }
                    } ;
                };
            },
            nextcourse() {
                let cptlist = document.querySelectorAll('.cptresult_a');
                console.log(cptlist);
                for (var i=0; i<cptlist.length; i++) {
                    if (cptlist[i].dataset.name === this.cptidvalue) {
                        var num = i+1;
                        if (num < cptlist.length) {
                            cptlist[num].click();
                            return false
                        } else {
                            this.$message({
                                showClose: true,
                                message: '已经是最后一节了！',
                                type: 'warning'
                            });
                        }
                    } ;
                };
                this.changebtn();
            },
            prevcourse() {
                let cptlist = document.querySelectorAll('.cptresult_a');
                console.log(cptlist);
                for (var i=0; i<cptlist.length; i++) {
                    if (cptlist[i].dataset.name === this.cptidvalue) {
                        var num = i - 1;
                        if (num >= 0) {
                            cptlist[num].click();
                            return false
                        } else {
                            this.$message({
                                showClose: true,
                                message: '已经是第一节了！',
                                type: 'warning'
                            });
                        }
                    }
                };
                this.changebtn();
            },
            islogin() {
                const that = this;
                /*是否登录*/
                if (that.userdata.custId) {
                    /*课程是否完成*/
                    lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.course.queryUserCoursePageById, lenye_base.base_data.getformatting({
                        csId: that.csId,
                        orderType: '1',
                    }), function(e) {
                        if (e.success === '1'){
                            if (e && e.data.length) {
                                that.studyTime.type = 'study';
                                setTimeout(function () {
                                    document.querySelectorAll('.cptresult_a')[0].click();
                                    that.changebtn();
                                },1500)
                            } else {
                                lenye_base.httpPost(lenye_base.base_data.getapiUrl() + '/course-service/api2/crsCustLearnCourse/addUserCourse.do', lenye_base.base_data.getformatting({
                                    studyUserId: that.userdata.custId,
                                    csId: that.csId,
                                    lcsNormal: 1
                                }), function(res) {
                                    if (res.success === '1') {
                                        that.$message({
                                            showClose: true,
                                            message: '成功选课！',
                                            type: 'success'
                                        });
                                    }
                                });
                                setTimeout(function () {
                                    document.querySelectorAll('.cptresult_a')[0].click();
                                    that.changebtn();
                                },1500)
                                // that.studyTime.time = that.studycontrol();
                                that.studyTime.type = 'nostudy';
                            }
                        }
                    });
                } else {
                    // that.studyTime.time = that.studycontrol();
                    that.studyTime.type = 'nologin';
                    setTimeout(function () {
                        document.querySelectorAll('.cptresult_a')[0].click();
                        that.changebtn();
                    },3000)
                }
            },
        }
    };
</script>
