Administrator
2022-04-11 79d9fc857559982b00b68b2d709807bdc4cd286f
src/views/trainExam/examStatistics.vue
@@ -1,8 +1,4 @@
/*
 * @Author: zhongrj
 * @Date: 2022-01-18
 * menu-name 考试统计查询
 */
/* * @Author: zhongrj * @Date: 2022-01-18 * menu-name 考试统计查询 */
<template>
  <el-row class="morpheus-box-paper">
    <el-col :span="24">
@@ -10,7 +6,7 @@
        <div
          :class="[
            'exam-card-body',
            $store.state.control.windowWidth >= 1024 ? 'oneRowSearch' : '',
            $store.state.control.windowWidth >= 1024 ? 'oneRowSearch' : ''
          ]"
        >
          <avue-crud
@@ -32,8 +28,9 @@
            @row-save="questionBankRowSave"
            @row-update="questionBankRowUpdate"
            @row-del="questionBankRowDel"
            @row-click="handleRowClick"
          >
            <template slot-scope="{ row }" slot="auditStatus">
            <!-- <template slot-scope="{ row }" slot="auditStatus">
              <el-tag class="dtype">
                {{
                  row.auditStatus == 1
@@ -46,12 +43,12 @@
                <i class="yj" v-if="row.auditStatus == 2"></i>
                <i class="gz" v-if="row.auditStatus == 3"></i>
              </el-tag>
            </template>
            </template> -->
            <template slot="menuLeft">
              <!--图例 components-->
              <span>
              <!-- <span>
                <Legend :datas="datalistLIU"></Legend>
              </span>
              </span> -->
            </template>
            <template slot-scope="{ row }" slot="menu">
@@ -61,62 +58,218 @@
                icon="el-icon-collection"
                class="start-kaoshi"
                v-if="permission.trainExam_trainPapers"
                @click="startExam(row)"
                >报名清册
              </el-button>
              <el-button
                type="text"
                size="mini"
                icon="el-icon-search"
                v-if="permission.trainExam_index_examScoreViews"
                @click="examScoreViews(row)"
                >成绩查看
                @click="getExamDetail(row)"
                >详情
              </el-button>
            </template>
          </avue-crud>
        </div>
      </el-card>
    </el-col>
    <el-drawer
      :title="title"
      :visible.sync="dialog"
      :modal="true"
      :modal-append-to-body="true"
      :append-to-body="true"
      direction="rtl"
      size="60%"
    >
      <div style="position: absolute;top: 3.5rem;left: 1rem;">
        <el-button
          type="warning"
          icon="el-icon-download"
          plain
          size="mini"
          @click="exportExamInfo"
          >导出</el-button
        >
      </div>
      <div style="height: 40%">
        <!-- <avue-crud
            v-model="formDetail"
            :option="option"
            v-if="dialog"
            :search.sync="search"
            :table-loading="loading"
            :data="data"
            ref="crud"
            :page.sync="page"
            @on-load="onLoad"
            :before-open="beforeOpen"
            @selection-change="selectionChange"
            @search-change="searchChange"
            @search-reset="searchReset"
            @current-change="currentChange"
            @size-change="sizeChange"
          >
            <template slot-scope="{ row }" slot="menu">
              <el-button
                type="text"
                size="mini"
                icon="el-icon-collection"
                class="start-kaoshi"
                v-if="permission.trainExam_trainPapers"
                @click="getExamDetail(row)"
                >详情
              </el-button>
            </template>
        </avue-crud> -->
        <el-table
          :data="data"
          stripe="true"
          border
          show-summary
          :summary-method="getSummaries"
          style="width: 98%; margin: 0 auto; margin-top: 1rem"
          size="small"
          header-align="center"
          height="22rem"
        >
          <el-table-column label="理论考试成绩统计" align="center">
            <el-table-column
              type="index"
              width="50"
              label="序号"
              align="center"
            ></el-table-column>
            <el-table-column
              prop="deptName"
              label="企业名称"
              minWidth="160"
              show-overflow-tooltip="true"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="znum" label="报名人数" align="center">
            </el-table-column>
            <el-table-column prop="ycnum" label="审查异常人数" align="center">
            </el-table-column>
            <el-table-column prop="qknum" label="缺考人数" align="center">
            </el-table-column>
            <el-table-column
              prop="absentProportion"
              label="缺考人数占比(%)"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="yknum" label="及格人数" align="center">
            </el-table-column>
            <el-table-column
              prop="qualifiedProportion"
              label="及格人数占比(%)"
              align="center"
            >
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
      <div style="height: 60%">
        <el-table
          :data="dataDetail"
          stripe="true"
          border
          height="25rem"
          style="width: 98%; margin: 0 auto"
          size="small"
          header-align="center"
        >
          <el-table-column label="考试成绩明细" align="center">
            <el-table-column
              type="index"
              width="50"
              label="序号"
              align="center"
            ></el-table-column>
            <el-table-column prop="securityName" label="姓名" align="center">
            </el-table-column>
            <el-table-column
              prop="companyName"
              label="企业名称"
              minWidth="160"
              show-overflow-tooltip="true"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="theoryGrade" label="理论成绩" align="center">
              <template slot-scope="scope">
                {{ scope.row.theoryGrade == -1 ? "" : scope.row.theoryGrade }}
              </template>
            </el-table-column>
            <el-table-column prop="learnGrade" label="实操成绩" align="center">
              <template slot-scope="scope">
                {{ scope.row.learnGrade == -1 ? "" : scope.row.learnGrade }}
              </template>
            </el-table-column>
            <el-table-column prop="allGrade" label="平均分" align="center">
            </el-table-column>
            <el-table-column
              prop="qualified"
              label="考试成绩状态"
              align="center"
            >
              <template slot-scope="scope">
                {{
                  scope.row.qualified == 0
                    ? "合格"
                    : scope.row.qualified == 1
                    ? "不合格"
                    : scope.row.qualified == 2
                    ? "暂未录入实操成绩"
                    : scope.row.qualified == 3
                    ? "缺考"
                    : ""
                }}
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
        <el-pagination
          style="margin-top: 1rem; margin-left: 25rem"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-sizes="[10, 20, 30, 50, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
        >
        </el-pagination>
      </div>
    </el-drawer>
  </el-row>
</template>
<script>
import {
  getList,
  add,
  remove,
  update,
  updateAudit,
  applyConfirm,
  getExamStatistics,
  getExamInfoByExamId
} from "@/api/examapi/examination";
import { mapGetters } from "vuex";
import Qs from "qs";
import { getToken } from "@/util/auth";
import { getList } from "@/api/examapi/performance";
import Legend from "@/components/liu-legend/Legend";
export default {
  components: {
    Legend,
    Legend
  },
  data() {
    return {
      startTime: "",
      title: "",
      companyName: "",
      trainUnitId: null,
      dialog: false,
      form: {},
      //legend-liu数据
      datalistLIU: [
        {
          color: "#29C093",
          text: "审核通过",
        },
        {
          color: "#F34A4A",
          text: "审核不通过",
        },
        {
          color: "#F48F57",
          text: "待审核",
        },
      ],
      formDetail: {},
      questionBankOption: {
        // 操作栏多余按钮去除
        delBtn: false,
        editBtn: true,
        editBtn: false,
        addBtn: false,
        menu: true,
        // 导出按钮
@@ -133,32 +286,19 @@
        indexLabel: "序号",
        dialogClickModal: false,
        // 操作栏宽度
        menuWidth: 320,
        menuWidth: 120,
        labelWidth: 140,
        ...this.$store.state.control.clearOtherBut,
        column: [
          {
            label: "培训学校名称",
            prop: "deptName",
            prop: "schoolName",
            slot: true,
            search:true,
            searchSpan:5,
            searchLabelWidth:110,
            // 表单新增时是否禁止
            addDisabled: true,
            // 表单新增时是否可见
            addDisplay: false,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: true,
            // 表单编辑时是否可见
            editDisplay: false,
            // 表单编辑时是否为查看模式
            editDetail: false,
            // hide: true,
            display: false,
            overHidden: true,
            search: true,
            searchSpan: 5,
            searchLabelWidth: 110,
            overHidden: true
            // width:180,
          },
          {
            label: "考试时间",
@@ -166,189 +306,166 @@
            type: "date",
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            search:true,
            searchSpan:4,
            search: true,
            searchSpan: 4,
            hide: true,
            // 表单新增时是否禁止
            addDisabled: false,
            // 表单新增时是否可见
            addDisplay: true,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: false,
            // 表单编辑时是否可见
            editDisplay: false,
            // 表单编辑时是否为查看模式
            editDetail: false,
            rules: [
              {
                required: true,
                message: "请选择考试时间",
                trigger: "blur",
              },
            ],
                trigger: "blur"
              }
            ]
          },
          {
            label: "考试时间",
            prop: "startTime",
            type: "datetime",
            format: "yyyy-MM-dd HH:mm",
            valueFormat: "yyyy-MM-dd HH:mm",
            hide: true,
            // 表单新增时是否禁止
            addDisabled: false,
            // 表单新增时是否可见
            addDisplay: true,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: false,
            // 表单编辑时是否可见
            editDisplay: true,
            // 表单编辑时是否为查看模式
            editDetail: false,
            rules: [
              {
                required: true,
                message: "请选择考试时间",
                trigger: "blur",
              },
            ],
          },
          {
            label: "考试开始时间",
            prop: "startTime",
            type: "datetime",
            format: "yyyy-MM-dd HH:mm",
            valueFormat: "yyyy-MM-dd HH:mm",
            // 表单新增时是否禁止
            addDisabled: false,
            // 表单新增时是否可见
            addDisplay: false,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: false,
            // 表单编辑时是否可见
            editDisplay: false,
            // 表单编辑时是否为查看模式
            editDetail: false,
            width: 120,
          },
          {
            label: "考试开始截止时间",
            prop: "endTime",
            type: "datetime",
            // span: 24,
            format: "yyyy-MM-dd HH:mm",
            valueFormat: "yyyy-MM-dd HH:mm",
            // 表单新增时是否禁止
            addDisabled: false,
            // 表单新增时是否可见
            addDisplay: false,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: false,
            // 表单编辑时是否可见
            editDisplay: true,
            // 表单编辑时是否为查看模式
            editDetail: false,
            width: 120,
            format: "yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd"
          },
          {
            label: "报名人数",
            prop: "num",
            type: "textarea",
            span: 24,
            slot: true,
            // 表单新增时是否禁止
            addDisabled: false,
            // 表单新增时是否可见
            addDisplay: true,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: false,
            // 表单编辑时是否可见
            editDisplay: false,
            // 表单编辑时是否为查看模式
            editDetail: false,
            width: 70,
            prop: "znum"
          },
          {
            label: "考试人数",
            prop: "examNum",
            type: "textarea",
            span: 24,
            slot: true,
            // 表单新增时是否禁止
            addDisabled: false,
            // 表单新增时是否可见
            addDisplay: true,
            // 表单新增时是否为查看模式
            addDetail: false,
            // 表单编辑时是否禁止
            editDisabled: false,
            // 表单编辑时是否可见
            editDisplay: false,
            // 表单编辑时是否为查看模式
            editDetail: false,
            width: 70,
            label: "机考人数",
            prop: "yknum"
          },
          {
            label: "审核状态",
            search: true,
            searchSpan: 4,
            prop: "auditStatus",
            slot: true,
            editDisplay: false,
            addDisplay: false,
            type: "select",
            rules: [
              {
                required: true,
                message: "请选择审核类型",
                trigger: "blur",
              },
            ],
            dicData: [
              {
                label: "审核通过",
                value: 1,
              },
              {
                label: "不通过",
                value: 2,
              },
              {
                label: "待审核",
                value: 3,
              },
            ],
            width: 110,
            label: "纸质考试人数",
            prop: "zznum"
          },
          {
            label: "缺考人数",
            prop: "qknum"
          },
          {
            label: "审查异常人数",
            prop: "ycnum"
          },
          {
            label: "已取消考试人数",
            prop: "qxnum"
          }
        ]
      },
      option: {
        // 操作栏多余按钮去除
        delBtn: false,
        editBtn: false,
        addBtn: false,
        menu: true,
        //合计
        showSummary: true,
        viewBtn: false,
        align: "center",
        height: "auto",
        calcHeight: 80,
        tip: false,
        searchMenuSpan: 4,
        index: true,
        indexLabel: "序号",
        ...this.$store.state.control.clearOtherBut,
        column: [
          {
            label: "企业名称",
            prop: "deptName",
            slot: true,
            // search:true,
            // searchSpan:5,
            searchLabelWidth: 110,
            overHidden: true
          },
          {
            label: "报名人数",
            prop: "znum"
          },
          {
            label: "审查异常人数",
            prop: "ycnum"
          },
          {
            label: "缺考/纸质考试人数",
            prop: "qknum"
          },
          {
            label: "缺考/纸质占比(%)",
            prop: "absentProportion"
          },
          {
            label: "及格人数",
            prop: "yknum"
          },
          {
            label: "及格人数占比(%)",
            prop: "qualifiedProportion"
          }
        ],
        sumColumnList: [
          {
            label: "合计:",
            name: "deptName"
          },
          {
            name: "znum",
            type: "sum"
          },
          {
            name: "ycnum",
            type: "sum"
          },
          {
            name: "qknum",
            type: "sum"
          },
          {
            name: "absentProportion",
            type: "avg"
          },
          {
            name: "yknum",
            type: "sum"
          },
          {
            name: "qualifiedProportion",
            type: "avg"
          },
          {
            name: "znum",
            type: "sum"
          }
        ]
      },
      questionBankSearch: {},
      search: {},
      questionBankLoading: true,
      loading: true,
      questionBankData: [],
      data: [],
      dataDetail: [],
      questionBankPage: {
        pageSize: 10,
        currentPage: 1,
        total: 16,
        ...this.$store.state.control.changePageSize,
        ...this.$store.state.control.changePageSize
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      questionBankQuery: {},
      query: {},
      questionBankSelectionList: [],
      selectionList: []
    };
  },
  mounted() {},
  computed: {
    ids() {
      let ids = [];
      this.questionBankSelectionList.forEach((ele) => {
      this.questionBankSelectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
@@ -357,26 +474,87 @@
    permissionList() {
      return {
        addBtn: this.vaildData(null, false),
        viewBtn: this.vaildData(this.permission.trainExam_edit, false),
        viewBtn: this.vaildData(null, false),
        delBtn: this.vaildData(null, false),
        editBtn: this.vaildData(null, false),
        editBtn: this.vaildData(null, false)
      };
    },
    }
  },
  watch: {},
  methods: {
    //导出考试统计数据
    exportExamInfo() {
      this.$confirm("是否导出考试统计情况数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //获取查询条件
        var data = {
          companyName: this.companyName,
          examDate: this.startTime,
          trainUnitId: this.trainUnitId,
          examType: 2
        };
        console.log(data, 11225111);
        //序列号url形式,用&拼接
        data = Qs.stringify(data);
        window.open(
          `/api/exampaper/export-examStatistics?${
            this.website.tokenHeader
          }=${getToken()}&` + data
        );
      });
    },
    //合计
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = sums[index];
          return;
        }
        if (index === 1) {
          sums[index] = "合计";
          return;
        }
        if (index === 5) {
          sums[index] = ((sums[4] / sums[2]) * 100).toFixed(2);
          return;
        }
        if (index === 7) {
          sums[index] = ((sums[6] / sums[2]) * 100).toFixed(2);
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index];
        } else {
          sums[index] = "N/A";
        }
      });
      return sums;
    },
    questionBankOnLoad(page, params = {}) {
      this.questionBankLoading = false;
      params["examType"] = 2;
      //如果是培训公司管理员,则只能看到当前培训公司申请的考试
      if (this.userInfo.role_name == "培训公司管理员") {
        params["deptId"] = this.userInfo.dept_id;
      }
      getList(
      getExamStatistics(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.questionBankQuery)
      ).then((res) => {
      ).then(res => {
        const data = res.data.data;
        this.questionBankPage.total = data.total;
        this.questionBankData = data.records;
@@ -384,9 +562,48 @@
        this.questionBankSelectionClear();
      });
    },
    onLoad(page, params = {}) {
      params["startTime"] = this.startTime;
      params["trainUnitId"] = this.trainUnitId;
      getExamInfoByExamId(1, 20, Object.assign(params, this.query)).then(
        res => {
          const data = res.data.data;
          this.data = data.records;
        }
      );
    },
    //明细table
    onLoadDetail(page, params = {}) {
      //判断角色,如果是保安公司管理员或保安,只能查看当前公司的考试成绩
      var that = this;
      params["examDate"] = this.startTime;
      params["trainUnitId"] = this.trainUnitId;
      params["examType"] = 2;
      getList(page.currentPage, page.pageSize, Object.assign(params)).then(
        res => {
          const data = res.data.data;
          that.page.total = data.total;
          that.dataDetail = data.records;
        }
      );
    },
    //每页数值改变
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.onLoadDetail(this.page);
    },
    //页数切换
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.onLoadDetail(this.page);
    },
    questionBankSelectionClear() {
      this.questionBankSelectionList = [];
      this.$refs.questionBankCrud.toggleSelection();
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    questionBankSelectionChange(list) {
      this.questionBankSelectionList = list;
@@ -407,175 +624,27 @@
    questionBankSizeChange(pageSize) {
      this.questionBankPage.pageSize = pageSize;
    },
    //审核
    submit(row, done, loading) {
      updateAudit(row).then(
        () => {
          this.dialogFormVisible = false;
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    //详情弹窗
    getExamDetail(row) {
      this.dialog = true;
      this.trainUnitId = row.trainUnitId;
      this.startTime = row.startTime;
      this.companyName = row.schoolName;
      this.title = row.schoolName + row.startTime + "考试情况";
      this.onLoad(this.page);
      this.onLoadDetail(this.page);
    },
     beforeOpen(done, type) {
      if(this.userInfo.role_name=="培训公司管理员"){
         if (["edit"].includes(type)) {
            if(this.form.auditStatus==1){
              this.$message({
                type: "warning",
                message: "当前考试申请已审核通过,无法再修改考试申请信息!",
              });
              return;
            }
          }
      }
      done();
    },
    startExam(row) {
      //正式考试
      if (row.examType == 1) {
        this.$router.push({
          path: `/applydetailed`,
          query: row,
        });
      }
      //模拟考试
      if (row.examType == 2) {
        this.$router.push({
          path: `/trainApply`,
          query: row,
        });
      }
    },
    examScoreViews(row) {
      //模拟考试
      if (row.examType == 2) {
        this.$router.push({
          path: `/trainExam/singleperformance`,
          query: row,
        });
      }
    },
    // 新增
    questionBankRowSave(row, done, loading) {
      row.startTime = row.startTime + ":00";
      row["examType"] = 2;
      // row.endTime = row.examTime[1];
      // row.examTime = JSON.stringify(row.examTime);
      add(row).then(
        () => {
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    questionBankRowUpdate(row, index, done, loading) {
      // if (Array.isArray(row.examTime) != true) {
      //   row.examTime = row.examTime.split(",");
      // }
      const data = {
        id: row.id,
        startTime: row.startTime + ":00",
        endTime: row.endTime + ":00",
      };
      // row.startTime = row.startTime + ":00";
      // row.endTime = row.endTime + ":00";
      // row.endTime = row.examTime[1];
      // row.examTime = JSON.stringify(row.examTime);
      update(data).then(
        () => {
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    questionBankRowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    handleConfirm(row) {
      this.$confirm("已确认当前考试申请人员名单无误?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          row["confirmUser"] = this.userInfo.Id;
          return applyConfirm(row);
        })
        .then(() => {
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    questionBankHandleDelete() {
      if (this.questionBankSelectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.questionBankOnLoad(this.questionBankPage);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.questionBankCrud.toggleSelection();
        });
    },
    handleAudit(row) {
      this.dialogFormVisible = true;
      this.Audit = row;
    },
  },
    //行单击详情弹窗
    handleRowClick(row) {
      this.dialog = true;
      this.trainUnitId = row.trainUnitId;
      this.startTime = row.startTime;
      this.companyName = row.schoolName;
      this.title = row.schoolName + row.startTime + "考试情况";
      this.onLoad(this.page);
      this.onLoadDetail(this.page);
    }
  }
};
</script>