<template>
  <div class="app-container">
    <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <student style="width: 500px; display: inline" @itemlist="itemlists"></student>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查看</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-row :gutter="24">
      <div v-if="itemshow" style="margin: 10px auto; width: 100%">
        <el-table
          :data="actionlist"
          border
          :span-method="arraySpanMethod"
          style="width: 95%; margin: 0 auto"
        >
          <el-table-column prop="categoryName" label="测试分类" align="center"></el-table-column>
          <el-table-column prop="itemName" label="测试项目" align="center"></el-table-column>
          <el-table-column prop="itemFraction" label="动作技能总分" align="center"></el-table-column>
          <el-table-column prop="unifiedStandardScore" label="统一最高得分" align="center"></el-table-column>
          <!-- <el-table-column
            prop="smallStandardScore"
            label="小班最高得分"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="middleStandardScore"
            label="中班最高得分"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="largeStandardScore"
            label="大班最高得分"
            align="center"
          >
          </el-table-column>-->
          <el-table-column prop="itemScoreAll" label="综合得分" align="center"></el-table-column>
          <el-table-column prop="rootCategoryScoreAll" label="国民体质测定总得分" align="center"></el-table-column>
          <el-table-column prop="nationalPhysiqueRank" label="国民体质测定等级" align="center"></el-table-column>
          <el-table-column prop="remark" label="测试目的" align="center"></el-table-column>
          <el-table-column prop="syntheticalAssess" label="备注" align="center"></el-table-column>
        </el-table>
      </div>
    </el-row>
    <el-row :gutter="20" v-if="itemshow2">
      <el-col :span="24" :offset="0">
        <el-card>
          <div slot="header" style="text-align: center">
            <img style="width: 40px" src="@/icons/笑脸.png" alt />

            <div>
              <!-- card title -->
              该学生此批次暂没数据
            </div>
          </div>
          <!-- card body -->
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import student from "@/views/assembly/student.vue";
import { getRoleInfo } from "@/api/system/quality";
import { listAction } from "@/api/system/action";

export default {
  name: "action",
  components: { student },
  data() {
    return {
      itemshow: false,
      itemshow2: false,
      // 显示搜索条件
      showSearch: true,
      actionlist: [],
      spanArr: [],
      position: 0, // 标记位置
      spanArr2: [],
      position2: 0, // 标记位置
      spanArr3: [],
      position3: 0, // 标记位置
      spanArr4: [],
      position4: 0, // 标记位置
      //查询传值
      queryParams: {
        pageNum: 1,
        pageSize: 999,
        // studentId: "10",
        // batchCode: "PC202208030005",
        studentId: "",
        batchCode: ""
      }
    };
  },
  created() {},
  mounted() {},
  methods: {
    actionforeach() {
      this.actionlist.forEach((item, index) => {
        if (index == 0) {
          this.spanArr.push(1);
          this.position = 0;
          this.spanArr2.push(1);
          this.position2 = 0;
          this.spanArr3.push(1);
          this.position3 = 0;
          this.spanArr4.push(1);
          this.position4 = 0;
        } else {
          // 判断当前元素与上一个元素是否相同  也就是判断 a 的值是否相同
          if (
            this.actionlist[index].categoryName ==
            this.actionlist[index - 1].categoryName
          ) {
            // 如果相同 当前位置的 值 加1
            this.spanArr[this.position] += 1;
            this.spanArr.push(0); // 下一个位置 给 0
          } else {
            this.spanArr.push(1); // 不相等下一个位置给 1
            this.position = index; // 标记位置 设置为当前位置
          }

          if (
            this.actionlist[index].categoryName ==
              this.actionlist[index - 1].categoryName &&
            this.actionlist[index].itemScoreAll ==
              this.actionlist[index - 1].itemScoreAll
          ) {
            this.spanArr2[this.position2] += 1;
            this.spanArr2.push(0); // 下一个位置 给 0
          } else {
            this.spanArr2.push(1); // 不相等下一个位置给 1
            this.position2 = index; // 标记位置 设置为当前位置
          }

          if (
            this.actionlist[index].rootCategoryScoreAll ==
              this.actionlist[index - 1].rootCategoryScoreAll &&
            this.actionlist[index].rootCategoryScoreAll ==
              this.actionlist[index - 1].rootCategoryScoreAll
          ) {
            this.spanArr3[this.position3] += 1;
            this.spanArr3.push(0); // 下一个位置 给 0
          } else {
            this.spanArr3.push(1); // 不相等下一个位置给 1
            this.position3 = index; // 标记位置 设置为当前位置
          }

          if (
            this.actionlist[index].nationalPhysiqueRank ==
              this.actionlist[index - 1].nationalPhysiqueRank &&
            this.actionlist[index].nationalPhysiqueRank ==
              this.actionlist[index - 1].nationalPhysiqueRank
          ) {
            this.spanArr4[this.position4] += 1;
            this.spanArr4.push(0); // 下一个位置 给 0
          } else {
            this.spanArr4.push(1); // 不相等下一个位置给 1
            this.position4 = index; // 标记位置 设置为当前位置
          }
        }
      });
    },
    // 合并单元格
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      // 对第一列 相对字段 a  进行合并
      if (columnIndex == 0) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex == 7) {
        const _row = this.spanArr2[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex == 8) {
        const _row = this.spanArr3[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex == 9) {
        const _row = this.spanArr4[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
    },
    //动作发展检测
    listActioninfo() {
      listAction(this.queryParams).then(res => {
        this.spanArr = [];
        this.position = 0;
        this.spanArr2 = [];
        this.position2 = 0;
        this.spanArr3 = [];
        this.position3 = 0;
        this.spanArr4 = [];
        this.position4 = 0;
        if (!res.rows || res.rows == "") {
          this.itemshow2 = true;
          this.itemshow = false;
        } else {
          // res.rows.forEach((e) => {
          //   if (e.rootCategoryScoreAll == null) {
          //     e.rootCategoryScoreAll = 0;
          //   }
          //   if (e.nationalPhysiqueRank == null) {
          //     e.nationalPhysiqueRank = 0;
          //   }
          // });
          //   res.rows.itemCategoryList.forEach((e) => {
          //     e.push(res.rows.categoryName);
          //   });
          this.actionlist = res.rows;
          this.actionforeach();
          this.itemshow = true;
          this.itemshow2 = false;
        }
      });
    },
    itemlists(studentId, batchCode) {
      this.queryParams.studentId = studentId;
      this.queryParams.batchCode = batchCode;
    },
    /** 查看按钮操作 */
    handleQuery() {
      this.spanArr = [];
      this.position = 0; // 标记位置
      this.spanArr2 = [];
      this.position2 = 0; // 标记位置
      this.listActioninfo();
    },

    getList() {
      //用户权限
      getRoleInfo().then(res => {
        this.classqueryParams.kindergartenId = res.data.kindergartenId;
        var user = res.data.roleKeys;
        if (user.includes("enchou")) {
          return;
        } else if (user.includes("teacher")) {
          return;
        } else if (user.includes("parent")) {
          return;
        }
      });
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    }
  }
};
</script>
<style scoped='scss'>
::v-deep .el-card__header {
  border: none;
}
::v-deep .el-form {
  display: inline;
}
</style>
