<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>
        <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" class="card-box" style>
        <el-card>
          <div slot="header" style="text-align: center; font-size: 20px">
            <span>体测达标分析</span>
          </div>
          <div style="margin-left: 50px; text-align: center; margin-top: 20px">
            <span>幼儿园名称:</span>
            <span style="margin-left: 20px; margin-right: 10px">
              {{
              analysislist.kindergartenName
              }}
            </span>

            <span style="margin-left: 50px">幼儿园性质:</span>
            <span style="margin-left: 20px; margin-right: 20px">
              {{
              analysislist.kindergartenType == type.dictValue
              ? type.dictLabel
              : type2.dictLabel
              }}
            </span>

            <span style="margin-left: 50px">参与体测人数:</span>
            <span style="margin-left: 20px">
              {{
              analysislist.testItemStudentCount
              }}
            </span>
            人
            <div style="display: flex; margin-top: 40px">
              <div slot="header" style="width: 50%; text-align: center; font-size: 18px">
                <span class="title">本园参加体测各年龄阶段人数分部</span>
                <div
                  id="main"
                  style="
                    width: 500px;
                    height: 300px;
                    margin: 0 auto;
                    padding-top: 40px;
                  "
                ></div>
              </div>

              <div
                slot="header"
                style="
                  width: 50%;
                  text-align: center;
                  font-size: 18px;
                  position: relative;
                "
              >
                <span class="title">国民体质测定达标率(%)</span>
                <span>
                  <span
                    style="
                      position: absolute;
                      top: 58%;
                      left: 0%;
                      font-size: 25px;
                      text-align:center;
                    width:100%;
                    "
                  >{{ analysislist.standardRate }}%</span>
                  <span
                    style="
                      position: absolute;
                      top: 67%;
                      font-size: 16px;
                      left:0;
                      text-align:center;
                    width:100%;
                    "
                  >达标率</span>
                </span>
                <div
                  id="main2"
                  style="
                    width: 500px;
                    height: 300px;
                    margin: 0 auto;
                    padding-top: 20px;
                  "
                ></div>
              </div>
            </div>
          </div>
        </el-card>
      </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 { tKindergartenInfo } from "@/api/system/kindergartenInfo";
import { getRoleInfo } from "@/api/system/quality";
import { KindergartenPhysicalTestanalysis } from "@/api/system/KindergartenPhysicalTest";
import Kindergarten from "../../assembly/kindergarten.vue";

