<template>
  <div class='m-container'>
    <h2>
      <div class="squrt"></div>课表列表
    </h2>
    <div class="m-core">
      <!-- 搜索类型 -->
      <el-form :inline="true"
              class="searchForm"
              v-model="searchForm">
        <el-form-item>
          <el-input v-model="searchForm.search" placeholder="乐团名或VIP课名" />
        </el-form-item>
        <el-form-item>
          <el-select v-model="searchForm.teacherIdList"
                    clearable
                    filterable
                    placeholder="请选择老师">
            <el-option v-for="(item, index) in teacherList"
                       :key="index"
                       :value="item.id"
                       :label="item.realName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select class='multiple'
                     v-model="searchForm.organIdList"
                     filterable
                     clearable
                     placeholder="请选择分部">
            <el-option v-for="(item,index) in organList"
                       :key="index"
                       :label="item.name"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="searchForm.courseType"
                    clearable
                    filterable
                    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>
          <el-select v-model="searchForm.courseStatus"
                    clearable
                    filterable
                    placeholder="课程状态">
            <el-option label="未开始"
                      value="NOT_START"></el-option>
            <el-option label="进行中"
                      value="UNDERWAY"></el-option>
            <el-option label="已结束"
                      value="OVER"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker v-model="searchForm.timer"
                          style="width:420px;"
                          type="daterange"
                          value-format="yyyy-MM-dd"
                          range-separator="至"
                          start-placeholder="开始日期"
                          end-placeholder="结束日期">
          </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'
                          prop="organName"
                         label="所属分部">
          </el-table-column> -->
          <el-table-column align='center'
                          width="200px"
                         label="时间">
            <template slot-scope="scope">
              {{ scope.row.startClassTime ? scope.row.startClassTime.substr(0, 16) : '' }}-{{ scope.row.endClassTime ? scope.row.endClassTime.substr(11,5) : ''}}
            </template>
          </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'
                          label="课程类型">
            <template slot-scope="scope">
              <div>
                {{ scope.row.type | coursesType}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                          label="教学模式">
            <template slot-scope="scope">
              <div>
                {{ scope.row.teachMode | teachMode}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                          prop="schoolName"
                          label="教学点">
          </el-table-column>
          <el-table-column align='center'
                          prop="courseScheduleStatus"
                          label="课程状态">
            <template slot-scope="scope">
              <div>
                {{ scope.row.status | coursesStatus }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                          label="是否签到">
            <template slot-scope="scope">
              <div>
                {{ scope.row.isSignIn | attendanceType}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                          label="是否签退">
            <template slot-scope="scope">
              <div>
                {{ scope.row.isSignOut | attendanceOutType}}
              </div>
            </template>
          </el-table-column>
          <el-table-column align='center'
                          prop="isCallNames"
                          label="是否点名">
            <template slot-scope="scope">
              {{ scope.row.isCallNames ? '是' : '否' }}
            </template>
          </el-table-column>
          <el-table-column align='center'
                          prop="teacherName"
                          label="指导老师">
          </el-table-column>
          
          <!-- <el-table-column align='center'
                          prop="subTeacherName"
                          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>
    
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { getTeacher, getMusicGroupAllClass, superFindCourseSchedules, getEmployeeOrgan } from '@/api/buildTeam'
import { courseType } from '@/utils/searchArray'
let nowTime = new Date()
nowTime = nowTime.getFullYear() + '-' + (nowTime.getMonth() + 1) + '-' + nowTime.getDate()
export default {
  data () {
    return {
      timerVisible: false,
      courseVisible: false,
      courseType: courseType,
      searchForm: {
        organIdList: null,
        courseStatus: null, 
        courseType: null, 
        timer: [nowTime, nowTime], // 时间
        class: null,
        search: null, // 乐团名称 编号 vip课名称
        teacherIdList: null, // 老师编号
      },
      tableList: [],
      searchLsit: [],
      organList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      teacherList: [],
      // classList: []
    }

  },
  components: {
    pagination
  },
  mounted () {
    this.getList();
    // 获取所有老师
    getTeacher().then(res => {
      if (res.code == 200) {
        this.teacherList = res.data;
      }
    })

    // 获取班级列表
    // getMusicGroupAllClass().then(res => {
    //   if (res.code == 200) {
    //     this.classList = res.data;
    //   }
    // })

    getEmployeeOrgan().then(res => {
      if (res.code == 200) {
        this.organList = res.data;
      }
    })
  },
  methods: {
    /**
     *  courseStatus: '', // 课程类型
        courseType: '', // 课程状态
        timer:[] // 时间
     * 
     */
    search () {
      this.rules.page = 1;
      this.getList();
    },
    getList () {
      let searchForm = this.searchForm
      if (!searchForm.timer) {
        searchForm.timer = []
      }
      let obj = {
        courseStatus: searchForm.courseStatus || null,
        courseType: searchForm.courseType || null,
        startTime: searchForm.timer[0] || null,
        endTime: searchForm.timer[1] || null,
        page: this.rules.page, rows: this.rules.limit,
        classGroupId: searchForm.class || null,
        organIdList: searchForm.organIdList || null,
        search: searchForm.search || null,
        teacherIdList: searchForm.teacherIdList || null
      }
      superFindCourseSchedules(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>