<template>
  <div class="courseInfo">
    <save-form :inline="true" :model="searchList" @submit="search" save-key='teacherDetail-outCourseList'>
      <el-form-item>
        <el-input
          placeholder="课程组名称"
          clearable
          @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 commGroupStatus"
            :key="index"
            :value="item.value"
            :label="item.label"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" native-type="submit">搜索</el-button>
      </el-form-item>
    </save-form>
    <div class="tableWrap">
      <el-table
        :data="teamList"
        :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
      >
        <el-table-column label="编号" prop="id" align="center">
          <template slot-scope="scope">
            <copy-text>
              {{ scope.row.id }}
            </copy-text>
          </template>
        </el-table-column>
        <el-table-column label="课程组名称" prop="name" align="center">
          <template slot-scope="scope">
            <copy-text>
              {{ scope.row.name }}
            </copy-text>
          </template>
        </el-table-column>
        <el-table-column label="课程组状态" align="center">
          <template slot-scope="scope">{{
            scope.row.status | courseGroup
          }}</template>
        </el-table-column>
        <el-table-column
          label="班级人数"
          prop="studentNum"
          align="center"
        ></el-table-column>
        <el-table-column
          label="课程组时间"
          prop="groupClassesTotalDuration"
          align="center"
        ></el-table-column>
        <el-table-column
          label="消耗时间"
          prop="groupClassesConsumeDuration"
          align="center"
        ></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">{{
            scope.row.firstClassesStartTime | formatterTime
          }}</template>
        </el-table-column>
        <el-table-column label="结束时间" align="center">
          <template slot-scope="scope">{{
            scope.row.lastClassesEndTime | formatTimer
          }}</template>
        </el-table-column>
        <el-table-column label="申请时间" align="center">
          <template slot-scope="scope">{{
            scope.row.createTime | formatterTime
          }}</template>
        </el-table-column>
      </el-table>
      <pagination
      save-key='teacherDetail-outCourseList'
        sync
        :total.sync="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 { findTeacherCourseGroupsWithWeb } from "@/api/teacherManager";
import pagination from "@/components/Pagination/index";
import { commGroupStatus } from "@/utils/searchArray";
import store from "@/store";
export default {
  name: "courseInfo1",
  components: {
    pagination,
  },
  data() {
    return {
      searchList: {
        status: "",
        search: "",
      },
      teamList: [],
      organId: null,
      commGroupStatus: commGroupStatus,
      teacherId: this.$route.query.teacherId,
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 1, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
    };
  },
  activated() {
    this.getList();
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.teacherId = this.$route.query.teacherId;
      findTeacherCourseGroupsWithWeb({
        rows: this.pageInfo.limit,
        page: this.pageInfo.page,
        teacherId: this.teacherId,
        groupStatus: 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" scoped>
// .courseInfo {
//   h4 {
//     margin-bottom: 20px;
//   }
//   .tableMargin {
//     margin-top: 20px;
//   }
// }
</style>
