Lesson.vue 6.46 KB
Newer Older
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 10:59:44
 * @LastEditors: 纪泽龙 jizelong@qq.com
纪泽龙's avatar
纪泽龙 committed
5
 * @LastEditTime: 2022-12-26 16:31:34
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 19
      <el-form-item label="考试标题" prop="courseName">
        <el-input style="width: 700px" v-model="form.courseName"></el-input>
纪泽龙's avatar
纪泽龙 committed
20
      </el-form-item>
21
      <div class="top flex">
纪泽龙's avatar
纪泽龙 committed
22
        <el-form-item label="开始时间" prop="testStartTime">
23
          <el-date-picker
纪泽龙's avatar
纪泽龙 committed
24 25
            style="margin-right: 50px"
            v-model="form.testStartTime"
26 27
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
纪泽龙's avatar
纪泽龙 committed
28 29 30
            placeholder="选择日期时间"
            default-time="00:00:00"
          />
31
        </el-form-item>
纪泽龙's avatar
纪泽龙 committed
32
        <el-form-item label="结束时间" prop="testEndTime">
纪泽龙's avatar
纪泽龙 committed
33
          <el-date-picker
纪泽龙's avatar
纪泽龙 committed
34
            v-model="form.testEndTime"
纪泽龙's avatar
纪泽龙 committed
35 36
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
纪泽龙's avatar
纪泽龙 committed
37 38 39
            placeholder="选择日期时间"
            default-time="00:00:00"
          />
纪泽龙's avatar
纪泽龙 committed
40
        </el-form-item>
41
      </div>
纪泽龙's avatar
纪泽龙 committed
42 43
      <el-form-item label="选择人员" prop="testPersons">
        <ChangePapel
44 45 46 47 48
          ref="changePaple"
          :jsonSelectNameList="jsonSelectNameList"
          @getPeopleList="getPeopleList"
        />
      </el-form-item>
纪泽龙's avatar
纪泽龙 committed
49
      <!-- </div> -->
50 51 52 53 54 55
    </el-form>
  </div>
</template>

<script>
import ChangePapel from "@/components/PeopleChange";
纪泽龙's avatar
纪泽龙 committed
56 57 58 59

// import Editor from "./Editor";
// import FileUpload from "@/components/FileUpload";
// import uploadfile from "@/assets/uploadfile.png";
60 61
// import { mapGetters } from "vuex";
import {
纪泽龙's avatar
纪泽龙 committed
62 63 64 65
  addLessons,
  getLessonById,
  changeLesson,
} from "@/api/educationPlanExam/lessonsProgram";
66 67 68 69

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

纪泽龙's avatar
纪泽龙 committed
209 210
              return true;
            }
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
          });
        }
      });
    },
    // 保存并进入题目
    saveAndNext() {
      this.save(3);
    },
  },
};
</script>
<style lang="scss" scoped>
.form-wrapper {
  padding-top: 22px;
  width: 100%;
纪泽龙's avatar
纪泽龙 committed
226 227
  height: 550px;
  overflow: hidden;
228 229
  // padding-bottom: 10px;
  margin-bottom: 20px;
纪泽龙's avatar
纪泽龙 committed
230

231 232 233
  // border-bottom: 1px solid #bbbbbb;
  .top {
    width: 100%;
纪泽龙's avatar
纪泽龙 committed
234
    // justify-content: space-between;
235 236 237
  }
}
</style>