<template>
  <el-card
    shadow="never"
    class="aui-card--fill"
  >
    <!--  <div class="title">
      欢迎登陆检察阳光码管理系统
    </div> -->
    <!-- 顶部标题 -->
    <div
      class="titleline"
      style="margin-top:0"
    >
      <div
        class="left"
        style="width:100%"
      >
        <img
          src="../../assets/img/logo_tj.png"
          alt=""
          style="width:20px;height:20px"
        >
        部门评价统计
      </div>

    </div>
    <div
      class="top"
      style="margin-top:10px"
    >
      <div
        class="item"
        v-for="item in listTop"
        :key="item.id"
      >
        <div
          class="title"
          style="line-height:25px"
        >{{item.title}}</div>
        <div class="item-content">

          <img
            src="../../assets/img/member_icon_54.png"
            alt=""
            class="title-img"
          >
          <div class="right">
            <div class="num">好：{{item.good}}%</div>
            <div class="num">中：{{item.middle}}%</div>
            <div class="num">差：{{item.bad}}%</div>
          </div>
        </div>

      </div>
    </div>
    <!-- 顶部标题 -->
    <div class="titleline">
      <div class="left">
        <img
          src="../../assets/img/logo_tj.png"
          alt=""
          style="width:20px;height:20px"
        >
        测评案件统计
      </div>
      <div class="right">
        <img
          src="../../assets/img/logo_tj.png"
          alt=""
          style="width:20px;height:20px"
        >
        近一年好差评统计趋势图
      </div>
    </div>
    <!-- 底部图形化 -->
    <div class="bottom">
      <!-- 饼图 -->
      <div style="width:40%;transform: translate3d(0, -10%, 0);">
        <Echarts
          :options="optionHandlingSituation"
          height="500px"
          width="100%"
          ref="pie"
        />
      </div>

      <!-- 柱状 -->
      <div style="width:60%;transform: translate3d(0, -10%, 0);">
        <Echarts
          :options="optionHandlingSituationZhe"
          height="250px"
          width="100%"
          ref="zhexian"
        />
        <Echarts
          :options="optionHandlingSituationZhu"
          height="250px"
          width="100%"
          ref="zhuzi"
        />
      </div>
    </div>

    <!-- <div class="bottom">



      <div style="width:60%;transform: translate3d(0, -10%, 0);">
        <Echarts
          :options="optionHandlingSituationZhe"
          height="470px"
          width="100%"
        />
      </div>
    </div> -->
  </el-card>
</template>

