<!--考试详情-->
<template>
  <div class="examInfo">
    <el-form ref="queryForm" :model="queryParams" label-width="80px" class="form-box">
      <el-form-item label="姓名" prop="nickName" label-width="50px">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入考试名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="通过状态" prop="passed">
        <!-- <el-select v-model="queryParams.openType" placeholder="请选择通过状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select> -->
        <el-select v-model="queryParams.passed" placeholder="请选择通过状态" clearable size="small">
          <el-option
            v-for="item in passeds"
            :key="item.type"
            :label="item.value"
            :value="item.type"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!--<el-form-item label="创建时间" prop="inTime" style="margin-left:10px;">-->
        <!--<el-date-picker clearable size="small"-->
                        <!--v-model="queryParams.inTime"-->
                        <!--type="date"-->
                        <!--value-format="yyyy-MM-dd"-->
                        <!--placeholder="请选择创建时间">-->
        <!--</el-date-picker>-->
      <!--</el-form-item>-->
      <el-form-item class="button-box">
        <p class="inquire-button-one" @click="handleQuery">查询</p>
        <p class="reset-button-one" @click="resetQuery">重置</p>
      </el-form-item>
      <p class="full-p"></p>
      <el-form-item class="button-box">
        <p class="reset-button-one" @click="backPage"><i class="el-icon-arrow-left"></i>返回</p>
      </el-form-item>
    </el-form>
    <el-table :data="examList" border @selection-change="handleSelectionChange">
      <el-table-column label="姓名" align="left" prop="nickName" />
      <el-table-column label="最高分" align="left" prop="maxScore" />
      <el-table-column label="通过状态" align="left" prop="passed" >
        <template slot-scope="scope">
          <span v-for="(item,index) in passeds" :key="index" v-if="scope.row.passed==item.type">{{item.value}}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后考试时间" align="left" prop="updateTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <div class="button-min-box">
            <p class="table-min-button"
               style="margin:0 auto;"
               @click="openButton(scope.row)"
            ><i class="el-icon-date"></i>考试明细</p>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      layout="total, prev, pager, next, sizes, jumper"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
    />
    <!-- 添加或修改考试对话框 -->
    <el-dialog title="考试明细" :visible.sync="open" width="790px" append-to-body>
      <div v-for="(item,index) in infoData" :key="index" style="display: flex;">
        <p style="margin:0;line-height:50px;font-size:16px;color:#333;width:257px;">考试时间：<span style="font-size:14px;color:#CCCCCC;">{{item.createTime}}</span></p>
        <p style="margin:0;line-height:50px;font-size:16px;color:#333;width:174px;">考试用时：<span style="font-size:14px;color:#CCCCCC;">{{item.userTime}}</span></p>
        <p style="margin:0;line-height:50px;font-size:16px;color:#333;width:185px;">考试得分：<span style="font-size:14px;color:#CCCCCC;">{{item.userScore}}</span></p>
        <p style="margin:0;line-height:50px;font-size:16px;color:#333;width:140px;">是否合格：<span style="font-size:14px;color:#CCCCCC;">{{item.userScore >= item.qualifyScore ?'是':'否'}}</span></p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { Message } from 'element-ui'
  import { listExam, getExam } from "@/api/exam/user_exam";
  import { listPaper } from "@/api/exam/paper";

  export default {
    props:{
      rowData:{},
    },
    name: 'examInfo',
    data() {
      return {
        // 总条数
        total: 10,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          title: null,
          content: null,
          openType: null,
          joinType: null,
          level: null,
          scopeType: null,
          state: null,
          convert: null,
          timeLimit: null,
          startTime: null,
          endTime: null,
          totalScore: null,
          totalTime: null,
          qualifyScore: null,
          examId: null,
          passed: null,
          nickName: null
        },
        infoParams: {
          examId: null,
          joinUserId: null
        },
        // 考试详情
        examList:[],
        // 弹出层
        open:false,
        // 考试明细
        infoData:[],
        passeds: [
        {
          type: 0,
          value: "未通过",
        },
        {
          type: 1,
          value: "已通过",
        },
      ]
      }
    },
    created(){
      this.queryParams.examId = this.rowData
      this.getList()
    },
    methods: {
    /** 查询考试记录列表 */
    getList() {
      this.loading = true;
      listExam(this.queryParams).then(response => {
        this.examList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询考试详情列表 */
    getInfoList() {
      this.loading = true;
      listPaper(this.infoParams).then(response => {
        this.infoData = response.rows;
        this.loading = false;
      });
    },
      backPage(){
        this.$parent.pageOff();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      //开启按钮
      openButton(row){
        this.open = true;
        this.infoParams.examId = row.examId
        this.infoParams.joinUserId = row.joinUserId
        this.getInfoList()
      },
      //关闭按钮
      cancel(){
        this.open = false;
        this.infoData = [];
      },
    }
  }
</script>

<style lang="scss" scoped>
  .examInfo{
    flex:1;
    display: flex;
    flex-direction: column;
    .form-box{
      display: flex;
      .full-p{
        flex:1;
      }
    }
    .button-min-box{
      width:160px;
      margin:0 auto;
      display: flex;
    }
  }
</style>
