<template>
  <div class="m-container">
    <h2>
      <el-page-header @back="onCancel"
                      content="学生点名总览"></el-page-header>
      <!-- <div class="term">第一学期</div>
      <div class="term active">第二学期</div> -->
    </h2>
    <div class='m-core'>
      <!-- <div class="searchBtn">导出</div> -->
      <!-- table  -->
      <el-form :inline="true"
               :model="searchForm">
        <el-form-item label='开课时间'>
          <el-date-picker v-model.trim="searchForm.times"
                          type="daterange"
                          value-format="yyyy-MM-dd"
                          format="yyyy-MM-dd"
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label='班级名称'>
          <el-select v-model.trim="searchForm.className"
                     clearable>
            <el-option v-for='(item,index) in classList'
                       :key='index'
                       :label="item.name"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label='学生名字'>
          <el-input v-model.trim="searchForm.studentName"></el-input>
        </el-form-item>
        <el-form-item label='签到'>
          <el-select v-model.trim="searchForm.sign"
                     clearable>
            <el-option label="正常"
                       value="NORMAL"></el-option>
            <el-option label="旷课"
                       value="TRUANT"></el-option>
            <el-option label="请假"
                       value="LEAVE"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="danger"
                     @click="search">搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
                     @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="tableList">
        <el-table :data='tableList'>
          <el-table-column align='center'
                           prop="signTime"
                           label="时间">
          </el-table-column>
          <el-table-column align='center'
                           prop="classGroupName"
                           label="班级名称">
          </el-table-column>
          <el-table-column align='center'
                           prop="name"
                           label="学生名称">
          </el-table-column>
          <el-table-column align='center'
                           prop="signStatus"
                           label="签到">
            <template slot-scope="scope">
              <div>
                {{ scope.row.signStatus|studentSign}}
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :total="rules.total"
                    :page.sync="rules.page"
                    :limit.sync="rules.limit"
                    :page-sizes="rules.page_size"
                    @pagination="getList" />
      </div>
    </div>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { getStudentRecord } from '@/api/studentManager'
import { getMusicGroupAllClass } from '@/api/buildTeam'
export default {
  name: 'tstudentSignin',
  components: {
    pagination
  },
  data () {
    return {
      tableList: [], // table列表
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      searchForm: {
        times: [],
        courseName: '',
        studentName: '',
        sign: ''
      },

      teamid: '',
      classList: []
    }
  },
  created () {
    this.init()
  },
  activated () {
    this.init()
  },
  methods: {
    init () {
      this.teamid = this.$route.query.id;
      // 判断是否带缓存参数
      if (this.$route.query.search) {
        this.Fsearch = this.$route.query.search;
      }
      if (this.$route.query.rules) {
        this.Frules = this.$route.query.rules
      }
    },
    mounted () {
      this.getList();
      // 获取乐团所有班级
      getMusicGroupAllClass({ musicGroupId: this.teamid }).then(res => {
        if (res.code == 200) {
          this.classList = res.data;
        }
      })
    },
    search () {
      this.rules.page = 1;
      this.getList()
    },
    reset () {
      this.searchForm = {
        times: [],
        courseName: '',
        studentName: '',
        sign: ''
      }
      this.rules.page = 1;
      this.getList()
    },
    onCancel () {
      // history.go(-1)
      let params = this.$route.query
      this.$router.push({
        path: '/business/teamDetails',
        query: {
          id: params.id,
          status: params.status,
          name: params.name,
          checkIndex: "3",
          rules: this.Frules, search: this.Fsearch
        }
      })
    },
    getList () {
      if (!this.searchForm.times) {
        this.searchForm.times = []
      }
      let startTime = this.searchForm.times[0] || null
      if (startTime) startTime += ' 00:00:00'

      let endTime = this.searchForm.times[1] || null
      if (endTime) endTime += ' 23:59:59'

      let courseScheduleName = this.searchForm.courseName || null
      let userName = this.searchForm.studentName || null
      let signStatus = this.searchForm.sign || null
      let musicGroupId = this.teamid
      let classGroupId = this.searchForm.className || null
      getStudentRecord({ musicGroupId, page: this.rules.page, rows: this.rules.limit, startTime, endTime, courseScheduleName, userName, signStatus, classGroupId }).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
        }
      })
    }
  },
}
</script>
<style lang="scss" scope>
// .m-container {
//   h2 {
//     height: 48px;
//     line-height: 48px;
//     position: relative;
//     // padding-left: 30px;
//     margin-bottom: 30px;
//     display: flex;
//     flex-direction: row;
//     justify-content: flex-start;
//     align-items: center;
//     .term {
//       height: 32px;
//       line-height: 32px;
//       border-radius: 24px;
//       width: 100px;
//       color: #14928a;
//       border: 1px solid rgba(20, 146, 138, 1);
//       font-size: 14px;
//       text-align: center;
//       margin-right: 12px;
//       &:nth-child(1) {
//         margin-left: 47px;
//       }
//     }
//     .term.active {
//       color: #fff;
//       background-color: #14928a;
//     }
//   }
// }
</style>