<script>
import Echarts from "../../components/echarts.vue";
export default {
  components: { Echarts },
  data() {
    return {
      optionHandlingSituation: {},
      optionHandlingSituationZhe: {},
      optionHandlingSituationZhu: {},
      flag: false,
      flag2: false,
      listTop: [
        {
          id: 9,
          title: "院领导",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 1,
          title: "第一检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 2,
          title: "第二检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 3,
          title: "第三检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 4,
          title: "第四检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 5,
          title: "第五检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 6,
          title: "第六检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 7,
          title: "第七检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
        {
          id: 8,
          title: "溪口检察部",
          goodnum: 0,
          middlenum: 0,
          bandnum: 0,
          good: "",
          middle: "",
          bad: "",
          totle: 0,
        },
      ],
      listTopPie: [
        {
          id: 9,
          title: "院领导",
          totle: 0,
        },
        {
          id: 1,
          title: "第一检察部",
          totle: 0,
        },
        {
          id: 2,
          title: "第二检察部",
          totle: 0,
        },
        {
          id: 3,
          title: "第三检察部",
          totle: 0,
        },
        {
          id: 4,
          title: "第四检察部",
          totle: 0,
        },
        {
          id: 5,
          title: "第五检察部",
          totle: 0,
        },
        {
          id: 6,
          title: "第六检察部",
          totle: 0,
        },
        {
          id: 7,
          title: "第七检察部",
          totle: 0,
        },
        {
          id: 8,
          title: "溪口检察部",
          totle: 0,
        },
      ],
      data: [],
      listByMonth: [
        /*  {
          id: 1,
          date: "2020-12",
          goodnum: 0,
          middlenum: 20,
          badnum: 0,
        },
        {
          id: 2,
          date: "2021-01",
          goodnum: 156,
          middlenum: 50,
          badnum: 1,
        },
        {
          id: 3,
          date: "2021-02",
          goodnum: 200,
          middlenum: 5,
          badnum: 0,
        },
        {
          id: 4,
          date: "2021-03",
          goodnum: 100,
          middlenum: 1,
          badnum: 5,
        },
        {
          id: 5,
          date: "2021-04",
          goodnum: 132,
          middlenum: 2,
          badnum: 2,
        },
        {
          id: 6,
          date: "2021-05",
          goodnum: 169,
          middlenum: 3,
          badnum: 1,
        },
        {
          id: 7,
          date: "2021-06",
          goodnum: 202,
          middlenum: 8,
          badnum: 10,
        },
        {
          id: 8,
          date: "2021-07",
          goodnum: 188,
          middlenum: 2,
          badnum: 0,
        },
        {
          id: 9,
          date: "2021-08",
          goodnum: 155,
          middlenum: 20,
          badnum: 0,
        },
        {
          id: 10,
          date: "2021-09",
          goodnum: 100,
          middlenum: 20,
          badnum: 0,
        },
        {
          id: 11,
          date: "2021-10",
          goodnum: 200,
          middlenum: 20,
          badnum: 0,
        },
        {
          id: 12,
          date: "2021-11",
          goodnum: 100,
          middlenum: 20,
          badnum: 0,
        }, */
      ],
    };
  },

  created() {
    //  this.getSysInfo();
    this.getInfo();
  },
  mounted() {},
  methods: {
    // 获取信息
    getInfo() {
      this.$http
        .get("/fhjw/fhjwcomment/getCountByDept")
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }

          this.listTop.forEach((ele) => {
            res.data.forEach((eles) => {
              if (ele.title === eles.deptName) {
                ele.goodnum = eles.committeeCountDTO.good;
                ele.middlenum = eles.committeeCountDTO.medium;
                ele.bandnum = eles.committeeCountDTO.bad;
                ele.totle = eles.committeeCountDTO.totalCount;
              }
            });
          });
          console.log("this.list", this.listTop);
        })
        .then(() => {
          this.init();
          this.flag = true;
        })
        .catch(() => {});

      this.$http
        .get("/fhjw/fhjwcomment/getCountByMouth")
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.listByMonth = res.data;
        })
        .then(() => {
          this.flag2 = true;
          this.getZhe();
          this.getZhu();
        })
        .catch(() => {});

      this.$http
        .get("/fhjw/fhjwcomment/getCaseCountByDept")
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }

          this.listTop.forEach((ele) => {
            res.data.forEach((eles) => {
              if (ele.title === eles.deptName) {
                ele.totle = eles.committeeCountDTO.totalCount;
              }
            });
            this.data.push({ value: ele.totle, name: ele.title });
          });
        })
        .then(() => {
          this.getPie();
        })
        .catch(() => {});
    },
    init() {
      this.listTop.forEach((ele) => {
        let totle = ele.goodnum + ele.middlenum + ele.bandnum;
        if (totle === 0) {
          ele.good = 0;
          ele.middle = 0;
          ele.bad = 0;
        } else {
          ele.good = ((ele.goodnum / totle) * 100).toFixed(1);
          ele.middle = ((ele.middlenum / totle) * 100).toFixed(1);
          ele.bad = ((ele.bandnum / totle) * 100).toFixed(1);
        }
      });
    },
    formatterNumber(v) {
      return (v * 1).toFixed(1);
    },
    getSysInfo() {
      this.$http
        .get("/sys/info")
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.sysInfo = res.data;
        })
        .catch(() => {});
    },
    getUpdatePass() {
      this.$http
        .get("/sys/updatePassInfo")
      .then(({ data: res }) => {
        if (res.data !== "") {
          this.$confirm(
            `${res.data}`,
            "密码更新",
            {
              confirmButtonText: "确定",
              type: "warning",
            }
          ).then({

          })
        }
      })
    },
    getPie() {
      console.log("data", this.data);
      this.optionHandlingSituation = {
        tooltip: {
          trigger: "item",
          formatter: "{b} : {c}件({d}%)",
        },
        legend: {
          bottom: 0,
          left: "center",

          data: [
            "院领导",
            "第一检察部",
            "第二检察部",
            "第三检察部",
            "第四检察部",
            "第五检察部",
            "第六检察部",
            "第七检察部",
            "溪口检察部",
          ],
        },

        series: [
          {
            name: "占比",
            type: "pie",
            radius: "50%",
            center: ["50%", "50%"],
            selectedMode: "single",
            data: this.data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
            label: {
              normal: {
                show: true,
                formatter: "{b}: {c}件({d}%)", //自定义显示格式(b:name, c:value, d:百分比)
              },
            },
          },
        ],
      };
    },
    getZhe() {
      let xAxisData = [];
      let goodnumData = [];
      let middlenumData = [];
      let badnumData = [];
      let goodpercentData = [];
      let middlepercentData = [];
      let badpercentData = [];
      console.log("ooopppp", xAxisData, goodnumData, middlenumData, badnumData);
      this.listByMonth.forEach((ele) => {
        xAxisData = xAxisData.concat(ele.createDate);
        goodnumData = goodnumData.concat(ele.good);
        middlenumData = middlenumData.concat(ele.medium);
        badnumData = badnumData.concat(ele.badnum);
        let totle = ele.medium + ele.good + ele.bad;
        goodpercentData = goodpercentData.concat(
          ((ele.good / totle) * 100).toFixed(1)
        );

        middlepercentData = middlepercentData.concat(
          ((ele.medium / totle) * 100).toFixed(1)
        );

        badpercentData = badpercentData.concat(
          ((ele.bad / totle) * 100).toFixed(1)
        );
      });
      console.log("dddddd", xAxisData, goodnumData, middlenumData, badnumData);
      this.optionHandlingSituationZhe = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
          formatter:
            "<div style='width:10px;height:10px;background:#40B27D;display:inline-block;border-radius:50%;margin-right:5px'></div>{a0}:{c0}%<br/>" +
            "<div style='width:10px;height:10px;background:#4B94E4;display:inline-block;border-radius:50%;margin-right:5px'></div>{a1}:{c1}%<br/>" +
            "<div style='width:10px;height:10px;background:#FF7070;display:inline-block;border-radius:50%;margin-right:5px'></div>{a2}:{c2}%",
        },
        color: ["#40B27D", "#4B94E4", "#FF7070"],
        grid: {
          top: "30%",
          left: "5%",
          right: "5%",
          bottom: "15%",
          containLabel: true,
        },

        legend: {
          data: ["好评占比", "中评占比", "差评占比"],
          bottom: 0,
        },
        xAxis: [
          {
            type: "category",
            data: xAxisData,
            axisPointer: {
              type: "shadow",
            },
            axisTick: {
              show: false,
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "占比（%）",
            min: -20,
            max: 100,
            axisLabel: {
              formatter: "{value}",
            },
          },
        ],
        series: [
          {
            name: "好评占比",
            type: "line",
            data: goodpercentData,
          },
          {
            name: "中评占比",
            type: "line",
            data: middlepercentData,
          },
          {
            name: "差评占比",
            type: "line",
            data: badpercentData,
          },
        ],
      };
      this.optionHandlingSituationZhu = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            crossStyle: {
              color: "#999",
            },
          },
          formatter:
            "<div style='width:10px;height:10px;background:#40B27D;display:inline-block;border-radius:50%;margin-right:5px'></div>{a0}:{c0}个<br/>" +
            "<div style='width:10px;height:10px;background:#4B94E4;display:inline-block;border-radius:50%;margin-right:5px'></div>{a1}:{c1}个<br/>" +
            "<div style='width:10px;height:10px;background:#FF7070;display:inline-block;border-radius:50%;margin-right:5px'></div>{a2}:{c2}个",
        },
        color: ["#40B27D", "#4B94E4", "#FF7070"],
        grid: {
          top: "20%",
          left: "5%",
          right: "5%",
          bottom: "15%",
          containLabel: true,
        },

        legend: {
          data: ["好评数量", "中评数量", "差评数量"],
          bottom: 0,
        },
        xAxis: [
          {
            type: "category",
            data: xAxisData,
            axisPointer: {
              type: "shadow",
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            name: "数量(个)",
            min: 0,

            axisLabel: {
              formatter: "{value}",
            },
          },
        ],
        series: [
          {
            name: "好评数量",
            type: "bar",
            data: goodnumData,
          },
          {
            name: "中评数量",
            type: "bar",
            data: middlenumData,
          },
          {
            name: "差评数量",
            type: "bar",
            data: badnumData,
          },
        ],
      };
    },
    getZhu() {
      let legendData = [];
      let goodData = [];
      let middleData = [];
      let badData = [];
      /* this.listByMonth.forEach((ele) => {
        legendData = legendData.push(ele.createDate).reverse();
        goodData = goodData.push(ele.good).reverse();
        middleData = middleData.push(ele.medium).reverse();
        badData = badData.push(ele.bad).reverse();
      }); */
      this.listByMonth.forEach((ele) => {
        legendData = legendData.concat(ele.createDate);
        goodData = goodData.concat(ele.good);
        middleData = middleData.concat(ele.medium);
        badData = badData.concat(ele.bad);
      });
      console.log("么么么么么", badData);
      this.optionHandlingSituationZhu = {
        color: ["#40B27D", "#FFDC60", "#FF7070"],
        //title: { text: "评价统计", left: "center" },
        legend: {
          bottom: 0,
          data: ["好", "中", "差"],
        },
        grid: {
          left: 60,
          right: 60,
        },
        xAxis: {
          type: "category",
          data: legendData,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "好",
            data: goodData,
            type: "bar",
            label: {
              show: true,
              position: "top",
            },
          },
          {
            name: "中",
            data: middleData,
            type: "bar",
            label: {
              show: true,
              position: "top",
            },
          },
          {
            name: "差",
            data: badData,
            type: "bar",
            label: {
              show: true,
              position: "top",
            },
          },
        ],
      };
    },
  },
  activated() {
    //  this.getPie();
    // this.flag = true;
    if (this.flag && this.flag2) {
      this.$refs.zhexian.resize();
      this.$refs.zhuzi.resize();
      this.$refs.pie.resize();
    }
  },
};
</script>
<style lang="less" scoped>
@media screen and (max-width: 1200px) {
  .top {
    display: flex;
    justify-content: space-between;
    .item {
      background: #4f96e1;
      color: #fff;
      display: flex;
      // width: 150px;
      margin-right: 3px;
      flex: 1;
      height: 90px;
      text-align: center;
      vertical-align: middle;
      padding: 10px 10px 0;
      border-radius: 8px;
      font-size: 14px;
      position: relative;
      .num {
        font-size: 8px;
      }
      .item-content {
        position: absolute;
        width: 96%;
        margin: 12px auto 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        justify-content: space-between;
      }
      .title-img {
        width: 25%;
        height: 25%;
        margin: 0 5px;
        //vertical-align: middle;
      }
      .right {
        // margin-left: 5px;
        text-align: right;
      }
      .title,
      .num {
        text-align: left;
      }
    }
  }
  .titleline {
    display: flex;
    line-height: 40px;
    font-size: 18px;
    margin-top: 35px;
    // border-bottom: 1px solid #eee;
    .left {
      width: 40%;
      margin-right: 20px;
      border-bottom: 1px solid #eee;
    }
    .right {
      width: 60%;
      border-bottom: 1px solid #eee;
    }
  }
  .bottom {
    width: 100%;
    display: flex;
    margin-top: 20px;
  }
}
@media screen and (min-width: 1200px) and (max-width: 1399px) {
  .top {
    display: flex;
    justify-content: space-between;
    .item {
      background: #4f96e1;
      color: #fff;
      display: flex;
      // width: 150px;
      margin-right: 3px;
      flex: 1;
      height: 90px;
      text-align: center;
      vertical-align: middle;
      padding: 10px 10px 0;
      border-radius: 8px;
      font-size: 14px;
      position: relative;
      .num {
        font-size: 8px;
      }
      .item-content {
        position: absolute;
        width: 96%;
        margin: 12px auto 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        justify-content: space-between;
      }
      .title-img {
        width: 25%;
        height: 25%;
        margin: 0 5px;
        //vertical-align: middle;
      }
      .right {
        // margin-left: 5px;
        text-align: right;
      }
      .title,
      .num {
        text-align: left;
      }
    }
  }
  .titleline {
    display: flex;
    line-height: 40px;
    font-size: 18px;
    margin-top: 35px;
    // border-bottom: 1px solid #eee;
    .left {
      width: 40%;
      margin-right: 20px;
      border-bottom: 1px solid #eee;
    }
    .right {
      width: 60%;
      border-bottom: 1px solid #eee;
    }
  }
  .bottom {
    width: 100%;
    display: flex;
    margin-top: 20px;
  }
}
@media screen and (min-width: 1400px) and (max-width: 1660px) {
  .top {
    display: flex;
    justify-content: space-between;
    .item {
      background: #4f96e1;
      color: #fff;
      display: flex;
      // width: 150px;
      margin-right: 8px;
      flex: 1;
      height: 90px;
      text-align: center;
      vertical-align: middle;
      padding: 10px 10px 0;
      border-radius: 8px;
      font-size: 14px;
      position: relative;
      .num {
        font-size: 8px;
      }
      .item-content {
        position: absolute;
        width: 95%;
        margin: 12px auto 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        justify-content: space-between;
      }
      .title-img {
        width: 25%;
        height: 25%;
        margin: 0 5px;
        //vertical-align: middle;
      }
      .right {
        margin-left: 5px;
        text-align: right;
      }
      .title,
      .num {
        text-align: left;
      }
    }
  }
  .titleline {
    display: flex;
    line-height: 40px;
    font-size: 18px;
    margin-top: 35px;
    // border-bottom: 1px solid #eee;
    .left {
      width: 40%;
      margin-right: 20px;
      border-bottom: 1px solid #eee;
    }
    .right {
      width: 60%;
      border-bottom: 1px solid #eee;
    }
  }
  .bottom {
    width: 100%;
    display: flex;
    margin-top: 20px;
  }
}
@media screen and (min-width: 1660px) and (max-width: 1900px) {
  .top {
    display: flex;
    justify-content: space-between;
    .item {
      background: #4f96e1;
      color: #fff;
      display: flex;
      // width: 150px;
      margin-right: 20px;
      flex: 1;
      height: 90px;
      text-align: center;
      vertical-align: middle;
      padding: 10px 10px 0;
      border-radius: 8px;
      font-size: 14px;
      position: relative;
      .num {
        font-size: 10px;
      }
      .item-content {
        position: absolute;
        width: 90%;
        margin: 12px auto 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        justify-content: space-between;
      }
      .title-img {
        width: 25%;
        height: 25%;
        margin: 0 5px;
        //vertical-align: middle;
      }
      .right {
        margin-left: 5px;
        text-align: right;
      }
      .title,
      .num {
        text-align: left;
      }
    }
  }
  .titleline {
    display: flex;
    line-height: 40px;
    font-size: 18px;
    margin-top: 35px;
    // border-bottom: 1px solid #eee;
    .left {
      width: 40%;
      margin-right: 20px;
      border-bottom: 1px solid #eee;
    }
    .right {
      width: 60%;
      border-bottom: 1px solid #eee;
    }
  }
  .bottom {
    width: 100%;
    display: flex;
    margin-top: 20px;
  }
}
@media screen and (min-width: 1910px) {
  .top {
    display: flex;
    justify-content: space-between;
    .item {
      background: #4f96e1;
      color: #fff;
      display: flex;
      // width: 150px;
      margin-right: 40px;
      flex: 1;
      height: 90px;
      text-align: center;
      vertical-align: middle;
      padding: 10px 10px 0;
      border-radius: 8px;
      font-size: 18px;
      position: relative;
      .num {
        font-size: 13px;
      }
      .item-content {
        position: absolute;
        width: 90%;
        margin: 12px auto 0;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        justify-content: space-between;
      }
      .title-img {
        width: 25%;
        height: 25%;
        margin: 0 5px;
        //vertical-align: middle;
      }
      .right {
        margin-left: 5px;
        text-align: right;
      }
      .title,
      .num {
        text-align: left;
      }
    }
  }
  .titleline {
    display: flex;
    line-height: 40px;
    font-size: 18px;
    margin-top: 35px;
    // border-bottom: 1px solid #eee;
    .left {
      width: 40%;
      margin-right: 20px;
      border-bottom: 1px solid #eee;
    }
    .right {
      width: 60%;
      border-bottom: 1px solid #eee;
    }
  }
  .bottom {
    width: 100%;
    display: flex;
    margin-top: 20px;
  }
}
</style>
