QuestionList.vue 11.5 KB
Newer Older
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 17:56:05
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2023-01-31 14:04:09
6 7 8 9 10 11 12
 * @FilePath: /danger-manage-web/src/views/lessonsProgram/components/QuestionList.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div ref="myBody" class="add-question flex">
    <div class="text flex">
      <div class="left">
纪泽龙's avatar
纪泽龙 committed
13
        目前有<span>{{ questionNum }}</span
14
        >道题
纪泽龙's avatar
纪泽龙 committed
15
        <span class="warn">温馨提示:发布课程前需要进行考试设置</span>
16 17 18
      </div>
      <div class="right">{{ courseName }}</div>
    </div>
19 20 21

    <div class="detail flex">
      <div class="detail-item">
22 23 24
        单选题<span>{{ bottomFrom.singleChoiceScore }}</span
        >分/题,共<span>{{ danxs }}</span
        >题,计<span class="textC">{{
25
          danxs * bottomFrom.singleChoiceScore
26 27
        }}</span
        >
28 29
      </div>
      <div class="detail-item">
30 31
        多选题<span>{{ bottomFrom.multipleChoiceScore }}</span
        >分/题,共<span>{{ duoxs }}</span> 题,计<span class="textC">{{
32
          duoxs * bottomFrom.multipleChoiceScore
33 34
        }}</span
        >
35 36
      </div>
      <div class="detail-item">
37 38 39 40
        判断提<span>{{ bottomFrom.judgmentScore }}</span>/题,共<span>{{ pds }}</span> 题,计<span
          class="textC"
          >{{ pds * bottomFrom.judgmentScore }}</span
        >
41 42
      </div>
      <div class="detail-item">
43
        一共<span>{{ danxs + duoxs + pds }}</span>道题,总共计<span class="textC">{{
44 45 46
          danxs * bottomFrom.singleChoiceScore +
          duoxs * bottomFrom.multipleChoiceScore +
          pds * bottomFrom.judgmentScore
47 48
        }}</span
        >
49 50 51
      </div>
    </div>

52 53 54
    <div class="table flex" v-loading="loading">
      <div class="th flex">
        <div class="left">序号</div>
55
        <div class="type">题目类型</div>
56 57 58 59 60 61
        <div class="middle">题目名称</div>
        <div class="right">操作</div>
      </div>
      <div class="td-wrapper">
        <div
          v-for="(item, index) in questionList"
纪泽龙's avatar
纪泽龙 committed
62
          :key="item.topicId"
63 64 65
          class="td flex"
        >
          <div class="left">{{ index + 1 }}</div>
66
          <div class="type">{{ topicTypeArr[item.topicType] }}</div>
67 68 69 70 71 72
          <div class="middle zzz">
            {{ item.topicTitle }}
          </div>
          <div class="right">
            <div>
              <el-button
纪泽龙's avatar
纪泽龙 committed
73
                @click="edit(item.topicId)"
74 75 76 77 78
                icon="el-icon-edit"
                type="text"
                >修改</el-button
              >
              <el-button
纪泽龙's avatar
纪泽龙 committed
79
                @click="deleteLesson(item.topicId)"
80 81 82 83 84 85 86 87 88
                icon="el-icon-delete"
                type="text"
                >删除</el-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>
纪泽龙's avatar
纪泽龙 committed
89 90
    <div class="rightNum flex">
      <div class="left">考试设置</div>
91
      <!-- <div class="middle flex">
92 93 94 95 96 97 98 99 100
        <div class="left-text">答对题目大于</div>
        <div>
          <el-input
            v-model="rightNum"
            style="width: 60px"
            size="mini"
          ></el-input>
        </div>
        <div>为合格</div>
101 102 103 104 105 106 107 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
      </div> -->
      <div class="middle flex">
        <div class="left-text">单选一题</div>
        <div>
          <el-input
            v-model="bottomFrom.singleChoiceScore"
            style="width: 50px"
            size="mini"
          ></el-input>
        </div>
        <div></div>
      </div>
      <div class="middle flex">
        <div class="left-text">多选一题</div>
        <div>
          <el-input
            v-model="bottomFrom.multipleChoiceScore"
            style="width: 50px"
            size="mini"
          ></el-input>
        </div>
        <div></div>
      </div>

      <div class="middle flex">
        <div class="left-text">判断一题</div>
        <div>
          <el-input
            v-model="bottomFrom.judgmentScore"
            style="width: 50px"
            size="mini"
          ></el-input>
        </div>
        <div></div>
      </div>

      <div class="middle flex">
        <div class="left-text">总分大于</div>
        <div>
          <el-input
            v-model="bottomFrom.qualifiedNum"
            style="width: 60px"
            size="mini"
          ></el-input>
        </div>
        <div>为合格</div>
