<template>
  <div style="margin-left: 160px">
    <el-table :data="tableData" :span-method="objectSpanMethod" border style="width: 100%">
      <el-table-column prop="parentclass" label="大类" width="180" align="center"></el-table-column>
      <el-table-column prop="childclass" label="小类" width="140" align="center"></el-table-column>
      <el-table-column prop="subpoint" label="小点" width="140" align="center"></el-table-column>
      <el-table-column prop="scoringelement" label="依据" align="center"></el-table-column>
      <el-table-column prop="awardtime" label="时间" width="160" align="center"></el-table-column>
      <el-table-column prop="score" label="得分" width="100" align="center"></el-table-column>
      <el-table-column prop="childscore" label="小类合计" width="100" align="center"></el-table-column>
      <el-table-column prop="parentscore" label="大类合计" width="100" align="center"></el-table-column>
    </el-table>
  </div>
</template>



<script>
import store from '../../../store'
let Datas = []
let pcArr = []
let ccArr = []
let subArr = []
let pos = 0
export default {
  name: "Statistics",
  data() {
    return {
      tableData: [],
      responseResult: []
    }
  },
  mounted() {
    this.getData();
    this.getMergeLists()
  },
  methods: {
    getData() {
      this.$axios
        .post('/personal/statistics', {
          username: store.state.user.username
        })
        .then(response => {
          if (response !== null){
            this.responseResult = response.data
            console.log(JSON.parse(JSON.stringify(this.responseResult)))
            this.responseResult = JSON.parse(JSON.stringify(this.responseResult))
            this.tableData = this.responseResult
            Datas = this.responseResult
          }
        })
    },
    getMergeLists() {
      pcArr = []; pos = 0;
      for(let i = 0; i < Datas.length; i++) {
        if (i === 0) {
          pcArr.push(1);
        } else {
          if (Datas.at(i).parentclass === Datas.at(i - 1).parentclass) {
            pcArr[pos] += 1;
            pcArr.push(0);
          } else {
            pcArr.push(1);
            pos = i;
          }
        }
      }
      console.log(pcArr)
      ccArr = []; pos = 0;
      for(let i = 0; i < Datas.length; i++) {
        if (i === 0) {
          ccArr.push(1);
        } else {
          if (Datas.at(i).childclass === Datas.at(i - 1).childclass) {
            ccArr[pos] += 1;
            ccArr.push(0);
          } else {
            ccArr.push(1);
            pos = i;
          }
        }
      }
      console.log(ccArr)
      subArr = []; pos = 0;
      for(let i = 0; i < Datas.length; i++) {
        if (i === 0) {
          subArr.push(1);
        } else {
          if (Datas.at(i).subpoint === Datas.at(i - 1).subpoint) {
            subArr[pos] += 1;
            subArr.push(0);
          } else {
            subArr.push(1);
            pos = i;
          }
        }
      }
      console.log(subArr)
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }){
      if ( columnIndex === 0 || columnIndex === 7) {
        const _row = pcArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        }
      }
      if ( columnIndex === 1 || columnIndex === 6) {
        const _row = ccArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        }
      }
      if ( columnIndex === 2) {
        const _row = subArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        }
      }
    }
  }
}
</script>

<style scoped>

</style>
