<template>
  <div>
    <el-form :inline="true">
      <!-- <el-form-item>
        <div class="newBand"
             @click="gotoPlan">新增</div>
      </el-form-item> -->
      <el-form-item label="课程类型">
        <el-select v-model.trim="classScheduleType"
                   @change="chioseList">
          <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-button type='danger'
                   @click="removeAllCourse">清空课表</el-button> -->
      </el-form-item>
    </el-form>
    <el-table :header-cell-style="{background:'#EDEEF0',color:'#444'}"
              :data="tableList">
      <el-table-column prop="classDate"
                       label="日期"
                       align="center"
                       width="180">
        <template slot-scope="scope">
          <div>
            {{ scope.row.classDate | formatTimer }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="上课时间"
                       align="center"
                       width="180">
        <template slot-scope="scope">
          <div>
            {{ scope.row.startClassTimeStr+ '-'+ scope.row.endClassTimeStr}}
          </div>
        </template>
      </el-table-column>
      </el-table-column>
      <el-table-column label="课程类型"
                       align="center"
                       width="180">
        <template slot-scope="scope">
          <div>
            {{scope.row.courseScheduleType |coursesType }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="classGroupName"
                       align="center"
                       label="班级名称">
      </el-table-column>
      <!-- <el-table-column prop="classGroupName"
                       align="center"
                       label="课程名称">
      </el-table-column> -->
      <!-- <el-table-column label="上课时间"
                       align="left"
                       width="180">
        <template slot-scope="scope">
          <div>
            {{ scope.row.startClassTimeStr+ '-'+ scope.row.endClassTimeStr}}
          </div>
        </template>
      </el-table-column> -->
      <el-table-column>
      </el-table-column>
      <el-table-column>
      </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 class="btnWrap">
      <div class="setBtn"
           @click="gotoNext">下一步</div>
    </div> -->
  </div>
</template>
<script>
import { deteleAllCourse, getCourseSchedule } from '@/api/buildTeam'
import pagination from "@/components/Pagination/index";
export default {
  name: 'lookCourse',
  props: {
    isSetSalary: {
      type: Boolean,
      required: true
    }
  },
  components: { pagination },
  data () {
    return {
      teamid: '',
      maxClassList: [],
      classScheduleType: null,
      tableList: [],
      courseType: [
        { label: "声部课", value: "SINGLE" },
        { label: "合奏课", value: "MIX" },
        { label: "基础技能课", value: "HIGH" },
        { label: "线上基础技能课", value: "HIGH_ONLINE" },
        { label: "综合课", value: "COMPREHENSIVE" },
        { label: "集训声部课", value: "TRAINING_SINGLE" },
        { label: "集训合奏课", value: "TRAINING_MIX" },
        { label: "课堂课", value: "CLASSROOM" },
      ],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
    }
  }, mounted () {
    this.init()
  },
  activated () {
    this.init()
  }, methods: {
    init () {
      localStorage.setItem('setStep', 2)
      localStorage.setItem('resetCode', 4)
      this.teamid = this.$route.query.id;
      this.getList()
    },
    getList () {
      // musicGroupId: this.teamid,
      getCourseSchedule({ classScheduleType: this.classScheduleType, musicGroupId: this.teamid, rows: this.rules.limit, page: this.rules.page }).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
        }
      })
    },
    gotoPlan () {
      if (this.isSetSalary) {
        this.$message.error('课酬确认后无法编辑')
        return;
      }
      this.$router.push({ path: '/business/coursePlan', query: { id: this.teamid } })
    },
    gotoNext () {
      if (this.isSetSalary) {
        this.$message.error('课酬确认后无法编辑')
        return;
      }
      // 获取课程类型 3.0跳小班课  2.0跳课酬
      let type = localStorage.getItem('chargeTypeId');
      type == 3 ? this.$emit('gotoNav', 3) : this.$emit('gotoNav', 4)

    },
    chioseList (val) {
      this.classScheduleType = val;
      this.getList();
    },
    // 删除乐团所有未上课程
    removeAllCourse () {
      if (this.isSetSalary) {
        this.$message.error('课酬确认后无法编辑')
        return;
      }
      this.$confirm('是否清除所有课程?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deteleAllCourse({ musicGroupId: this.teamid }).then(res => {
          if (res.code == 200) {
            this.$message.success('删除成功');
            this.getList();
          }
        })

      })
    },
  }
}
</script>
<style lang="scss" scoped>
.setBtn {
  width: 120px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  border-radius: 4px;
  color: #fff;
  background-color: #444;
  cursor: pointer;
  margin: 20px 0;
}
</style>
