<template>
  <div class="app-container">
    <el-form :model="queryForm" ref="queryForm" size="small" :inline="true" label-width="70px">
      <el-form-item label="学年" prop="classYear">
        <el-date-picker v-model="queryForm.classYear" type="year" @change="getList" format="yyyy" value-format="yyyy"
          placeholder="选择年度"></el-date-picker>

      </el-form-item>
      <el-form-item>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:assets:export']">导出
        </el-button>
      </el-form-item>

      <div id="table">
        <el-row>
          <el-row v-for="(item, index) in gradeList" :label="item" :key="index" align="center" v-loading="loading">
            <el-col class="first-level-title all" :span="4">{{ gradeName[index] }}</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="second-level-title all" :span="12">班级数</el-col>
                <el-col class="cell all" :span="12">{{ gradeList[index].classNum }}</el-col>
              </el-row>
              <el-row>
                <el-col class="second-level-title all" :span="12">人数</el-col>
                <el-col class="cell all" :span="12">{{ gradeList[index].allNum }}</el-col>
              </el-row>
              <el-row>
                <el-col class="second-level-title all" :span="12">男生</el-col>
                <el-col class="cell all" :span="12">{{ gradeList[index].boyNum }}</el-col>
              </el-row>
              <el-row>
                <el-col class="second-level-title all" :span="12">女生</el-col>
                <el-col class="cell all" :span="12">{{ gradeList[index].girlNum }}</el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-row>
      </div>
    </el-form>
  </div>
</template>

<script>
import {
  getGradeList,
} from '@/api/smartSchool/logisticsManage/affairStatistics'
import { getNewYear } from "@/api/smartSchool/teachAffairAdministration/affairClassView/index.js";



export default {
  name: "index",
  data() {
    return {
      
      //数据
      queryForm: {
        gradeValue: '',
        gradeName: '',
        classNum: '',
        boyNum: '',
        girlNum: '',
        allNum: '',
        classYear: '',
      }
      ,
      // 遮罩层
      loading: false,
      total: 0,
      // 信息列表
      gradeList: [],

      gradeName: ['高中一年级', '高中二年级', '高中三年级']
    }
  },

  created() {
    this.newYear();

  },
  methods: {
    //获得当前年份
    newYear() {
      getNewYear().then((res) => {
        this.queryForm.classYear = res.schoolYear + '';
        console.log('this.queryForm.classYear', typeof this.queryForm.classYear);
        this.getList();
      });
    },

    getList() {
      this.loading = true;
      const classYear = this.queryForm.classYear;
      console.log('his.queryForm.classYear', this.queryForm.classYear);
      getGradeList(classYear)
        .then(response => {
          this.loading = false;
          this.gradeList = response.rows;
          this.total = response.total;
        })
        .catch(error => {
          // ...
        });
    },


    // 导出按钮
    handleExport() {
      this.throttle(() => {
        this.download('/Educational/grade/exportGrade/' + this.classYear, {
          ...this.queryForm
        }, `年级信息统计${new Date().getTime()}.xlsx`)
      })
    },

    //合并单元格
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex === 0 || rowIndex === 4 || rowIndex === 8) {
          return {
            rowspan: 4,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    },
  }
}
</script>

<style scoped>
#table {
  width: 85%;
}

.all {
  border-bottom: 1px solid #dfe6ec;
  word-break: break-word;
  background-color: #f8f8f9;
  color: #515a6e;
  height: 40px;
  font-size: 13px;
  border: 1px solid #e8e7e7;
}

.first-level-title {
  /* background-color: blue; */
  height: 160px;
  text-align: center;
  line-height: 160px;
}

.second-level-title {
  /* background-color: red; */
  height: 40px;
  text-align: center;
  line-height: 40px;
}

.cell {
  /* background-color: yellow; */
  height: 40px;
  text-align: center;
  line-height: 40px;
}

.background {
  background-color: #f8f8f9;
}
</style>
