Lesson.vue 6.84 KB
Newer Older
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 10:59:44
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2023-02-01 16:58:26
6 7 8 9 10 11 12 13 14 15 16 17
 * @FilePath: /danger-manage-web/src/views/lessonsProgram/components/Lession.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="form-wrapper">
    <el-form
      class="form"
      ref="form"
      :model="form"
      label-width="auto"
      :rules="rules"
    >
纪泽龙's avatar
纪泽龙 committed
18
      <el-form-item label="考试标题" prop="courseName">
19 20 21 22 23
        <el-input
          :disabled="checkLock"
          style="width: 700px"
          v-model="form.courseName"
        ></el-input>
纪泽龙's avatar
纪泽龙 committed
24
      </el-form-item>
25
      <div class="top flex">
纪泽龙's avatar
纪泽龙 committed
26
        <el-form-item label="开始时间" prop="testStartTime">
27
          <el-date-picker
纪泽龙's avatar
纪泽龙 committed
28 29
            style="margin-right: 50px"
            v-model="form.testStartTime"
30 31
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
纪泽龙's avatar
纪泽龙 committed
32 33
            placeholder="选择日期时间"
            default-time="00:00:00"
34
            :disabled="checkLock"
纪泽龙's avatar
纪泽龙 committed
35
          />
36
        </el-form-item>
纪泽龙's avatar
纪泽龙 committed
37
        <el-form-item label="结束时间" prop="testEndTime">
纪泽龙's avatar
纪泽龙 committed
38
          <el-date-picker
纪泽龙's avatar
纪泽龙 committed
39
            v-model="form.testEndTime"
纪泽龙's avatar
纪泽龙 committed
40 41
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
纪泽龙's avatar
纪泽龙 committed
42 43
            placeholder="选择日期时间"
            default-time="00:00:00"
44
            :disabled="checkLock"
纪泽龙's avatar
纪泽龙 committed
45
          />
纪泽龙's avatar
纪泽龙 committed
46
        </el-form-item>
47
      </div>
纪泽龙's avatar
纪泽龙 committed
48 49
      <el-form-item label="选择人员" prop="testPersons">
        <ChangePapel
50 51
          ref="changePaple"
          :jsonSelectNameList="jsonSelectNameList"
52
          :disabled="checkLock"
53 54 55
          @getPeopleList="getPeopleList"
        />
      </el-form-item>
纪泽龙's avatar
纪泽龙 committed
56
      <!-- </div> -->
57 58 59 60 61 62
    </el-form>
  </div>
</template>

<script>
import ChangePapel from "@/components/PeopleChange";
纪泽龙's avatar
纪泽龙 committed
63 64 65 66

// import Editor from "./Editor";
// import FileUpload from "@/components/FileUpload";
// import uploadfile from "@/assets/uploadfile.png";
67 68
// import { mapGetters } from "vuex";
import {
纪泽龙's avatar
纪泽龙 committed
69 70 71 72
  addLessons,
  getLessonById,
  changeLesson,
} from "@/api/educationPlanExam/lessonsProgram";
73 74 75 76

