<!-- 考试结果 -->
<template>
  <div class="app-container examinationResult">
    <div class="page-container examinationResultPage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="academicYear">
            <el-select v-model="queryParams.academicYear" placeholder="学年" style="width: 140px">
              <el-option
                v-for="dict in optionListA"
                :key="dict.gradeNumber"
                :label="dict.gradeNumber"
                :value="dict.gradeNumber"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-cascader
              style="width: 180px"
              v-model="queryParams.deptId"
              :options="optionListB"
              :props="{
                    emitPath:false,
                    checkStrictly: true,
                    value: 'deptId',
                    label: 'deptName',
                    children: 'child',
                  }"
              :show-all-levels="false"
              filterable
              placeholder="学院单位"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="" prop="examTypeId">
            <el-select v-model="queryParams.examTypeId" placeholder="考试类型" style="width: 160px">
              <el-option
                v-for="dict in optionListC"
                :key="dict.id"
                :label="dict.examTypeName"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="makeup">
            <el-select v-model="queryParams.makeup" placeholder="是否补考" style="width: 140px">
              <el-option label="补考" value="1"/>
              <el-option label="不补考" value="0"/>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="考试名称"
              style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-add-common-style-button"
             v-hasPermiRouter="['exam:elExamResult:export']"
             style="float: right;" @click="exportButton()">导出</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box"  border :data="dataList">
          <el-table-column label="考试名称" prop="examName"  show-overflow-tooltip/>
          <el-table-column label="考试类型" prop="examTypeName" width="200" show-overflow-tooltip/>
          <el-table-column label="考试时间" prop="startTime" width="290" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.startTime,"{y}-{m}-{d} {h}:{i}") }} 至 {{ parseTime(scope.row.endTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="参加人数" prop="participantCount" width="140" show-overflow-tooltip/>
          <el-table-column label="合格人数" prop="passedCount" width="140" show-overflow-tooltip/>
          <el-table-column label="缺考人数" prop="absentCount" width="140" show-overflow-tooltip/>
          <el-table-column label="补考人数" prop="makeupCount" width="140" show-overflow-tooltip/>
          <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   v-hasPermiRouter="['exam:elExamResult:scorePage']"
                   @click="tableButton(1,scope.row)"
                >查看成绩</p>
                <p class="table-button-p"
                   v-hasPermiRouter="['exam:elExamResult:rewardPage']"
                   @click="tableButton(2,scope.row)"
                >学习情况</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <el-drawer
      size="100%"
      custom-class="examinationResult-index-drawer"
      :append-to-body="true"
      :title="drawerTitle"
      ref="drawer"
      :visible.sync="drawer"
      direction="rtl">
      <viewGrades v-if="drawerType==1&&drawer" :drawerPropsData="drawerPropsData"></viewGrades>
      <academicPerformance v-if="drawerType==2&&drawer" :drawerPropsData="drawerPropsData"></academicPerformance>
    </el-drawer>
  </div>
</template>
<script>
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  import viewGrades from "./viewGrades.vue";
  import academicPerformance from "./academicPerformance.vue";
  import {
    systemUserGetAcademicYear,
    examElExamResultPage,examElExamTypeList,systemDeptCurrentDept,
  } from "@/api/safetyEducationExaminationNew/index";
  export default {
    name: 'index',
    components: {
      viewGrades,
      academicPerformance,
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['exam:elExamResult:scorePage','exam:elExamResult:rewardPage',]),
        //页面状态
        pageType:1,
        //下拉列表数据
        optionListA:[],
        optionListB:[],
        optionListC:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          academicYear:null,
          deptId :null,
          examTypeId :null,
          makeup :null,
          searchValue :'',
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
        //弹窗相关
        drawerTitle: '',
        drawerType: '',
        drawer: false,
        drawerPropsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getList();
      this.examElExamTypeList();
      this.systemDeptCurrentDept();
      this.systemUserGetAcademicYear();
    },
    methods: {
      //导出
      exportButton(){
        let self = this;
        self.$confirm(`确认导出数据?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(async () => {
          let obj = JSON.parse(JSON.stringify(this.queryParams))
          if(this.dateRange[0]){
            obj.startTime = this.dateRange[0]+'T00:00:00'
            obj.endTime = this.dateRange[1]+'T23:59:59'
          }else{
            obj.startTime = "";
            obj.endTime = "";
          }
          self.download('/exam/elExamResult/export', {...obj}, '考试结果.xlsx')
        }).catch(() => {})
      },
      //弹窗返回
      drawerReturnButton(){
        this.$refs.drawer.closeDrawer();
      },
      //弹窗确定
      drawerConfirmButton(){
        this.$refs.drawer.closeDrawer();
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          academicYear:null,
          deptId :null,
          examTypeId :null,
          makeup :null,
          searchValue :'',
        });
        this.getList();
      },
      //获取数据列表
      getList(){

        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startTime = this.dateRange[0]+'T00:00:00'
          obj.endTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startTime = "";
          obj.endTime = "";
        }
        examElExamResultPage(obj).then(response => {

          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          // TODO: 查看成绩
          this.$set(this, 'drawerTitle', '查看成绩-'+row.examName)
          this.$set(this, 'drawerType', 1)
          this.$set(this, 'drawer', true)
          this.$set(this, 'drawerPropsData', row)
        }else if(type == 2){
          // TODO: 学习情况
          this.$set(this, 'drawerTitle', '学习情况-'+row.examName)
          this.$set(this, 'drawerType', 2)
          this.$set(this, 'drawer', true)
          this.$set(this, 'drawerPropsData', row)
        }
      },
      //学年下拉列表
      systemUserGetAcademicYear(){
        systemUserGetAcademicYear({}).then(response => {
          this.$set(this,'optionListA',response.data);
        });
      },
      //查询全部考试类型
      examElExamTypeList(){
        examElExamTypeList({}).then(response => {
          this.$set(this,'optionListC',response.data);
        });
      },
      //学院列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionListB',list);
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .examinationResult{
    .examinationResultPage{

    }
  }
</style>
<style lang="scss">
  .examinationResult-index-drawer{
    .el-drawer__body{
      padding:0;
    }
    .el-drawer__header{
      margin:0;
    }
  }
</style>
