<!--
 * @Author: SunTao 328867980@qq.com
 * @Date: 2024-11-18 09:13:34
 * @LastEditors: SunTao 328867980@qq.com
 * @LastEditTime: 2024-11-18 09:13:42
 * @FilePath: \znxjxt-ui\src\views\xj\inspection-report\daily-monitoring\components\one-content.vue
 * @Description: 巡检报告-日常监测报告-今日巡查
-->
<template>
  <div class="one-content">
    <div class="title">
      <span>今日巡查</span>
    </div>
    <div class="day-echart" ref="dayChart"></div>
  </div>
</template>

<script>
import { getTaskToday } from "@/api/xj/index/index";
import * as echarts from "echarts";
export default {
  name: "OneContent",
  data() {
    return {
      // 病害趋势echart数据
      diseaseChart: [],
    };
  },
  created() {
    this.getData();
  },
  methods: {
    /**
     * @description: 获取数据
     * @param {*}
     * @return {*}
     */
    getData() {
      getTaskToday().then(({ code, data }) => {
        if (code === 200) {
          this.diseaseChart = data.xclcbhqs;
          this.$nextTick(() => {
            this.drawTrendChart();
          });
        }
      });
    },

    /**
     * @description: 绘制病害趋势柱状图
     * @param {*}
     * @return {*}
     */
    drawTrendChart() {
      const xData = this.diseaseChart.map((item) => {
        return item.label;
      });
      const y1Data = this.diseaseChart.map((item) => {
        return item.value;
      });
      const y2Data = this.diseaseChart.map((item) => {
        return item.long;
      });
      if (this.$refs.dayChart) {
        const chart = echarts.init(this.$refs.dayChart);
        chart.setOption({
          color: ["#388BD8", "#FFC400"],
          title: [
            // 中心比例
            {
              text: "巡查里程-病害趋势",
              x: "1%",
              y: "1%",
              textStyle: {
                fontSize: 14,
              },
            },
          ],
          tooltip: {
            trigger: "axis",
          },
          grid: {
            top: "20%",
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true,
          },
          legend: {
            right: "5%",
          },
          xAxis: [
            {
              type: "category",
              data: xData,
              axisTick: {
                show: false, //隐藏X轴刻度
              },
              axisLabel: { color: "#A2B0B8" },
              axisLine: {
                lineStyle: {
                  color: "#3C6579",
                  width: 1,
                },
              },
              splitLine: {
                show: true,
              },
            },
          ],
          yAxis: [
            {
              name: "",
              type: "value",
              axisLine: {
                lineStyle: {
                  color: "#A2B0B8",
                },
              },
              axisLabel: {
                // "formatter": "{value} T/h"
                // formatter: "{value}",
              },
              splitLine: {
                show: true,
              },
            },
            {
              name: "",
              type: "value",
              axisLine: {
                lineStyle: {
                  color: "#A2B0B8",
                },
              },
              axisLabel: {
                // "formatter": "{value} T/W㎡"
                // formatter: "{value}",
              },
              splitLine: {
                show: false,
              },
            },
          ],
          series: [
            {
              type: "bar",
              barWidth: 10,
              name: "累计病害",
              data: y1Data,
            },
            {
              type: "line",
              symbolSize: 5,
              name: "巡查里程",
              smooth: 1,
              data: y2Data,
              yAxisIndex: 1,
            },
          ],
          dataZoom: [
            {
              // 设置滚动条的隐藏与显示
              show: false,
              // 设置滚动条类型
              type: "slider",
              // 设置背景颜色
              backgroundColor: "rgba(225,225,225,0.2)",
              // 设置选中范围的填充颜色
              fillerColor: "#ccc",
              // 设置边框颜色
              borderColor: "rgba(225,225,225,0.2)",
              // 是否显示detail，即拖拽时候显示详细数值信息
              showDetail: false,
              // 数据窗口范围的起始数值
              startValue: 0,
              // 数据窗口范围的结束数值（一页显示多少条数据）
              endValue: 6,
              // empty：当前数据窗口外的数据，被设置为空。
              // 即不会影响其他轴的数据范围
              filterMode: "empty",
              // 设置滚动条宽度，相对于盒子宽度
              width: "80%",
              // 设置滚动条高度
              height: 5,
              // 设置滚动条显示位置
              left: "center",
              // 是否锁定选择区域（或叫做数据窗口）的大小
              zoomLoxk: true,
              // 控制手柄的尺寸
              handleSize: 10,
              // dataZoom-slider组件离容器下侧的距离
              bottom: 0,
            },
            {
              // 没有下面这块的话，只能拖动滚动条，
              // 鼠标滚轮在区域内不能控制外部滚动条
              type: "inside",
              // 滚轮是否触发缩放
              zoomOnMouseWheel: false,
              // 鼠标滚轮触发滚动
              moveOnMouseMove: true,
              moveOnMouseWheel: true,
            },
          ],
        });
        window.addEventListener("resize", () => {
          chart.resize();
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.one-content {
  width: 100%;
  height: 100%;
  padding: 0.5rem;

  .title {
    width: 100%;
    height: 10%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 3rem;
    background: url("~@/assets/index/div-title.png") no-repeat;
    background-size: 5%;
    background-position: 0 30%;

    span {
      font-family: "DouYu";
    }
  }
}

.day-echart {
  height: 90%;
  width: 100%;
}
</style>