<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="chioseMix"
                   @change="chioseList">
          <el-option v-for='(item,index) in maxClassList'
                     :key="index"
                     :value="item.id"
                     :label="item.name"></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>
      <el-table-column label="课程类型"
                       align="center"
                       width="180">
        <template slot-scope="scope">
          <div>
            {{scope.row.type |coursesType }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="classGroupName"
                       align="center"
                       label="班级名称">
      </el-table-column>
      <el-table-column prop="name"
                       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>
    <div class="btnWrap">
      <div class="setBtn"
           @click="gotoNext">下一步</div>
    </div>
  </div>
</template>
<script>
import { getAllClass, getClassCOurse, deteleAllCourse } from '@/api/buildTeam'
export default {
  name: 'lookCourse',
  props: {
    isSetSalary: {
      type: Boolean,
      required: true
    }
  },
  data () {
    return {
      teamid: '',
      maxClassList: [],
      chioseMix: '',
      tableList: []
    }
  }, mounted () {
    sessionStorage.setItem('setStep', 2)
    sessionStorage.setItem('resetCode', 4)
    this.teamid = this.$route.query.id;
    getAllClass({ musicGroupId: this.teamid }).then(res => {
      if (res.code == 200 && res.data.length > 0) {
        this.maxClassList = res.data;
        this.chioseMix = this.maxClassList[0].id;
        // 发请求获取数据
        getClassCOurse({ classGroupId: this.chioseMix }).then(res => {
          if (res.code == 200) {
            this.tableList = res.data;
          }
        })
      }
    })
  }, methods: {
    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 = sessionStorage.getItem('chargeTypeId');
      type == 3 ? this.$emit('gotoNav', 3) : this.$emit('gotoNav', 4)

    },
    chioseList (val) {
      getClassCOurse({ classGroupId: val }).then(res => {
        if (res.code == 200) {
          this.tableList = res.data;
        }
      })
    },
    // 删除乐团所有未上课程
    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.chioseList(this.maxClassList[0].id)
          }
        })

      })
    },
  }
}
</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>