<template>
  <div class="examination-analysis">
    <div class="box">
      <el-card class="box-card" v-for="(item , index) in cardData" :key="index">
        <div slot="header" class="title">
          <span class="weight">{{ item.title }}</span>
        </div>
        <div class="box-content">
          <span class="weight">{{ item.num }}</span>
          {{ item.unit }}
        </div>
      </el-card>
    </div>
    <div class="table">
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column prop="examName" label="考试名" min-width="150" align="center"></el-table-column>
        <el-table-column prop="examUserCount" label="参与考试人数" min-width="100" align="center"></el-table-column>
        <el-table-column prop="userCountForPassExam" label="通过考试人数" min-width="80" align="center"></el-table-column>
        <el-table-column prop="userCountList[0]" label="成绩优秀人数" min-width="80" align="center"></el-table-column>
        <el-table-column prop="userCountList[1]" label="成绩合格人数" min-width="80" align="center"></el-table-column>
        <el-table-column label="操作" fixed="right" align="center" min-width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="goPage(scope.row)">查看名单</el-button>
          </template>
        </el-table-column>
        <div slot="empty">
          <div class="table-empty">
            <img src="../../assets/image/no-content1.png">
            <p>没有查询到相关结果</p>
          </div>
        </div>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="[10, 30, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalRows"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { log } from 'util';
import * as operationData from "../../utils/operation";
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
let vm
export default {
  props: {
    formInline: {
      type: Object
    },
    activeName: {
      type: String
    },
    dialogData: {
      type: Object
    },
    organizationNum: {
      type: Number
    },
    organizationList: {
      type: Array
    }
  },
  data() {
    return {
      projectId: '',
      tableData: [],
      cardData: [
        {
          title: "项目所有考试数",
          num: 0,
          unit: "门考试"
        },
        {
          title: "项目所有考题数",
          num: 0,
          unit: "道题"
        }
      ],
      totalRows: 0, //数据总数
      pageNo: 1, //当前是第几页
      pageSize: 1, //页面总数
    };
  },
  created() {
    vm = this;
    this.projectId = vm.getUrlSearch(window.location.href, "id");
    // vm.search();
  },
   // 挂载到Dom完成时
  mounted: function() {
    this.$on('search',()=>{
      console.log(this.formInline);
      this.search();
    })
  },
  methods: {
    setCardData(data) {
      vm.totalRows = data.projectExamCount;
      vm.cardData[0].num = data.projectExamCount;
      vm.cardData[1].num = data.projectExamQuestionCount;
    },
    // 搜索列表
    search() {
      if (vm.formInline.region.length == 0) {
        vm.$message("请选择地区");
        return;
      }
      let checkAll = operationData.hasAll(vm.formInline.organization)
       let req = {
        projectId: vm.projectId,
        ids: operationData.getIds(vm.formInline,vm.organizationList,checkAll),
        type: operationData.getSearchType(vm.formInline),
        originalFlag: vm.formInline.checked == false ? 0 : 1
      };
      console.log("4 req", req);
      openLoading(vm);
      vm.GET("report/portalProjectExam/getTotal", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          vm.setCardData(res.data);
        }
      });
      let reqList = req;
      reqList.pageNo = vm.pageNo;
      reqList.pageSize = vm.pageSize;
      vm.GET("report/portalProjectExam/getExamList", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          vm.tableData = res.data.list;
        }
      });

      //
    },
    // 跳转查看名单页面
    goPage(data) {
      let routerData = this.dialogData;
      routerData.tableType = 2
      routerData.id = data.examId;
      this.$router.push({ path: '/course-training', params: routerData});
      // vm.$router.push("course-training?tableType=2&id="+data.examId+"&region="+this.dialogData.region+"&organization="+this.dialogData.organization);
    },
    // 更改数据显示数量
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      vm.pageSize = val
      vm.search()
    },
    // 换页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      vm.pageNo = value
      vm.search()
    }
  }
};
</script>

<style lang='scss' rel='stylesheet/scss'>
.examination-analysis {
  background: #fff;
  .box {
    overflow: hidden;
  }
  .table {
    margin-top: 30px;
  }
  .box-card {
    width: 49%;
    margin-right: 1%;
  }
}
</style>
