index.vue 9.48 KB
Newer Older
1 2 3 4 5 6
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
纪泽龙's avatar
纪泽龙 committed
7
      label-width="100px"
8
    >
纪泽龙's avatar
纪泽龙 committed
9
      <el-form-item label="考试名称" prop="courseType">
10 11 12 13 14 15 16
        <el-input
          v-model="queryParams.courseName"
          placeholder="请输入课程名称"
          clearable
          size="small"
        />
      </el-form-item>
纪泽龙's avatar
纪泽龙 committed
17
      <el-form-item label="考试开始时间" prop="startTime">
18
        <el-date-picker
纪泽龙's avatar
纪泽龙 committed
19
          v-model="queryParams.testStartTime"
20 21 22 23
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime"
          placeholder="选择日期时间"
          default-time="12:00:00"
纪泽龙's avatar
纪泽龙 committed
24
        />
25
      </el-form-item>
纪泽龙's avatar
纪泽龙 committed
26
      <el-form-item label="考试结束时间" prop="endTime">
27
        <el-date-picker
纪泽龙's avatar
纪泽龙 committed
28
          v-model="queryParams.testEndTime"
29 30 31 32
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetime"
          placeholder="选择日期时间"
          default-time="12:00:00"
纪泽龙's avatar
纪泽龙 committed
33 34
        />
      </el-form-item>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="search"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetClick"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:book:add']"
          >新增</el-button
        >
      </el-col>
    </el-row>

纪泽龙's avatar
纪泽龙 committed
64
    <el-table v-loading="loading" :data="lessonsList">
纪泽龙's avatar
纪泽龙 committed
65
      <el-table-column label="序号" align="center" prop="bankNum" width="55" />
纪泽龙's avatar
纪泽龙 committed
66 67 68 69 70 71 72
      <el-table-column label="课程标题" align="center" prop="courseName" />
      <el-table-column
        label="开始时间"
        align="center"
        prop="testStartTime"
        :formatter="formatter"
      />
73
      <el-table-column
纪泽龙's avatar
纪泽龙 committed
74
        label="结束时间"
75
        align="center"
纪泽龙's avatar
纪泽龙 committed
76
        prop="testEndTime"
77
        :formatter="formatter"
纪泽龙's avatar
纪泽龙 committed
78 79 80
      />
      <el-table-column
        label="考试题"
81 82 83 84
        align="center"
        prop="topicNum"
        width="180"
      >
纪泽龙's avatar
纪泽龙 committed
85
        <template v-slot="{ row: { topicNum, courseId } }">
86
          <div class="timuNum">
87 88 89 90
            <div v-if="topicNum > 0">{{ `已录入${topicNum}题` }}</div>
            <div v-else>未录入</div>
          </div>
        </template>
纪泽龙's avatar
纪泽龙 committed
91 92 93 94 95 96 97
      </el-table-column>
      <el-table-column
        label="答对几题算合格"
        align="center"
        prop="qualifiedNum"
        :formatter="formatter"
      />
98 99 100 101 102
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
纪泽龙's avatar
纪泽龙 committed
103
        <template v-slot="{ row: { status, courseId, qualifiedNum } }">
104
          <!-- <div>{{status}}</div> -->
纪泽龙's avatar
纪泽龙 committed
105
          <el-button
纪泽龙's avatar
纪泽龙 committed
106
            :disabled="status == 1"
纪泽龙's avatar
纪泽龙 committed
107
            v-if="status == 0"
108 109
            size="mini"
            type="text"
纪泽龙's avatar
纪泽龙 committed
110 111
            icon="el-icon-edit"
            @click="checkQuestion(courseId)"
112 113 114
            >录入考题</el-button
          >
          <el-button
纪泽龙's avatar
纪泽龙 committed
115
            :disabled="status == 1"
纪泽龙's avatar
纪泽龙 committed
116
            v-if="status == 0"
117 118 119
            size="mini"
            type="text"
            icon="el-icon-edit"
纪泽龙's avatar
纪泽龙 committed
120
            @click="changeLesson(courseId)"
