Lesson.vue 8.86 KB
Newer Older
纪泽龙's avatar
纪泽龙 committed
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 10:59:44
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2022-12-17 14:36:14
纪泽龙's avatar
纪泽龙 committed
6 7 8 9 10 11 12 13 14 15 16 17 18
 * @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"
    >
      <div class="top flex">
19 20
        <el-form-item label="题库名称" prop="bankName">
          <el-input style="width: 300px" v-model="form.bankName"></el-input>
纪泽龙's avatar
纪泽龙 committed
21 22
        </el-form-item>

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
        <el-form-item
          label="归属部门"
          prop="deptId"
          label-width="140px"
          ref="treeItem"
        >
          <Treeselect
            class="tree"
            v-model="form.deptId"
            :options="deptOptions"
            :show-count="true"
            placeholder="请选择归属部门"
            @open="treeOpen"
            @close="treeClose"
            @select="select"
          />
纪泽龙's avatar
纪泽龙 committed
39 40 41 42
        </el-form-item>
      </div>

      <!-- </div> -->
43
      <!-- <el-form-item label="课程内容" prop="courseConent">
纪泽龙's avatar
纪泽龙 committed
44 45 46 47 48 49
        <Editor v-model="form.courseConent" :min-height="192" />
        <el-input
          v-show="false"
          disabled
          v-model="form.courseConent"
        ></el-input>
50
      </el-form-item> -->
纪泽龙's avatar
纪泽龙 committed
51

52
      <!-- <div class="flex">
纪泽龙's avatar
纪泽龙 committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        <el-form-item label="视频上传" v-if="!readOnly" prop="video">
          <FileUpload
            listType="picture"
            @resFun="getFileInfoVideo"
            @remove="listRemoveVideo"
            :fileArr="fileListVideo"
            :fileSize="500"
            :fileType="['mp4']"
          />
          <el-input v-show="false" disabled v-model="form.video"></el-input>
        </el-form-item>
        <el-form-item label="附件上传" v-if="!readOnly" prop="enclosure">
          <FileUpload
            listType="picture"
            @resFun="getFileInfoFile"
            @remove="listRemoveFile"
            :fileArr="fileListFile"
          />
          <el-input v-show="false" disabled v-model="form.enclosure"></el-input>
        </el-form-item>
73
      </div> -->
纪泽龙's avatar
纪泽龙 committed
74 75 76 77 78 79 80 81
    </el-form>
  </div>
</template>

<script>
import Editor from "./Editor";
import FileUpload from "@/components/FileUpload";
import uploadfile from "@/assets/uploadfile.png";
82 83 84 85 86 87
// import { mapGetters } from "vuex";
// import {
//   addLessons,
//   getLessonById,
//   changeLesson,
// } from "@/api/educationPlanExam/lessonsProgram";
88 89 90 91 92 93
import {
  listBank,
  addBank,
  updateBank,
  getBank,
  
94
} from "@/api/educationPlanExam/questionBank";
纪泽龙's avatar
纪泽龙 committed
95

