<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 10:38:49
 * @LastEditors: 纪泽龙 jizelong@qq.com
 * @LastEditTime: 2022-12-28 15:01:59
 * @FilePath: /danger-manage-web/src/views/lessonsProgram/components/addLesson.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-dialog
    class="add-lession"
    :title="title"
    :visible.sync="visible"
    width="1020px"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :before-close="dialogCancel"
    @closed="closeFinished"
    destroy-on-close
  >
    <div v-if="visible" ref="myBody" class="body">
      <transition name="fade" mode="out-in">
        <component
          :is="currentComponent"
          :bankId.sync="bankId"
          :subjectId.sync="subjectId"
          :jsonData="jsonData"
          ref="current"
        ></component>
      </transition>
      <!-- <Lesson ref='lesson'/> -->
      <!-- <AddQuestion />
      <QuestionList/> -->
    </div>

    <div slot="footer" class="dialog-footer">
      <!--<el-button-->
        <!--type="primary"-->
        <!--v-if="this.componentsNum == 1 || this.componentsNum == 3"-->
        <!--@click="save"-->
        <!--&gt;保存</el-button-->
      <!--&gt;-->

      <!--<el-button type="primary" @click="saveAndNext">{{-->
        <!--saveNextText-->
      <!--}}</el-button>-->
      <el-button
        v-if="this.componentsNum == 2"
        type="primary"
        @click="savePlan"
        >{{ "确认" }}</el-button
      >
      <el-button @click="dialogCancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import Lesson from "./Lesson";
import AddQuestion from "../../textPaper/components/AddQuestion";
import QuestionList from "../../textPaper/components/QuestionList";

export default {
  name: "AnswerLesson",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    componentsNum: {
      type: Number,
      default: 1,
    },
    bankId: {
      type: Number,
    },
    jsonData:{
      type:Array,
    }
  },
  // components: {
  //   Lesson,
  //   AddQuestion,
  //   QuestionList,
  // },

  data() {
    return {
      title: "录入课程",
      currentComponent: Lesson,
      // 当前题目查看
      subjectId: null,
    };
  },
  watch: {
    componentsNum: {
      handler(num) {
        if (num === 1) {
          this.currentComponent = Lesson;
          if (this.bankId) {
            this.title = "修改课程";
          } else {
            this.title = "新增课程";
          }
        } else if (num === 2) {
          this.currentComponent = QuestionList;

          this.title = "题目列表";
        } else {
          this.currentComponent = AddQuestion;
          if (this.subjectId) {
            this.title = "修改题目";
          } else {
            this.title = "新增题目";
          }
        }
      },
      deep: true,
    },
  },
  computed: {
    saveNextText() {
      let text;
      if (this.componentsNum == 1) {
        text = "保存并录入题目";
      } else if (this.componentsNum == 2) {
        text = "录入考题";
      } else {
        text = "保存并录入下一题";
      }
      return text;
    },
  },
  methods: {
    saveBody() {
      this.startHeight = this.$refs.myBody.offsetHeight - 55 + "px";
    },

    closeFinished() {},
    // 关闭之后
    // 只保存
    save() {
      // this.answerClear();
      this.$refs.current.save();
    },
    savePlan() {
      // this.answerClear();
      this.$refs.current.savePlan();
    },
    // 保存并录入
    saveAndNext() {
      this.$refs.current.saveAndNext();
    },
    // 隐藏与显示dialog
    dialogCancel() {
      this.$emit("update:visible", false);
    },
    // 把ID改变了
    changeCourseId(bankId) {
      this.$emit("update:bankId", bankId);
    },
    // 改变当前组件
    componentsNumChange(num) {
      this.$emit("update:componentsNum", num);
    },

    answerClear() {
      this.answerArr = [];
      this.changeCourseId(null);
    },
  },
};
</script>
<style lang="scss" scoped>
.body {
  width: 100%;
  height: 100%;
  padding-right: 40px;
  padding-left: 36px;
}
</style>