<style>
.lessonPreparation .lessTop {
    color: #000000;
    font-weight: bold;
    font-size: 14px;
}

.lessonPreparation .Less_LeftIcon {
    background-color: #3FC4FF;
    width: 2px;
    height: 10px;
}

.lessonPreparation .w260 {
    width: 260px !important;
}

.lessonPreparation .w180 {
    width: 180px !important;
}

.lessonPreparation .less_Time {
    color: #999999;
    font-size: 13px;
}

.lessonPreparation .teach_Content {
    color: #111111;
    font-size: 14px;
    margin: 20px 0;
    font-weight: bold;
}

.lessonPreparation .add_Lesson {
    width: 30px;
    height: 30px;
    background-color: #2961FE;
    color: #fff;
    text-align: center;
    line-height: 30px;
    border-radius: 50%;
    display: inline-block;
    cursor: pointer;
}

.lessonPreparation .beikeBtn {
    padding: 6px 30px;
    background-color: #2961FE;
    color: #fff;
    font-size: 13px;
    border-radius: 5px;
    margin-left: 20px;
    cursor: pointer;
}

.lessonPreparation .beikeModule {
    padding: 9px 15px;
    background-color: #FFFFFF;
    color: #A1AAB2;
    font-size: 13px;
    border-radius: 5px;
    margin-right: 20px;
    cursor: pointer;
    border: 1px solid #A1AAB2;
}

.lessonPreparation .teach_Lessback {
    width: 64.5%;
    height: 50px;
    min-width: 908px;
    text-align: right;
    line-height: 50px;
    padding-right: 20px;
    background-color: #F0F5FB;
}

.lessonPreparation .Less_Delete {
    width: 30px;
    height: 30px;
    background-color: red;
    color: #fff;
    text-align: center;
    line-height: 30px;
    border-radius: 50%;
    cursor: pointer;
    margin-top: 5px;
    margin-left: 8px;
    position: absolute;
    right: -10px;
    top: -10px;
    display: none;
}

.lessonPreparation .Less_Delete:hover {
    opacity: 0.6;
}

.lessonPreparation .w60 {
    width: 60px !important;
}

.lessonPreparation .addbtn {
    width: 100%;
    height: 45px;
    border-radius: 5px;
    border: 1px dashed #E2E2E2;
    margin-top: 10px;
    cursor: pointer;
}

.lessonPreparation .cont {
    padding: 1px;
    border: 1px dashed #FFF;
    position: relative;
}

.lessonPreparation .cont:hover {
    border: 1px dashed #E2E2E2;
}

/* .lessonPreparation .cont .q-gutter-y-xs>*,
.q-gutter-xs>* {
    margin: 0;
} */

.lessonPreparation .cont:hover .Less_Delete {
    display: inline-block;
}

.lessonPreparation .edui-editor {
    z-index: 99 !important;
}

.prepareTopTitle {
    display: flex;
    align-items: center;
    font-size: 12px;
}

.prePare_Line {
    width: 3px;
    height: 14px;
    background-color: #3FC4FF;
    margin-right: 10px;
}

.preSecond {
    font-size: 18px;
    color: #000000;
    position: relative;
    margin: 20px 0;
}

.preSecond:after {
    position: absolute;
    content: '';
    display: inline-block;
    width: 75px;
    height: 5px;
    background: #3FC4FF;
    position: absolute;
    left: 0;
    top: 18px;
    opacity: 0.6;
}

.prePare_Content {
    /* width: 430px; */
    min-height: 100px;
    height: auto;
    background-color: #F0F5FB;
    padding: 20px;
    margin: 20px auto;
}
  .prePare_Content h6,
  .prePare_Content h5,
  .prePare_Content h4,
  .prePare_Content h3,
  .prePare_Content h2,
  .prePare_Content h1{
    font-size: unset !important;
    line-height: unset !important;
    letter-spacing: unset !important;
  }
