<!-- 考试记录 -->
<template>
  <div class="page-container examRecords-addPage">
    <div class="page-container myGradesPage" v-if="pageType === 1">
      <div class="page-container-top-max-big-box">
        <p class="top-1-p">考试记录</p>
        <p class="top-2-p" @click="backPage()">返回</p>
      </div>
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <div class="table-top-button-box">
            <div>
              <p :class="passStatus === ''?'check-table-button':''" @click="tableTypeButton('')">全部</p>
              <p :class="passStatus === 1?'check-table-button':''" @click="tableTypeButton(1)">通过</p>
              <p :class="passStatus === 0?'check-table-button':''" @click="tableTypeButton(0)">未通过</p>
            </div>
          </div>
          <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>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box"  border :data="dataList">
          <el-table-column label="考试时间" prop="startTime"  show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.startTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="用时" prop="examDuration" width="200" show-overflow-tooltip/>
          <el-table-column label="得分" prop="totalScore" width="200" show-overflow-tooltip/>
          <el-table-column label="及格分" prop="passScore" width="200" show-overflow-tooltip/>
          <el-table-column label="考试结果" prop="passStatus" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="scope.row.passStatus == 1?'colorA':(scope.row.passStatus == 0?'colorB':(scope.row.passStatus ==2?'colorC':''))">
                {{scope.row.passStatus == 1?'通过':(scope.row.passStatus == 0?'未通过':(scope.row.passStatus ==2?'成绩无效':''))}}
              </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="tableButton(1,scope.row)"
                >试卷详情</p>
                <p class="table-button-p"
                   @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>
    <historyOfIncorrectQuestions :historyOfIncorrectQuestionsPropsData="historyOfIncorrectQuestionsPropsData" v-if="pageType === 2"></historyOfIncorrectQuestions>
    <el-drawer
      size="100%"
      custom-class="examRecords-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 { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  import historyOfIncorrectQuestions from "@/views/safetyEducationExaminationNew/components/historyOfIncorrectQuestions.vue";
  import examDetails from '@/views/safetyEducationExaminationNew/components/examDetails.vue'
  import { examElUserExamAttemptAttemptRecord, } from "@/api/safetyEducationExaminationNew/index";
  export default {
    name: 'addPage',
    components: {
      historyOfIncorrectQuestions,
      examDetails,
    },
    props: {
      propsData: {}
    },
    data() {
      return {
        pageType:1,
        newData: {},
        passStatus:'',
        queryParams: {
          page: 1,
          pageSize: 20,
        },
        //时间数据
        dateRange: [],
        //列表数据
        dataList: [],
        //数据数量
        total: 0,
        //弹窗相关
        drawerTitle: '',
        drawerType: '',
        drawer: false,
        examDetailsPropsData:{},
        historyOfIncorrectQuestionsPropsData:{},
      }
    },
    created() {

    },
    mounted() {
      this.getList()
    },
    methods: {
      // 返回按钮
      backPage() {
        this.$parent.tableButton(6)
      },
      tableTypeButton(val){
        if(this.passStatus !== val){
          this.$set(this,'passStatus',val);
          this.handleQuery();
        }
      },
      //查询按钮
      handleQuery() {
        this.$set(this.queryParams, 'page', 1)
        this.getList()
      },
      //重置按钮
      resetQuery() {
        this.$set(this, 'dateRange', [])
        this.$set(this, 'queryParams', {
          page: 1,
          pageSize: 20,
        })
        this.getList()
      },
      //获取数据列表
      getList() {
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        obj.examId = this.propsData.examId
        obj.passStatus = this.passStatus
        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 = ''
        }
        examElUserExamAttemptAttemptRecord(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) {
          // 试卷详情
          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
        } else if (type == 2) {
          // 历史错题
          this.$set(this, 'pageType', 2)
          let obj = {
            type:2,
            attemptId:row.attemptId,
          };
          this.$set(this, 'historyOfIncorrectQuestionsPropsData', obj)
        } else if (type == 6) {
          //返回并刷新
          this.$set(this, 'pageType', 1)
          this.getList()
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  .examRecords-addPage {

    .table-top-button-box{
      display: inline-block;
      vertical-align: top;
      margin-right:10px;
      div{
        display: flex;
        p{
          border:1px solid #DCDFE6;
          width:80px;
          text-align: center;
          height:40px;
          line-height:40px;
          cursor: pointer;
          font-size:14px;
        }
        p:nth-child(1){
          border-top-left-radius:4px;
          border-bottom-left-radius:4px;
        }
        p:nth-child(2){
          border-left:none;
          border-right:none;
        }
        p:nth-child(3){
          border-top-right-radius:4px;
          border-bottom-right-radius:4px;
        }
        .check-table-button{
          border:1px solid #0183fa;
          background-color: #0183fa;
          color:#fff;
        }
      }
    }
    .colorA{
      color:#70B603;
    }
    .colorB{
      color:#D90029;
    }
    .colorC{
      color:#999999;
    }
  }
</style>
