<template>
  <div class="project-info">
    <div class="title">
      数据更新时间
      <span class="history" @click="historyVisible = true">查看历史记录</span>
      <HistoryDust
        :visible="historyVisible"
        :project-id="projectId"
        @change-visible="(val) => (historyVisible = val)"
      ></HistoryDust>
    </div>
    <div class="info">
      <div class="dust-bg">
        <div class="temp">
          <img src="@/assets/images/common/temp.png" alt="" />
          <div class="label">当前温度</div>
          <div class="value">{{ noiseData.temperature }}℃</div>
        </div>
        <div class="temp">
          <img src="@/assets/images/common/humidy.png" alt="" />
          <div class="label">当前湿度</div>
          <div class="value">{{ noiseData.humidity }}%</div>
        </div>
      </div>
      <div class="dust-bg values-inline">
        <div class="lt-label">
          <div class="great" v-if="noiseData.pm25.qualified == 0">优</div>
          <div class="good" v-else-if="noiseData.pm25.qualified == 1">良</div>
          <div class="bad" v-else-if="noiseData.pm25.qualified == 2">差</div>
          <div class="label">当前 PM2.5 值为</div>
          <div
            :class="[
              'value',
              noiseData.pm25.qualified == 0
                ? 'great-value'
                : noiseData.pm25.qualified == 1
                ? 'good-value'
                : 'bad-value',
            ]"
          >
            {{ noiseData.pm25.pm25 }} <span class="unit">ug/m³</span>
          </div>
        </div>
        <div class="rt-label">
          <div>
            <div>
              <div class="great tip">优</div>
              扬尘值0-35ug/m3
            </div>
            <div>
              <div class="good tip">良</div>
              扬尘值36-75ug/m3
            </div>
            <div>
              <div class="bad tip">差</div>
              扬尘值>75ug/m3
            </div>
          </div>
        </div>
      </div>
      <div class="dust-bg values-inline">
        <div class="lt-label">
          <div class="great" v-if="noiseData.pm10.qualified == 0">优</div>
          <div class="good" v-else-if="noiseData.pm10.qualified == 1">良</div>
          <div class="bad" v-else-if="noiseData.pm10.qualified == 2">差</div>
          <div class="label">当前 PM10 值为</div>
          <div
            :class="[
              'value',
              noiseData.pm10.qualified == 0
                ? 'great-value'
                : noiseData.pm10.qualified == 1
                ? 'good-value'
                : 'bad-value',
            ]"
          >
            {{ noiseData.pm10.pm10 }} <span class="unit">ug/m³</span>
          </div>
        </div>
        <div class="rt-label">
          <div>
            <div>
              <div class="great tip">优</div>
              浓度值0-50ug/m3
            </div>
            <div>
              <div class="good tip">良</div>
              浓度值51-150ug/m3
            </div>
            <div>
              <div class="bad tip">差</div>
              浓度值>150ug/m3
            </div>
          </div>
        </div>
      </div>
      <div class="dust-bg values-inline">
        <div class="lt-label">
          <div class="great" v-if="noiseData.noise.qualified == 0">优</div>
          <div class="good" v-else-if="noiseData.noise.qualified == 1">良</div>
          <div class="bad" v-else-if="noiseData.noise.qualified == 2">差</div>
          <div class="label">当前 噪音 值为</div>

          <div
            :class="[
              'value',
              noiseData.pm25.qualified == 0
                ? 'great-value'
                : noiseData.pm25.qualified == 1
                ? 'good-value'
                : 'bad-value',
            ]"
          >
            {{ noiseData.noise.noise }} <span class="unit">dB</span>
          </div>
        </div>
        <div class="rt-label">
          <div>
            <div>
              <div class="great tip">优</div>
              噪音值0-40dB
            </div>
            <div>
              <div class="good tip">良</div>
              噪音值41-70dB
            </div>
            <div>
              <div class="bad tip">差</div>
              噪音值>70dB
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getRealTimeDustData } from "@/api/index";
import HistoryDust from "./HistoryDust.vue";
export default {
  components: { HistoryDust },
  props: {
    projectId: {
      type: [Number, String],
      default: "",
    },
  },
  data() {
    return {
      noiseData: {
        noise: {},
        pm10: {},
        pm25: {},
      },
      historyVisible: false,
    };
  },
  mounted() {
    getRealTimeDustData(this.projectId).then((res) => {
      this.noiseData = res.data;
    });
  },
};
</script>
  <style lang="less" scoped>
.project-info {
  padding-top: 16px;
}
.title {
  background: #0e4092;
  line-height: 36px;
  padding-left: 22px;
  color: #fff;
  font-size: 14px;
  position: relative;
  &::before {
    content: "";
    position: absolute;
    width: 3px;
    height: 16px;
    background: #f99b2d;
    left: 10px;
    top: 10px;
  }
  .history {
    float: right;
    cursor: pointer;
    margin-right: 20px;
  }
}
.info {
  background: #072c5d;
  padding: 30px;
}
.dust-bg {
  background: url("@/assets/images/index/dust-bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  height: 130px;
  width: 100%;
  padding: 30px 0;
  margin-bottom: 30px;
  &:last-child {
    margin-bottom: 0;
  }
}
.temp {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50%;
  img {
    width: 50px;
  }
  .label {
    padding-left: 60px;
    padding-right: 100px;
  }
  .value {
    color: #22c3ed;
    font-size: 24px;
    font-weight: bold;
  }
  &:first-child {
    border-right: 1px solid #7e8ed4;
  }
}
.dust-bg {
  display: flex;
  justify-content: center;
  font-size: 16px;
  color: #fff;
}
.great {
  background: rgba(19, 169, 86, 0.3);
  border-radius: 4px;
  border: 1px solid #13a956;
  color: #1ecc6c;
  font-size: 16px;
  line-height: 24px;
  width: 54px;
  text-align: center;
  display: inline-block;
}
.good {
  background: rgba(205, 111, 29, 0.3);
  border-radius: 4px;
  border: 1px solid #cd6f1d;
  color: #e17e27;
  font-size: 16px;
  line-height: 24px;
  width: 54px;
  text-align: center;
  display: inline-block;
}
.bad {
  background: rgba(219, 68, 53, 0.3);
  border-radius: 4px;
  border: 1px solid #db4435;
  color: #db4435;
  font-size: 16px;
  line-height: 24px;
  width: 54px;
  text-align: center;
  display: inline-block;
}

.lt-label,
.rt-label {
  width: 50%;
}
.lt-label {
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #7e8ed4;
  .label {
    padding-left: 60px;
    padding-right: 40px;
    font-size: 16px;
  }
  .value {
    font-size: 24px;
    .unit {
      font-size: 16px;
    }
  }
}
.rt-label {
  display: flex;
  justify-content: center;
  align-items: center;
}
.tip {
  margin-right: 10px;
  margin-bottom: 4px;
}
.great-value {
  color: #1ecc6c;
}
.good-value {
  color: #e17e27;
}
.bad-value {
  color: #ff6151;
}
</style>