<template>
  <div v-loading="loading">
    <el-button
      type="primary"
      size="mini"
      style="margin-bottom: 10px"
      @click="dianji"
    >
      {{ $t('defalult.qp') }}
    </el-button>
    <iframe
      id="iframeId"
      ref="iframe"
      :src="src"
      style="width: 100%; height: 495px"
    ></iframe>
  </div>
</template>

<script>
export default {
  props: {
    deviceCode: {
      type: Number,
    },
    // screenView: {
    //   type: String,
    //   default: '',
    // },
  },
  data() {
    return {
      technologyData: [],
      loading: true,
      fullscreenLoading: true,
      queryForm: {
        deviceCode: '',
      },
      src: '',
    };
  },
  watch: {
    deviceCode: function (newVal, oldVal) {
      const projectId = sessionStorage.getItem('projectId');
      const userId = localStorage.getItem('userId');
      this.src =
        'https://dp.lidinghb.com/chudy_visual/view/1861637774365560832?projectId=' +
        projectId +
        '&userId=' +
        userId +
        '&id=' +
        newVal;
    },
  },
  created() {},
  mounted() {
    const { iframe } = this.$refs;
    // IE和非IE浏览器，监听icframe加载事件不一样，需要兼容
    const that = this;
    if (iframe.attachEvent) {
      // IE
      iframe.attachEvent('onload', () => {
        that.stateChange();
      });
    } else {
      // 非IE
      iframe.onload = function () {
        that.stateChange();
      };
    }
  },
  methods: {
    showData(row) {
      console.log(row);
    },
    stateChange() {
      this.loading = false;
    },
    dianji() {
      //设置后就是id==con_lf_top_div 的容器 {{ $t('defalult.qp') }}
      const case1 = document.getElementById('iframeId');
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen();
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen();
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen();
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen();
        }
      } else {
        if (case1.requestFullscreen) {
          case1.requestFullscreen();
        } else if (case1.webkitRequestFullScreen) {
          case1.webkitRequestFullScreen();
        } else if (case1.mozRequestFullScreen) {
          case1.mozRequestFullScreen();
        } else if (case1.msRequestFullscreen) {
          // IE11
          case1.msRequestFullscreen();
        }
      }
    },
  },
};
</script>
