Dia.vue 6.04 KB
Newer Older
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 10:38:49
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2023-02-01 17:34:25
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="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"
纪泽龙's avatar
纪泽龙 committed
25 26
          :courseId.sync="courseId"
          :topicId.sync="topicId"
27
          :checkLock="checkLock"
28 29 30 31 32 33 34 35
          ref="current"
        ></component>
      </transition>
      <!-- <Lesson ref='lesson'/> -->
      <!-- <AddQuestion />
      <QuestionList/> -->
    </div>

36
    <!-- <div slot="footer" class="dialog-footer">
纪泽龙's avatar
纪泽龙 committed
37 38 39 40 41 42 43
      <el-button
        type="primary"
        v-if="this.componentsNum == 2"
        @click="componentsNumChange(4)"
        >从题库选择</el-button
      >

44 45 46 47 48 49
      <el-button
        type="primary"
        v-if="this.componentsNum == 1 || this.componentsNum == 3"
        @click="save"
        >保存</el-button
      >
50 51 52 53 54 55
      <el-button
        type="primary"
        v-if="this.componentsNum == 4"
        @click="componentsNumChange(2)"
        >返回题目列表</el-button
      >
56 57 58 59 60 61 62 63 64 65
      <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>
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
    </div> -->
    <div slot="footer" class="dialog-footer" v-if="!checkLock">
      <el-button
        type="primary"
        v-if="this.componentsNum == 2 && !checkLock"
        @click="componentsNumChange(4)"
        >从题库选择</el-button
      >
      <el-button
        type="primary"
        v-if="this.componentsNum == 4 || this.componentsNum == 3"
        @click="componentsNumChange(2)"
        >返回题目列表</el-button
      >
      <el-button
        type="primary"
        v-if="
          this.componentsNum == 1 ||
          this.componentsNum == 3 ||
          this.componentsNum == 4
        "
        @click="save"
        >保存</el-button
      >

      <el-button type="primary" @click="saveAndNext" v-if="!checkLock">{{
        saveNextText
      }}</el-button>
      <el-button
        v-if="this.componentsNum == 2"
        type="primary"
        @click="dialogCancel"
        >{{ "确认" }}</el-button
      >
      <el-button @click="dialogCancel">取消</el-button>
    </div>
    <div slot="footer" class="dialog-footer" v-else>
      <el-button
        type="primary"
        v-if="this.componentsNum == 3 && checkLock"
        @click="componentsNumChange(2)"
        >返回题目列表</el-button
      >
      <el-button type="primary" @click="dialogCancel">{{ "确认" }}</el-button>
      <el-button @click="dialogCancel">取消</el-button>
111 112 113 114 115 116 117 118
    </div>
  </el-dialog>
</template>

<script>
import Lesson from "./Lesson";
import AddQuestion from "./AddQuestion";
import QuestionList from "./QuestionList";
纪泽龙's avatar
纪泽龙 committed
119
import ChangeQuestion from "./ChangeQuestion";
120 121 122 123 124 125 126 127 128 129 130 131

export default {
  name: "AnswerLesson",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    componentsNum: {
      type: Number,
      default: 1,
    },
纪泽龙's avatar
纪泽龙 committed
132
    courseId: {
133 134
      type: Number,
    },
135 136 137
    checkLock: {
      type: Boolean,
    },
138 139 140 141 142 143 144 145 146 147 148 149
  },
  // components: {
  //   Lesson,
  //   AddQuestion,
  //   QuestionList,
  // },

  data() {
    return {
      title: "录入课程",
      currentComponent: Lesson,
      // 当前题目查看
纪泽龙's avatar
纪泽龙 committed
150
      topicId: null,
151 152 153 154 155 156 157
    };
  },
  watch: {
    componentsNum: {
      handler(num) {
        if (num === 1) {
          this.currentComponent = Lesson;
纪泽龙's avatar
纪泽龙 committed
158
          if (this.courseId) {
159 160 161 162 163 164 165 166
            this.title = "修改课程";
          } else {
            this.title = "新增课程";
          }
        } else if (num === 2) {
          this.currentComponent = QuestionList;

          this.title = "题目列表";
纪泽龙's avatar
纪泽龙 committed
167
        } else if (num === 3) {
168
          this.currentComponent = AddQuestion;
纪泽龙's avatar
纪泽龙 committed
169
          if (this.topicId) {
170 171 172 173
            this.title = "修改题目";
          } else {
            this.title = "新增题目";
          }
纪泽龙's avatar
纪泽龙 committed
174 175 176
        } else if (num == 4) {
          this.currentComponent = ChangeQuestion;
          this.title = "从题库选题";
177 178 179 180 181 182 183 184 185 186 187 188
        }
      },
      deep: true,
    },
  },
  computed: {
    saveNextText() {
      let text;
      if (this.componentsNum == 1) {
        text = "保存并录入题目";
      } else if (this.componentsNum == 2) {
        text = "录入考题";
189
      } else  {
190
        text = "保存并录入下一题";
191
      } 
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
      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
213 214 215 216
      // 录入考题的时候不会有修改的缓存
      if (this.topicId) {
        this.topicId = null;
      }
217
      this.$emit("update:visible", false);
218
      this.$emit("update:checkLock", false);
219 220
    },
    // 把ID改变了
纪泽龙's avatar
纪泽龙 committed
221 222
    changeCourseId(courseId) {
      this.$emit("update:courseId", courseId);
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    },
    // 改变当前组件
    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>