96 97 98 99
// 所有部门
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
纪泽龙's avatar
纪泽龙 committed
100 101 102
export default {
  name: "",
  props: {
103
    bankId: {
纪泽龙's avatar
纪泽龙 committed
104 105 106 107 108 109
      type: Number,
    },
  },
  components: {
    Editor,
    FileUpload,
110
    Treeselect,
纪泽龙's avatar
纪泽龙 committed
111 112 113 114
  },
  data() {
    return {
      form: {
115 116 117 118 119 120
        bankName: "",
        // courseType: "",
        // courseConent: "",
        // video: "",
        // enclosure: "",
        deptId: null,
纪泽龙's avatar
纪泽龙 committed
121
      },
122 123 124
      // 归属部门列表
      deptOptions: [],

纪泽龙's avatar
纪泽龙 committed
125 126 127 128
      fileListVideo: [],
      fileListFile: [],
      readOnly: false,
      rules: {
129
        bankName: [
纪泽龙's avatar
纪泽龙 committed
130 131
          { required: true, trigger: "blur", message: "课程名称不能为空" },
        ],
132 133
        deptId: [
          { required: true, trigger: "blur", message: "请选择所属部门" },
纪泽龙's avatar
纪泽龙 committed
134
        ],
135 136 137 138 139 140 141 142 143 144
        // courseType: [
        //   { required: true, trigger: "change", message: "课程类型不能为空" },
        // ],
        // courseConent: [
        //   { required: true, trigger: "blur", message: "课程内容不能为空" },
        // ],
        // video: [{ required: true, trigger: "blue", message: "视频不能为空" }],
        // enclosure: [
        //   { required: true, trigger: "blur", message: "附件不能为空" },
        // ],
纪泽龙's avatar
纪泽龙 committed
145 146 147 148 149
      },
    };
  },
  computed: {
    // 获取课程类型
150
    // ...mapGetters(["courseOptions"]),
纪泽龙's avatar
纪泽龙 committed
151 152
  },
  created() {
153
    if (this.bankId) {
纪泽龙's avatar
纪泽龙 committed
154 155
      this.getLessonById();
    }
156 157
    // 归属部门列表
    this.getTreeselect();
纪泽龙's avatar
纪泽龙 committed
158 159 160 161 162
  },
  mounted() {},
  methods: {
    // 添加课程
    addLessons(data) {
163
      if (!this.bankId) {
纪泽龙's avatar
纪泽龙 committed
164
        console.log("添加");
165
        return addBank(data);
纪泽龙's avatar
纪泽龙 committed
166 167
      } else {
        console.log("修改");
168
        return updateBank({ bankId: this.bankId, ...data });
纪泽龙's avatar
纪泽龙 committed
169 170
      }
    },
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then((response) => {
        this.deptOptions = response.data;
        console.log(this.deptOptions);
      });
    },
    // 当树形组件打开
    treeOpen() {
      document.querySelector(".vue-treeselect__control").style.borderColor = "";
    },
    // 当属性组件关闭
    treeClose(a, b) {
      if (!a) {
        // 手动添加报红功能,没值的时候报红
        document.querySelector(".vue-treeselect__control").style.borderColor =
          "red";
        this.save();
      } else {
        document.querySelector(".vue-treeselect__control").style.borderColor =
          "";
        this.$refs.treeItem.clearValidate();
      }
    },
    select() {},
纪泽龙's avatar
纪泽龙 committed
196 197
    // 复现
    getLessonById() {
198
      getBank(this.bankId).then((res) => {
199
        console.log("res", res);
纪泽龙's avatar
纪泽龙 committed
200 201
        if (res.code == 200) {
          this.form = {
202 203
            bankName: res.data.bankName,
            deptId: res.data.deptId,
纪泽龙's avatar
纪泽龙 committed
204
          };
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
          //   const data = res.data;
          //   const { bankName, courseType, courseConent, video, enclosure } =
          //     data;
          //   this.form = {
          //     bankName,
          //     courseType,
          //     courseConent,
          //     video,
          //     enclosure,
          //   };
          //   this.fileListVideo = [
          //     {
          //       name: bankName + "视频",
          //       url: uploadfile,
          //     },
          //   ];
          //   this.fileListFile = [
          //     {
          //       name: bankName + "附件",
          //       url: uploadfile,
          //     },
          //   ];
纪泽龙's avatar
纪泽龙 committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
        }
      });
    },
    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;
    },
    save(num = 2) {
      // 因为富文本编辑器会残留<p><br></p>,所以要清
262 263 264
      // if (this.form.courseConent === "<p><br></p>") {
      //   this.form.courseConent = "";
      // }
纪泽龙's avatar
纪泽龙 committed
265 266 267 268
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.addLessons({ ...this.form }).then((res) => {
            // 如果添加会传回来,就用传回来的,如果是修改本身就有,就用本身的
269
            // console.log('res',res)
270
            const bankId = this.bankId || res;
271 272 273 274 275 276 277 278 279 280 281 282
            // if (res.code == 200) {
            // 这样调比较纯函数一点
            if (num == 2) {
              this.$message({
                message: "保存题库成功",
                type: "success",
              });
            } else if (num == 3) {
              this.$message({
                message: "保存题库成功,请开始录入题目",
                type: "success",
              });
纪泽龙's avatar
纪泽龙 committed
283
            }
284
            this.$parent.$parent.componentsNumChange(num);
285
            this.$parent.$parent.changeCourseId(bankId);
286 287 288 289
            this.$parent.$parent.$parent.getList();

            return true;
            // }
纪泽龙's avatar
纪泽龙 committed
290
          });
291 292 293 294 295 296 297 298 299 300 301
        } else {
          if (!this.form.deptId) {
            document.querySelector(
              ".vue-treeselect__control"
            ).style.borderColor = "red";
          } else {
            document.querySelector(
              ".vue-treeselect__control"
            ).style.borderColor = "";
            this.$refs.treeItem.clearValidate();
          }
纪泽龙's avatar
纪泽龙 committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315
        }
      });
    },
    // 保存并进入题目
    saveAndNext() {
      this.save(3);
    },
  },
};
</script>
<style lang="scss" scoped>
.form-wrapper {
  padding-top: 22px;
  width: 100%;
316 317
  height: 100px;
  // overflow: hidden;
纪泽龙's avatar
纪泽龙 committed
318 319 320 321 322 323 324 325 326 327
  // padding-bottom: 10px;
  margin-bottom: 20px;

  border-bottom: 1px solid #bbbbbb;
  .top {
    width: 100%;
    justify-content: space-between;
  }
}
</style>