
<template>
  <div class='studentvip'>
    <!-- <div class="topCard">
      <div class="cardItem" @click="onCheckCourse(item)" :class="[item.id == checkIndex ? 'active' : '']"
       v-for="(item, index) in courseList" :key="index">
        <div class="top">
          <p class='name'>{{ item.name }}</p>
          <p class="type">{{ item.giveTeachMode == 'ONLINE' ? '线上' : '线下' }}</p>
        </div>
        <div class="bottom">
          <div>
            <p class="title">指导老师</p>
            <p>{{ item.userName }}</p>
          </div>
          <div>
            <p class="title">学员数量</p>
            <p>{{ item.studentNum }}</p>
          </div>
          <div>
            <p class="title">剩余课时</p>
            <p>{{ item.totalClassTimes - item.currentClassTimes }}</p>
          </div>
        </div>
      </div>
    </div> -->
    <!-- 搜索类型 -->
    <el-form :inline="true"
             class="searchForm"
             v-model.trim="searchForm">
      <el-form-item>
        <el-input placeholder="课程名称"
                  @keyup.enter.native='onSearch'
                  v-model.trim="searchForm.classGroupName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="onSearch"
                   type="danger">搜索</el-button>
      </el-form-item>
    </el-form>

    <div class="tableWrap">
      <el-table :header-cell-style="{background:'#EDEEF0',color:'#444'}"
                :data='tableList'>
        <el-table-column label="VIP编号"
                         align='center'
                         prop='vipGroupId'>
        </el-table-column>
        <el-table-column label="VIP课名称"
                         align='center'
                         prop="vipGroupName">
        </el-table-column>
        <el-table-column label="VIP课状态"
                         align='center'>
          <template slot-scope="scope">
            {{ scope.row.vipGroupStatus | vipCourseStatus }}
          </template>
        </el-table-column>
        <el-table-column label="指导老师"
                         align='center'
                         prop="teacherName">
        </el-table-column>
        <el-table-column label="班级人数"
                         align='center'
                         prop="studentNum">
        </el-table-column>
        <el-table-column label="活动方案"
                         align='center'
                         prop="activeName">
        </el-table-column>
        <el-table-column label="开课时间"
                         align='center'
                         prop="courseStartDate">
        </el-table-column>
        <el-table-column label="当前课次"
                         align='center'
                         prop="currentClassTimes">
          <template slot-scope="scope">
            {{ scope.row.currentClassTimes }}/{{ scope.row.totalClassTimes }}
          </template>
        </el-table-column>
        <el-table-column label="操作"
                         align='center'>
          <template slot-scope="scope">
            <el-button @click="onCourse(scope.row)"
                       v-permission="'studentManage/findStudentVipGroups'"
                       type="text">课表</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination :total="pageInfo.total"
                  :page.sync="pageInfo.page"
                  :limit.sync="pageInfo.limit"
                  :page-sizes="pageInfo.page_size"
                  @pagination="getCourseList" />

      <el-dialog :title="dialogTitle"
                 :visible.sync="dialogTableVisible">
        <el-table :data="gridData">
          <el-table-column prop="courseDate"
                           label="时间"
                           align='center'
                           width="150"></el-table-column>
          <el-table-column prop="classGroupName"
                           label="课程名称"
                           align='center'
                           width="200"></el-table-column>
          <el-table-column label="课程类型"
                           align='center'>
            <template slot-scope="scope">
              {{ scope.row.teachMode == 'ONLINE' ? '线上' : '线下' }}
            </template>
          </el-table-column>
          <el-table-column prop="courseStatus"
                           align='center'
                           label="课程状态">
            <template slot-scope="scope">
              {{ scope.row.courseStatus |coursesStatus }}
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { findStudentVipGroups, findStudentVipGroupClass, findStudentCourses } from '@/api/studentManager'
export default {
  name: 'studentvip',
  components: { pagination },
  data () {
    return {
      searchForm: {
        studentId: null,
        classGroupName: null
      },
      checkIndex: null, // 选中的课程
      dialogTableVisible: false,
      searchLsit: [],
      tableList: [],
      courseList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      dialogTitle: '',
      gridData: [],
      userId: ''
    }
  },
  created () {
    this.userId = this.$route.query.userId || null;
  },
  mounted () {
    this.searchForm.studentId = this.$route.query.userId
    this.getCourseList()
  },
  activated() {
    this.userId = this.$route.query.userId || null
    this.searchForm.studentId = this.$route.query.userId
    this.getCourseList()
  },
  methods: {
    // onCheckCourse(item) {
    //   this.checkIndex = item.id
    //   this.getList()
    // },
    getCourseList () {
      let params = this.searchForm
      params.rows = this.pageInfo.limit
      params.page = this.pageInfo.page
      findStudentVipGroupClass(params).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.rows
          this.pageInfo.total = res.data.total
        }
      })
    },
    onCourse (row) {
      findStudentVipGroups({ vipGroupId: row.vipGroupId, studentId: this.userId }).then(res => {
        this.dialogTitle = row.vipGroupName
        if (res.code == 200) {
          this.gridData = res.data.rows
          this.dialogTableVisible = true
        }
      })
    },
    onSearch () {
      this.pageInfo.page = 1
      this.getCourseList()
    }
    // getList() {
    //   findStudentCourses({
    //     vipGroupId: this.checkIndex,
    //     rows: this.pageInfo.limit,
    //     page: this.pageInfo.page
    //   }).then(res => {
    //     if(res.code ==200) {
    //       this.tableList = res.data.rows
    //       this.pageInfo.total = res.data.total
    //     }
    //   })
    // }
  }
}
</script>
<style lang="scss">
.studentvip {
  .topCard {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    margin-bottom: 30px;
    .cardItem {
      margin-right: 15px;
      width: 300px;
      height: 130px;
      padding: 20px 24px;
      box-shadow: 0px 8px 20px 0px rgba(0, 0, 0, 0.1);
      box-sizing: border-box;
      border-radius: 6px;
      .top {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin-bottom: 23px;
        .name {
          font-size: 14px;
          color: #323c47;
          font-weight: 500;
        }
        .type {
          font-size: 14px;
          color: #aaa;
        }
      }
      .bottom {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        text-align: center;
        p {
          font-size: 14px;
          color: #444;
        }
        .title {
          color: #aaa;
          margin-bottom: 8px;
        }
      }
    }
    .cardItem.active {
      background-color: #14928a;
      .name {
        font-size: 14px;
        color: #fff;
        font-weight: 500;
      }
      .type {
        font-size: 14px;
        color: #fff;
      }
      .bottom {
        p {
          color: #fff;
        }
        .title {
          color: #fff;
        }
      }
    }
  }
}
</style>