export default {
  name: "",
  props: {
纪泽龙's avatar
纪泽龙 committed
77
    courseId: {
78 79
      type: Number,
    },
80 81 82
    checkLock: {
      type: Boolean,
    },
83 84
  },
  components: {
纪泽龙's avatar
纪泽龙 committed
85 86
    // Editor,
    // FileUpload,
87 88 89 90 91
    ChangePapel,
  },
  data() {
    return {
      form: {
纪泽龙's avatar
纪泽龙 committed
92 93 94 95
        courseName: "",
        testStartTime: "",
        testEndTime: "",
        testPersons: "",
96
      },
纪泽龙's avatar
纪泽龙 committed
97 98
      jsonSelectNameList: null,
      // '[{"peoPleId":880,"peoPleName":"孙卓亚"},{"peoPleId":871,"peoPleName":"张玉宾"}]',
99 100 101 102
      fileListVideo: [],
      fileListFile: [],
      readOnly: false,
      rules: {
纪泽龙's avatar
纪泽龙 committed
103
        courseName: [
104 105
          { required: true, trigger: "blur", message: "课程名称不能为空" },
        ],
纪泽龙's avatar
纪泽龙 committed
106 107 108 109 110
        testStartTime: [
          { required: true, trigger: "blur", message: "考试开始时间不能为空" },
        ],
        testEndTime: [
          { required: true, trigger: "blur", message: "课程名称不能为空" },
111 112 113 114 115 116 117 118 119
        ],
      },
    };
  },
  computed: {
    // 获取课程类型
    // ...mapGetters(["courseOptions"]),
  },
  created() {
纪泽龙's avatar
纪泽龙 committed
120
    if (this.courseId) {
121 122 123 124 125 126 127 128 129
      this.getLessonById();
    }
  },
  mounted() {
    this.$refs.changePaple.changeNameList(this.jsonSelectNameList);
  },
  methods: {
    // 添加课程
    addLessons(data) {
纪泽龙's avatar
纪泽龙 committed
130 131
      console.log("this.courseId", this.courseId);
      if (!this.courseId) {
132
        console.log("添加");
纪泽龙's avatar
纪泽龙 committed
133
        return addLessons({ dataKind: 1, ...data });
134 135
      } else {
        console.log("修改");
纪泽龙's avatar
纪泽龙 committed
136
        return changeLesson({ courseId: this.courseId, ...data });
137 138
      }
    },
纪泽龙's avatar
纪泽龙 committed
139 140 141 142 143
    getPeopleList(list) {
      console.log("参考人员", list);
      // this.peopleList = list;
      this.form.testPersons = list;
    },
144 145
    // 复现
    getLessonById() {
纪泽龙's avatar
纪泽龙 committed
146
      getLessonById(this.courseId).then((res) => {
147
        if (res.code == 200) {
纪泽龙's avatar
纪泽龙 committed
148 149
          const data = res.data;
          const { courseName, testStartTime, testEndTime, testPersons } = data;
150
          this.form = {
纪泽龙's avatar
纪泽龙 committed
151 152 153 154
            courseName,
            testStartTime,
            testEndTime,
            testPersons,
155
          };
纪泽龙's avatar
纪泽龙 committed
156 157
          this.jsonSelectNameList = testPersons;
          this.$refs.changePaple.changeNameList(this.jsonSelectNameList);
158 159 160
        }
      });
    },
纪泽龙's avatar
纪泽龙 committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    getFileInfoVideo(res) {
      this.form.video = res.url;
      // this.form.videoName = res.fileName;
      this.fileListVideo = [
        {
          name: res.fileName,
          url: uploadfile,
        },
      ];
    },
    listRemoveVideo(e) {
      this.fileListVideo = [];
      this.form.video = "";
      // this.form.videoName = null;
    },
    getFileInfoFile(res) {
      this.form.enclosure = res.url;
      // this.form.enclosureName = res.fileName;
      this.fileListFile = [
        {
          name: res.fileName,
          url: uploadfile,
        },
      ];
    },
    listRemoveFile(e) {
      this.fileListFild = [];
      this.form.enclosure = "";
      // this.form.fileName = null;
190 191 192 193 194 195 196 197
    },
    save(num = 2) {
      // 因为富文本编辑器会残留<p><br></p>,所以要清
      // if (this.form.courseConent === "<p><br></p>") {
      //   this.form.courseConent = "";
      // }
      this.$refs.form.validate((valid) => {
        if (valid) {
纪泽龙's avatar
纪泽龙 committed
198
          // console.log(this.form);
199 200
          this.addLessons({ ...this.form }).then((res) => {
            // 如果添加会传回来,就用传回来的,如果是修改本身就有,就用本身的
纪泽龙's avatar
纪泽龙 committed
201 202 203 204 205 206 207 208
            const courseId = res.data || this.courseId;
            if (res.code == 200) {
              // 这样调比较纯函数一点
              if (num == 2) {
                this.$message({
                  message: "保存课程成功",
                  type: "success",
                });
209
                this.$parent.$parent.dialogCancel();
纪泽龙's avatar
纪泽龙 committed
210 211 212 213 214
              } else if (num == 3) {
                this.$message({
                  message: "保存课程成功,请开始录入题目",
                  type: "success",
                });
215 216
                this.$parent.$parent.componentsNumChange(num);
                this.$parent.$parent.changeCourseId(courseId);
纪泽龙's avatar
纪泽龙 committed
217
              }
218 219
              // this.$parent.$parent.componentsNumChange(num);
              // this.$parent.$parent.changeCourseId(courseId);
纪泽龙's avatar
纪泽龙 committed
220
              this.$parent.$parent.$parent.getList();
221

纪泽龙's avatar
纪泽龙 committed
222 223
              return true;
            }
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
          });
        }
      });
    },
    // 保存并进入题目
    saveAndNext() {
      this.save(3);
    },
  },
};
</script>
<style lang="scss" scoped>
.form-wrapper {
  padding-top: 22px;
  width: 100%;
纪泽龙's avatar
纪泽龙 committed
239 240
  height: 550px;
  overflow: hidden;
241 242
  // padding-bottom: 10px;
  margin-bottom: 20px;
纪泽龙's avatar
纪泽龙 committed
243

244 245 246
  // border-bottom: 1px solid #bbbbbb;
  .top {
    width: 100%;
纪泽龙's avatar
纪泽龙 committed
247
    // justify-content: space-between;
248 249 250
  }
}
</style>