<template>
  <div class="mainMonitor">
    <div class="title-top" @click="getDetail">主通风系统</div>
    <div class="toggle-search">
      <i class="icon-search">
        <SvgIcon class="icon" size="14" name="toggle" />
      </i>
      <a-select
        v-model:value="searchValue"
        style="width: 180px; margin-right: 10px"
        :options="options1"
        aria-placeholder="请选择"
        @change="changeSelect"
      />
      <div class="status-yx">
        <div class="now-name">
          <i style="margin: 0px 5px 0px 5px">
            <SvgIcon class="icon" size="14" name="yxfj" />
          </i>
          <span style="color: #fff">运行风机</span>
        </div>

        <div class="now-status">主风机</div>
      </div>
    </div>
    <div class="main-contents">
      <div class="main" ref="main"></div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, onMounted, nextTick } from 'vue';
  import { SvgIcon } from '/@/components/Icon';
  import * as echarts from 'echarts';
  let searchValue = ref('1号回风斜井');
  const options1 = reactive<any>([
    {
      value: '1号回风斜井',
      label: '1号回风斜井',
    },
    {
      value: '2号回风斜井',
      label: '2号回风斜井',
    },
    {
      value: '3号回风斜井',
      label: '3号回风斜井',
    },
  ]);

  //获取dom节点
  let main = ref<any>();
  //echart图表数据
  let echartData = reactive<any>({
    xdata: ['1000', '2000', '3000', '4000', '5000', '6000'],
    ydata: [0, 20, 50, 90, 140, 200],
    ydata1: [210, 190, 160, 120, 80, 30],
  });
  //跳转详情
  function getDetail() {
    console.log('跳转详情');
  }
  //选项切换
  function changeSelect(val) {
    switch (val) {
      case '1号回风斜井':
        (echartData.xdata = ['1000', '2000', '3000', '4000', '5000', '6000']),
          (echartData.ydata = [0, 20, 50, 90, 140, 200]),
          (echartData.ydata1 = [210, 190, 160, 120, 80, 30]),
          getOption();
        break;
      case '2号回风斜井':
        (echartData.xdata = ['1000', '2000', '3000', '4000', '5000', '6000']),
          (echartData.ydata = [20, 40, 70, 110, 160, 220]),
          (echartData.ydata1 = [270, 260, 240, 210, 170, 120]),
          getOption();
        break;
      case '3号回风斜井':
        (echartData.xdata = ['1000', '2000', '3000', '4000', '5000', '6000']),
          (echartData.ydata = [40, 60, 100, 160, 240, 340]),
          (echartData.ydata1 = [380, 360, 320, 260, 180, 80]),
          getOption();
        break;
    }
  }

  function getOption() {
    nextTick(() => {
      const myChart = echarts.init(main.value);
      let option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
          },
        },

        legend: {
          align: 'left',
          right: '4%',
          top: '6%',
          type: 'plain',
          textStyle: {
            color: '#7ec7ff',
            fontSize: 14,
          },
          // icon:'rect',
          itemGap: 25,
          itemWidth: 18,
          icon: 'path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z',
          data: [
            {
              name: '风阻',
            },
            {
              name: '负压',
            },
            // {
            //   name: '工作面需风'
            // }
          ],
        },

        grid: {
          top: '22%',
          left: '5%',
          right: '16%',
          bottom: '5%',
          containLabel: true,
        },

        xAxis: [
          {
            type: 'category',
            name: '风量\n(m³/min)',
            nameTextStyle: {
              color: '#b3b8cc',
              fontSize: 12,
              padding: -5,
            },
            // boundaryGap: false,
            axisLine: {
              //坐标轴轴线相关设置。数学上的x轴
              show: true,
              lineStyle: {
                color: 'rgba(62, 103, 164)',
              },
            },
            axisLabel: {
              //坐标轴刻度标签的相关设置
              textStyle: {
                color: '#b3b8cc',
                padding: 0,
                fontSize: 14,
              },
              formatter: function (data) {
                return data;
              },
            },
            splitLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            data: echartData.xdata,
          },
        ],

        yAxis: [
          {
            name: '负压(Pa)',
            nameTextStyle: {
              color: '#b3b8cc',
              fontSize: 12,
              padding: -5,
            },
            min: 0,
            splitLine: {
              show: true,
              lineStyle: {
                color: 'rgba(62, 103, 164,.4)',
              },
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: 'rgba(62, 103, 164)',
              },
            },
            axisLabel: {
              show: true,
              textStyle: {
                color: '#b3b8cc',
                padding: 0,
                fontSize: 14,
              },
              formatter: function (value) {
                if (value === 0) {
                  return value;
                }
                return value;
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: '风阻',
            type: 'line',
            smooth: true,
            yAxisIndex: 0,
            symbolSize: 6,
            lineStyle: {
              normal: {
                width: 2,
                color: 'orange', // 线条颜色
              },
              borderColor: 'rgba(0,0,0,.4)',
            },
            itemStyle: {
              color: 'orange',
              borderColor: '#646ace',
              borderWidth: 0,
            },
            data: echartData.ydata,
          },
          {
            name: '负压',
            type: 'line',
            smooth: true,
            yAxisIndex: 0,
            symbolSize: 6,

            lineStyle: {
              normal: {
                width: 2,
                color: '#00ba01', // 线条颜色
              },
              borderColor: 'rgba(0,0,0,.4)',
            },
            itemStyle: {
              color: '#00ba01',
              borderColor: '#646ace',
              borderWidth: 0,
            },
            data: echartData.ydata1,
          },
        ],
      };
      myChart.setOption(option);
      window.onresize = function () {
        myChart.resize();
      };
    });
  }
  onMounted(() => {
    getOption();
  });
</script>

<style lang="less" scoped>
  @font-face {
    font-family: 'douyuFont';
    src: url('../../../../../assets/font/douyuFont.otf');
  }
  .mainMonitor {
    width: 100%;
    height: 100%;
    position: relative;
    .title-top {
      position: absolute;
      top: 9px;
      left: 46px;
      color: #fff;
      font-size: 16px;
      font-family: 'douyuFont';
      cursor: pointer;
      &:hover{
        color: #66ffff;
      }
    }
    .toggle-search {
      position: absolute;
      left: 9px;
      top: 37px;
      display: flex;
      .icon-search {
        position: absolute;
        top: 50%;
        left: 5px;
        transform: translate(0%, -50%);
      }
      .status-yx {
        height: 30px;
        width: 180px;
        background-color: rgba(8, 148, 255, 0.3);
        border: 1px solid #1d80da;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .now-status {
          margin-right: 5px;
          padding-top: 3px;
          font-family: 'douyuFont';
          color: #3df6ff;
        }
      }
    }
    .main-contents {
      position: absolute;
      top: 66px;
      left: 0;
      height: calc(100% - 66px);
      width: 100%;
      .main {
        width: 100%;
        height: 100%;
      }
    }
  }
  :deep .zxm-select-selector {
    width: 100%;
    height: 30px !important;
    padding: 0 11px 0px 25px !important;
    background-color: rgba(8, 148, 255, 0.3) !important;
    border: 1px solid #1d80da !important;
  }
  :deep .zxm-select-selection-item {
    color: #fff !important;
    line-height: 28px !important;
  }
  :deep .zxm-select-arrow {
    color: #fff !important;
  }
</style>
