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

      <el-form-item label="学生性别" prop="studentSex" label-width="70px">
        <el-select v-model="analysisqueryParams.studentSex" clearable placeholder="请选择">
          <el-option v-for="item in sexs" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <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 v-show="itemshow">
      <el-col
        :span="24"
        :offset="0"
        style="
          margin-bottom: 40px;
          font-size: 15px;
          border-bottom: 1px solid #8fd6d9;
        "
      >
        <div class="test" style="height: 90px">
          <div style="text-align: center; line-height: 40px">
            <span>本园幼儿综合体质评估平均得分</span>
          </div>
          <div
            class="el-table--enable-row-hover el-table--medium"
            style="margin: 0 auto; line-height: 40px; text-align: center"
          >
            <div style="display: inline-block">
              <span
                style="
                  position: relative;
                  display: inline-block;
                  text-align: center;
                "
                v-for="(item, index) in firstCategoryScoreList"
                :key="index"
              >
                <span :style="index == 0 ? '' : 'margin: 0 20px'">
                  {{
                  index == 0 ? null : "+"
                  }}
                </span>
                <span>{{ item.categoryName }} ({{ item.avgCategoryFraction }})</span>
              </span>
            </div>
            <div style="display: inline-block; position: relative">
              <span style="margin: 0 20px">=</span>
              <span style="display: inline-block; width: 120px">综合得分({{ totalAvgFraction }})</span>

              <span
                style="
                  display: inline-block;
                  position: absolute;
                  top: 20px;
                  width: 100px;
                  left: 40px;
                  margin: 0 20px;
                "
              ></span>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="24" :offset="0">
        <div style="text-align: center">
          <span>幼儿园综合体质分析图</span>
        </div>
        <div class>
          <div ref="chart" id="chart" style="width: 1000px; height: 600px; margin: 0 auto"></div>
        </div>
      </el-col>
      <el-col :span="24" :offset="0">
        <div style="margin: 0 auto; width: 100%; line-height: 60px">
          <div style="font-size: 12px; width: 100%; overflow: auto; height: 600px">
            <div
              style="
                display: flex;
                text-align: center;
                justify-content: center;
                color: black;
              "
            >
              <div style="border: 0.5px solid #f0f0f0; background: #f5f7fa">
                <div style="width: 90px; line-height: 58px">年龄</div>
              </div>

              <div style="border: 0.5px solid #f0f0f0; background: #f5f7fa">
                <div style="width: 90px; line-height: 58px">平均总分</div>
              </div>

              <div v-for="item in categoryTableNameList" :key="item.prentId">
                <div
                  style="
                    text-align: center;
                    line-height: 30px;
                    border: 1px solid #f0f0f0;
                    background: #f5f7fa;
                    color: black;
                  "
                >{{ item.parentName }}</div>
                <div
                  style="
                    display: flex;
                    line-height: 32px;
                    border: 1px solid #f0f0f0;
                    background: #f5f7fa;
                    color: black;
                  "
                >
                  <div
                    v-for="uitem in item.childrenTableNameList"
                    :key="uitem.categoryId"
                    style="width: 90px"
                  >{{ uitem.categoryName }}</div>
                </div>
              </div>
            </div>
            <div>
              <div
                style="
                  text-align: center;
                  display: flex;
                  justify-content: center;
                  font-size: 14px;
                "
                v-for="item in categoryAgeFractionList"
                :key="item.prentId"
              >
                <div style="border: 1px solid #f0f0f0">
                  <div style="width: 90px; line-height: 50px">{{ item.studentAge }}</div>
                </div>
                <div style="border: 1px solid #f0f0f0">
                  <div
                    style="width: 90px; line-height: 50px; height: 50px"
                  >{{ item.totalAvgFraction }}</div>
                </div>
                <div>
                  <div style="display: flex; line-height: 50px">
                    <div
                      v-for="uitem in item.list"
                      :key="uitem.categoryId"
                      style="
                        width: 90px;
                        border: 0.5px solid #f0f0f0;
                        line-height: 52px;
                        height: 52px;
                      "
                    >{{ uitem }}</div>
                  </div>
                </div>
              </div>
            </div>
            <div></div>
          </div>
        </div>
      </el-col>
    </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 * as echarts from "echarts";
import { getRoleInfo } from "@/api/system/quality";
import { physiqueanalysis } from "@/api/system/physique";
import Kindergarten from "../../assembly/kindergarten.vue";

