<template>
  <div>
    <!-- 搜索类型 -->
     <save-form
        :inline="true"
        ref="searchForm"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
      >
        <el-form-item prop="teacherId">
          <remote-search :commit='"setTeachers"' v-model='searchForm.teacherId' />
        </el-form-item>
        <el-form-item prop="musicGroupId">
          <el-input
            v-model.trim="searchForm.musicGroupId"
            clearable
            @keyup.enter.native="search"
            placeholder="乐团编号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="courseScheduleId">
          <el-input
            v-model.trim="searchForm.courseScheduleId"
            clearable
            @keyup.enter.native="search"
            placeholder="课程编号"
          ></el-input>
        </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="courseScheduleType">
          <el-select
            v-model.trim="searchForm.courseScheduleType"
            clearable
            placeholder="请选择课程类型"
          >
            <el-option
              v-for="(item, index) in courseType"
              :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="请选择考勤状态"
          >
            <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 prop="dates" >
          <el-date-picker
            v-model="dates"
            type="daterange"
            style="width: 405px;"
            range-separator="至"
            start-placeholder="课程开始日期"
            end-placeholder="课程结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" 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
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="courseSchedule.organization.name"
            label="分部"
          ></el-table-column>
          <el-table-column align="center" prop="username" label="学生姓名">
            <template slot-scope="scope">
              <div>
                {{ scope.row.username }}
                <p style="color: #f56c6c">
                  (<copy-text>{{ scope.row.userId }}</copy-text
                  >)
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="courseSchedule.teacherName"
            label="老师姓名"
          >
            <template slot-scope="scope">
              {{ scope.row.courseSchedule.teacherName }}
              <p style="color: #f56c6c">
                (<copy-text>{{ scope.row.teacherId }}</copy-text
                >)
              </p>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="musicGroupId"
            label="乐团编号"
          >
          <template slot-scope="scope">
            <div>
              <copy-text>{{ scope.row.musicGroupId }}</copy-text>
            </div>
          </template>
          </el-table-column>
          <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
            align="center"
            prop="courseSchedule.classDate"
            label="上课日期"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.courseSchedule.classDate | dayjsFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="startClassTime"
            label="上课时间"
          >
            <template slot-scope="scope">
              <div>
                {{
                  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="签到时间" width="180px">
            <template slot-scope="scope">
              <div>
                {{ scope.row.signInTime }}
              </div>
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            prop="startClassTime"
            width="180px"
            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>
                {{ scope.row.status | clockingIn }}
              </div>
            </template>
          </el-table-column>
             <el-table-column align="center" label="教学模式">
            <template slot-scope="scope">
              <div>
                {{ scope.row.courseSchedule.teachMode | teachMode }}
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          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 pagination from "@/components/Pagination/index";
import { findStudentAttendance } from "@/api/buildTeam";
import { getTimes } from "@/utils";
import {
  courseType,
  courseListType,
  attendanceStatus,
} from "@/utils/searchArray";
export default {
  name: "studentRecord",
  components: { pagination },
  data () {
    return {
      searchForm: {
        studentID: "",
        groupType: "MUSIC",
        musicGroupId: "",
        courseScheduleId: "",
        status: "",
        teacherId:'',
        courseScheduleType:''
      },
      dates:[],
      searchLsit: [],
      tableList: [],
         courseType,
      courseListType,
      attendanceStatus,
      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 obj = {
        page: this.pageInfo.page,
        rows: this.pageInfo.limit,
        ...this.searchForm,
        ...getTimes(this.dates, ["startDateOfCourse", "endDateOfCourse"],'YYYY-MM-DD'),
      };
      findStudentAttendance(obj).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>
