<template>
  <div>
    <!-- 搜索类型 -->
    <el-form :inline="true"
             class="searchForm"
             v-model.trim="searchForm">
      <el-form-item>
        <el-select v-model.trim="searchForm.classGroupType"
                   filterable
                   clearable
                   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.trim="searchForm.attendanceStatus"
                   filterable
                   clearable
                   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-select v-model.trim="searchForm.courseStatus"
                   filterable
                   clearable
                   placeholder="课程状态">
          <el-option v-for="(item, index) in courseStatus"
                     :key="index"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="班级名称"
                  v-model.trim="searchForm.classGroupName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="老师姓名"
                  v-model.trim="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.courseStatus | coursesStatus }}
          </template>
        </el-table-column>
        <el-table-column align='center'
                         label="班级类型">
          <template slot-scope="scope">
            {{ scope.row.classGroupType | classType }}
          </template>
        </el-table-column>
        <el-table-column align='center'
                         prop="classGroupName"
                         label="班级名称">
        </el-table-column>
        <el-table-column align='center'
                         prop="currentCLassTimes"
                         label="当前课次">
          <template slot-scope="scope">
            <div>
              {{ scope.row.currentCLassTimes + '/'+scope.row.totalClassTimes }}
            </div>
          </template>
        </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">
            <div>
              <p v-if="scope.row.courseStatus != 'NOT_START'">{{ scope.row.attendanceStatus | clockingIn }}</p>
              <p v-if="scope.row.courseStatus == 'NOT_START'">未签到 </p>
            </div>
            
          </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'
import { courseStatus } from '@/utils/searchArray'
export default {
  name: 'studentRecord',
  components: { pagination },
  data () {
    return {
      searchForm: {
        studentId: null,
        classGroupType: null,
        attendanceStatus: null,
        classGroupName: null,
        teacherName: null,
        courseStatus: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: "请假" },
      ],
      courseStatus:courseStatus,
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },

    }
  },
  mounted () {
    this.searchForm.studentId = this.$route.query.userId
    this.getList()
  },
  activated() {
    this.searchForm.studentId = this.$route.query.userId
    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>