121 122
            >编辑</el-button
          >
纪泽龙's avatar
纪泽龙 committed
123
          <el-button
124 125
            size="mini"
            type="text"
纪泽龙's avatar
纪泽龙 committed
126 127 128
            icon="el-icon-delete"
            @click="deletLesson(courseId)"
            >删除</el-button
129
          >
纪泽龙's avatar
纪泽龙 committed
130
          <el-button
纪泽龙's avatar
纪泽龙 committed
131
            :disabled="status == 1"
132 133 134 135
            v-if="status == 0"
            size="mini"
            type="text"
            icon="el-icon-delete"
纪泽龙's avatar
纪泽龙 committed
136
            @click="issueLesson(courseId, qualifiedNum)"
纪泽龙's avatar
纪泽龙 committed
137 138
            >发布考试</el-button
          >
139 140 141 142 143 144 145 146 147 148 149 150 151 152
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <Dia
      ref="Dia"
      :componentsNum.sync="componentsNum"
纪泽龙's avatar
纪泽龙 committed
153
      :courseId.sync="courseId"
154 155
      :visible.sync="dilogFlag"
    />
纪泽龙's avatar
纪泽龙 committed
156 157 158
    <el-dialog title="提示" :visible.sync="issue" width="30%">
      <div>123</div>
    </el-dialog>
159 160 161 162
  </div>
</template>

<script>
纪泽龙's avatar
纪泽龙 committed
163 164 165 166 167
import {
  getLessons,
  getLessonById,
  issue,
  deleteLesson,
纪泽龙's avatar
纪泽龙 committed
168
  testPublish,
纪泽龙's avatar
纪泽龙 committed
169 170 171 172
} from "@/api/educationPlanExam/lessonsProgram.js";
// 获取培训计划
import { getPlanList } from "@/api/educationPlanExam/trainingProgram";
import { mapGetters, mapMutations } from "vuex";
173 174 175 176

import Dia from "./components/Dia";

