<template>
  <div class='cl-container'>
    <!-- 搜索类型 -->
    <el-form :inline="true"
             class="searchForm"
             v-model.trim="searchForm">
      <el-form-item label="课程类型">
        <el-select v-model.trim="searchForm.courseStatus"
                   clearable
                   filterable
                   placeholder="课程类型">
          <el-option label="基础技能课"
                     value="HIGH"></el-option>
          <el-option label="综合课"
                     value="COMPREHENSIVE"></el-option>
          <el-option label="课堂课"
                     value="CLASSROOM"></el-option>
          <el-option label="合奏课"
                     value="MIX"></el-option>
          <el-option label="集训合奏课"
                     value="TRAINING_MIX"></el-option>
          <el-option label="集训声部课"
                     value="TRAINING_SINGLE"></el-option>
          <el-option label="声部课"
                     value="SINGLE"></el-option>
          <el-option label="线上基础技能课"
                     value="HIGH_ONLINE"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班级名称">
        <!-- getMusicGroupAllClass -->
        <el-select v-model.trim="searchForm.class"
                   filterable
                   clearable>
          <el-option v-for='(item,index) in classList'
                     :key="index"
                     :value="item.id"
                     :label="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="选择日期">
        <el-date-picker v-model.trim="searchForm.timer"
                        style="width:420px;"
                        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>
        <div class='searchBtn'
             @click="search">搜索</div>
      </el-form-item>
    </el-form>
    <div class="btnWraps">
    </div>
    <!-- 列表 -->
    <div class="tableWrap">
      <el-table :data='tableList'
                :header-cell-style="{background:'#EDEEF0',color:'#444'}">
        <el-table-column align='center'
                         label="时间">
          <template slot-scope="scope">
            {{ scope.row.classDate }} {{ scope.row.startClassTime ? scope.row.startClassTime.substr(0, 5) : '' }}-{{ scope.row.endClassTime ? scope.row.endClassTime.substr(0, 5) : '' }}
          </template>
        </el-table-column>
        <el-table-column align='center'
                         prop="classGroupName"
                         label="班级名称">
        </el-table-column>
        <el-table-column align='center'
                         prop="courseScheduleType"
                         label="课程类型">
          <template slot-scope="scope">
            <div>
              {{ scope.row.courseScheduleType | coursesType}}
            </div>
          </template>
        </el-table-column>
        <el-table-column align='center'
                         prop="masterTeacherName"
                         label="指导老师">
        </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>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { getTeacher, getMusicGroupAllClass, getCourseSchedule } from '@/api/buildTeam'
export default {
  name: 'tcourseList',
  props: {
    teamid: {
      type: String,
      required: true
    },
  },
  data () {
    return {
      timerVisible: false,
      courseVisible: false,
      searchForm: {
        courseStatus: '', // 课程类型
        classStatus: '', // 课程状态
        timer: [], // 时间
        class: ''
      },
      tableList: [],
      searchLsit: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      teacherList: [],
      classList: []
    }

  },
  components: {
    pagination
  },
  activated () {
    this.init()
  },
  mounted () {

    this.init()
  },
  methods: {
    /**
     *  courseStatus: '', // 课程类型
        classStatus: '', // 课程状态
        timer:[] // 时间
     *
     */
    init () {
      this.getList();
      // 获取所有老师
      getTeacher().then(res => {
        if (res.code == 200) {
          this.teacherList = res.data;
        }
      })

      // 获取班级列表
      getMusicGroupAllClass({ musicGroupId: this.teamid }).then(res => {
        if (res.code == 200) {
          this.classList = res.data;
        }
      })
    },
    search () {
      this.rules.page = 1;
      this.getList();
    },
    getList () {
      if (!this.searchForm.timer) {
        this.searchForm.timer = []
      }
      let obj = {
        classScheduleStatus: this.searchForm.classStatus || null,
        classScheduleType: this.searchForm.courseStatus || null,
        musicGroupId: this.teamid,
        startTime: this.searchForm.timer[0] || null,
        endTime: this.searchForm.timer[1] || null,
        page: this.rules.page, rows: this.rules.limit,
        classGroupId: this.searchForm.class || null

      }
      getCourseSchedule(obj).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
        }
      })
    }
  }
}
</script>
<style lang="scss" scope>
.cl-container {
  .topFrom {
    margin: 20px 30px 0;
    .classlist {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      ul {
        li {
          list-style: none;
        }
      }
    }
  }
  .searchForm {
    margin: 0 30px;
  }
}
.btnWraps {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  div {
    margin-right: 20px;
  }
}
</style>
