
<template>
  <div class="box" style="height: calc(100% - 41px)">
    <div class="top-box">
      <div class="topbox-item">
        <div class="topbox-item-left">
          <div class="topbox-itemleft-img"></div>
          <span>不良反应</span>
        </div>
        <div class="topbox-item-content">
          <div class="topbox-itemleft-color">{{ pieData[0].value || 0 }}</div>
          <span>例</span>
        </div>
        <div class="topbox-item-right">
          <div>较去年</div>
          <!-- <span class="spanxia">↑</span> -->
          <span class="spanshang">↓</span>
        </div>
      </div>
      <div class="topbox-item">
        <div class="topbox-item-left">
          <div class="topbox-itemleft-img"></div>
          <span>严重不良反应</span>
        </div>
        <div class="topbox-item-content">
          <div class="topbox-itemleft-color">{{ pieData[1].value || 0 }}</div>
          <span>例</span>
        </div>
        <div class="topbox-item-right">
          <div class="redStyle">较去年</div>
          <span class="spanxia">↑</span>
          <!-- <span class="spanshang">↓</span> -->
        </div>
      </div>
      <div class="topbox-item">
        <div class="topbox-item-left">
          <div class="topbox-itemleft-img"></div>
          <span>发生死亡不良反应</span>
        </div>
        <div class="topbox-item-content">
          <div class="topbox-itemleft-color">{{ pieData[2].value || 0 }}</div>
          <span>例</span>
        </div>
        <div class="topbox-item-right">
          <div class="redStyle">较去年</div>
          <span class="spanxia">↑</span>
          <!-- <span class="spanshang">↓</span> -->
        </div>
      </div>
    </div>
    <div class="footers">
      <div class="lefts">
        <div class="bottom-box" ref="bottom-box"></div>
      </div>
      <div class="rights">
        <div>
          <div class="pt-top">
            <div class="ptleftbox">
              <div class="rectangular1"></div>
            </div>
            <div class="texts">一般不良反应</div>
          </div>
          <div class="pt-top">
            <div class="ptleftbox"></div>
            <div class="boxLine"></div>
            <div class="ptStyle react1">0%</div>
          </div>
        </div>
        <div>
          <div class="pt-top">
            <div class="ptleftbox">
              <div class="rectangular2"></div>
            </div>
            <div class="texts">严重不良反应</div>
          </div>
          <div class="pt-top">
            <div class="ptleftbox"></div>
            <div class="boxLine"></div>
            <div class="ptStyle react2">0%</div>
          </div>
        </div>
        <div>
          <div class="pt-top">
            <div class="ptleftbox">
              <div class="rectangular3"></div>
            </div>
            <div class="texts">发生死亡不良反应</div>
          </div>
          <div class="pt-top">
            <div class="ptleftbox"></div>
            <div class="boxLine"></div>
            <div class="ptStyle react3">0%</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import {
  getCosmeticsBL,
  getMedicalDevicesBL,
  getDrugBL,
} from "@/api/largeScreen";

