QuestionList.vue 11.9 KB
Newer Older
纪泽龙's avatar
纪泽龙 committed
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-22 17:56:05
 * @LastEditors: 纪泽龙 jizelong@qq.com
5
 * @LastEditTime: 2023-01-15 13:47:35
纪泽龙's avatar
纪泽龙 committed
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">
13
        目前有<span>{{ questionNum || 0 }}</span
纪泽龙's avatar
纪泽龙 committed
14
        >道题
15
        <!-- <span class="warn">温馨提示:发布课程前需要进行考试设置</span> -->
纪泽龙's avatar
纪泽龙 committed
16
      </div>
17
      <div class="right">{{ courseName }}</div>
纪泽龙's avatar
纪泽龙 committed
18
    </div>
吴卿华's avatar
吴卿华 committed
19
    <el-row :gutter="10" class="mb8">
纪泽龙's avatar
纪泽龙 committed
20 21 22 23 24 25 26 27 28 29
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          >导入</el-button
        >
      </el-col>
吴卿华's avatar
吴卿华 committed
30 31
    </el-row>

纪泽龙's avatar
纪泽龙 committed
32 33 34
    <div class="table flex" v-loading="loading">
      <div class="th flex">
        <div class="left">序号</div>
35
        <div class="type">题目类型</div>
纪泽龙's avatar
纪泽龙 committed
36 37 38 39 40 41
        <div class="middle">题目名称</div>
        <div class="right">操作</div>
      </div>
      <div class="td-wrapper">
        <div
          v-for="(item, index) in questionList"
42
          :key="item.subjectId"
纪泽龙's avatar
纪泽龙 committed
43 44 45
          class="td flex"
        >
          <div class="left">{{ index + 1 }}</div>
46
          <div class="type">{{ topicTypeArr[item.topicType] }}</div>
纪泽龙's avatar
纪泽龙 committed
47 48 49 50 51 52
          <div class="middle zzz">
            {{ item.topicTitle }}
          </div>
          <div class="right">
            <div>
              <el-button
53
                @click="edit(item.subjectId)"
纪泽龙's avatar
纪泽龙 committed
54 55 56 57 58
                icon="el-icon-edit"
                type="text"
                >修改</el-button
              >
              <el-button
59
                @click="deleteLesson(item.subjectId)"
纪泽龙's avatar
纪泽龙 committed
60 61 62 63 64 65 66 67 68
                icon="el-icon-delete"
                type="text"
                >删除</el-button
              >
            </div>
          </div>
        </div>
      </div>
    </div>
69 70 71
    <!-- <div class="rightNum flex">

       <div class="left">录入考题</div>
纪泽龙's avatar
纪泽龙 committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      <div class="middle flex">
        <div class="left-text">答对题目大于</div>
        <div>
          <el-input
            v-model="rightNum"
            style="width: 60px"
            size="mini"
          ></el-input>
        </div>
        <div>为合格</div>
      </div>
      <div class="right">
        <el-button
          @click="saveRightNum"
          icon="el-icon-check"
          size="mini"
          type="success"
          >保存</el-button
        >
吴卿华's avatar
吴卿华 committed
91
      </div>
92
    </div> -->
吴卿华's avatar
吴卿华 committed
93 94

    <!-- 设备导入对话框 -->
纪泽龙's avatar
纪泽龙 committed
95 96 97 98 99 100
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
    >
吴卿华's avatar
吴卿华 committed
101 102 103 104 105
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
纪泽龙's avatar
纪泽龙 committed
106 107 108 109 110 111 112
        :action="
          upload.url +
          '?updateSupport=' +
          upload.updateSupport +
          '&bankId=' +
          upload.bankId
        "
吴卿华's avatar
吴卿华 committed
113 114 115 116 117 118 119 120 121 122 123 124
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处,或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
纪泽龙's avatar
纪泽龙 committed
125 126
          <!--          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的设备数据-->
          <!--          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>-->
吴卿华's avatar
吴卿华 committed
127 128 129 130 131
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDownload(upload)"
纪泽龙's avatar
纪泽龙 committed
132 133 134 135 136
            >下载模板</el-button
          >
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示:仅允许导入“xls”或“xlsx”格式文件!
吴卿华's avatar
吴卿华 committed
137 138 139 140 141 142 143
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
纪泽龙's avatar
纪泽龙 committed
144 145 146 147 148 149 150 151 152 153
  </div>
</template>

