<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" />
    </div>
  </div>
</template>

<script setup>
import GasInfoItem from "./childComps/GasInfoItem.vue";
const props = defineProps({
  list: Array,
  badGasData:Array
});
const badGasList=ref([])
watch(() => props.list, (now, old) => {
  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
  }
}
</script>

<style lang="scss" scoped>
#bad-gas-info {
  position: absolute;
  z-index: 100;
  width: 824px;
  height: 621px;
  top: 1441px;
  right: 72px;
  background-image: url(@/assets/images/badGasInfo/bg.png);
  .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>