</style>
<template>
<div class="row full-height">
    <div class="page-body lessonPreparation" style="width:40%;height: calc(100% - 30px) !important;">
         <q-scroll-area
            :thumb-style="thumbStyle"
            :content-style="contentStyle"
            :content-active-style="contentActiveStyle"
            class="full-width full-height"
        >
            <div class="row">
                <div class="prepareTopTitle q-table__title col">
                    <div class="prePare_Line"></div>
                    <div>{{courseName}}</div>
                </div>
                <div class="prepareTopTitle q-table__title" v-if="chapters && chapters.length>0">
                    <div class="prePare_Line"></div>
                    <div>{{chapters[0].ChapterName}}</div>
                </div>
            </div>
            <div v-if="chapters && chapters.length>0">
                <div v-for="(chapter,i) in chapters[0].ChildList">
                    <div class="preSecond">
                        {{chapter.ChapterName}}
                    </div>
                    <div class="prepareTopTitle q-table__title">
                        <div class="prePare_Line" style="background-color:#2961FE"></div>
                        <div>章节学习内容</div>
                    </div>
                    <div class="prePare_Content" v-if="chapter.ChapterContent!=''" v-html="decodeURIComponent(chapter.ChapterContent)"></div>
                    <div class="prePare_Content text-center q-pa-lg" v-else>暂无内容</div>
                    <div class="prepareTopTitle q-table__title">
                        <div class="prePare_Line" style="background-color:#2961FE"></div>
                        <div>教学目标</div>
                    </div>
                    <div class="prePare_Content" style="background:#F7F0FB" v-if="chapter.Objectives!=''" v-html="decodeURIComponent(chapter.Objectives)">
                    </div>
                    <div class="prePare_Content text-center q-pa-lg" style="background:#F7F0FB" v-else>暂无内容</div>
                    <div class="prepareTopTitle q-table__title">
                        <div class="prePare_Line" style="background:#2961FE"></div>
                        <div>学生学习要求</div>
                    </div>
                    <div class="prePare_Content" style="background:#FBF6F0" v-if="chapter.Requirement!=''" v-html="decodeURIComponent(chapter.Requirement)">
                    </div>
                    <div class="prePare_Content text-center q-pa-lg" style="background:#FBF6F0" v-else>暂无内容</div>
                </div>
            </div>
            <div v-else class="q-pa-lg bg-grey-2 rounded-borders q-my-lg">暂无章节信息</div>
         </q-scroll-area>
    </div>
    <div class="page-body lessonPreparation row col" style="height: calc(100% - 30px) !important;">
        <q-scroll-area
            :thumb-style="thumbStyle"
            :content-style="contentStyle"
            :content-active-style="contentActiveStyle"
            class="full-width full-height"
        >
            <div>
                <div class="lessTop">备课编辑</div>
                <div style="margin:20px 0;">
                    <span class="Less_LeftIcon"></span>
                    教案名称：<el-input v-model="addMsg.LessonPlan" placeholder="教案名称" class="w260"></el-input>
                    <span style="margin-left:30px;">第
                        <el-input v-model="addMsg.CourseNum" style="margin:0 5px;" placeholder="第几课" @keyup.native="checkInteger(addMsg,'CourseNum')" class="w60"></el-input>课</span>
                    <span style="float:right;display:inline-block;margin-left:20px;">
                        <q-btn color="accent" size="sm" class="q-mr-md" icon="add" label="选择模板" @click="getModule()" />
                    </span>
                </div>
                <div style="display:flex;">
                    <div>
                        <span class="less_Time" style="margin-left:30px;">时间：</span>
                        <span>{{WorkDate}}</span>
                    </div>
                    <div style="margin-left:188px;">
                        <span class="less_Time">担当者：</span>
                        <span>{{TeacherName}}</span>
                    </div>
                </div>
                <div class="teach_Content">
                    教学目标
                </div>
                <div style="" v-for="(item,index) in addMsg.LessonPlanList" v-if="index==0">
                    <q-input :rows="5" type="textarea"  filled stack-label v-model="item.CourseTitle" :dense="false" class="col-12 q-pb-lg" label="教学目标" />
                </div>
                <div class="teach_Content">
                    教学难点
                </div>
                <div style="" v-for="(item,index) in addMsg.LessonPlanList" v-if="index==0">
                    <!-- <div style="margin-top: 10px">{{item.CourseName}}</div> -->
                    <UeEditor class="col-8" v-model="item.LessonPlanProjectsList[0].ProjectContent" :config="config"></UeEditor>
                </div>
                <div style="" v-for="(item,index) in addMsg.LessonPlanList" v-if="index==0">
                    <div class="teach_Content">
                        教学流程
                    </div>
                    <div class="row q-gutter-xs cont" v-for="(subItem,subIndex) in item.LessonPlanDetailsList" style="margin-top:20px;align-items: self-end;width:100%;">

                        <q-input filled stack-label v-model="subItem.Duration" @keyup.native="checkInteger(subItem,'Duration')" style="width: 100%;" :dense="false" class=" " label="时长" suffix="分钟" />

                        <UeEditor class="" style="width: 100%;" v-model="subItem.ProjectContent" :config="config"></UeEditor>
                        <div class="Less_Delete " title="删除详情" @click="delLessInfo(index,subIndex)">
                            <i class="iconfont icon-shanchu"></i>
                        </div>
                    </div>

                    <div class="addbtn flex flex-center" @click="addPlanDetailsList(index)">
                        <i class="iconfont icon-add"></i>
                    </div>
                </div>

                <div style="margin-top:30px;">
                    <span class="beikeModule" @click="saveInfo(1)">存为模板</span>
                    <q-btn label="提交" size="md" color="accent q-px-md" @click="saveInfo(0)" />
                </div>
                <lessoncheck-form v-if="IsShowLessForm" @close="closeTeachSaveForm" @success="refreshPage">
                </lessoncheck-form>
            </div>
        </q-scroll-area>
    </div>