export default {
  name: "KindergartenPhysicalTest",
  components: { Kindergarten },
  data() {
    return {
      sexs: [
        {
          value: "MALE",
          label: "男"
        },
        {
          value: "FEMALE",
          label: "女"
        }
      ],
      itemshow: false,
      itemshow2: false,
      // 显示搜索条件
      showSearch: true,
      //查询传值
      analysisqueryParams: {
        // kindergartenId: "2",
        // batchCode: "PC202208290002",
        // studentSex: "FEMALE",
        kindergartenId: "",
        batchCode: "",
        studentSex: ""
      },
      categoryTableNameList: [],
      categoryAgeFractionList: [],
      categoryScoreList: [],
      firstCategoryScoreList: [],
      totalAvgFraction: ""
    };
  },
  mounted() {},
  created() {
    this.getList();
    // this.analysisinfo();
  },
  methods: {
    handleQuery() {
      this.analysisinfo();
    },
    kinbatlist(kin, batchCode) {
      var a = kin;
      this.analysisqueryParams.kindergartenId = a;
      this.analysisqueryParams.batchCode = batchCode;
    },

    analysisinfo() {
      physiqueanalysis(this.analysisqueryParams).then(res => {
        if (res.data == [] || !res.data) {
          this.itemshow2 = true;
          this.itemshow = false;
        } else {
          this.totalAvgFraction = res.data.totalAvgFraction;
          this.categoryTableNameList = res.data.categoryTableNameList;
          this.categoryAgeFractionList = res.data.categoryAgeFractionList;
          this.categoryScoreList = res.data.categoryScoreList;
          this.firstCategoryScoreList = res.data.firstCategoryScoreList;
          if (res.data == [] || !res.data) {
            this.itemshow2 = true;
            this.itemshow = false;
          } else {
            var list = [];
            this.categoryTableNameList.forEach(e => {
              e.childrenTableNameList.forEach(el => {
                list.push(el.categoryId);
              });
            });
            this.categoryAgeFractionList.forEach(el => {
              var list1 = list.map(e => {
                var num = 0;
                var number = el.categoryAvgFractionList.findIndex(
                  o => o.categoryId == e
                );
                if (number != -1) {
                  num = el.categoryAvgFractionList[number].avgCategoryFraction;
                }
                return num;
              });
              el.list = list1;
            });
            let seriesData = [];
            let yindicator = [];
            this.categoryScoreList.forEach(el => {
              seriesData.push(el.avgItemFraction);
              if (el.avgCategoryName == null) {
                el.avgCategoryName = "暂无";
              }
              if (this.categoryScoreList.length == 1) {
                yindicator.push({
                  name: el.categoryName,
                  max: el.maxFraction
                });
                yindicator.push({
                  name: "暂无数据",
                  max: 100
                });
                yindicator.push({
                  name: "暂无数据",
                  max: 100
                });
              } else if (this.categoryScoreList.length == 2) {
                yindicator.push({
                  name: el.categoryName,
                  max: el.maxFraction
                });
                yindicator.push({
                  name: "暂无数据",
                  max: 100
                });
              } else {
                yindicator.push({
                  name: el.categoryName,
                  max: el.maxFraction
                });
              }
            });
            var myChart = echarts.init(document.getElementById("chart"));
            let option = {
              //配置维度的最大值
              color: "#D9A508",
              radar: {
                name: {
                  show: true,
                  color: "black"
                },
                center: ["50%", "50%"],
                //   雷达图的指示器，用来指定雷达图中的多个变量（维度）
                indicator: yindicator,
                shape: "polygon" //对雷达图形设置成一个圆形,可选 circle:圆形,polygon:多角形(默认)
              },
              series: [
                {
                  type: "radar",
                  label: {
                    show: true,
                    color: "#D9A508" //显示数值
                  },
                  areaStyle: {}, //每个雷达图形成一个阴影的面积
                  data: [
                    {
                      name: "成绩区域",
                      value: seriesData
                    }
                  ],
                  areaStyle: {
                    color: new echarts.graphic.RadialGradient(0.1, 0.6, 1, [
                      {
                        color: "rgba(255,192,0, 0.8)",
                        offset: 0
                      },
                      {
                        color: "rgba(255,192,0, 0.9)",
                        offset: 1
                      }
                    ])
                  }
                }
              ]
            };
            // 绘制图表
            myChart.setOption(option);
            this.itemshow2 = false;
            this.itemshow = true;
          }
        }
      });
    },
    getList() {
      //用户权限
      getRoleInfo().then(res => {
        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'>
.test {
  /* width: 70%; */
  margin: 0 auto;
  /* background-color: #f0f0f0; */
  color: #27848b;
}
::v-deep .el-form {
  display: inline;
}
</style>
