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

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

  .w260 {
    width: 260px !important;
  }

  .w180 {
    width: 180px !important;
  }

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

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

  .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: 6px 15px;
    background-color: #FFFFFF;
    color: #A1AAB2;
    font-size: 13px;
    border-radius: 5px;
    margin-left: 20px;
    cursor: pointer;
    border:1px solid #A1AAB2;
  }

</style>
<template>
  <div class="page-body lessonPreparation">
    <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>
      <el-input v-model="addMsg.CourseNum" style="margin-left:20px;" placeholder="第几课" class="w180"></el-input>
    </div>
    <div style="display:flex;">
      <div>
        <span class="less_Time">时间：</span>
        <span>2016年4月18日</span>
      </div>
      <div style="margin-left:200px;">
        <span class="less_Time">担当者：</span>
        <span>张三丰</span>
      </div>
    </div>
    <div class="teach_Content">
      上课内容
    </div>
    <div>
      <span class="add_Lesson" @click="addPlanList()">
        <i class="iconfont icon-add"></i>
      </span>
    </div>
    <div style="margin-top:20px;" v-for="(item,index) in addMsg.LessonPlanList">
      <div class="row">
        <q-input filled stack-label maxlength="20" v-model="item.CourseName" :dense="false" class="col-2 q-pr-lg q-pb-lg" label="课程名称" />
        <q-input filled stack-label maxlength="20" v-model="item.CourseTitle" :dense="false" class="col-8 q-pr-lg q-pb-lg" label="课程标题" />
      </div>
      <div>
        <span class="add_Lesson" style="margin-top:70px;" @click="addPlanDetailsList(index)">
          <i class="iconfont icon-add"></i>
        </span>
      </div>
      <div class="row" v-for="(subItem,subIndex) in item.LessonPlanDetailsList">
        <UeEditor class="col-8" v-model="subItem.ProjectContent" :config="config"></UeEditor>
        <q-input filled stack-label maxlength="20" v-model="subItem.Duration" style="margin-left:10px;" :dense="false"
          class="col-2 q-pr-lg q-pb-lg" label="时长" />
      </div>
      <div style="margin-top:20px;">
        <el-tag :key="tag" v-for="tag in item.LessonPlanProjectsList" closable :disable-transitions="false" @close="handleClose(tag,index)">
          {{tag}}
        </el-tag>
        <el-input class="input-new-tag w260" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small"
          @keyup.enter.native="handleInputConfirm(index)" @blur="handleInputConfirm(index)">
        </el-input>
        <el-button v-else class="button-new-tag" size="small" @click="showInput">新增教案项目</el-button>
      </div>
    </div>
    <div style="margin-top:30px;">
        <span class="beikeModule" @click="saveInfo(1)">存为模板</span>
        <span class="beikeBtn" @click="saveInfo(0)">提交</span>
    </div>
  </div>
</template>

<script>
  import UeEditor from '../../components/editor/UeEditor'
  import {
    SetClassLessPlan,
    GetClassLessPlan
  } from '../../api/course/class';
  export default {
    meta: {
      title: "备课编辑"
    },
    props: {},
    components: {
      UeEditor
    },
    data() {
      return {
        msg:{
          ClassId:0,
          School_Id:0,
          ClassPlanId:0
        },
        addMsg: {
          CourseNum: '', //第几课
          ClassId: 0, //班级
          School_Id: 0,
          ClassPlanId: 0, //排课id
          LessonPlan: '', //教案名称
          IsTemplate: 0, //是否设置成模板0-否，1-是
          LessonPlanList: [] //老师教案详情
        },
        config: {
          initialFrameWidth: null,
          initialFrameHeight: 150,
        },
        inputVisible: false,
        inputValue: ''
      }
    },
    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.getList();
    },
    methods: {
      getList() {
        GetClassLessPlan(this.msg).then(res => {
            console.log(res,'数据来了');
            if(res.Code==1){
                let data = res.Data;
                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;
                this.addMsg.LessonPlanList = data.IsTemplate;
            }
        })
      },
      handleClose(tag,index) {
        this.addMsg.LessonPlanList[index].LessonPlanProjectsList.splice(this.addMsg.LessonPlanList[index].LessonPlanProjectsList.indexOf(tag), 1);
      },
      showInput() {
        this.inputVisible = true;
        this.$nextTick(() => {
          this.$refs.saveTagInput[0].$refs.input.focus();
        });
      },
      handleInputConfirm(index) {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.addMsg.LessonPlanList[index].LessonPlanProjectsList.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
      //新增教案
      addPlanList(){
          let obj={
            CourseName:'', //课程名称（活动篇/理解篇）
            CourseTitle:'', //课程标题
            LessonPlanDetailsList:[], //老师教案详情
            LessonPlanProjectsList:[] //老师教案详情
          }
          this.addMsg.LessonPlanList.push(obj);
      },
      //添加老师教案详情
      addPlanDetailsList(index){
         var obj={
            ProjectContent:'',
            Duration:''
         }
         this.addMsg.LessonPlanList[index].LessonPlanDetailsList.push(obj);
      },
      //提交
      saveInfo(num){
        this.addMsg.IsTemplate=num;
        SetClassLessPlan(this.addMsg).then(res => {
          this.$q.notify({
            icon: 'iconfont icon-chenggong',
            color: 'accent',
            timeout: 2000,
            message: '数据保存成功！',
            position: 'top'
          })      
        })
      },
    },
  }

</script>
<style lang="sass">
  @import url('~assets/css/table.sass');

</style>
