<!-- 查看成绩 -->
<template>
  <div class="page-container viewGrades-addPage">
    <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="deptId">
          <el-cascader
            style="width: 180px"
            v-model="queryParams.deptId"
            :options="optionListA"
            :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="academicYear">
          <el-select v-model="queryParams.academicYear" placeholder="年级" style="width: 120px">
            <el-option
              v-for="dict in optionListB"
              :key="dict.gradeNumber"
              :label="dict.gradeNumber"
              :value="dict.gradeNumber"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="disciplineId">
          <el-select v-model="queryParams.disciplineId" placeholder="专业" style="width: 140px">
            <el-option
              v-for="dict in optionListC"
              :key="dict.id"
              :label="dict.disciplineName"
              :value="dict.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="userType">
          <el-select v-model="queryParams.userType" placeholder="用户类别" style="width: 120px">
            <el-option
              v-for="dict in optionListD"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="passStatus">
          <el-select v-model="queryParams.passStatus" placeholder="是否通过" style="width: 120px">
            <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: 140px"
          />
        </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" 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="userName"  show-overflow-tooltip/>
        <el-table-column label="学工号" prop="account" width="140" show-overflow-tooltip/>
        <el-table-column label="专业" prop="disciplineName" width="200" show-overflow-tooltip/>
        <el-table-column label="学年" prop="academicYear" width="140" show-overflow-tooltip/>
        <el-table-column label="学院单位" prop="deptName" width="240" show-overflow-tooltip/>
        <el-table-column label="交卷时间" prop="submitTime" width="200" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.submitTime,"{y}-{m}-{d} {h}:{i}") }}至{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="用时" prop="durationText" width="140" show-overflow-tooltip/>
        <el-table-column label="成绩" prop="score" width="140" show-overflow-tooltip/>
        <el-table-column label="结果" prop="resultStatus" width="140" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.resultStatus == 0">未开始</span>
            <span v-if="scope.row.resultStatus == 1">考试中</span>
            <span class="colorA" v-if="scope.row.resultStatus == 2">通过</span>
            <span class="colorB" v-if="scope.row.resultStatus == 3">未通过</span>
            <span class="colorC" v-if="scope.row.resultStatus == 4">缺考</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" show-overflow-tooltip>
          <template slot-scope="scope">
            <div class="table-button-box">
              <p class="table-button-null"></p>
              <p class="table-button-p"
                 @click="lockExam(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>
    <el-drawer
      size="100%"
      custom-class="viewGrades-addPage-drawer"
      :append-to-body="true"
      :title="drawerTitle"
      ref="drawer"
      :visible.sync="drawer"
      direction="rtl">
      <examDetails v-if="drawer" :examDetailsPropsData="examDetailsPropsData"></examDetails>
    </el-drawer>
  </div>
</template>

<script>
  import {
    systemUserGetCategories,systemUserGetAcademicYear,
    examElExamResultScorePage,examElDisciplineTypeList,systemDeptCurrentDept,
  } from "@/api/safetyEducationExaminationNew/index";
  import examDetails from '@/views/safetyEducationExaminationNew/components/examDetails.vue'
  export default {
    name: 'addPage',
    components: {
      examDetails
    },
    props: {
      drawerPropsData: {}
    },
    data() {
      return {
        //下拉列表数据
        optionListA:[],
        optionListB:[],
        optionListC:[],
        optionListD:[],
        optionListE:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          deptId:null,
          academicYear :null,
          disciplineId :null,
          userType :null,
          passStatus :null,
          searchValue :'',
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //弹窗相关
        drawerTitle: '',
        drawerType: '',
        drawer: false,
        examDetailsPropsData:{},
      }
    },
    created() {

    },
    mounted() {
      this.getList();
      this.examElDisciplineTypeList();
      this.systemDeptCurrentDept();
      this.systemUserGetCategories();
      this.systemUserGetAcademicYear();
    },
    methods: {
      //导出
      exportButton(){
        let self = this;
        self.$confirm(`确认导出数据?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(async () => {
          let obj = JSON.parse(JSON.stringify(self.queryParams))
          obj.examId = self.drawerPropsData.examId
          self.download('/exam/elExamResult/score-export', {...obj}, '查看成绩-'+self.drawerPropsData.examName+'.xlsx')
        }).catch(() => {})
      },
      lockExam(row){
        this.$set(this, 'drawerTitle', '试卷详情')
        this.$set(this, 'drawerType', 2)
        this.$set(this, 'drawer', true)
        let obj = {
          attemptId:row.attemptId,
          showType:true,
        }
        this.$set(this,'examDetailsPropsData',obj);//attemptId
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId:null,
          academicYear :null,
          disciplineId :null,
          userType :null,
          passStatus :null,
          searchValue :'',
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        obj.examId = this.drawerPropsData.examId
        examElExamResultScorePage(obj).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //查询全部专业类别
      examElDisciplineTypeList(){
        examElDisciplineTypeList({}).then(response => {
          this.$set(this,'optionListC',response.data);
        });
      },
      //学院列表
      systemDeptCurrentDept(){
        systemDeptCurrentDept({}).then(response => {
          const list = response.data || [];
          this.formatTreeData(list);
          this.$set(this,'optionListA',list);
        });
      },
      //学年下拉列表
      systemUserGetAcademicYear(){
        systemUserGetAcademicYear({}).then(response => {
          this.$set(this,'optionListB',response.data);
        });
      },
      //用户类别下拉列表
      systemUserGetCategories(){
        systemUserGetCategories({}).then(response => {
          this.$set(this,'optionListD',response.data);
        });
      },
    }
  }
</script>

<style scoped lang="scss">
  .viewGrades-addPage {
    flex:1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    .colorA{
      color:#41C599;
    }
    .colorB{
      color:#EF98A2;
    }
    .colorC{
      color:#F6A53C;
    }
  }
</style>
