<template>
  <!-- 试卷列表 -->
  <el-dialog :visible.sync="visible" :title="title">
    <div class="app-container">
      <el-table
        v-loading="loading"
        :data="list"
        :header-cell-style="{
          'font-weight': 'bold',
          'color': '#000'
        }"
        tooltip-effect="dark"
        border
        fit
        highlight-current-row>
        <el-table-column label="序号" width="70px" type="index"/>
        <el-table-column show-overflow-tooltip prop="DEPARTMENT_NAME" label="部门"/>
        <el-table-column show-overflow-tooltip prop="POST_NAME" label="岗位"/>
        <el-table-column show-overflow-tooltip prop="CURRICULUMNAME" label="涉及课程"/>
        <el-table-column show-overflow-tooltip label="试卷类型">
          <template slot-scope="{row}">
            {{ row.PAPERSELECTTYPE == '1' ? '平台试卷' : '' }}
            {{ row.PAPERSELECTTYPE == '2' ? '自动生成试卷' : '' }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template slot-scope="{row}">
            <el-button
              type="text"
              @click="openInfo(row)">
              查看
            </el-button>
          </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>
    </div>
    <span slot="footer">
      <el-button @click="visible = false">关 闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
export default {
  components: { Pagination },
  directives: { waves },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '试卷列表'
    }
  },
  data() {
    return {
      visible: false,
      loading: false,
      list: [],
      total: '0',
      listQuery: {
        page: 1,
        limit: 10
      },
      Id: ''
    }
  },
  methods: {
    async init(e) {
      if (!e.Id) {
        this.$message.error('数据异常:[未找到Id]')
        return
      }
      this.Id = e.Id
      await this.getList()
      this.visible = true
    },
    getList() {
      return requestFN(`classpost/listClassPost?showCount=${this.listQuery.limit}&currentPage=${this.listQuery.page}`, {
        CLASS_ID: this.Id
      }).then((data) => {
        this.list = data.varList
        this.total = data.page.totalResult
      })
    },
    openInfo(target) {
      this.$emit('getChoose', { heirloom: '', target: target, name: 'papers' })
    }
  }
}

</script>
