<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="mainTypeList"
        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>
      <!-- <echartLine ref="main" style="width: 100%; height: 100%"></echartLine> -->
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref, reactive, onMounted, nextTick, defineProps, watch } from 'vue';
  import { SvgIcon } from '/@/components/Icon';
  // import echartLine from './EchartLineCharacter3.vue'
  import * as echarts from 'echarts';

  let props = defineProps({
    maindata: Array,
  });
  const emit = defineEmits(['goDetail']);
  let searchValue = ref('');
  let mainTypeList = reactive<any>([]); //下拉框
  let mainList = reactive<any[]>([]); //主风机列表

  //获取dom节点
  let main = ref<any>();
  //echart图表数据
  let echartData = reactive<any>({
    xdata: ['1000', '2000', '3000', '4000', '5000', '6000'],
    ydata: [],
    ydata1: [],
  });
  //跳转详情
  function getDetail() {
    console.log('跳转详情');
    emit('goDetail', 'fanmain');
  }
  //选项切换
  function changeSelect(val) {
    (echartData.ydata.length = 0), (echartData.ydata1.length = 0);
    switch (val) {
      case '1号回风斜井':
        mainList.forEach((el) => {
          echartData.ydata1.push(el.readData.DataPa);
          echartData.ydata.push(el.readData.m3);
        });
        getOption();
        break;
      case '2号回风立井':
        break;
    }
  }

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

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

        xAxis: [
          {
            type: 'category',
            name: '负压(Pa)',
            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: '风量\n(m³/min)',
            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();
      };
    });
  }
  // 设置曲线数据
  //  function setChart(param,character) {
  //     // if(this.startfan !=1 && this.startfan !=2){
  //     //   return
  //     // }

  //     param.dataQ = param.dataQ == null?0:param.dataQ
  //     param.dataH = param.dataH == null?0:param.dataH
  //     let Q1 = Math.round(parseFloat(param.dataQ)/60*100)/100;
  //     let H1 = parseFloat(param.dataH);

  //     let q = Q1 - character.dataha3;
  //     let h = H1 - character.dataha4;
  //     // 风压特性曲线1
  //     let data = [];
  //     // 风压特性曲线2
  //     let data2 = [];
  //     let data3 = [];

  //       for (let i = 30; i <= 400; i++) {
  //         let x = i;
  //         let y4 =
  //           character.dataha0 * (x - q) * (x - q) +
  //           character.dataha1 * (x - q) +
  //           character.dataha2 +
  //           h;
  //         data2.push([x, y4]);
  //       }
  //     for (let i = 0; i <= 400; i++) {
  //       let x = i;
  //       let y = (H1 / Q1 / Q1) * x * x;
  //       data.push([x, y]);
  //     }
  //     // if(this.$refs.chartlineCharacter != null){

  //     if(main.value)main.value.setXData(data,data2,[[Q1, H1]]);

  //     // }
  //   }

  watch(
    () => props.maindata,
    (val) => {
      console.log(val, '主风机数据');
      mainList = val;
      mainTypeList.length = 0;
      mainTypeList.push({
        label: mainList[0].strinstallpos,
        value: mainList[0].strinstallpos,
      });
      searchValue.value = mainTypeList[0].value;
      changeSelect(searchValue.value);
    },
    {
      deep: true,
    }
  );
  onMounted(() => {
    // 添加resize事件监听
    // if(main.value)main.value.setXMax(400);
    // if(main.value)main.value.setYMax(4000);
    // window.addEventListener("resize", this.chartResize);
    // setChart({ dataQ: 100, dataH: 200 }, { dataha0: 20, dataha1: 40, dataha2: 60, dataha3: 80, dataha4: 70 })
  });
</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>
