<template>
  <div class="page-body">
    <q-tabs v-model="tabCheck" @input="getList" narrow-indicator dense align="left" class="text-primary q-mb-sm">
      <q-tab :ripple="false" :name="1" label="年份统计" />
      <q-tab :ripple="false" :name="2" label="成长率" />
    </q-tabs>
    <div class="col row wrap q-mb-lg">
      <div class="col-3 Sysuser_Date q-mr-lg" style="display:none;">
        <q-field filled dense>
          <template v-slot:control>
            <el-date-picker v-model="msg.YearStr" @change="getList" style="width:100%" value-format="yyyy" size="small"
              type="year" placeholder="选择年">
            </el-date-picker>
          </template>
        </q-field>
      </div>
      <div>
        <q-btn color="accent" class="q-mr-md" size="sm" icon="download" style="margin-top:15px;" label="下载"
          @click="downloadStudentStaticYear" />
      </div>
    </div>
    <yearFirst :dataList="dataList" :tabCheck="tabCheck"></yearFirst>
  </div>
</template>
<script>
  import {
    EduDownLoad
  } from "../../api/common/common";
  import yearFirst from '../sale/yearFirst';
  import {
    GetStudentStaticYear
  } from '../../api/sale/sale';
  import {
    GetStudentStaticYearRate
  } from '../../api/sale/sale';

  export default {
    props: {},
    meta: {
      title: "课程顾问部年度数据统计"
    },
    components: {
      yearFirst
    },
    data() {
      return {
        tabCheck: 1,
        dataList: [],
        msg: {
          YearStr: '',
          rowsPerPage: 0
        }
      }
    },
    created() {

    },
    mounted() {
      let d = new Date();
      this.msg.YearStr = d.getFullYear().toString();
      this.getList();
    },
    methods: {
      //下载文件
      downloadStudentStaticYear() {
        this.loading = true;
        var msg = JSON.parse(JSON.stringify(this.msg));
        var url = "/StudentStat/DownLoadStudentStaticYear";
        var fileName = "课程顾问部年数据统计.xls";
        if (this.tabCheck == 2) {
          url = "/StudentStat/DownLoadStudentStaticYearRate";
          fileName = "课程顾问部年成长率数据统计.xls";
        }
        EduDownLoad(
          url,
          msg,
          fileName, res => {
            this.loading = false;
          }
        );
      },
      //获取数据
      getList() {
        if (this.tabCheck == 1) {
          this.loading = true;
          GetStudentStaticYear(this.msg).then(res => {
            this.loading = false;
            if (res.Code == 1) {
              this.dataList = res.Data;
            }
          })
        } else {
          this.loading = true;
          GetStudentStaticYearRate(this.msg).then(res => {
            this.loading = false;
            if (res.Code == 1) {
              this.dataList = res.Data;
            }
          })
        }
      }

    }
  }
</script>