<template>
  <div class='courseInfo'>
    <el-form :inline="true"
             :model="searchList">
      <el-form-item>
        <el-input placeholder="vip编号或vip名称"
                  @keyup.enter.native='search'
                  v-model.trim="searchList.search"></el-input>
      </el-form-item>
      <el-form-item label="课程状态">
        <el-select v-model.trim="searchList.status"
                   clearable>
          <el-option v-for="(item,index) in vipGroupStatus"
                     :key="index"
                     :value='item.value'
                     :label='item.text'></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="danger"
                   @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <div class="tableWrap tableMargin">
      <el-table :data='teamList'
                :header-cell-style="{background:'#EDEEF0',color:'#444'}">
        <el-table-column label="VIP编号"
                         prop="id">
        </el-table-column>
        <el-table-column label="VIP课名称"
                         prop="name">
        </el-table-column>
        <el-table-column label="VIP课状态">
          <template slot-scope="scope">
            {{ scope.row.status | formatterStatus}}
          </template>
        </el-table-column>
        <el-table-column label="班级人数"
                         prop="studentNum">
        </el-table-column>
        <el-table-column label="课程单价">
          <template slot-scope="scope">
            线上：{{ scope.row.onlineClassesUnitPrice }} <br />
            线下：{{ scope.row.offlineClassesUnitPrice }}
          </template>
        </el-table-column>
        <el-table-column label="活动方案"
                         prop="vipGroupActivityName">
        </el-table-column>
        <el-table-column label="当前课次">
          <template slot-scope="scope">
            <p>{{scope.row.currentClassTimes + '/' + scope.row.totalClassTimes}}</p>
          </template>
        </el-table-column>
        <el-table-column label="月均消耗">
          <template slot-scope="scope">
            {{ scope.row.monthConsumeRate }}%
          </template>
        </el-table-column>
        <el-table-column label="开课时间">
          <template slot-scope="scope">
            {{scope.row.courseStartDate | formatterTime}}
          </template>
        </el-table-column>
        <el-table-column label="截止时间">
          <template slot-scope="scope">
            {{ scope.row.coursesExpireDate | formatTimer }}
          </template>
        </el-table-column>
        <el-table-column label="申请时间">
          <template slot-scope="scope">
            {{scope.row.createTime | formatterTime}}
          </template>
        </el-table-column>
      </el-table>
      <pagination :total="pageInfo.total"
                  :page.sync="pageInfo.page"
                  :limit.sync="pageInfo.limit"
                  :page-sizes="pageInfo.page_size"
                  @pagination="getList" />
    </div>
  </div>
</template>
<script>
// import { getTeacherVipClass } from '@/api/teacherManager'
import { getVipList } from '@/api/vipSeting'
import pagination from '@/components/Pagination/index'
import { vipGroupStatus } from '@/utils/searchArray'
import store from '@/store'
export default {
  name: 'courseInfo1',
  components: {
    pagination
  },
  data () {
    return {
      searchList: {
        status: '',
        search: ''
      },
      teamList: [],
      organId: null,
      vipGroupStatus: null,
      teacherId: this.$route.query.teacherId,
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 1, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      }
    }
  },
  activated () {
    this.teacherId = this.$route.query.teacherId
    this.vipGroupStatus = vipGroupStatus;
    this.getList()
  },
  mounted () {
    this.vipGroupStatus = vipGroupStatus;
    this.getList()
  },
  methods: {
    getList () {
      getVipList({
        rows: this.pageInfo.limit,
        page: this.pageInfo.page,
        teacherId: this.teacherId,
        status: this.searchList.status || null,
        search: this.searchList.search || null
      }).then(res => {
        if (res.code == 200) {
          this.teamList = res.data.rows
          this.pageInfo.total = res.data.total
        }
      })
    },
    search () {
      this.pageInfo.page = 1;
      this.getList();
    }
  },
  filters: {
    formatterTime (val) {
      let result
      if (val) {
        result = val.split(' ')[0];
      } else {
        result = ''
      }
      return result
    },
    formatterStatus (val) {
      let arr = ["未开始", "报名中", "进行中", '取消', '已结束', '报名结束','暂停']
      return arr[val];
    }
  }
}
</script>
<style lang="scss" scope>
.courseInfo {
  h4 {
    margin-bottom: 20px;
  }
  .tableMargin {
    margin-top: 20px;
  }
}
</style>