export default {
纪泽龙's avatar
纪泽龙 committed
177
  name: "Book",
178 179 180 181 182 183 184 185 186 187
  components: {
    Dia,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // courseOptions: [],
纪泽龙's avatar
纪泽龙 committed
188
      lessonsList: [],
189 190 191 192
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
纪泽龙's avatar
纪泽龙 committed
193 194
        dataKind: 1,
        courseName: null,
纪泽龙's avatar
纪泽龙 committed
195 196
        testStartTime: "",
        testEndTime: "",
197 198 199 200 201 202 203 204
      },
      // 表单参数
      form: {},
      // 表单校验

      dilogFlag: false,
      componentsNum: 1,
      // 点击的id,如果是新增为空
纪泽龙's avatar
纪泽龙 committed
205
      courseId: null,
纪泽龙's avatar
纪泽龙 committed
206
      issue: false,
207 208 209
    };
  },
  computed: {
纪泽龙's avatar
纪泽龙 committed
210
    ...mapGetters(["courseOptions"]),
211 212 213 214 215 216 217
  },
  created() {
    // this.getPlanList();
    this.getList();
  },

  methods: {
纪泽龙's avatar
纪泽龙 committed
218
    ...mapMutations({ setOptions: "SET_COURSE_OPTIONS" }),
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    // 获取课程类别,也就是计划名称
    // getPlanList() {
    //   getPlanList().then((res) => {
    //     const courseOptions = res.data.map((item) => {
    //       return {
    //         planId: item.planId,
    //         planName: item.planName,
    //       };
    //     });
    //     // this.$store.commit("SET_COURSE_OPTIONS");
    //     this.setOptions(courseOptions);
    //   });
    // },

    /** 查询课程列表 */
    getList() {
      this.loading = true;
纪泽龙's avatar
纪泽龙 committed
236
      getLessons(this.queryParams)
237 238
        .then((res) => {
          console.log(res);
纪泽龙's avatar
纪泽龙 committed
239 240 241 242 243 244 245 246 247
          this.lessonsList = res.rows.map((item, index) => {
            return {
              bankNum:
                index +
                1 +
                (this.queryParams.pageNum - 1) * this.queryParams.pageSize,
              ...item,
            };
          });
248 249 250 251 252 253 254 255 256 257 258 259
          this.total = res.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    search() {
      // console.log(this.queryParams);
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
纪泽龙's avatar
纪泽龙 committed
260
      this.$refs.Dia.title = "新增考试试卷";
261
      this.componentsNum = 1;
纪泽龙's avatar
纪泽龙 committed
262
      this.courseId = null;
263 264
      this.dilogFlag = true;
    },
纪泽龙's avatar
纪泽龙 committed
265
    changeLesson(courseId) {
纪泽龙's avatar
纪泽龙 committed
266
      this.$refs.Dia.title = "修改考试试卷";
267
      this.componentsNum = 1;
纪泽龙's avatar
纪泽龙 committed
268
      this.courseId = courseId;
269 270 271 272
      this.dilogFlag = true;
    },

    // 直接查看考题
纪泽龙's avatar
纪泽龙 committed
273
    checkQuestion(courseId) {
274
      // 要查看考题的id
纪泽龙's avatar
纪泽龙 committed
275 276
      this.courseId = courseId;
      console.log(this.courseId);
277 278 279 280 281 282 283 284 285 286 287 288 289 290
      // 2代表列表组件
      this.componentsNum = 2;
      this.dilogFlag = true;
    },
    // 重置
    resetClick() {
      this.reset();
      this.getList();
    },
    // 复位
    reset() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
纪泽龙's avatar
纪泽龙 committed
291
        dataKind: 1,
292
        courseName: null,
纪泽龙's avatar
纪泽龙 committed
293 294
        testStartTime: "",
        testEndTime: "",
295 296
      };
    },
纪泽龙's avatar
纪泽龙 committed
297
    deletLesson(courseId) {
298 299 300 301 302 303
      this.$confirm("请确定删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
纪泽龙's avatar
纪泽龙 committed
304
          return deleteLesson(courseId);
305 306 307 308 309 310 311 312 313 314 315 316 317
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "删除成功",
              type: "success",
            });
          }
          this.getList();
        })
        .catch(() => {});
    },
    // 发布
纪泽龙's avatar
纪泽龙 committed
318
    issueLesson(courseId, qualifiedNum) {
纪泽龙's avatar
纪泽龙 committed
319 320 321 322 323 324 325 326 327 328
      this.$confirm("请确定发布", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          // 判断是否录入答题合格数
          return getLessonById(courseId);
        })
        .then((res) => {
329 330 331 332 333 334
          if (
            res.data.singleChoiceScore > 0 &&
            res.data.multipleChoiceScore > 0 &&
            res.data.judgmentScore > 0 &&
            res.data.qualifiedNum > 0
          ) {
纪泽龙's avatar
纪泽龙 committed
335 336 337 338 339 340
            return true;
          }
        })
        .then((res) => {
          if (res) {
            // 成功就发布
纪泽龙's avatar
纪泽龙 committed
341 342 343
            // return issue({ courseId });

            return testPublish({ courseId, personnelType: 1 });
纪泽龙's avatar
纪泽龙 committed
344 345
          } else {
            this.$message({
346
              message: "请先在题目列表录入题目分数跟合格分数",
纪泽龙's avatar
纪泽龙 committed
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
              type: "warning",
            });
          }
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "发布成功",
              type: "success",
            });
            this.getList();
          }
        })
        .catch(() => {});
    },
362 363 364 365 366 367 368 369 370 371 372 373 374 375
    formatter(row, column, cellValue, index) {
      // console.log(row, column, cellValue, index);
      if (!cellValue) return "-";
      else return cellValue;
    },
  },
};
</script>
<style lang="scss" scoped>
.down-load {
  color: #0bab0c;
}
.timuNum {
  color: #1d84ff;
纪泽龙's avatar
纪泽龙 committed
376
  // cursor: pointer;
377 378 379 380 381 382 383 384
}
::v-deep .el-select {
  width: 100%;
}
::v-deep .el-dialog {
  margin-top: 15vh !important;
}
</style>