export default {
  name: "KindergartenPhysicalTest",
  components: { Kindergarten },
  data() {
    return {
      itemshow: false,
      itemshow2: false,
      // 显示搜索条件
      showSearch: true,
      kindergartenType: "kindergarten_type",
      type: {},
      type2: {},
      analysislist: [],
      //查询传值
      analysisqueryParams: {
        kindergartenId: "",
        batchCode: ""
        // kindergartenId: "18",
        // batchCode: "PC202208030005",
      }
    };
  },
  mounted() {},
  created() {
    this.getList();
  },
  methods: {
    handleQuery() {
      this.analysisinfo();
    },
    kinbatlist(kindergartenId, batchCode) {
      this.analysisqueryParams.kindergartenId = kindergartenId;
      this.analysisqueryParams.batchCode = batchCode;
      if (batchCode == "请选择批次") {
        this.analysisqueryParams.batchCode = "";
      }
    },

    analysisinfo() {
      KindergartenPhysicalTestanalysis(this.analysisqueryParams).then(res => {
        if (res.data == [] || !res.data) {
          this.itemshow2 = true;
          this.itemshow = false;
        } else {
          this.analysislist = res.data;
          this.options();
          var app = {};

          var myChart = echarts.init(document.getElementById("main"));
          var option;

          const posList = [
            "left",
            "right",
            "top",
            "bottom",
            "inside",
            "insideTop",
            "insideLeft",
            "insideRight",
            "insideBottom",
            "insideTopLeft",
            "insideTopRight",
            "insideBottomLeft",
            "insideBottomRight"
          ];
          app.configParameters = {
            rotate: {
              min: 0,
              max: 90
            },
            align: {
              options: {
                left: "left",
                center: "center",
                right: "right"
              }
            },
            verticalAlign: {
              options: {
                top: "top",
                middle: "middle",
                bottom: "bottom"
              }
            },
            position: {
              options: posList.reduce(function(map, pos) {
                map[pos] = pos;
                return map;
              }, {})
            },
            distance: {
              min: 0,
              max: 100
            }
          };
          app.config = {
            rotate: 0,
            align: "center",
            verticalAlign: "middle",
            position: "top",
            distance: 15,
            onChange: function() {
              const labelOption = {
                rotate: app.config.rotate,
                align: app.config.align,
                verticalAlign: app.config.verticalAlign,
                position: app.config.position,
                distance: app.config.distance
              };
              myChart.setOption({
                series: [
                  {
                    label: labelOption
                  },
                  {
                    label: labelOption
                  },
                  {
                    label: labelOption
                  },
                  {
                    label: labelOption
                  }
                ]
              });
            }
          };
          const labelOption = {
            show: true,
            position: app.config.position,
            distance: app.config.distance,
            align: app.config.align,
            verticalAlign: app.config.verticalAlign,
            rotate: app.config.rotate,
            formatter: "{c}",
            fontSize: 16,
            rich: {
              name: {}
            }
          };
          option = {
            tooltip: {
              trigger: "axis",
              axisPointer: {
                type: "shadow"
              }
            },
            legend: {
              data: ["男", "女"]
            },
            xAxis: [
              {
                type: "category",
                axisTick: { show: false },
                data: ["3-4岁", "4-5岁", "5-6岁", "6岁以上"]
              }
            ],
            yAxis: [
              {
                type: "value"
              }
            ],
            series: [
              {
                name: "男",
                type: "bar",
                barGap: 0,
                color: "#60C5F1",
                label: labelOption,
                emphasis: {
                  focus: "series"
                },
                data: [
                  this.analysislist.threeAndFourMaleCount,
                  this.analysislist.fourAndFiveMaleCount,
                  this.analysislist.fiveAndSixMaleCount,
                  this.analysislist.sixAndMoreMaleCount
                ]
              },
              {
                name: "女",
                type: "bar",
                color: "#98E0AD",
                label: labelOption,
                emphasis: {
                  focus: "series"
                },
                data: [
                  this.analysislist.threeAndFourFeMaleCount,
                  this.analysislist.fourAndFiveFeMaleCount,
                  this.analysislist.fiveAndSixFeMaleCount,
                  this.analysislist.sixAndMoreFeMaleCount
                ]
              }
            ]
          };

          option && myChart.setOption(option);
          this.itemshow = true;
          this.itemshow2 = false;
        }
      });
    },
    options() {
      var chartDom = document.getElementById("main2");
      var myChart = echarts.init(chartDom);
      var option2;

      option2 = {
        tooltip: {
          trigger: "item",
          formatter: function(params) {
            return params.name + ":" + params.data.value + "人";
          }
        },
        legend: {
          top: "10%",
          left: "center"
        },
        series: [
          {
            center: ["50%", "60%"],
            itemStyle: {
              normal: {
                label: {
                  show: true,
                  formatter: "{d}%", //只要百分比
                  position: "inside"
                },
                labelLine: { show: true },
                color: function(colors) {
                  var colorList = [
                    "#5470c6",
                    "#fc8251",
                    "#91cd77",
                    "#ef6567",
                    "#f9c956",
                    "#75bedc"
                  ];
                  return colorList[colors.dataIndex];
                }
              }
            },
            name: "",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center"
            },
            emphasis: {
              label: {
                show: false,
                fontSize: "20",
                fontWeight: "bold"
              }
            },
            labelLine: {
              show: false
            },
            data: [
              {
                value: this.analysislist.thirtyOneScoreCount,
                name: ">31(优秀)"
              },
              {
                value: this.analysislist.twentySevenScoreCount,
                name: "28-31(良好)"
              },
              {
                value: this.analysislist.twentyScoreCount,
                name: "20-27(合格)"
              },
              { value: this.analysislist.twentyCount, name: "<20(不合格)" }
            ]
          }
        ]
      };
      option2 && myChart.setOption(option2);
    },
    getList() {
      tKindergartenInfo(this.kindergartenType).then(res => {
        this.type = res.data[0];
        this.type2 = res.data[1];
      });
      //用户权限
      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'>
::v-deep .el-card__header {
  border: none;
}
::v-deep .el-form {
  display: inline;
}
.title {
  display: block;
  width: 350px;
  margin: 0 auto;
  line-height: 35px;
  background-color: #60c5f1;
  color: #fff;
  font-size: 15px;
  border-radius: 20px;
}
</style>
