<template>
  <div v-loading="loading" class="app-container">
    <iframe id="companyIframe" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" width="100%" :style="{height:iframeHight+'px'}" :src="src" />
  </div>
</template>

<script>
import { steerScroll } from '@/assets/js/jskplug'
export default {
  name: 'Company',
  components: {

  },
  data() {
    return {
      loading: false, // 是否加载完成-当前页控制
      iframeTimer: '',  // 是否加载中定时器-当前页控制
      iframeHight: window.innerHeight, // iframe高度-当前页控制
      navigation: {isFixed: true, fixedHeight: 56, totalHeight: 68},  // iframe之外页面顶部对象，ifFixed:是否浮动；fixedHeight：浮动对象高度；totalHeight：顶部整体高度
      src: '',  //iframe嵌套页面地址
      domain: 'https://pre-plug.jiansheku.com',
      // domain: 'http://192.168.60.30:3300',
      ak: 'aec7b3ff2y2q8x6t49a7e2c463ce21912' // 需要携带的sdkId
    }
  },
  created() {
    if (this.$route.params.id) { // 获取companyId
      this.loading = true
      if(this.$route.name=='Company'){  //企业详情
        this.src = `${this.domain}/enterprise/${this.$route.params.id}?ak=${this.ak}`
      }
      if(this.$route.name=='Personnel'){ //人员详情
        this.src = `${this.domain}/personnel/${this.$route.params.id}.html?ak=${this.ak}`
      }
    }
  },
  mounted() {
    this.iframeLoading() // 判断iframe页面是否加载完成-当前页控制
    steerScroll('companyIframe', this.navigation, true) // 监听滚动（iframe的id、页面排除iframe后页面剩下顶部高度[例:80]、增加监听[不传就是移除监听]、父级id[不带默认就是铺满整个页面]]）
  },
  beforeDestroy() {
    clearInterval(this.iframeTimer) // -当前页控制
    steerScroll('companyIframe', this.navigation) // 销毁滚动
  },
  methods: {
    //判断iframe页面是否加载完成-当前页控制
    iframeLoading() {
      let iframeHeight = document.getElementById("companyIframe").clientHeight, number = 0
      this.iframeTimer = setInterval(()=>{
        number ++
        if(document.getElementById("companyIframe").clientHeight != iframeHeight || number == 5000){
          this.loading = false
          clearInterval(this.iframeTimer)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .app-container{
    padding: 0;
  }
</style>
