<template>
  <div id="bad-gas-info">
    <div class="title">有害气体</div>
    <div class="info-list">
      <gas-info-item v-for="item in badGasList" :key="item.equipmentId" :gasInfo="item" @click="handleOpenChart"/>
    </div>
    <el-dialog v-model="isVisited" title="1号有害气体监控数据" width="958px" :modal="false">
      <div class="left-icon"></div>
      <div class="right-icon"></div>

    </el-dialog>
  </div>
</template>

<script setup>
import GasInfoItem from "./childComps/GasInfoItem.vue";

const props = defineProps({
  list: Array,
  badGasData: Array
});
const isVisited = ref(true);
const badGasList = ref([])
const option = reactive({
  //图例
  legend: {
    data: [],
    selected: {},
    selectedMode: false
  },
  //离容器四侧的距离
  // grid: {
  //   left: 40, // 左边距
  //   right: 60, // 右边距
  //   top: 40, // 顶边距
  //   bottom: 20, // 底边距
  //   // containLabel: true,
  // },
  //提示框组件
  tooltip: {
    show: true,
    trigger: 'axis'
  },
  //X轴
  xAxis: {
    name: '',
    type: 'category',
    data: [],
    axisLine: {
      show: true
    }
  },
  //Y轴
  yAxis: {
    name: '',
    type: 'value',
    data: [],
    axisLine: {
      show: true
    }
  },
  radar: {
    // shape: 'circle',
  },
  //配置项
  series: []
})

watch(() => props.list, (now) => {
  badGasList.value.forEach(item => {
    now.forEach(newItem => {
      if (item.equipmentId === newItem.equipmentId) {
        item.value = newItem.value
      }
    })
  })
}, {deep: true});

watch(() => props.badGasData, (now) => {
  getBadGasInfo(now.sensorList)
}, {deep: true});
const getBadGasInfo = (now) => {
  let windPressureObj = {}
  let windPressureArr = []
  now.map(item => {
    if (item.equipmentType === "carbonDioxide" || item.equipmentType === "carbonMonoxide" || item.equipmentType === "hydrogenSulfide" || item.equipmentType === "sulfurDioxide" || item.equipmentType === "sulfurMonoxide" || item.equipmentType === "nitrogenDioxide") {
      windPressureObj = changeData(item)
      windPressureArr.push(windPressureObj)
    }
  })
  badGasList.value = windPressureArr
}
const changeData = (item) => {
  return {
    equipmentId: item.equipmentId,
    name: item.equipmentName.slice(0, item.equipmentName.length - 2),
    max: 120,
    value: item.value,
    point: item.valueThreshold,
    unit: item.unit
  }
}
const handleOpenChart = () => {
  console.log('有害气体弹窗')
  isVisited.value = true
}
</script>

<style lang="scss" scoped>
:deep(.el-dialog) {
  border: 2px solid #0F82AF;
  background: rgba(6, 34, 71, 0.78);
  border-radius: 20px;
  padding: 47px 20px;
  box-sizing: border-box;
  margin: 588px auto 0 auto;

  .el-dialog__header {
    padding: 0;
    //display: none;
    .el-dialog__title {
      font-size: 32px;
      font-weight: bold;
      color: #D6F1FA;
    }

    .el-dialog__close {
      color: #05FEFF;
      font-size: 35px;
    }
  }
}

#bad-gas-info {
  position: absolute;
  z-index: 100;
  width: 824px;
  height: 621px;
  top: 1441px;
  right: 72px;
  background-image: url(@/assets/images/badGasInfo/bg.png);

  .left-icon {
    position: absolute;
    top: -3px;
    left: -3px;
    width: 41px;
    height: 41px;
    background-image: url(@/assets/images/badGasInfo/sp_jz.png);
  }

  .right-icon {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 41px;
    height: 41px;
    background-image: url(@/assets/images/badGasInfo/sp_jz.png);
    transform: rotate(90deg);
  }

  .title {
    width: 128px;
    height: 45px;
    font-size: 32px;
    font-family: PingFang-SC, PingFang-SC;
    font-weight: 800;
    color: #38cafb;
    line-height: 45px;
    margin: 22px 0px 0px 62px;
  }

  .info-list {
    width: 100%;
    height: calc(621px - 45px - 22px);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    padding: 10px 0px 0px 10px;
  }
}
</style>
