<template>
  <div class="app-container">
    <el-table v-loading="juLoading" :data="juData" border fit highlight-current-row style="width: 100%">
      <el-table-column prop="ranking" label="排名" width="100" />
      <el-table-column prop="deptName" label="铁路局名称" />
      <el-table-column prop="subject2Avg" label="线路专业(平均分)" />
      <el-table-column prop="subject3Avg" label="桥隧专业(平均分)" />
      <el-table-column prop="allAvgScore" label="整体平均分" />
      <el-table-column label="操作" align="center">
        <template slot-scope="{row}">
          <el-button size="mini" @click="getDuanData(row)" class="link-left">工务段排名</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="工务段排名" :visible.sync="duanDialog" width="60%">
      <el-table :data="duanData" stripe height="600" v-loading="duanLoading">
        <el-table-column prop="ranking" label="排名" width="100" />
        <el-table-column prop="deptName" label="工务段名称" />
        <el-table-column prop="subject2Avg" label="线路专业(平均分)" />
        <el-table-column prop="subject3Avg" label="桥隧专业(平均分)" />
        <el-table-column prop="allAvgScore" label="整体平均分" />
        <el-table-column label="操作" align="center">
          <template slot-scope="{row}">
            <el-button size="mini" @click="getChejianData(row)" class="link-left">车间排名</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="车间排名" :visible.sync="chejianDialog" style="margin-top: 50px;">
      <el-table :data="chejianData" stripe height="500" v-loading="chejianLoading">
        <el-table-column prop="ranking" label="排名" width="100" />
        <el-table-column prop="deptName" label="工务段名称" />
        <el-table-column prop="subject2Avg" label="线路专业(平均分)" />
        <el-table-column prop="subject3Avg" label="桥隧专业(平均分)" />
        <el-table-column prop="allAvgScore" label="整体平均分" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
  import examPaperAnswerApi from '@/api/examPaperAnwser'

  export default {
    data() {
      return {
        juLoading: false,
        duanLoading: false,
        chejianLoading: false,
        duanDialog: false,
        chejianDialog: false,
        juData: [],
        duanData: [],
        chejianData: [],
      }
    },
    created() {
      this.getJuData()
    },
    methods: {
      getJuData() {
        this.juData = []
        this.juLoading = true
        examPaperAnswerApi.getRanking(-1).then(data => {
          this.juData = data.response
          this.juLoading = false
        })
      },
      getDuanData(row) {
        this.duanData = []
        this.duanLoading = true
        this.duanDialog = true
        examPaperAnswerApi.getRanking(row.deptId).then(data => {
          this.duanData = data.response
          this.duanLoading = false
        })
      },
      getChejianData(row) {
        this.chejianData = []
        this.chejianLoading = true
        this.chejianDialog = true
        examPaperAnswerApi.getRanking(row.deptId).then(data => {
          this.chejianData = data.response
          this.chejianLoading = false
        })
      }
    }
  }
</script>
