<template>
  <section>
    <!--搜索栏-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" @submit.native.prevent>
        <el-form-item label="姓名">
          <el-input v-model="keyword" placeholder="请输入" clearable @change="searchList" size="small"></el-input>
        </el-form-item>
        <el-form-item label="课程名称">
          <el-input v-model="courseName" placeholder="请输入" clearable @change="searchList" size="small"></el-input>
        </el-form-item>
        <el-form-item label="课程分类">
          <el-select v-model="courseType" placeholder="请选择" size="small" clearable @change="searchList">
            <!-- <el-option label="线上课" :value="0"></el-option> -->
            <!-- <el-option label="线下课" :value="1"></el-option> -->
          </el-select>
        </el-form-item>
      </el-form>
    </el-col>

    <!--表格-->
    <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
      <el-table-column prop="course" label="姓名" min-width="120" align="center"></el-table-column>
      <el-table-column prop="name" label="课程分类" min-width="120" align="center"></el-table-column>
      <el-table-column prop="course" label="课程名称" min-width="180" align="center"></el-table-column>
      <el-table-column prop="name" label="价格" min-width="120" align="center"></el-table-column>
    </el-table>

    <!--分页-->
    <el-col :span="24" class="toolbar">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 50, 100]" :page-size="size" layout="total, sizes, prev, pager, next" :total="total"
        style="float:right;"></el-pagination>
    </el-col>
  </section>
</template>

<script>
export default {
  data() {
    return {
      // 搜索条件
      keyword: null,
      courseName: null,
      courseType: null,

      // 表格相关
      tableHeight: 0,
      listLoading: false,
      total: 0,
      page: 1,
      size: 20,
      list: []
    }
  },
  methods: {
    // 搜索考试信息
    searchList() {
      this.page = 1;
      this.getList();
    },

    // 获取考试信息列表
    getList() {
      // 待接口联调
      return
      this.listLoading = true;
      this.http.post('/exam-info/pageList', {
        name: this.keyword,
        courseName: this.courseName,
        page: this.page,
        size: this.size
      }, res => {
        this.list = res.data.records;
        this.total = res.data.total;
        this.listLoading = false;
      }, () => {
        this.listLoading = false;
      })
    },

    // 分页相关
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    handleSizeChange(val) {
      this.page = 1;
      this.size = val;
      this.getList();
    }
  },
  created() {
    let height = window.innerHeight;
    this.tableHeight = height - 195;
    const that = this;
    window.onresize = function temp() {
      that.tableHeight = window.innerHeight - 195;
    };
  },
  mounted() {
    this.getList();
  }
}
</script>

<style lang="scss" scoped>
.toolbar {
  padding-bottom: 10px;
}
</style>
