<template>
  <div class="fanMonitor">
    <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="fan-contents">
      <div class="fan" ref="fan"></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';
  import { useGo } from '/@/hooks/web/usePage';
  const go = useGo();

  let searchValue = ref('局扇监测');
  const options1 = reactive<any>([
    {
      value: '局扇监测',
      label: '局扇监测',
    },
    {
      value: '局扇监测1',
      label: '局扇监测1',
    },
    {
      value: '局扇监测2',
      label: '局扇监测2',
    },
  ]);

  //获取dom节点
  let fan = ref<any>();
  //echart图表数据
  let echartData=reactive<any>({
    xdata:80,
    ydata:60
  })
//跳转详情
function getDetail(){
    console.log('跳转详情')
    go('/micro-vent-3dModal/dashboard/analysis')
  }
  //选项切换
  function changeSelect(val){
    console.log(val,'val-------')
    switch(val){
        case '局扇监测':
          echartData.xdata=80
          echartData.ydata=60
          getOption()
          break;
          case '局扇监测1':
          echartData.xdata=50
          echartData.ydata=70
          getOption()
          break;
          case '局扇监测2':
          echartData.xdata=40
          echartData.ydata=90
          getOption()
          break;

    }
    
  }
  function getOption() {
    nextTick(() => {
      const myChart = echarts.init(fan.value);
      let option = {
        grid: {
          top: '20%',
          left: '5%',
          bottom: '10%',
          right: '5%',
          containLabel: true,
        },
        xAxis: [
          {
            type: 'category',
            data: ['吸风量', '供风量'],
            axisTick: {
              alignWithLabel: true,
            },
            nameTextStyle: {
              color: 'red',
            },
            axisLine: {
              //坐标轴轴线相关设置。数学上的x轴
              show: true,
              lineStyle: {
                color: 'rgba(62, 103, 164)',
              },
            },
            axisLabel: {
              //坐标轴刻度标签的相关设置
              textStyle: {
                color: '#b3b8cc',
                padding: 10,
                fontSize: 14,
              },
              formatter: function (data) {
                return data;
              },
            },
          },
        ],
        yAxis: [
          {
            type: 'value',
            min: 0,
            name: '(m³/min)',
            nameTextStyle: {
              color: '#b3b8cc',
              fontSize: 12,
              padding: -5,
            },
            splitLine: {
              show: false,
              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: 'pictorialBar',
            symbolSize: [60, 16],
            symbolOffset: [0, -10],
            symbolPosition: 'end',  
            z: 12,
            //"barWidth": "20",
            label: {
              normal: {
                show: true,
                position: 'top',
                formatter: '{c}',
                color:'#fff'
              },
            },
            data: [
              {
                value: echartData.xdata,
                itemStyle: {
                  color: '#59cb42',
                },
              },
              {
                value: echartData.ydata,
                itemStyle: {
                  color: '#3cefff',
                },
              },
            ],
          },
          {
            name: '',
            type: 'pictorialBar',
            symbolSize: [60, 16],
            symbolOffset: [0, 10],
            // "barWidth": "20",
            z: 12,
            data: [
              {
                value: 100,
                itemStyle: {
                  color: '#59cb42',
                },
              },
              {
                value: 100,
                itemStyle: {
                  color: '#3cefff',
                },
              },
            ],
          },
          {
            name: '',
            type: 'pictorialBar',
            symbolSize: [90, 30],
            symbolOffset: [0, 20],
            z: 10,
            itemStyle: {
              normal: {
                color: 'transparent',
                borderColor: '#14b1eb',
                borderType: 'dashed',
                borderWidth: 5,
              },
            },
            data: [100, 100],
          },
          {
            type: 'bar',
            itemStyle: {
              normal: {
                //color: '#14b1eb',
                opacity: 0.7,
              },
            },
            //silent: true,
            barWidth: '60',
            //barGap: '-100%', // Make series be overlap
            data: [
              {
                value: echartData.xdata,
                itemStyle: {
                  color: '#59cb42',
                },
              },
              {
                value: echartData.ydata,
                itemStyle: {
                  color: '#3cefff',
                },
              },
            ],
            markLine: {
              symbol: 'none',
              label: {
                position: 'middle',
                formatter: '{b}',
              },
              data: [
                {
                  name: '目标值',
                  yAxis: 40, //res.targetTwo,
                  lineStyle: {
                    color: 'rgba(0, 119, 233,.8)',
                  },
                },
              ],
            },
          },
        ],
      };
      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');
  }
  .fanMonitor {
    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;
        }
      }
    }
    .fan-contents {
      position: absolute;
      top: 66px;
      left: 0;
      height: calc(100% - 66px);
      width: 100%;
      .fan {
        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>
