Dia.vue 4.06 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
纪泽龙's avatar
纪泽龙 committed
5
 * @LastEditTime: 2022-12-26 09:55:56
纪泽龙's avatar
纪泽龙 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * @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"
25 26
          :bankId.sync="bankId"
          :subjectId.sync="subjectId"
纪泽龙's avatar
纪泽龙 committed
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
          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,
    },
73
    bankId: {
纪泽龙's avatar
纪泽龙 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87
      type: Number,
    },
  },
  // components: {
  //   Lesson,
  //   AddQuestion,
  //   QuestionList,
  // },

  data() {
    return {
      title: "录入课程",
      currentComponent: Lesson,
      // 当前题目查看
88
      subjectId: null,
纪泽龙's avatar
纪泽龙 committed
89 90 91 92 93 94 95
    };
  },
  watch: {
    componentsNum: {
      handler(num) {
        if (num === 1) {
          this.currentComponent = Lesson;
96
          if (this.bankId) {
纪泽龙's avatar
纪泽龙 committed
97 98 99 100 101 102 103 104 105 106
            this.title = "修改课程";
          } else {
            this.title = "新增课程";
          }
        } else if (num === 2) {
          this.currentComponent = QuestionList;

          this.title = "题目列表";
        } else {
          this.currentComponent = AddQuestion;
107
          if (this.subjectId) {
纪泽龙's avatar
纪泽龙 committed
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
            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() {
纪泽龙's avatar
纪泽龙 committed
148 149 150 151
      // 录入题目的时候不会有修改的缓存
      if (this.subjectId) {
        this.subjectId = null;
      }
纪泽龙's avatar
纪泽龙 committed
152 153 154
      this.$emit("update:visible", false);
    },
    // 把ID改变了
155 156
    changeCourseId(bankId) {
      this.$emit("update:bankId", bankId);
纪泽龙's avatar
纪泽龙 committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    },
    // 改变当前组件
    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>