</div>
</template>

<script>
import UeEditor from '../../components/editor/UeEditor'
import lessoncheckForm from '../../components/course/lessoncheck-form'
import {
    SetClassLessPlan,
    GetClassLessPlan
} from '../../api/course/class';
export default {
    meta: {
        title: "备课编辑"
    },
    props: {},
    components: {
        UeEditor,
        lessoncheckForm
    },
    data() {
        return {
            contentStyle: {},
            contentActiveStyle: {},
            thumbStyle: {
                right: '2px',
                borderRadius: '5px',
                backgroundColor: '#027be3',
                width: '5px',
                opacity: 0.75
            },
            msg: {
                ClassId: 0,
                School_Id: 0,
                ClassPlanId: 0
            },
            addMsg: {
                CourseNum: '', //第几课
                ClassId: 0, //班级
                School_Id: 0,
                ClassPlanId: 0, //排课id
                LessonPlan: '', //教案名称
                IsTemplate: 0, //是否设置成模板0-否，1-是
                LessonPlanList: [], //老师教案详情
            },
            TeacherName: '', //教师名字
            WorkDate: '', //时间
            config: {
                initialFrameWidth: null,
                initialFrameHeight: 150,
            },
            IsShowLessForm: false,
            nowDate: '',
            chapters: null,
            courseName:"",
            isShowEdit: false, //是否显示提交按钮
        }
    },
    created() {},
    mounted() {
        if (this.$route.query) {
            this.msg.ClassId = this.$route.query.ClassId;
            this.msg.School_Id = this.$route.query.School_Id;
            this.msg.ClassPlanId = this.$route.query.ClassPlanId;
            this.addMsg.CourseNum = this.$route.query.Ranks;
        }
        this.getList();

        var today = new Date();
        var y = today.getFullYear();
        var m = today.getMonth() + 1;
        var d = today.getDate();
        var h = today.getHours();
        var i = today.getMinutes();
        var s = today.getSeconds(); // 在小于10的数字钱前加一个‘0’
        this.nowDate = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
    },
    methods: {
        getList() {
            GetClassLessPlan(this.msg).then(res => {
                if (res.Code == 1) {
                    let data = res.Data;
                    if (data.Chapter && data.Chapter.length>0) {
                        if(!data.Chapter[0].ChildList || data.Chapter[0].ChildList.length==0){
                            data.Chapter[0].ChildList=[]
                            data.Chapter[0].ChildList.push(data.Chapter[0])
                        }
                        this.chapters = data.Chapter
                    }
                    this.courseName=data.CourseName
                    // this.addMsg.CourseNum = data.CourseNum;
                    this.addMsg.ClassId = data.ClassId;
                    this.addMsg.School_Id = data.School_Id;
                    this.addMsg.ClassPlanId = data.ClassPlanId;
                    this.addMsg.LessonPlan = data.LessonPlan;
                    this.addMsg.IsTemplate = data.IsTemplate;
                    if (data.LessonPlanList == null) {
                        this.addMsg.LessonPlanList = [];
                    } else {
                        this.addMsg.LessonPlanList = data.LessonPlanList;
                        this.addMsg.LessonPlanList.forEach(x => {
                            x.ClassDate=data.ClassStartTime.slice(0,10);
                            x.LessonPlanProjectsList.push({
                                ProjectContent: ''
                            })
                        })
                    }
                    this.TeacherName = data.TeacherName;
                    this.WorkDate = data.WorkDate;

                    var beginTimes = this.nowDate.replace(/-/g, "/"); //当前
                    var endTimes = data.ClassStartTime.replace(/-/g, "/"); //开始时间
                    var a = (Date.parse(endTimes) - Date.parse(beginTimes)) / 3600 / 1000;
                    if (a > 0) {
                        this.isShowEdit = true; //可以编辑
                    }
                }
            })
        },
        handleClose(tag, index) {
            this.addMsg.LessonPlanList[index].LessonPlanProjectsList[0].ProjectContentList.splice(this.addMsg
                .LessonPlanList[index].LessonPlanProjectsList[0].ProjectContentList.indexOf(tag), 1);
        },
        showInput(item) {
            item.isShow = true;
            this.$nextTick(() => {
                this.$refs.saveTagInput[0].$refs.input.focus();
            });
        },
        handleInputConfirm(item, index) {
            if (item.isValue) {
                this.addMsg.LessonPlanList[index].LessonPlanProjectsList[0].ProjectContentList.push(item.isValue);
            }
            item.isShow = false;
            item.isValue = '';
        },
        //新增教案
        addPlanList() {
            let obj = {
                CourseName: '', //课程名称（活动篇/理解篇）
                CourseTitle: '', //课程标题
                LessonPlanDetailsList: [], //老师教案详情
                LessonPlanProjectsList: [{
                    ProjectContentList: []
                }], //老师教案详情
                isShow: false,
                isValue: ''
            }
            this.addMsg.LessonPlanList.push(obj);
        },
        //添加老师教案详情
        addPlanDetailsList(index) {
            var obj = {
                ProjectContent: '',
                Duration: ''
            }
            this.addMsg.LessonPlanList[index].LessonPlanDetailsList.push(obj);
        },
        //删除教案详情
        delLessInfo(index, subIndex) {
            this.addMsg.LessonPlanList[index].LessonPlanDetailsList.splice(subIndex, 1);
        },
        //删除整个教案
        delLessOne(index) {
            this.addMsg.LessonPlanList.splice(index, 1);
        },
        //关闭弹窗
        closeTeachSaveForm() {
            this.IsShowLessForm = false
        },
        //选择模板
        getModule() {
            this.IsShowLessForm = true;
        },
        //获取选择模板数据
        refreshPage(val) {
            if (val && val.LessonPlanList.length > 0) {
                let data = val.LessonPlanList;
                data.forEach((x, i) => {
                    if (i == 0) {
                        x.LessonPlanId = this.addMsg.LessonPlanList[0].LessonPlanId;

                    } else if (i == 1) {
                        x.LessonPlanId = this.addMsg.LessonPlanList[1].LessonPlanId;

                    } else {
                        x.LessonPlanId = 0;

                    }
                    x.LessonPlanDetailsList.forEach(j => {
                        j.LessonPlanDetailsId = 0
                    })
                    x.LessonPlanProjectsList.forEach(j => {
                        j.LessonPlanProjectsId = 0
                    })
                })
                this.addMsg.LessonPlanList = data
            }
        },
        //提交
        saveInfo(num) {
            this.addMsg.IsTemplate = num;
            for (let i = 0; i < this.addMsg.LessonPlanList.length; i++) {
                for (let j = 0; j < this.addMsg.LessonPlanList[i].LessonPlanDetailsList.length; j++) {
                    if (this.addMsg.LessonPlanList[i].LessonPlanDetailsList[j].ProjectContent == '') {
                        this.$q.notify({
                            type: 'negative',
                            position: 'top',
                            timeout: 1500,
                            message: `请检查内容填写是否完整`
                        })
                        return;
                    }
                }
            }
            SetClassLessPlan(this.addMsg).then(res => {
                if (res.Code == 1) {
                    this.$q.notify({
                        icon: 'iconfont icon-chenggong',
                        color: 'accent',
                        timeout: 2000,
                        message: '数据保存成功！',
                        position: 'top'
                    })
                    var tempStr = '/course/teacherLesson';
                    this.$router.push({
                        path: tempStr
                    });
                }
            })
        },
    },
}
</script>
<style lang="sass">
  @import url('~assets/css/table.sass')

</style>
