<template>
  <!-- CIM -->
  <div class="container">
    <div class="leftBox">
      <div class="leftTop">
        <leftTop title="模型" />
      </div>
      <div class="leftCenter">
        <leftCenter title="模型审报" />
      </div>
    </div>
    <div class="centerBox">
      <iframe src="/bim.html" frameborder="0" width="100%" height="100%" id="iframe" @load="load"></iframe>
    </div>
    <div class="rightBox">
      <div class="rightTop">
        <rightTop title="BIM预留接口" />
      </div>
      <div class="rightCenter">
        <rightCenter title="设计变更" />
      </div>
    </div>
  </div>
</template>

<script>
import leftTop from './leftTop'
import leftCenter from './leftCenter'
import rightTop from './rightTop'
import rightCenter from './rightCenter'

import { projectJlwBimListApi, getJlwTokenApi } from '@/assets/js/api/project'
export default {
  components: {
    leftTop,
    leftCenter,
    rightTop,
    rightCenter
  },
  mounted() {
    this.iframe = document.getElementById('iframe')
    window.addEventListener('message', this.getIframeMessage)
    this.getModelList()
  },
  data() {
    return {
      iframe: null
    }
  },
  methods: {
    load() {
      this.iframe.contentWindow.postMessage('Message from parent：load complate！')
    },
    getIframeMessage(e) {
      // console.log('Message from iframe：', e.data)
    },
    getModelList() {
      projectJlwBimListApi({ projectSn: this.$store.state.projectSn }).then(res => {
        this.buildList = res.result.page.records
        res.result.page.records.forEach(item => {
          if (item.isEnable) {
            // this.iframe.contentWindow.postMessage({ fileId: item.fileId })
            this.getToken(item.fileId)
          }
        })
      })
    },
    getToken(fileId) {
      getJlwTokenApi({ fileId, projectSn: this.$store.state.projectSn }).then(res => {
        const token = res.result
        console.log('token', token)
      })
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  position: relative;
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  background-color: #07162b;
  background-image: url('~@/assets/images/projectImg/Bimbgc.png');
}
.topBox {
  height: 20%;
}
.leftBox {
  position: relative;
  width: 25%;
  height: 100%;
  margin-right: 15px;
  margin-left: 15px;
  .leftTop {
    height: 33%;
    margin-bottom: 15px;
  }
  .leftCenter {
    height: 33%;
    margin-bottom: 15px;
  }
  .leftBottom {
    height: 33%;
  }
  z-index: 2;
}
.centerBox {
  position: absolute;
  margin-right: 15px;
  padding-left: 6px;
  width: 100%;
  height: 100%;
  line-height: 30px;
  font-size: 18px;
  color: #6ee4f0;
}

.rightBox {
  position: relative;
  width: 25%;
  height: 100%;
  .rightTop {
    height: 33%;
    margin-bottom: 15px;
  }
  .rightCenter {
    height: 33%;
    margin-bottom: 15px;
  }
  z-index: 2;
}
</style>
