<template>
  <div>
    <!-- 搜索类型 -->
    <el-form :inline="true"
             class="searchForm"
             v-model="searchForm">
      <el-form-item>
        <el-select v-model="searchForm.classGroupType"
                   placeholder="课程类型">
          <el-option v-for="(item, index) in courseArray"
                     :key="index"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="searchForm.attendanceStatus"
                   placeholder="考勤状态">
          <el-option v-for="(item, index) in att"
                     :key="index"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="班级名称"
                  v-model="searchForm.classGroupName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="老师姓名"
                  v-model="searchForm.teacherName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="search"
                   type="danger">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="onReSet"
                   type="primary">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 查询列表 -->
    <!-- <div class="searchWrap">
      <p>查询条件:</p>
      <div class="searchItem"
           @click="closeSearch(item)"
           v-for="(item,index) in searchLsit">
        {{ item.key }}
        <i class="el-icon-close"></i>
      </div>
    </div> -->
    <!-- 列表 -->
    <div class="tableWrap">
      <el-table :data='tableList'
                :header-cell-style="{background:'#EDEEF0',color:'#444'}">
        <el-table-column align='center'
                         prop="courseDate"
                         label="上课时间">
        </el-table-column>
        <el-table-column align='center'
                         label="星期几">
          <template slot-scope="scope">
            {{ scope.row.courseDate | formatWeek }}
          </template>
        </el-table-column>
        <el-table-column align='center'
                         label="课程类型">
          <template slot-scope="scope">
            {{ scope.row.classGroupType | coursesType }}
          </template>
        </el-table-column>
        <el-table-column align='center'
                         prop="classGroupName"
                         label="班级名称">
        </el-table-column>
        <el-table-column align='center'
                         prop="currentCLassTimes"
                         label="当前课次">
        </el-table-column>
        <el-table-column align='center'
                         prop="teacherName"
                         label="课程老师">
        </el-table-column>
        <el-table-column align='center'
                         prop="attendanceStatus"
                         label="考勤状态">
          <template slot-scope="scope">
            {{ scope.row.attendanceStatus | clockingIn }}
          </template>
        </el-table-column>
      </el-table>
      <pagination :total="pageInfo.total"
                  :page.sync="pageInfo.page"
                  :limit.sync="pageInfo.limit"
                  :page-sizes="pageInfo.page_size"
                  @pagination="getList" />
    </div>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { findStudentAttendances } from '@/api/studentManager'
export default {
  name: 'studentRecord',
  components: { pagination },
  data () {
    return {
      searchForm: {
        studentId: this.$route.query.userId,
        classGroupType: null,
        attendanceStatus: null,
        classGroupName: null,
        teacherName: null
      },
      searchLsit: [],
      tableList: [],
      courseArray: [
        { label: '单技课', value: 'NORMAL' },
        { label: '合奏课', value: 'MIX' },
        { label: '基础技能班', value: 'HIGH' },
        { label: 'VIP课', value: 'VIP' },
        { label: '试听课', value: 'DEMO' }
      ],
      att: [
        { value: "NORMAL", label: "正常" },
        { value: "TRUANT", label: "旷课" },
        { value: "LEAVE", label: "请假" },
        { value: "DROP_OUT", label: "休学" },
      ],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },

    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    search () {
      this.pageInfo.page = 1;
      this.getList();
    },
    getList () {
      let params = this.searchForm
      params.rows = this.pageInfo.limit
      params.page = this.pageInfo.page
      findStudentAttendances(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows
          this.pageInfo.total = res.data.total
        }
      })
    },
    onReSet () { // 重置搜索
      this.searchForm = {
        studentId: this.$route.query.userId,
        classGroupType: null,
        attendanceStatus: null,
        classGroupName: null,
        teacherName: null
      }
      this.getList()
    },
  }
}
</script>
<style lang="scss">
</style>