export default {
  name: "",
  components: {},
  data() {
    return {
      option1: {},
      // echarts
      myChart1: {},
      a1: 0,
      a2: 0,
      a3: 0,
      center: ["50%", "50%"],
      pieData: [
        {
          value: 0,
          name: "一般不良反应",
        },
        {
          value: 0,
          name: "严重不良反应",
        },
        {
          value: 0,
          name: "发生死亡不良反应",
        },
      ],
      total: 0,
    };
  },
  created() {},
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      let newRouter = this.$route.query;
      if (newRouter.type == 1) {
        //药品
        getDrugBL({ name: newRouter.code }).then((res) => {
          res.data.result.forEach((value, index) => {
            this.pieData.forEach((value1, index1) => {
              if (value.reportType == "一般" && value1.name == "一般不良反应") {
                this.pieData[index1].value = value.reportCount;
              }
              if (value.reportType == "严重" && value1.name == "严重不良反应") {
                this.pieData[index1].value = value.reportCount;
              }
              if (
                value.reportType != "一般" &&
                value.reportType != "严重" &&
                value1.name == "发生死亡不良反应"
              ) {
                this.pieData[index1].value = value.reportCount;
              }
            });
          });
          this.$nextTick(() => {
            let chartDom = this.$refs["bottom-box"];
            this.myChart1 = echarts.init(chartDom);
            this.initEcharts();
          });
        });
      }
      if (newRouter.type != 1 && newRouter.type != 2) {
        //化妆品
        getCosmeticsBL({ name: newRouter.code }).then((res) => {
          res.data.result.forEach((value, index) => {
            this.pieData.forEach((value1, index1) => {
              if (value.reportType == "一般" && value1.name == "一般不良反应") {
                this.pieData[index1].value = value.reportCount;
              }
              if (value.reportType == "严重" && value1.name == "严重不良反应") {
                this.pieData[index1].value = value.reportCount;
              }
              if (
                value.reportType != "一般" &&
                value.reportType != "严重" &&
                value1.name == "发生死亡不良反应"
              ) {
                this.pieData[index1].value = value.reportCount;
              }
            });
          });
          this.$nextTick(() => {
            let chartDom = this.$refs["bottom-box"];
            this.myChart1 = echarts.init(chartDom);
            this.initEcharts();
          });
        });
      }
      if (newRouter.type == 2) {
        //医疗器械
        getMedicalDevicesBL({ name: newRouter.code }).then((res) => {
          res.data.result.forEach((value, index) => {
            this.pieData.forEach((value1, index1) => {
              if (
                value.reportType == "严重伤害" &&
                value1.name == "严重不良反应"
              ) {
                this.pieData[index1].value = value.reportCount;
              }
              if (value.reportType == "其他" && value1.name == "一般不良反应") {
                this.pieData[index1].value = value.reportCount;
              }
              if (
                value.reportType != "严重伤害" &&
                value.reportType != "其他" &&
                value1.name == "发生死亡不良反应"
              ) {
                this.pieData[index1].value = value.reportCount;
              }
            });
          });
          this.$nextTick(() => {
            let chartDom = this.$refs["bottom-box"];
            this.myChart1 = echarts.init(chartDom);
            this.initEcharts();
          });
        });
      }
    },
    initEcharts() {
      this.option1 = {
        tooltip: {
          trigger: "item",
          formatter: "{b} : {c} ({d}%)",
          position: "right",
        },
        polar: { center: this.center, color: "#0B3A72" },
        angleAxis: { center: this.center, color: "#0B3A72" },
        radiusAxis: {
          color: "#0B3A72",
          center: this.center,
          min: 10,
          max: 70,
          interval: 10,
          axisLine: {
            show: false,
            lineStyle: {
              color: "#0B3E5E",
              width: 1,
              type: "solid",
            },
          },
          axisLabel: {
            formatter: "{value} %",
            show: false,
            padding: [0, 0, 20, 0],
            color: "#0B3E5E",
            fontSize: 16,
          },
          splitLine: {
            lineStyle: {
              color: "#0B3E5E",
              width: 2,
              type: "solid",
            },
          },
        },
        calculable: true,
        series: [
          {
            color: "#0B3A72",
            center: this.center,
            type: "pie",
            radius: ["9%", "16%"],
            hoverAnimation: false,
            tooltip: { show: false },
            labelLine: {
              normal: {
                show: false,
                length: 30,
                length2: 55,
              },
              emphasis: {
                show: false,
              },
            },
            data: [
              {
                name: "",
                value: 0,
                itemStyle: {
                  normal: {
                    color: "#fff",
                  },
                },
              },
            ],
          },
          {
            center: this.center,
            type: "pie",
            radius: ["96%", "95%"],
            color: "#0B3A72",
            hoverAnimation: false,
            labelLine: {
              normal: {
                show: false,
                length: 30,
                length2: 55,
              },
              emphasis: {
                show: false,
              },
            },
            name: "",
            data: [
              {
                name: "",
                value: 0,
                itemStyle: {
                  normal: {
                    color: "#0B3A72",
                  },
                },
              },
            ],
          },
          {
            center: this.center,
            stack: "a",
            type: "pie",
            radius: ["26%", "68%"],
            roseType: "area",
            zlevel: 10,
            label: {
              normal: {
                show: false,
                formatter: "",
                textStyle: {
                  fontSize: 12,
                },
              },
              emphasis: {
                show: true,
              },
            },
            labelLine: {
              normal: {
                show: false,
                length: 200,
                length2: 55,
              },
              emphasis: {
                show: false,
              },
            },
            data: this.pieData,
          },
        ],
      };

      this.myChart1.setOption(this.option1);
    },
  },
  computed: {},
};
</script>
<style scoped lang='scss'>
.top-box {
  .topbox-item {
    &:nth-child(1) {
      .topbox-itemleft-img {
        background: url("../../../assets/images/daping/buliang1.png");
      }

      .topbox-itemleft-color {
        background: linear-gradient(0deg, #ffffff 0%, #0373e0 100%);
      }
    }

    &:nth-child(2) {
      .topbox-itemleft-img {
        background: url("../../../assets/images/daping/buliang2.png");
      }

      .topbox-itemleft-color {
        background: linear-gradient(0deg, #ffffff 0%, #bf6e35 100%);
      }
    }

    &:nth-child(3) {
      .topbox-itemleft-img {
        background: url("../../../assets/images/daping/buliang3.png");
      }

      .topbox-itemleft-color {
        background: linear-gradient(0deg, #ffffff 0%, #f04f50 100%);
      }
    }

    display: flex;
    align-items: center;
    height: 40px;
    width: 98%;
    background: url("../../../assets/images/daping/toushi.png");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: bottom;

    > div {
      display: flex;
      align-items: center;
    }

    .topbox-item-left {
      margin-left: 20px;
      flex: 1.9;

      .topbox-itemleft-img {
        width: 20px;
        height: 20px;
        background-size: contain;
        background-repeat: no-repeat;
        margin-right: 10px;
      }

      span {
        font-size: 14px;
        font-family: Alibaba PuHuiTi;
        font-weight: 400;
        color: #b7d4f5;
        // line-height: 50px;
      }
    }

    .topbox-item-content {
      flex: 1.5;

      .topbox-itemleft-color {
        max-width: 110px;
        white-space: nowrap;
        /* 不换行 */
        overflow: hidden;
        /* 溢出内容隐藏 */
        text-overflow: ellipsis;
        /* 显示省略号 */
        font-size: 26px;
        font-family: YouSheBiaoTiHei;
        font-weight: 400;
        color: #ffffff;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-right: 5px;
      }

      span {
        font-size: 16px;
        font-family: Alibaba PuHuiTi;
        font-weight: 400;
        color: #b7d4f5;
        // line-height: 50px;
        opacity: 0.5;
      }
    }

    .topbox-item-right {
      flex: 1;
      .redStyle {
        font-size: 16px;
        font-family: Alibaba PuHuiTi;
        font-weight: 400;
        color: #ffffff;
        background: linear-gradient(0deg, #ffffff 0%, #d21b1b 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-right: 5px;
      }
      div {
        font-size: 16px;
        font-family: Alibaba PuHuiTi;
        font-weight: 400;
        color: #ffffff;
        background: linear-gradient(0deg, #ffffff 0%, #26e0c4 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        margin-right: 5px;
      }

      span {
        font-size: 16px;
        font-family: Alibaba PuHuiTi;
        font-weight: 400;
      }

      .spanshang {
        color: #26e0c4;
      }

      .spanxia {
        color: #da1b1b;
      }
    }
  }
}
.footers {
  height: calc(100% - 120px);
  display: flex;

  .lefts {
    height: 100%;
    width: 50%;
    padding: 10px;
    .bottom-box {
      height: 100%;
      width: 100%;
    }
  }
  .rights {
    height: 100%;
    padding-left: 15px;
    width: 50%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
  }
}

.pt-top {
  display: flex;
  align-items: center;
  position: relative;
  .ptleftbox {
    width: 12%;
    height: 100%;
    .rectangular1 {
      height: 8px;
      width: 8px;
      background: #2e87e8;
    }
    .rectangular2 {
      height: 8px;
      width: 8px;
      background: #f0a436;
    }
    .rectangular3 {
      height: 8px;
      width: 8px;
      background: #f35656;
    }
  }
  .texts {
    width: 60%;
    font-size: 16px;
    font-family: Alibaba PuHuiTi;
    font-weight: 400;
    color: #b7d4f5;
  }
  .react1 {
    // font-size: 20px;
    font-family: Alibaba PuHuiTi;
    font-weight: 400;
    color: #2e87e8;
    padding-left: 10px;
  }
  .react2 {
    // font-size: 20px;
    font-family: Alibaba PuHuiTi;
    font-weight: 400;
    color: #f0a436;
    padding-left: 10px;
  }
  .react3 {
    // font-size: 20px;
    font-family: Alibaba PuHuiTi;
    font-weight: 400;
    padding-left: 10px;

    color: #f35656;
  }
  .ptStyle {
    width: 60%;
    margin-top: 5px;
    background: linear-gradient(
      to right,
      rgba(36, 64, 97, 1),
      rgba(36, 64, 97, 0)
    );
  }
  .boxLine {
    position: absolute;
    width: 18px;
    height: 20px;
    border: 1px solid #0e2339;
    border-right: none;
    border-top: none;
    left: 3px;
    top: -5px;
  }
}
</style>
