<template>
  <div class="teacher">
    <div class="header">
      <el-row>
        <el-col :span="6">
          <label>老师：</label>{{detail.type | teacherType}} {{detail.name}}
        </el-col>
        <el-col :span="6">
          <label>微信号：</label> {{detail.alias}}
        </el-col>
        <el-col :span="6">
          <label>二维码：</label>
          <a :href="detail.qr">
            <img class="avatar" :src="detail.qr"/>
          </a>
        </el-col>
        <el-col :span="6">
          <label>老师状态：</label>{{detail.status === 0 ? '正常' : '禁用'}}
        </el-col>
      </el-row>
      <el-row v-if="detail.user_info">
        <el-col :span="6">
          <label>绑定用户：</label>
          <a :href="detail.user_info.avatar" target="_blank">
            <img class="avatar" :src="detail.user_info.avatar"/>
          </a>
          {{detail.user_info.nickname}}(ID:{{detail.user_info.user_id}})
        </el-col>
      </el-row>
    </div>
    <el-table
      :data="list"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="班级ID">
      </el-table-column>
      <el-table-column
        prop="periods_title"
        label="期数名称">
      </el-table-column>
      <el-table-column
        prop="join_num"
        label="参加人数">
      </el-table-column>
      <el-table-column
        prop="max_join_num"
        label="最大班级人数">
      </el-table-column>
      <el-table-column
        prop="start_at"
        label="开始时间">
      </el-table-column>
      <el-table-column
        prop="created_at"
        label="创建时间">
      </el-table-column>
    </el-table>
    <page :total="total" :limit="limit" @pageChange="onPageChange"/>
  </div>
</template>

<script>
import {getTeacherDetailApi} from "../../service/api";
import {TEACHERTYPE} from "../../util/wordbook";
import page from '../framework/page'
  export default {
    name: "index",
    components:{
      page
    },
    data(){
      return {
        list:[],
        id: '',
        detail: {},
        total: 0,
        limit: 10,
        nowPage: 1
      }
    },
    methods:{
      onPageChange(val){
        this.nowPage = val
        this.getTeacherDetail()
      },
      getTeacherDetail(){
        let id = this.id;
        let json = {
          limit: this.limit,
          page: this.nowPage
        }
        getTeacherDetailApi(id, json).then((res)=>{
          if (res.class_list) {
            this.list = res.class_list.list || [];
            this.total = res.class_list.total;
          }
          this.detail = res;
        })
      }
    },
    filters:{
      teacherType(value){
        return TEACHERTYPE[value]
      }
    },
    mounted(){
      this.id = this.$route.params.id;
      this.getTeacherDetail();
    }
  }
</script>

<style scoped lang="less">
  .teacher {
    padding: 20px 0;
  }
  .avatar {
    width: 80px;
    margin-right: 5px;
  }
  .header {
    padding: 0 20px;
    margin-bottom: 20px;
  }
  .el-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    color: #666;
    font-size: 16px;
    label{
      margin-right: 10px;
    }
  }
  .el-col{
    /*height: 50px;*/
    display: flex;
    justify-content: flex-start;
    align-items: center;
    img{
      width: 50px;
      border-radius: 100px;
    }
    label{
      color: #5982e6;
    }
  }
</style>
