<template>
  <div class="tr-cotainer">
    <!-- 搜索标题 -->
    <save-form
      :inline="true"
      save-key="teacherDetail-record"
      class="searchForm"
      :model="searchForm"
      @submit="search"
      @reset="onReSet"
    >
      <el-form-item>
        <el-input
          placeholder="课程编号/课程名称"
          @keyup.enter.native="search"
          v-model.trim="searchForm.search"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          style="width: 400px"
          v-model.trim="searchForm.courseDate"
          type="daterange"
          value-format="yyyy-MM-dd"

          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-select
          v-model.trim="searchForm.signInStatus"
          filterable
          clearable
          placeholder="签到状态"
        >
          <el-option :value="1" label="正常签到"></el-option>
          <el-option :value="0" label="异常签到"></el-option>
          <el-option :value="3" label="未签到"></el-option>
          <!-- <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-select
          v-model.trim="searchForm.signOutStatus"
          filterable
          clearable
          placeholder="签退状态"
        >
          <!-- <el-option
            v-for="(item, index) in attendance"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option> -->
          <el-option :value="1" label="正常签退"></el-option>
          <el-option :value="0" label="异常签退"></el-option>
          <el-option :value="3" label="未签退"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button native-type="search" type="danger">搜索</el-button>
        <el-button native-type="reset" type="primary">重置</el-button>
      </el-form-item>
    </save-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="课程编号"
          >
            <template slot-scope="scope">
              <copy-text>
                {{ scope.row.courseScheduleId }}
              </copy-text>
            </template>
          </el-table-column>
               <el-table-column align="center" label="课程名称">
            <template slot-scope="scope">
              <copy-text>
                {{ scope.row.courseScheduleName }}
              </copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" label="上课日期" prop="classDate" 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) }} -->
              {{ scope.row.startClassTime + "-" + scope.row.endClassTime }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="课程类型">
            <template slot-scope="scope">{{
              scope.row.courseScheduleType | coursesType
            }}</template>
          </el-table-column>
          <el-table-column align="center" label="签到时间">
            <template slot-scope="scope">
              <div>
                {{ scope.row.signInTime }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="签到状态">
            <template slot-scope="scope">
              <div v-if="scope.row.courseScheduleStatus != 'NOT_START'">
                {{ scope.row.signInStatus | attendanceType }}
              </div>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            prop="startClassTime"
            label="签退时间"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.signOutTime }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="签退状态">
            <template slot-scope="scope">
              <div v-if="scope.row.courseScheduleStatus != 'NOT_START'">
                {{ scope.row.signOutStatus | attendanceOutType }}
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" label="签到状态">
            <template slot-scope="scope">
              <div v-if="scope.row.courseStatus != 'NOT_START'">{{
              scope.row.signInStatus | attendanceType
            }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="签退状态">
            <template slot-scope="scope">
              <div v-if="scope.row.courseStatus != 'NOT_START'">{{
              scope.row.signOutStatus | attendanceOutType
            }}</div>
            </template>
          </el-table-column> -->
          <el-table-column
            align="center"
            prop="remark"
            label="备注"
          ></el-table-column>
        </el-table>
        <pagination
         save-key="teacherDetail-record"
          sync
          :total.sync="pageInfo.total"
          :page.sync="pageInfo.page"
          :limit.sync="pageInfo.limit"
          :page-sizes="pageInfo.page_size"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>
<script>
import { queryTeacherAttendances } from "@/api/recodeManager";
import pagination from "@/components/Pagination/index";
import store from "@/store";
import { courseType, attendance } from "@/utils/searchArray";
import { getTimes } from "@/utils";
import cleanDeep from 'clean-deep'
export default {
  name: "teacherRecord",
  components: {
    pagination,
  },
  data() {
    return {
      courseType: courseType, // 课程类型
      attendance: attendance, // 考勤状态

      searchForm: {
        courseStartDate: null,
        courseEndDate: null,
        search: null,
        courseScheduleType: null,
        signInStatus: null,
        signOutStatus: null,
        courseDate:[]
      },
      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() {
        const { courseDate, ...rest } = this.searchForm;
      let params = {
        ...rest,
        ...getTimes(courseDate, ["courseStartDate", "courseEndDate"]),
        page: this.pageInfo.page,
        rows: this.pageInfo.limit,
        teacherId: this.teacherId
      };
      // let params = this.searchForm;
      // params.rows = this.pageInfo.limit;
      // (params.page = this.pageInfo.page), (params.teacherId = this.teacherId);
      queryTeacherAttendances(cleanDeep(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,
        search: null,
        courseScheduleType: null,
        signInStatus: null,
        signOutStatus: null
      };
      this.getList()
    },
  },
};
</script>
<style lang="scss" scope>
.tr-cotainer {
  // margin-top: 20px;
}
</style>
