<template>
  <div>
    <el-form :inline="true" ref="searchForm" :model="searchForm">
      <el-form-item prop="dates">
        <el-date-picker
          v-model="searchForm.dates"
          type="daterange"
          style="width: 405px"
          range-separator="至"
          start-placeholder="课程开始日期"
          end-placeholder="课程结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="groupType">
        <el-select
          v-model.trim="searchForm.groupType"
          placeholder="请选择课程组类型"
        >
          <el-option
            v-for="(item, index) in courseListType"
            :key="index"
            :value="item.value"
            :label="item.label"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="status">
        <el-select
          v-model.trim="searchForm.status"
          placeholder="请选择考勤状态"
          clearable
        >
          <el-option
            v-for="(item, index) in attendanceStatus"
            :key="index"
            :value="item.value"
            :label="item.label"
          ></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>
    <el-table
      style="width: 100%"
      :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
      :data="tableList"
    >
      <el-table-column align="center" prop="courseScheduleId" label="课程编号">
        <template slot-scope="scope">
          <div>
            <copy-text>{{ scope.row.courseScheduleId }}</copy-text>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        prop="courseSchedule.name"
        label="课程名称"
      ></el-table-column>

      <el-table-column
        width="180px"
        align="center"
        prop="startClassTime"
        label="上课时间"
      >
        <template slot-scope="scope">
          <div>
            {{ scope.row.courseSchedule.classDate | dayjsFormat }}
            {{ scope.row.courseSchedule.startClassTime | dayjsFormatMinute }}-{{
              scope.row.courseSchedule.endClassTime | dayjsFormatMinute
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="startClassTime" label="课程组类型">
        <template slot-scope="scope">
          <div>
            {{ scope.row.groupType | coursesType }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="startClassTime" label="课程类型">
        <template slot-scope="scope">
          <div>
            {{ scope.row.courseSchedule.type | coursesType }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="考勤状态">
        <template slot-scope="scope">
          <div>
            {{ scope.row.status | clockingIn }}
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total.sync="rules.total"
      :page.sync="rules.page"
      :limit.sync="rules.limit"
      :page-sizes="rules.page_size"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { courseListType, stuAttendance } from "@/utils/searchArray";
import pagination from "@/components/Pagination/index";
import { findStudentAttendance } from "@/api/buildTeam";
import { getTimes } from "@/utils";
export default {
  components: { pagination },
  props:['studentId'],
  data() {
    return {
      searchForm: {
        studentID: "",
        groupType: "",
        status: "",
        dates: [],
      },
      courseListType,
      attendanceStatus: stuAttendance,
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      tableList: [],
    };
  },
  mounted() {
    this.searchForm.studentID = this.studentId
    if (this.searchForm.dates?.length < 1) {
      this.searchForm.dates = [new Date().setDate(1), new Date()];
    }
    this.init();
  },
  methods: {
    init(){
      this.getList()
    },
    search() {
      this.rules.page =1;
      this.getList()
    },
    onReSet() {
      this.$refs["searchForm"].resetFields();
      this.search();
    },
    getList() {
      const { dates, ...rest } = this.searchForm;
      let obj =  {
        ...rest,
        page: this.rules.page,
        rows: this.rules.limit,
        ...getTimes(dates, ["startDateOfCourse", "endDateOfCourse"],  "YYYY-MM-DD"),
      }
       findStudentAttendance(obj).then((res) => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
