
<template>
  <div class="studentvip">
    <!-- 搜索类型 -->
    <save-form
      :inline="true"
      class="searchForm"
      :model="searchForm"
      @submit="onSearch"
      save-key="studentDetail-studentVip"
    >
      <el-form-item>
        <el-input
          placeholder="课程名称"
          clearable
          @keyup.enter.native="onSearch"
          v-model.trim="searchForm.vipGroupName"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button native-type="submit" type="danger">搜索</el-button>
      </el-form-item>
    </save-form>

    <div class="tableWrap">
      <el-table
        :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
        :data="tableList"
      >
        <el-table-column label="VIP课程组编号" align="center" prop="vipGroupId">
          <template slot-scope="scope">
            <el-button type="text" @click="gotoVip(scope.row.vipGroupId)">
              <copy-text>{{ scope.row.vipGroupId }}</copy-text>
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="VIP课程组名称"
          align="center"
          prop="vipGroupName"
        >
          <template slot-scope="scope">
            <!-- class="vipGroupName" -->
            <div >
              <el-button type="text"  @click="gotoVip(scope.row.vipGroupName)">
                <copy-text width='110px'>{{ scope.row.vipGroupName }}</copy-text>
              </el-button>
            </div>
          </template>
        </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="eduTeacherName"
        ></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="开课时间"
          width="150"
          align="center"
          prop="courseStartDate"
        >
          <template slot-scope="scope">{{
            scope.row.courseStartDate | dateForMinFormat
          }}</template>
        </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
        save-key="studentDetail-studentVip"
        sync
        :total.sync="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"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
        >
          <el-table-column prop="courseDate" label="时间" align="center">
            <template slot-scope="scope">{{
              scope.row.courseDate | dateForMinFormat
            }}</template>
          </el-table-column>
          <el-table-column
            prop="classGroupName"
            label="课程名称"
            align="center"
          ></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>
        <pagination
          :total="studentInfo.total"
          :page.sync="studentInfo.page"
          :limit.sync="studentInfo.limit"
          :page-sizes="studentInfo.page_size"
          @pagination="onCourse"
        />
      </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,
        vipGroupName: null,
      },
      checkIndex: null, // 选中的课程
      dialogTableVisible: false,
      searchLsit: [],
      tableList: [],
      courseList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      studentInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      dialogTitle: "",
      gridData: [],
      userId: "",
      activeRow: null,
    };
  },
  created() {
    this.userId = this.$route.query.userId || null;
  },
  mounted() {
    this.userId = this.$route.query.userId || null;
    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) {
      if (row.vipGroupId) {
        this.activeRow = row;
      }
      findStudentVipGroups({
        vipGroupId: this.activeRow.vipGroupId,
        studentId: this.userId,
        page: this.studentInfo.page,
        rows: this.studentInfo.limit,
      }).then((res) => {
        this.dialogTitle = this.activeRow.vipGroupName;
        if (res.code == 200) {
          this.studentInfo.total = res.data.total;
          this.gridData = res.data.rows;
          this.dialogTableVisible = true;
        }
      });
    },
    onSearch() {
      this.pageInfo.page = 1;
      this.getCourseList();
    },
    gotoVip(str) {
      this.$router.push({
        path: "/vipManager/vipList",
        query: { search: str },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.vipGroupName {
  width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.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>
