<template>
  <div>
    <!-- 头部展示 -->
    <!-- <div class="headWrap">
      <div class="left">
        <div class="headItem">
          <p>本月请假:<span>12345</span></p>
        </div>
      </div>
      <div class="right">
      </div>
    </div> -->
    <!-- 搜索标题 -->
    <el-form :inline="true"
             class="searchForm"
             v-model.trim="searchForm">
      <el-form-item>
        <el-date-picker style="width: 400px;"
                        v-model.trim="courseDate"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        @change="searchCourseDate"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="search"
                   type="danger">搜索</el-button>
        <el-button @click="onReSet"
                   type="primary">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <div class="tableWrap">
      <el-table :data='tableList'
                :header-cell-style="{background:'#EDEEF0',color:'#444'}">
        <el-table-column align='center'
                         prop="createTime"
                         label="请假发起时间">
        </el-table-column>
        <el-table-column align='center'
                         label="请假时间">
          <template slot-scope="scope">
            {{ scope.row.startTime }} - {{ scope.row.endTime }}
          </template>
        </el-table-column>
        <el-table-column align='center'
                         prop="remark"
                         label="请假说明">
        </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 { teacherLeaveRecordQuery } from '@/api/teacherManager'
import pagination from '@/components/Pagination/index'
import store from '@/store'
import { attendance } from '@/utils/searchArray'
export default {
  name: 'leaveRecord',
  components: {
    pagination
  },
  data () {
    return {
      attendance: attendance,
      courseDate: null,
      searchForm: {
        startTime: null,
        endTime: null,
        status: 'PASS'
      },
      tableList: [],
      tableList: [],
      organId: null,
      teacherId: this.$route.query.teacherId,
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 1, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      }
    }
  },
  mounted () {
    this.getList()
  },
  activated () {
    this.teacherId = this.$route.query.teacherId
    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,
        params.teacherId = this.teacherId
      teacherLeaveRecordQuery(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows
          this.pageInfo.total = res.data.total
        }
      })
    },
    searchCourseDate (value) {
      if (value) {
        this.searchForm.startTime = value[0]
        this.searchForm.endTime = value[1]
      } else {
        this.searchForm.startTime = null
        this.searchForm.endTime = null
      }
    },
    onReSet () {
      this.courseDate = null
      this.searchForm = {
        startTime: null,
        endTime: null,
      }
    }
  }
}
</script>
<style lang="scss">
</style>