<script>
import {
  getQuestion,
  deleteQuestion,
  changeLesson,
  getLessonById,
} from "@/api/educationPlanExam/lessonsProgram";
154 155
import { listSubject, delSubject } from "@/api/educationPlanExam/subject";
import { getBank } from "@/api/educationPlanExam/questionBank";
吴卿华's avatar
吴卿华 committed
156
import { getToken } from "@/utils/auth";
纪泽龙's avatar
纪泽龙 committed
157 158 159
export default {
  name: "AnswerLesson",
  props: {
160
    bankId: {
纪泽龙's avatar
纪泽龙 committed
161 162 163 164 165 166 167 168 169 170 171 172
      type: Number,
    },
  },
  components: {},
  data() {
    return {
      // 当前课程的第几题,调一遍接口
      questionNum: null,
      // 答对几道题
      rightNum: 0,
      questionList: [],
      loading: false,
173
      courseName: "",
吴卿华's avatar
吴卿华 committed
174 175 176 177 178
      // 是否显示弹出层
      open: false,
      // 设备导入参数
      upload: {
        //题库id
纪泽龙's avatar
纪泽龙 committed
179
        bankId: 0,
吴卿华's avatar
吴卿华 committed
180 181 182 183 184 185 186 187 188 189 190
        // 是否显示弹出层(用户导入)
        open: false,
        // 弹出层标题(用户导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
纪泽龙's avatar
纪泽龙 committed
191
        url: process.env.VUE_APP_BASE_API + "/system/subject/import",
吴卿华's avatar
吴卿华 committed
192
      },
吴卿华's avatar
吴卿华 committed
193
      queryParams: {
194 195 196 197 198 199
        bankId: 0,
      },
      topicTypeArr: {
        1: "单选题",
        2: "多选题",
        3: "判断题",
吴卿华's avatar
吴卿华 committed
200
      },
纪泽龙's avatar
纪泽龙 committed
201 202 203 204 205 206 207 208 209 210 211 212 213
    };
  },
  // watch: {
  //   visible(newValue) {
  //     if (newValue) {
  //       this.$nextTick(() => {
  //         this.saveBody();
  //       });
  //     }
  //   },
  // },

  created() {
214 215 216
    console.log("this.bankId", this.bankId);
    if (this.bankId) {
      this.getQuestion({ bankId: this.bankId });
纪泽龙's avatar
纪泽龙 committed
217
      // 获取只题目正确几题算过关
218
      this.getLessonById(this.bankId);
纪泽龙's avatar
纪泽龙 committed
219 220 221
    }
  },
  methods: {
吴卿华's avatar
吴卿华 committed
222 223
    // 文件下载处理
    handleDownload(row) {
224 225 226 227 228 229 230 231
      const a = document.createElement("a");
      a.setAttribute("download", "试题导入模板");
      a.setAttribute("target", "_blank");
      a.setAttribute(
        "href",
        "http://36.138.181.113:8091/dangerManage/profile/upload/2022/kaoshi/shitimoban.xlsx"
      );
      a.click();
吴卿华's avatar
吴卿华 committed
232 233 234 235
    },

    /** 导入按钮操作 */
    handleImport() {
纪泽龙's avatar
纪泽龙 committed
236
      this.upload.bankId = this.bankId;
吴卿华's avatar
吴卿华 committed
237 238 239 240 241 242 243 244 245 246 247 248
      this.upload.title = "题目导入";
      this.upload.open = true;
    },
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
吴卿华's avatar
吴卿华 committed
249
      this.getQuestion({ bankId: this.bankId });
纪泽龙's avatar
纪泽龙 committed
250 251
      // this.getList();
      this.$parent.$parent.$parent.getList();
吴卿华's avatar
吴卿华 committed
252 253 254
    },
    /** 下载模板操作 */
    importTemplate() {
纪泽龙's avatar
纪泽龙 committed
255
      importTemplate().then((response) => {
吴卿华's avatar
吴卿华 committed
256 257 258 259 260 261 262 263 264 265 266 267
        this.download(response.msg);
      });
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },

纪泽龙's avatar
纪泽龙 committed
268 269 270 271 272 273
    save() {
      console.log("QuestionList");
    },
    saveAndNext() {
      this.$parent.$parent.componentsNumChange(3);
    },
274 275
    getQuestion(bankId) {
      return listSubject(bankId).then((res) => {
纪泽龙's avatar
纪泽龙 committed
276 277
        this.questionList = res.rows.map((item) => {
          return {
278
            topicType:item.topicType,
279
            subjectId: item.subjectId,
纪泽龙's avatar
纪泽龙 committed
280 281 282 283 284 285 286
            topicTitle: item.topicTitle,
          };
        });
        this.questionNum = res.total;
        return true;
      });
    },
287 288
    getLessonById(bankId) {
      getBank(bankId).then((res) => {
289 290 291
        // console.log(res);
        // this.rightNum = res.data.qualifiedNum;
        this.courseName = res.data.bankName;
纪泽龙's avatar
纪泽龙 committed
292 293
      });
    },
294
    edit(subjectId) {
295
      this.$emit("update:subjectId", subjectId);
纪泽龙's avatar
纪泽龙 committed
296 297
      this.$parent.$parent.componentsNumChange(3);
    },
298
    deleteLesson(subjectId) {
纪泽龙's avatar
纪泽龙 committed
299 300 301 302 303 304 305
      this.$confirm("请确定删除该题", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.loading = true;
306
          return delSubject(subjectId);
纪泽龙's avatar
纪泽龙 committed
307 308 309 310 311 312 313 314
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "删除成功",
              type: "success",
            });
          }
315
          return this.getQuestion({ bankId: this.bankId });
纪泽龙's avatar
纪泽龙 committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
        })
        .finally(() => {
          this.loading = false;
          // 课程列表重置一下
          this.$parent.$parent.$parent.getList();
        });
    },
    saveRightNum() {
      if (this.rightNum > this.questionList.length) {
        this.$message({
          message: "答对题目数应小于等于考试题目总数",
          type: "warning",
        });
        return;
      }
331
      changeLesson({
332
        bankId: this.bankId,
333 334 335 336 337 338 339
        qualifiedNum: this.rightNum,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "答题合格数修改成功",
            type: "success",
          });
纪泽龙's avatar
纪泽龙 committed
340
        }
341
      });
纪泽龙's avatar
纪泽龙 committed
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    },
  },
};
</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;

  .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;
    }
  }
  .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;
      }
401 402 403 404
      .type {
        width: 10%;
        text-align: center;
      }
纪泽龙's avatar
纪泽龙 committed
405
      .middle {
406 407
        width: 50%;
        padding-left: 50px;
纪泽龙's avatar
纪泽龙 committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
      }
      .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;
        }
433 434 435 436
        .type {
          width: 10%;
          text-align: center;
        }
纪泽龙's avatar
纪泽龙 committed
437
        .middle {
438 439
          width: 50%;
          padding-left: 50px;
纪泽龙's avatar
纪泽龙 committed
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 476 477 478
        }
        .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>