<template>
  <div class="app-container">
    <el-form
      :model="queryForm"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="70px"
    >
      <el-form-item label="异动时间" prop="daterange">
        <el-date-picker
          v-model="daterange"
          type="daterange"
          align="right"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-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>

      <!-- <el-table :data="changeList" :span-method="objectSpanMethod" v-loading="loading" border :row-style="{ height: '30px' }" :cell-style="{ padding: '0' }" style="font-size: 14px" stripe >
      <el-table-column prop="gradeName" label="类型" width="240" align="center"></el-table-column>
      <el-table-column prop="classNum" label="人数" align="center"></el-table-column>
    </el-table> -->

      <div id="table" v-cloak>
        <el-row align="center" v-loading="loading" v-cloak>
          <el-row>
            <el-col class="background all" :span="4">类型</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="background all" :span="12">人数</el-col>
              </el-row>
            </el-col>
          </el-row>

          <el-row>
            <el-col class="all" :span="4">转入</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="all" :span="12" v-if="changeList[0]">{{
                  changeList[0].into
                }}</el-col>
              </el-row>
            </el-col>
          </el-row>

          <el-row>
            <el-col class="all" :span="4">转入借读</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="all" :span="12" v-if="changeList[0]">{{
                  changeList[0].intoBorrowing
                }}</el-col>
              </el-row>
            </el-col>
          </el-row>

          <el-row>
            <el-col class="all" :span="4">转出</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="all" :span="12" v-if="changeList[0]">{{
                  changeList[0].out
                }}</el-col>
              </el-row>
            </el-col>
          </el-row>

          <el-row>
            <el-col class="all" :span="4">转出借读</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="all" :span="12" v-if="changeList[0]">{{
                  changeList[0].outBorrowing
                }}</el-col>
              </el-row>
            </el-col>
          </el-row>

          <el-row>
            <el-col class="all" :span="4">退学/注销学籍</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="all" :span="12" v-if="changeList[0]">{{
                  changeList[0].dropped
                }}</el-col>
              </el-row>
            </el-col>
          </el-row>

          <el-row>
            <el-col class="all" :span="4">合计</el-col>
            <el-col :span="20">
              <el-row>
                <el-col class="all" :span="12" v-if="changeList[0]">{{
                  changeList[0].all
                }}</el-col>
              </el-row>
            </el-col>
          </el-row>
        </el-row>
      </div>
    </el-form>
    
  </div>
</template>
  
  <script>
import { getChangeList } from "@/api/smartSchool/logisticsManage/affairStatistics";

export default {
  name: "index",
  data() {
    return {
      // 查询表单
      //数据
      queryForm: {
        out: "",
        all: "",
        into: "",
        outBorrowing: "",
        dropped: "",
        intoBorrowing: "",
      },
      // 遮罩层
      loading: false,
      total: 0,
      // 信息列表
      changeList: [],
      classYear: "2022",
      daterange:[],
      thismon:'',
      nextmon:'',
      data:'',
      data1:'',
      title: ["转入", "转入借读", "转出", "转出借读", "退学/注销学籍", "合计"],
    };
  },
  created() {
    this.getToday();
    this.daterange.push(this.thismon,this.nextmon);
    this.data = this.daterange[0];
    this.data1 = this.daterange[1];
    this.getList();
  }, 
  methods: {
    // 获取列表
    getList() {
      this.loading = true;
      getChangeList(this.data,this.data1).then((response) => {
          this.loading = false;
          this.changeList = response.rows;
          this.total = response.total;
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索按钮
    handleQuery() {
      // console.log(this.daterange)
      if (this.daterange.length == "0") {
        this.$alert("请输入要查询的时间！", "提示", {
          confirmButtonText: "确定",
          type: "waring",
        });
      } else {
        this.data = this.daterange[0];
        this.data1 = this.daterange[1];
      }
      this.getList();
    },
    // 重置按钮
    resetQuery() {
      this.queryForm = {
        out: "",
        all: "",
        into: "",
        outBorrowing: "",
        dropped: "",
        intoBorrowing: "",
      };
      this.resetForm("queryForm");
      this.daterange=[];
      this.daterange[0]= this.thismon;
      this.daterange[1]=this.nextmon;
      this.handleQuery();
    },
    // 导出按钮
    handleExport() {
      this.throttle(() => {
        this.download(
          "/Educational/variation/exportGrade",
          {
            data: this.daterange[0],
            data1: this.daterange[1],
          },
          `异动统计${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,
          };
        }
      }
    },

    getToday() {
      //获取当前日期
      let myDate = new Date();
      console.log(myDate)
      let nowY = myDate.getFullYear();
      let nowM = myDate.getMonth() + 1;
      let nowD = new Date(new Date().getFullYear(), new Date().getMonth() +1 , 0).getDate();
      this.nextmon=nowY + "-" + nowM + "-" +nowD; //当前月份后一个月日期
      this.thismon=nowY + "-" +(nowM < 10 ? "0" + nowM : nowM) + "-" +'1'; //当月日期
    },
  },
};
</script>
  
  <style scoped>
[v-clock] {
  display: none;
}
#table {
  margin: auto;
}
.background {
  background-color: #f8f8f9;
}
.all {
  line-height: 40px;
  height: 4px;
  text-align: center;
  border-bottom: 1px solid #dfe6ec;
  word-break: break-word;
  color: #515a6e;
  height: 40px;
  font-size: 13px;
  border: 1px solid #e8e7e7;
}
</style>
  