<template>
  <div class="tr-cotainer">
    <!-- 搜索标题 -->
    <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="课程结束日期"
                        :picker-options="{
        firstDayOfWeek: 1
    }"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-select v-model.trim="searchForm.courseScheduleType"
                   clearable
                   filterable
                   placeholder="课程类型">
          <el-option v-for="(item, index) in courseType"
                     :key="index"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="课程名称"
                  @keyup.enter.native="search"
                  v-model.trim="searchForm.classGroupName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model.trim="searchForm.signInStatus"
                   filterable
                   clearable
                   placeholder="考勤状态">
          <el-option v-for="(item, index) in attendance"
                     :key="index"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </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">
      <div class="tableWrap">
        <el-table :data="tableList"
                  :header-cell-style="{background:'#EDEEF0',color:'#444'}">
          <el-table-column align="center"
                           prop="courseScheduleId"
                           label="课程编号"></el-table-column>
          <el-table-column align="center"
                           label="上课时间"
                           width="150">
            <template slot-scope="scope">{{ scope.row.classDate }} {{ scope.row.startClassTime.substring(0,5) }}</template>
          </el-table-column>
          <el-table-column align="center"
                           label="下课时间"
                           width="150">
            <template slot-scope="scope">{{ scope.row.classDate }} {{ scope.row.endClassTime.substring(0,5) }}</template>
          </el-table-column>
          <el-table-column align="center"
                           label="课程类型">
            <template slot-scope="scope">{{ scope.row.type | coursesType }}</template>
          </el-table-column>
          <el-table-column align="center"
                           prop="name"
                           label="课程名称"></el-table-column>
          <el-table-column align="center"
                           label="签到">
            <template slot-scope="scope">{{ scope.row.signInStatus | attendanceType }}</template>
          </el-table-column>
          <el-table-column align="center"
                           label="签退">
            <template slot-scope="scope">{{ scope.row.signOutStatus | attendanceOutType }}</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>
  </div>
</template>
<script>
import { getTeacherPersonalAttendances } from "@/api/teacherManager";
import pagination from "@/components/Pagination/index";
import store from "@/store";
import { courseType, attendance } from "@/utils/searchArray";
export default {
  name: "teacherRecord",
  components: {
    pagination
  },
  data () {
    return {
      courseType: courseType, // 课程类型
      attendance: attendance, // 考勤状态
      courseDate: null, // 上课时间
      searchForm: {
        courseStartDate: null,
        courseEndDate: null,
        classGroupName: null,
        courseScheduleType: null,
        signInStatus: null
      },
      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.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);
      getTeacherPersonalAttendances(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.pageInfo.total = res.data.total;
        }
      });
    },
    searchCourseDate (value) {
      if (value) {
        this.searchForm.courseStartDate = value[0];
        this.searchForm.courseEndDate = value[1];
      } else {
        this.searchForm.courseStartDate = null;
        this.searchForm.courseEndDate = null;
      }
    },
    onReSet () {
      this.courseDate = null;
      this.searchForm = {
        courseStartDate: null,
        courseEndDate: null,
        classGroupName: null,
        courseScheduleType: null,
        signInStatus: null
      };
    }
  }
};
</script>
<style lang="scss" scope>
.tr-cotainer {
  margin-top: 20px;
}
</style>