Dia.vue 3.94 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 10:38:49
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2022-12-17 10:24:41
耿迪迪's avatar
耿迪迪 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
 * @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="1000px"
    :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"
          :courseId.sync="courseId"
          :topicId.sync="topicId"
          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"
        >保存</el-button
      >

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

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

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

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

          this.title = "题目列表";
        } else {
          this.currentComponent = AddQuestion;
          if (this.topicId) {
            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();
    },
    // 保存并录入
    saveAndNext() {
      this.$refs.current.saveAndNext();
    },
    // 隐藏与显示dialog
    dialogCancel() {
      this.$emit("update:visible", false);
    },
    // 把ID改变了
    changeCourseId(courseId) {
      this.$emit("update:courseId", courseId);
    },
    // 改变当前组件
    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>