<!-- 查看成绩 -->
<template>
  <div>
    <el-dialog
      :before-close="handleClose"
      :close-on-click-modal="false"
      :visible="visible"
      custom-class="bbsl-location-dialog"
      title="成绩列表"
      top="5vh"
      width="75%"
    >
      <el-table
        ref="multipleSelection"
        v-loading="loading"
        :cell-style="{'text-align': 'center'}"
        :data="tableData"
        :header-cell-style="{'text-align': 'center'}"
        :style="{width: '100%'}"
        max-height="500"
        size="mini"
      >
        <!-- <el-table-column type="selection" width="55"></el-table-column> -->
        <el-table-column
          fixed
          label="序号"
          type="index"
          width="55"
        ></el-table-column>
        <el-table-column
          label="试卷名称"
          min-width="150"
          prop="paperName"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="课目名称"
          min-width="100"
          prop="subjectName"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="考试状态"
          min-width="100"
          prop="statusName"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column label="考核类型" min-width="120" prop="paperTypeName">
        </el-table-column>
        <el-table-column
          label="总分"
          min-width="70"
          prop="totalScore"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column
          label="总时长"
          min-width="100"
          prop="timeLength"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column
          label="得分"
          min-width="70"
          prop="sysScore"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column
          label="用时"
          min-width="100"
          prop="answerTime"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column
          label="交卷时间"
          min-width="150"
          prop="endTime"
          show-overflow-tooltip
          sortable
        >
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          min-width="120"
          show-overflow-tooltip
        >
          <template #default="scope">
            <el-button @click="handleClick(scope.row)">设为最终成绩</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-footer>
        <el-pagination
          ref="paginationPanel"
          :current-page="queryParam.pageBean.page"
          :page-size="queryParam.pageBean.pageSize"
          :page-sizes="[20, 30, 40, 50]"
          :total="total"
          align="right"
          background
          layout="prev, pager, next,total, sizes, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        ></el-pagination>
      </el-footer>
    </el-dialog>
  </div>
</template>

<script>
import dictUtils from '@/components/dict/DictSelectUtils.js'
import ndbbMenu from '@/api/examination/ndbbMenu.js'

export default {
  name: 'resultsDialog',
  data() {
    return {
      loading: false,
      visible: false,
      tableData: [],
      total: 0,
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 10
        },
        querys: [
          {
            group: 'main',
            operation: 'LIKE',
            parentGroup: '',
            property: 'e.id_',
            relation: 'AND',
            value: ''
          },
          {
            group: 'main',
            operation: 'LIKE',
            parentGroup: '',
            property: 'b.subject_id_',
            relation: 'AND',
            value: ''
          }
        ]
      },
      yearId: ''
    }
  },
  created() {},
  mounted() {
    this.ksztList = dictUtils.getDictItemsFromCache('kszt')
    this.khlxList = dictUtils.getDictItemsFromCache('khlx')
  },
  methods: {
    add(val, subjectId) {
      this.visible = true
      this.yearId = val
      this.queryParam.querys[0].value = this.yearId
      this.queryParam.querys[1].value = subjectId
      this.loadData(1)
    },
    searchName() {},
    // 获取列表
    loadData(page) {
      if (page) {
        this.queryParam.pageBean.page = page
      }
      this.loading = true
      this.tableData = []
      ndbbMenu.detailPage(this.queryParam, res => {
        this.total = res.total
        this.tableData = res.rows
        this.tableData.forEach(e => {
          this.ksztList.forEach(k => {
            if (e.status == k.value) {
              e.statusName = k.name
            }
          })
          this.khlxList.forEach(k => {
            if (e.paperType == k.value) {
              e.paperTypeName = k.name
            }
          })
        })
        this.$set(this.tableData)
        this.loading = false
      })
    },
    handleSizeChange(val) {
      this.queryParam.pageBean.pageSize = val
      this.loadData()
    },
    handleCurrentChange(val) {
      this.queryParam.pageBean.page = val
      this.loadData()
    },
    //设置最终成绩
    handleClick(val) {
      let params = {
        id: this.yearId,
        recordId: val.id
      }
      ndbbMenu.settingYear(params, res => {
        if (res.state) {
          this.$message.success('设置成功')
          this.visible = false
          this.$emit('loadData')
        }
      })
    },

    // 关闭新增人员窗口
    handleClose() {
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__body {
  height: 100% !important;
  max-height: 80%;
}

.left-aside {
  border-right: 1px solid #eee;
  padding: 10px;
}

.select-aside {
  border-left: 1px solid #eee;
}

::v-deep .el-table__header-wrapper .el-checkbox {
  //找到表头那一行，然后把里面的复选框隐藏掉
  display: none;
}

::v-deep .el-dialog__body {
  padding: 10px 0 0 0;
  margin: 0 5px;
}
</style>
