<template>
  <div>

    <div class="app-container">
      <div class="filter-container">
        <el-input v-model="KEYWORDS" placeholder="搜索学员姓名" clearable class="filter-item" style="width: 200px;" @clear="getQuery" />
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
          搜索
        </el-button>
        <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
          重置
        </el-button>
      </div>
      <el-table
        v-loading="listLoading"
        ref="multipleTable"
        :data="varList"
        :row-key="getRowKey"
        :header-cell-style="{
          'font-weight': 'bold',
          'color': '#000'
        }"
        tooltip-effect="dark"
        border
        fit
        highlight-current-row>
        <el-table-column :reserve-selection="true" type="selection" width="55" align="center" />
        <el-table-column type="index" label="序号" width="50" align="center" />
        <el-table-column prop="USERNAME" label="参考人姓名" align="center" />
        <el-table-column prop="LEARNERCATEGORYNAME" label="参考人类别" align="center" />
        <el-table-column prop="STAGEEXAMSTATE" label="考试状态" align="center">
          <template slot-scope="{row}">
            <div v-if="row.STAGEEXAMSTATE === '1'">未考试</div>
            <div v-else-if="row.STAGEEXAMSTATE === '4'">未参考</div>
            <div v-else>考试完成</div>
          </template>
        </el-table-column>
        <el-table-column prop="STAGEEXAMSCORE" label="考试成绩" align="center">
          <template slot-scope="{row}">
            <a v-if="row.STAGEEXAMSTATE === '3'" @click="handleStageExam(row.STAGEEXAMPAPER_ID, row.USER_ID)">
              <el-tag size="medium">{{ row.STAGEEXAMSCORE }}</el-tag>
            </a>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-btn-group">
        <div />
        <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
      </div>

      <el-dialog v-if="dialogStageExamShow" :visible.sync="dialogStageExamShow" title="课程试卷" width="90%">
        <StageExamInfo :paperid="STAGEEXAMPAPER_ID" :userid="USER_ID" />
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogStageExamShow = false">关 闭</el-button>
        </div>
      </el-dialog>
      <div class="ui-height" />
    </div>

    <div class="ui-foot">
      <el-button plain type="info" @click="goBack">返 回</el-button>
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import StageExamInfo from '../../exam/components/info'
export default {
  components: { Pagination, StageExamInfo },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      config: config,
      KEYWORDS: '',
      varList: [],
      pd: [],
      form: {
        CURRICULUMNAME: '', // 课程名称
        CURRICULUMINTRODUCE: '', // 课程介绍
        CURRICULUMAIM: '', // 课程目的
        STARTTIME: '', // 开始时间
        ENDTIME: '', // 结束时间
        VIDEOCOURSEWARES: '', // 视频课件组
        DATACOURSEWARES: ''// 资料课件组
      },
      multipleSelectionAll: [], // 所有选中的数据包含跨页数据
      multipleSelection: [], // 当前页选中的数据
      dialogStageExamShow: false,
      STAGEEXAMPAPER_ID: '',
      USER_ID: '',
      rules: {
        CURRICULUMNAME: [{ required: true, message: '课程名称不能为空', trigger: 'blur' }],
        CURRICULUMINTRODUCE: [{ required: true, message: '课程介绍不能为空', trigger: 'blur' }],
        CURRICULUMAIM: [{ required: true, message: '课程目的不能为空', trigger: 'blur' }],
        STARTTIME: [{ required: true, message: '开始时间不能为空', trigger: 'blur' }],
        ENDTIME: [{ required: true, message: '结束时间不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getDict()
    this.getList()
  },
  methods: {
    getRowKey(row) {
      return row.STAGESTUDENTRELATION_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.getList()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/stagestudentrelation/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS,
          STAGEEXAMPAPER_ID: this.$parent.STAGEEXAMPAPER_ID
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
        this.hasButton()
        this.pd = data.pd
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 查看阶段试卷答题结果
    handleStageExam(STAGEEXAMPAPER_ID, USER_ID) {
      // this.STAGEEXAMPAPER_ID = STAGEEXAMPAPER_ID
      // this.USER_ID = USER_ID
      // this.dialogStageExamShow = true
      this.$parent.STAGEEXAMPAPER_ID = STAGEEXAMPAPER_ID
      this.$parent.USER_ID = USER_ID
      this.$parent.activeName = 'StageExamResult'
    },
    // 判断按钮权限，用于是否显示按钮
    hasButton: function() {
      var keys = 'curriculum:add,curriculum:del,curriculum:edit,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys
        }
      ).then((data) => {
        this.add = data.curriculumfhadminadd		// 新增权限
        this.del = data.curriculumfhadmindel		// 删除权限
        this.edit = data.curriculumfhadminedit	// 修改权限
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 获取数据字典数据
    getDict: function() {
    },
    goBack() {
      this.$parent.activeName = 'List'
    }
  }
}

</script>
