<template>
  <div class="enviLeft enviLeft1">
    <!-- <div class="d0 d-1" >
      <div class="layerWd1">
        <div class="in-box">
          <div class="tit-bg"></div>
          <h3
            class="el-icon-s-unfold"
            @click="to3d('环境|1#气象站')"
            style="cursor: pointer"
          >
            {{ "点位1" }}七天变化趋势图
          </h3>
          <el-carousel
            :interval="4000"
            arrow="never"
            style="width: 500px; height: 250px"
          >
            <el-carousel-item v-for="item in 3" :key="item">
              <div
                class="ctn-absfull"
                :id="['dw1' + item]"
                :ref="['charthj1' + item]"
                style="width: 100%; height: 100%"
              ></div>
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>
    </div> -->
  </div>
</template>
<script>
import { listPoint } from "@/api/envi/point.js";
import { envisearch } from "@/api/bigscreen/index.js";
export default {
  name: "enviLeft",
  components: {},
  props: ["air"],

  data() {
    return {
      pointList: [{ name: "aaa", value: 333 }],
      hjjcchartList: {},
      hjjcchartdata: {
        pm25data: [],
        pm10data: [],
        zydata: [],
        hjtime: [],
        szjctime: [],
        PHdata: [],
        qlzdata: [],
        zddata: [],
        adData: [],
      },
      dl: [{ name: "aaa", value: 333 }],
      pl: [{ name: "aaa", value: 333 }],
      settime: 5000, //定时器时间
      hjjcList: { aaa: 0 },
    };
  },
  watch: {
    air(newValue, oldValue) {
      console.log(newValue, "newValue");
      if (newValue !== 3) {
        this.destroytime();
      } else {
        this.settime = 5000;
        // this.getenviLeft();
      }
    },
  },
  created() {
    this.$nextTick(function () {});
  },
  mounted() {
    this.$nextTick(function () {
      this.getPoint();
      // console.log(this.air, "air");
      // this.getenviLeft();
    });
  },
  methods: {
    getPoint() {
      this.pointList = [];
      let queryParams = {
        pageNum: 1,
        pageSize: 999,
        pointName: null,
        monitorType: "空气监测",
      };
      listPoint(queryParams)
        .then((response) => {
          console.log(response.rows);
          let data = response.rows;
          for (let i = 0; i < data.length; i++) {
            this.pointList.push(data[i].pointName);
          }
        })
        .then(() => {
          this.getenviLeft();
        });
    },
    //生产管理
    getenviLeft() {
      let that = this;
      this.hjjcList = {};
      that.dl = [];
      that.pl = [];
      let tempTimer = this.settime;
      (function reqData() {
        clearTimeout(this.timeoutFalg);
        for (let j = 0; j < that.pointList.length; j++) {
          that.hjjcchartList[that.pointList[j]] = {
            pm25data: [],
            pm10data: [],
            zydata: [],
            hjtime: [],
            szjctime: [],
            PHdata: [],
            qlzdata: [],
            zddata: [],
            adData: [],
          };
          envisearch({ monitorType: "空气监测", pointName: that.pointList[j] })
            .then((res) => {
              let that = this;
              if (res.code === 200) {
                let data = res.rows;
                for (let i = 0; i < data.length; i++) {
                  if (data[i].items === "pm2.5") {
                    that.hjjcchartList[that.pointList[j]].pm25data.push(
                      data[i].evalue
                    );
                    that.hjjcchartList[that.pointList[j]].hjtime.push(
                      data[i].time
                    );
                  } else if (data[i].items === "pm10") {
                    that.hjjcchartList[that.pointList[j]].pm10data.push(
                      data[i].evalue
                    );
                  } else if (data[i].items === "噪声") {
                    that.hjjcchartList[that.pointList[j]].zydata.push(
                      data[i].evalue
                    );
                  }
                }
              }
              console.log(that.hjjcchartList);
            })
            .then(() => {
              this.timeoutFalg = setTimeout(reqData.bind(this), tempTimer);
            });
        }
      }.bind(this)());
    },
    destroytime() {
      clearTimeout(this.timeoutFalg);
      this.settime = null;
    },
  },

  // beforeRouteLeave(to, form, next) {
  //   clearTimeout(this.timeoutFalg);
  //   next();
  // },
  destroyed() {
    clearTimeout(this.timeoutFalg);
  },
};
</script>
<style scoped lang="scss">
</style>