<template>
  <div class="intelligent_drawing-container">
    <div class="apass_breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>在线组件工具</el-breadcrumb-item>
        <el-breadcrumb-item>智能制图</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="main-container">
      <iframe ref="intelligent_drawing_iframe" width="100%" height="100%" scrolling="no" :src="znztUrl" frameborder="0"></iframe>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      url:'https://apaasgis.wodcloud.com/portal/apaasplat/viewer/mapViewer.html',
    };
  },
  computed:{
    getZnztParams() {
      return this.$store.state.znztParams;
    },
    znztUrl(){
      return this.url+this.urlParams
    },
    urlParams(){
      if(this.$store.state.znztParams){
        return `?webmap=${this.$store.state.znztParams.id}`;
      }else{
        return ''
      }
    },
  },
  watch: {
    getZnztParams(newVal) {
      this.urlParams = `?webmap=${newVal.id}`
      console.log('智能制图参数'+newVal)
    },
  },
  mounted() {
    this.$nextTick(() => {
      window.addEventListener('message',event =>{
        let data = event.data;
        // 智能制图发布服务
        if (data.cmd == 'mapviewmsg'){
          console.log(data);
          this.$store.commit("setZnztParams", data.params);
          this.$router.push(`/fwzc/fwcs`);
        }
        // App Builder页面 -- 新窗口打开
        if (data.cmd == 'mapviewtoapp'){
          console.log(data);
          let params = {
            title: data.params.title,
            tags: data.params.tags,
            sharewithwebmap:data.params.shareWithWebMap,
            webmap:data.params.id,
            summary: data.params.summary,
          };
          let routeData = this.$router.resolve({
            name: "intelligent_appbuilder",
            query: params,
          });
          window.open(routeData.href, '_blank');
          // this.$store.commit("setAppBuilderParams", data.params);
        }
        // 智能制图服务详情--新窗口打开
        if (data.cmd == 'mapdetailmsg'){
          console.log(data);
          let routeData = this.$router.resolve({
            name: "intelligent_details",
            query: data.params,
          });
          window.open(routeData.href, '_blank');
        }
      })
    })
  },
  methods: {},
  destroyed () {
    window.removeEventListener('message')
  } 
};
</script>

<style scoped>
.intelligent_drawing-container {
  margin: -157px 40px 20px;
}
.intelligent_drawing-container .main-container {
  height: calc(100vh - 150px - 43px);
  border-radius: 12px;
  background-color: #fff;
  padding: 0px;
}
.intelligent_drawing-container .main-container iframe {
  border-radius: 12px;
}
</style>

<style>
.intelligent_drawing-container .apass_breadcrumb {
  padding: 0 20px;
}
.intelligent_drawing-container .apass_breadcrumb > .el-breadcrumb .el-breadcrumb__inner {
  color: #626de9;
}
.intelligent_drawing-container
  .apass_breadcrumb
  > .el-breadcrumb
  .el-breadcrumb__item:last-child
  .el-breadcrumb__inner {
  color: #b4c0f5;
}
</style>