147 148 149 150 151 152 153 154 155
      </div>
      <div class="right">
        <el-button
          @click="saveRightNum"
          icon="el-icon-check"
          size="mini"
          type="success"
          >保存</el-button
        >
纪泽龙's avatar
纪泽龙 committed
156 157
      </div>
    </div>
158 159 160 161 162 163 164 165 166 167 168 169 170
  </div>
</template>

<script>
import {
  getQuestion,
  deleteQuestion,
  changeLesson,
  getLessonById,
} from "@/api/educationPlanExam/lessonsProgram";
export default {
  name: "AnswerLesson",
  props: {
纪泽龙's avatar
纪泽龙 committed
171
    courseId: {
172 173 174 175 176 177 178 179
      type: Number,
    },
  },
  components: {},
  data() {
    return {
      // 当前课程的第几题,调一遍接口
      questionNum: null,
180 181 182 183 184 185
      bottomFrom: {
        singleChoiceScore: 0,
        multipleChoiceScore: 0,
        judgmentScore: 0,
        qualifiedNum: 0,
      },
186 187 188 189 190
      // 答对几道题
      rightNum: 0,
      questionList: [],
      loading: false,
      courseName: "",
191 192 193 194 195
      topicTypeArr: {
        1: "单选题",
        2: "多选题",
        3: "判断题",
      },
196 197 198 199 200 201 202 203 204 205 206
    };
  },
  // watch: {
  //   visible(newValue) {
  //     if (newValue) {
  //       this.$nextTick(() => {
  //         this.saveBody();
  //       });
  //     }
  //   },
  // },
207 208 209 210 211 212 213 214 215 216 217
  computed: {
    danxs() {
      return this.questionList.filter((item) => item.topicType === 1).length;
    },
    duoxs() {
      return this.questionList.filter((item) => item.topicType === 2).length;
    },
    pds() {
      return this.questionList.filter((item) => item.topicType === 3).length;
    },
  },
218
  created() {
纪泽龙's avatar
纪泽龙 committed
219 220 221
    console.log("this.courseId", this.courseId);
    if (this.courseId) {
      this.getQuestion({ courseId: this.courseId });
222
      // 获取只题目正确几题算过关
纪泽龙's avatar
纪泽龙 committed
223
      this.getLessonById(this.courseId);
224 225 226 227 228 229 230 231 232
    }
  },
  methods: {
    save() {
      console.log("QuestionList");
    },
    saveAndNext() {
      this.$parent.$parent.componentsNumChange(3);
    },
纪泽龙's avatar
纪泽龙 committed
233 234 235
    getQuestion(courseId) {
      return getQuestion(courseId).then((res) => {
        console.log(res);
236 237 238

        this.questionList = res.rows.map((item) => {
          return {
239
            topicType: item.topicType,
纪泽龙's avatar
纪泽龙 committed
240
            topicId: item.topicId,
241 242 243 244 245 246 247
            topicTitle: item.topicTitle,
          };
        });
        this.questionNum = res.total;
        return true;
      });
    },
纪泽龙's avatar
纪泽龙 committed
248 249 250
    getLessonById(courseId) {
      getLessonById(courseId).then((res) => {
        console.log(res);
251 252 253 254 255 256 257
        // this.rightNum = res.data.qualifiedNum;
        this.bottomFrom = {
          singleChoiceScore: res.data.singleChoiceScore || 0,
          multipleChoiceScore: res.data.multipleChoiceScore || 0,
          judgmentScore: res.data.judgmentScore || 0,
          qualifiedNum: res.data.qualifiedNum || 0,
        };
纪泽龙's avatar
纪泽龙 committed
258
        this.courseName = res.data.courseName;
259 260
      });
    },
纪泽龙's avatar
纪泽龙 committed
261 262
    edit(topicId) {
      this.$emit("update:topicId", topicId);
263 264
      this.$parent.$parent.componentsNumChange(3);
    },
纪泽龙's avatar
纪泽龙 committed
265
    deleteLesson(topicId) {
266 267 268 269 270 271 272
      this.$confirm("请确定删除该题", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.loading = true;
纪泽龙's avatar
纪泽龙 committed
273
          return deleteQuestion(topicId);
274 275 276 277 278 279 280 281
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "删除成功",
              type: "success",
            });
          }
纪泽龙's avatar
纪泽龙 committed
282
          return this.getQuestion({ courseId: this.courseId });
283 284 285 286 287 288 289 290
        })
        .finally(() => {
          this.loading = false;
          // 课程列表重置一下
          this.$parent.$parent.$parent.getList();
        });
    },
    saveRightNum() {
291 292 293 294 295 296 297 298 299
      // if (this.rightNum > this.questionList.length) {
      //   this.$message({
      //     message: "答对题目数应小于等于考试题目总数",
      //     type: "warning",
      //   });
      //   return;
      // }
      if (
        !(
300 301 302 303
          this.bottomFrom.singleChoiceScore >= 0 &&
          this.bottomFrom.multipleChoiceScore >= 0 &&
          this.bottomFrom.judgmentScore >= 0 &&
          this.bottomFrom.qualifiedNum >= 0
304 305
        )
      ) {
306
        this.$message({
307
          message: "请将分数填写完整",
308 309 310 311 312
          type: "warning",
        });
        return;
      }
      changeLesson({
纪泽龙's avatar
纪泽龙 committed
313
        courseId: this.courseId,
314 315
        // qualifiedNum: this.rightNum,
        ...this.bottomFrom,
316 317 318 319 320 321
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "答题合格数修改成功",
            type: "success",
          });
纪泽龙's avatar
纪泽龙 committed
322
          this.$parent.$parent.$parent.getList();
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.add-question {
  width: 100%;
  height: 550px;
  // overflow: hidden;
  flex-direction: column;
  padding-bottom: 7px;
  margin-bottom: 20px;
  border-bottom: 1px solid #bbbbbb00;
338
  position: relative;
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365

  .text {
    margin-top: 13px;
    margin-bottom: 32px;
    justify-content: space-between;
    height: 28px;
    .left {
      line-height: 28px;
      color: #101010;
      font-size: 14px;
      .warn {
        display: inline-flex;
        font-size: 12px;
        color: red;
        margin-left: 10px;
      }
    }

    .right {
      width: 411px;
      line-height: 28px;
      background: #1d84ff;
      padding-right: 5px;
      color: #fff;
      text-align: right;
    }
  }
366 367
  .detail {
    position: absolute;
368 369 370 371 372 373
    bottom: -20px;
    left: 10px;
    .textC {
      font-weight: 800;
      font-size: 18px;
    }
374 375 376 377 378
    .detail-item {
      margin-right: 20px;
      color: red;
    }
  }
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
  .table {
    flex: 1;
    height: 0;

    flex-direction: column;
    .th {
      width: 100%;
      height: 70px;
      line-height: 70px;
      background: #f5f5f5;
      color: #606266;

      > div {
        height: 100%;
      }
      .left {
        width: 15%;
        text-align: center;
      }
398 399 400 401
      .type {
        width: 10%;
        text-align: center;
      }
402
      .middle {
403 404
        width: 50%;
        padding-left: 50px;
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
      }
      .right {
        width: 25%;
        text-align: center;
      }
    }
    .td-wrapper {
      flex: 1;
      overflow-y: auto;
      // 这样子元素才能有滚动条
      .td {
        height: 68px;
        line-height: 68px;
        box-sizing: border-box;
        border-bottom: 1px solid #bbbbbb;
        &:last-child {
          border-bottom: none;
        }
        > div {
          height: 100%;
        }
        .left {
          width: 15%;
          text-align: center;
        }
430 431 432 433
        .type {
          width: 10%;
          text-align: center;
        }
434
        .middle {
435 436
          width: 50%;
          padding-left: 50px;
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
        }
        .right {
          width: 25%;
          text-align: center;
        }
      }
    }
  }
  .rightNum {
    margin-top: 5px;
    height: 55px;
    box-sizing: border-box;
    border: 1px solid #bbbbbb;
    line-height: 55px;
    > .left {
      width: 140px;
      background: #0bab0c;
      font-size: 14px;
      color: #fff;
      text-align: center;
    }
    > .middle {
      > div {
        margin-right: 5px;
      }
      .left-text {
        margin-left: 10px;
      }
      .middle {
        margin-right: 20px;
      }
    }
    .right {
      margin-left: 20px;
    }
    // background: black;
  }
}
</style>