<template>
  <div>
    <h2 class="title">班主任业绩排行</h2>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="业绩总排行" name="first">
        <el-form ref="searchFirstFrom" inline :model="searchFirstFrom" label-width="100px">
          <el-form-item label="起止日期">
            <el-date-picker
              v-model="searchFirstFrom.dateValue"
              unlink-panels
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="searchFirstPage">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="searchFirstPage()">
              搜索
            </el-button>
          </el-form-item>
        </el-form>
        <el-table
          :data="firstList" 
          style="width: 100%">
          <el-table-column
            label="班主任名字"
          >
          <template slot-scope="scope">
            <!-- <el-button type="text" @click="nameClick(scope.row)">   -->
              {{scope.row.teacher_name}}
              <!-- </el-button> -->
          </template>
          </el-table-column>
          <el-table-column
            prop="total_money"
            label="销售额" sortable 
          >
          </el-table-column>
          <el-table-column
            prop="three_month"
            label="季课" sortable
          >
          </el-table-column>
          <el-table-column
            prop="one_year"
            label="年课" sortable
          >
          </el-table-column>
          <el-table-column
            prop="two_year"
            label="2年课" sortable
          >
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="业绩按天排行" name="second">
        <el-form ref="searchSecondFrom" inline :model="searchSecondFrom" label-width="100px">
          <el-form-item label="起止日期">
            <el-date-picker
              v-model="searchSecondFrom.dateValue"
              unlink-panels
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="searchSecondPage">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="searchSecondPage()">
              搜索
            </el-button>
          </el-form-item>
        </el-form>
        <el-table
          :data="secondList"
          style="width: 100%">
          <el-table-column
            prop="cur_date"
            label="时间" sortable 
          >
          </el-table-column>
          <el-table-column
            label="班主任名字"
          >
           <template slot-scope="scope">
            <!-- <el-button type="text" @click="nameClick(scope.row)">   -->
              {{scope.row.teacher_name}}
              <!-- </el-button> -->
          </template>
          </el-table-column>
          <el-table-column
            prop="total_money"
            label="销售额" sortable  
          >
          </el-table-column>
          <el-table-column
            prop="three_month"
            label="季课" sortable 
          >
          </el-table-column>
          <el-table-column
            prop="one_year"
            label="年课" sortable 
          >
          </el-table-column>
          <el-table-column
            prop="two_year"
            label="2年课" sortable 
          >
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <class-dialog :dialogObj="dialogObj"></class-dialog>
  </div>
</template>

<script>
    import {getTeacherRankListApi,getTeacherDayRankListApi} from "../../service/api";
     import classDialog from './dialog'
    export default {
      name: "index",
      data(){
        return {
          activeName: 'first',
          firstList: [],
          secondList: [],
          searchFirstFrom: {
            dateValue:[]
          },
          searchSecondFrom:{
            dateValue:[]
          },
           dialogObj:{
            show:false,
            title:'售卖课程',
            id:"",
            time:""
        },
        }
      },
       components:{
      classDialog,
    },
      mounted(){
        this.defaultTime();
        this.searchFirstPage();
      },
      methods: {
        a(a,b){
          return a-b
        },
        handleClick(tab) {
          let _name = tab.name
          if (_name === 'first') {
            this.searchFirstPage();
          } else {
            this.searchSecondPage();
          }
        },
        searchFirstPage(){
          let json = {}
          if(this.searchFirstFrom.dateValue){
            json = {
              start_at:this.searchFirstFrom.dateValue[0],
              end_at:this.searchFirstFrom.dateValue[1]
            };
          }
           console.log(json)
          getTeacherRankListApi(json).then(res=>{
            this.firstList = res;
          })
        },
        searchSecondPage(){
          let json = {}
          if(this.searchSecondFrom.dateValue){
            json = {
              start_at:this.searchSecondFrom.dateValue[0],
              end_at:this.searchSecondFrom.dateValue[1]
            };
          }
          getTeacherDayRankListApi(json).then(res=>{
            this.secondList = res;
          })
        },
        defaultTime(){
        let date = new Date();
        let year = date.getFullYear();
        let Month = date.getMonth()+1;
        if(Month < 10){
          Month = `0${Month}`
        }
        let Day = date.getDate();
        if(Day<10)Day = `0${Day}`
        let star = `${year}-${Month}-01`;
        let end = `${year}-${Month}-${Day}`
        this.searchFirstFrom.dateValue = [star,end]
        this.searchSecondFrom.dateValue = [star,end]
      },
      nameClick(val){
        console.log(val)
          this.dialogObj.show=true;
      },
      }
    }
</script>

<style scoped>
  .title {
    font-size: 26px;
    font-weight: 400;
    line-height: 1;
    margin: 40px;
  }
</style>
