<template>
  <div class="bpwyxyz" id="bpwyxyz">
    <div class="d_1_21 dx">表面位移X位移变化量： {{ xVal }}mm</div>
    <div class="d_1_21 dy">表面位移Y位移变化量： {{ yVal }}mm</div>
    <div class="d_1_21 dz">表面位移Z位移变化量： {{ zVal }}mm</div>
  </div>
</template>
<script>
import { bpNowData } from "@/api/bigscreen/index.js";
export default {
  name: "bpwyxyz",
  components: {},
  props: ["air"],
  data() {
    return {
      settime: 60 * 1000 * 10, //定时器时间
      equipStatus: null,
      xVal: null,
      yVal: null,
      zVal: null,
    };
  },
  watch: {
    air(newValue, oldValue) {
      if (newValue !== 1) {
        this.destroytime();
      } else {
        this.settime = 60 * 1000 * 10;
        this.bpXYZ();
      }
    },
  },
  created() {
    this.$nextTick(function () {});
  },
  mounted() {
    this.$nextTick(function () {
      // console.log(this.air, "air");
      this.bpXYZ();
    });
  },
  methods: {
    //边坡xyz
    bpXYZ() {
      let that = this;
      this.bpStutasList = [];
      let hjjcdata = [];
      let items = [];
      let tempTimer = this.settime;
      (function reqData() {
        clearTimeout(this.timeoutFalg);
        bpNowData()
          .then((res) => {
            // console.log(res.rows, "边坡xyz");
            this.xVal = res.rows[0].dispX;
            this.yVal = res.rows[0].dispY;
            this.zVal = res.rows[0].dispH;
            // for (let key in res) {
            //   items.push({ name: key, items: res[key] });
            // }

            // this.bpStutasList = items;
          })
          .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">
#bpwyxyz {
  width: 427px;
  margin: 0 auto;
  clear: both;
  float: none;

  div.d_1_21 {
    width: 427px;
    height: 52px;
    border: 1px solid #00f0ff;
    line-height: 52px;
    margin-bottom: 16px;
    font-family: Source Han Sans CN;
    font-size: 20px;
    text-align: center;
  }
  div.dx {
    margin-top: 10px;

    color: #0cbbfc;
  }
  div.dy {
    color: #3dfbeb;
  }
  div.dz {
    color: #00f20e;
  }
}
</style>