<!--
 * @Author: your name
 * @Date: 2022-04-11 15:07:47
 * @LastEditTime: 2022-04-20 11:09:34
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /gassafety-progress/gassafetyprogress-web/src/views/operationMonitor/xunjianxuncha/topChars/left.vue
-->
<template>
  <div class="charsCom all-flex-h">
    <div class="title">入户安检隐患统计</div>
    <div class="two all-flex">
      <div class="left">

        <!--<div class="first">-->
          <!--<span class="text">隐患整改率</span>-->
        <!--</div>-->
        <div id="main"  class="chars-box" >
          <!--<Chars  :options="option"></Chars>-->

        </div>
      </div>
      <div class="right">
        <div ref="myChartWidth" style="margin-top: 60px" class="chars-box">
          <Chars :options="comoption" />
        </div>
      </div>
    </div>

    <!--<div class="three all-flex-h">-->
      <!--<div class="first">隐患原因</div>-->
      <!--<div ref="myChartWidth" class="chars-box">-->
        <!--<Chars :options="reasonOptions" />-->
      <!--</div>-->
    <!--</div>-->
  </div>
</template>

<script>
import Chars from "@/components/allCharsCom/Chars";
import { hiddenBookqiyeStatistics,hiddenBookYearStatistics } from "@/api/standingBook/hidden";
export default {
  components: {
    Chars,
  },
  props:{
    annual: {
      type: String,
      default: 2025,
    },
    companyInfoId: {
      type: String,
      default: 23,
    },
  },
  data() {
    return {
      bottomData: [
        [
          { name: "裂缝", value: 0, color: "#604AFF" },
          { name: "管道称重", value: 0, color: "#FFC337" },
          { name: "其他", value: 0, color: "#86FF5B" },
          { name: "腐蚀", value: 0, color: "#03C4F1" },
          { name: "漏气", value: 0, color: "#1F8DF3" },
        ],
      ],
      option:{
        color:['RoyalBlue',"lightblue"],
        title: {
          text: '隐患统计'
        },
        legend: {
          data: ['已整改', '未整改']
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: ['2020', '2021', '2022', '2023', '2024', '2025', '2026']
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '已整改',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: '未整改',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: [220, 182, 191, 234, 290, 330, 310]
          }
        ]
      },
      comoption:{
        color:['RoyalBlue',"lightblue"],
        legend: {},
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          offset: 0, // 向右偏移50像素
          data: ['企业企业企业一个两个三个', '企业2', '企业3', '企业4', '企业5', '企业6'],
          axisLabel: {
            rotate: 15,  // 旋转45度
            formatter: function (value,index) {
              if(value.length>6){
                if(value.length>12){
                  return value.slice(0,6)+"\n"+value.slice(6,11)+"...";
                }else{
                  return value.slice(0,6)+"\n"+value.slice(6,value.length);
                }
              }else{
                return value;
              }
            }
          }
        },
        series: [
          {
            name: '已整改',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [320, 302, 301, 334, 390, 330]
          },
          {
            name: '未整改',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 230]
          }
        ]
      },
      reasonOptions:{},
      hiddenBookInfo: {
        unFinishNum: 0,
        finishNum: 0
      }
    };
  },
  created(){
    setTimeout(this.getzhanshi,1000)
    this.getHiddenBookInfo();
  },

  methods: {
    getzhanshi(){
      hiddenBookYearStatistics({companyInfoId:this.companyInfoId,annual:this.annual}).then(res =>{
        this.option.series[0].data = res.data.yeshidden;
        this.option.series[1].data = res.data.nohidden;
        this.option.xAxis[0].data = res.data.yearNum;
      var myChart =  this.$echarts.init(document.getElementById('main'));
        myChart.setOption(this.option);
      })

    },
    bottomOptions() {
      return {
        series: this.bottomData.map((data, idx) => {
          const rich = {};
          data
            .map((item) => ({
              fontsize: 12,
              color: item.color,
            }))
            .forEach((item, index) => {
              rich[`dataIndex${index}`] = item;
            });

          return {
            type: "pie",
            radius: ["68%", "80%"],
            tooltip: {
              trigger: "item",
            },
            color: data.map((item) => item.color),
            itemStyle: {
              borderWidth: 2,
              borderRadius: 10,
              borderColor: "#fff",
            },
            label: {
              alignTo: "edge",
              // formatter: "{name|{b}}\n{num|{c} 个}",
              formatter: (parm) => {
                return `{dataIndex${parm.dataIndex}|${parm.data.name}}\n{dataIndex${parm.dataIndex}|${parm.data.value}}`;
              },
              minMargin: 5,
              edgeDistance: 10,
              lineHeight: 15,
              rich,
            },
            labelLine: {
              length: 15,
              length2: 0,
              maxSurfaceAngle: 80,
            },
            labelLayout: (params) => {
              const { width } = this.$refs.myChartWidth.getBoundingClientRect();
              const isLeft = params.labelRect.x < width / 2;
              const points = params.labelLinePoints;
              console.log("points",points)
              // Update the end point.
              points[2][0] = isLeft
                ? params.labelRect.x
                : params.labelRect.x + params.labelRect.width;
              return {
                labelLinePoints: points,
              };
            },
            data: data,
          };
        }),
      };
    },
    getHiddenBookInfo(){
      hiddenBookqiyeStatistics().then(res =>{

          if(res.code == 200){
            this.comoption.series[0].data = res.data.yeshidden;
            this.comoption.series[1].data = res.data.nohidden;
            this.comoption.yAxis.data = res.data.enterpriseName;
          }
          //console.log("res==================",res)
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.charsCom {
  width: 100%;
  height: 100%;
  color: #333333;
}
.title {
  text-align: center;
  font-size: 24px;
  margin-bottom: 7px;
}
.two {
  flex: 1;
  > .left {
    max-width: 50%;
    margin-right: 70px;
    .first {
      margin-bottom: 6px;
    }
    .chars-box {
      width: 90%;
      height: 100%;
      margin: 0 auto;
    }
    .second {
      width: 213px;
      height: 30px;
      line-height: 30px;
      box-sizing: border-box;
      box-shadow: 0px 0px 3px 1px #dddddd;
      margin-bottom: 19px;
      > div {
        // flex: 1;
        text-align: center;

        &.left {
          color: #1d8cf3;
        }
        &.right {
          color: #00c3f1;
        }
      }
    }
    .third {
      text-align: center;
      width: 213px;
      margin-bottom: 24px;
    }
  }
  > .right {
    width: 50%;
    .first {
      text-align: center !important;
    }
    .chars-box {
      width: 100%;
      height: 90%;
      margin: 0 auto;
    }
  }
  > div {
    font-size: 16px;
    flex: 1;
    // display: flex;
    // flex-direction: column;
  }
  .left,
  .right {
    // display: flex;
    // flex-direction: column;
    // justify-content: space-between;
    .first {
      text-align: left;
      .text {
        display: inline-block;
        margin-right: 8px;
      }
    }
  }
}
.three {
  font-size: 16px;
  flex: 1;
  // background: red;
  .chars-box {
    flex: 1;
  }
}
</style>
