<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="classYear" clearable type="year" value-format="yyyy" style="width: 100%"
                        placeholder="选择年度"></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <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'


export default {
  name: "index",
  data() {
    return {
      // 查询表单
      //数据
      queryForm: {
        gradeValue: '',
        gradeName: '',
        classNum: '',
        boyNum: '',
        girlNum: '',
        allNum: '',
      }
      ,
      // 遮罩层
      loading: false,
      total: 0,
      // 信息列表
      gradeList: [],
      classYear: '2022',
      gradeName: ['高中一年级', '高中二年级', '高中三年级']
    }
  },

  created() {
    this.getNowYear();
    this.getList();
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true;
      getGradeList(this.classYear).then(response => {
        this.loading = false;
        this.gradeList = response.rows;
        this.total = response.total;
      }).catch(err => {
        this.loading = false;
      })
    },

    // 搜索按钮
    handleQuery() {
      this.getList();
    },
    // 重置按钮
    resetQuery() {
      this.getNowYear();
      this.getList();
    },
    // 导出按钮
    handleExport() {
      this.throttle(() => {
        this.download('/Educational/grade/exportGrade/' + this.classYear, {
          ...this.queryForm
        }, `年级信息统计${new Date().getTime()}.xlsx`)
      })
    },
    //获得当前年份
    getNowYear() {
      this.classYear = new Date().getFullYear() + '';
    },
    //合并单元格
    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>
