<!--考试详情-->
<template>
  <div class="examInfo">
    <div class="page-container">
      <div class="page-form-title-box">
        <el-form ref="queryForm" :inline="true" :model="queryParams" label-width="80px">
          <el-form-item label="姓名" prop="joinUserName" label-width="50px">
            <el-input
              v-model="queryParams.joinUserName"
              placeholder="请输入姓名"

              size="small"
            />
          </el-form-item>
          <el-form-item label="通过状态" prop="passed">
            <el-select v-model="queryParams.passed" placeholder="请选择通过状态"  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>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p class="page-out-common-style-button"
             style="float: right;"
             @click="backPage"
          >返回</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table :data="examList" border class="table-box" @selection-change="handleSelectionChange">
          <el-table-column label="姓名" align="left" prop="joinUserName" />
          <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.createTime, '{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="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="openButton(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"
                    layout="total, prev, pager, next, sizes, jumper"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
        />
      </div>
    </div>
    <!-- 添加或修改考试对话框 -->
    <el-dialog title="考试明细" :visible.sync="open" width="790px" class="scrollbar-box" append-to-body :close-on-click-modal="false">
      <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 dialog-footer-box">
        <p class="dialog-footer-button-null"></p>
        <p class="dialog-footer-button-primary" @click="cancel">确定</p>
        <p class="dialog-footer-button-null"></p>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { Message } from 'element-ui'
  import {examUserExamList, listPaper} from "@/api/safetyEducationExam/index";
  export default {
    props:{
      rowData:{},
    },
    name: 'examInfo',
    data() {
      return {
        // 总条数
        total: 10,
        // 查询参数
        queryParams: {
          page: 1,
          pageSize:20,
          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,
          joinUserName: null
        },
        infoParams: {
          examId: null,
          joinUserId: null,
          pageSize:-1,
        },
        // 考试详情
        examList:[],
        // 弹出层
        open:false,
        // 考试明细
        infoData:[],
        passeds: [
        {
          type: 0,
          value: "未通过",
        },
        {
          type: 1,
          value: "已通过",
        },
      ]
      }
    },
    created(){
      this.queryParams.examId = this.rowData
      this.getList()
    },
    methods: {
    /** 查询考试记录列表 */
    getList() {
      this.loading = true;
      examUserExamList(this.queryParams).then(response => {
        this.examList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 查询考试详情列表 */
    getInfoList() {
      this.loading = true;
      listPaper(this.infoParams).then(response => {
        this.infoData = response.data.records;
        this.loading = false;
      });
    },
      backPage(){
        this.$parent.pageOff();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 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>
