<template>
  <div
    class="height100"
    :style="'position: relative;overflow:auto;background:'+(params.type=='physical'?'#fff':'var(--light-back-grey)')"
  >
    <div
      class="height100"
      v-for="(item, index) in menu"
      :key="index"
      style="position: absolute; left: 0; top: 0; width: 100%;"
      :style="{ opacity: item.id == params.id ? '1':'0', 'pointer-events': item.id == params.id ? '':'none', 'z-index': item.id == params.id ? '10':'1' }"
    >
      <!--物理单表 -->
      <!-- <previewPhysical
        v-if="item.type=='physical'"
        :params="item"
        :key="'page' + params.id"
        :ref="'customModF' + index"
      ></previewPhysical> -->
      <!--页面设计器 -->
      <biPreviewForm
        :params="item"
        :key="'page' + index + new Date()"
        :ref="'customModF' + index"
        :isFromPreview="true"
      ></biPreviewForm>
    </div>
  </div>
</template>

<script>
// import biPreviewForm from './biPreviewForm'
// import previewPhysical from '../systemAssemble/dataAssemble/physicalForm/previewPhysical'
export default {
  name: 'biPreview',
  components: {
    // biPreviewForm
    // previewPhysical
  },
  data: function() {
    return {
      show: true,
      menu: [],
      nowPage: {},
      params: {}
    }
  },
  created() {
    this.params = this.paramsFn()
    this.menu.push(this.params)
  },
  deactivated(val) {},
  mounted() {
    //非物理表
    if (this.params && this.params.type != 'physical') {
      this.setLog(this.params.id)
    }
  },
  methods: {
    // 地址参数获取
    paramsFn() {
      if (this.$route.query && this.$route.query.mid) {
        // 门户或者自定义报表或物理单表
        return {
          id: this.$route.path.substring(14),
          type: this.$route.query.type
        }
      }
      return { id: '' }
    },
    // 记录
    setLog(fromId) {
      if (fromId&&window.biUsersLog) {
        let param = {
          runtime: this.$utils.getTodayDate('time'),
          usercode: global.userInfo.usercode,
          fun_Id: fromId,
          fun_type: 1,
          deptname: global.userInfo.deptname,
          username: global.userInfo.username,
          deptcode: global.userInfo.deptcode
        }
        // 记录行迹
        this.$api({
          url: '/ts-platform-work/http/UsersLog',
          method: 'post',
          loading: false,
          data: param,
          headers: {
            'Content-Type': 'application/json; charset=utf-8',
            'trasen-token': window.platToken
          }
        }).then(res => {})
      }
    }
  },
  deactivated() {},
  watch: {
    $route(to, from) {
      let fromId =
        from.path &&
        from.path.indexOf('/bi/biPreview_') == 0 &&
        from.query.type != 'physical'
          ? from.path.substring(14)
          : ''
      if (fromId) {
        // 删除跳转走后的页面内容
        let biPreviewMap = { ...this.$store.state.bi.biPreviewMap }
        delete biPreviewMap[fromId]
        this.$store.commit('setAllBiPreviewMap', { ...biPreviewMap })
      }
      let toId =
        to.path &&
        to.path.indexOf('/bi/biPreview_') == 0 &&
        to.query.type != 'physical'
          ? to.path.substring(14)
          : ''
      if (toId) {
        this.setLog(toId)
      }
      let state = true
      let index = 0
      this.params = this.paramsFn()
      this.menu.forEach((v, i) => {
        if (v.id === this.params.id) {
          state = false
          index = i
        }
      })
      if (state === true) {
        this.menu = [this.params]
      }
      // this.$nextTick(() => {
      //   this.$refs['customModF' + index][0].refresh()
      // })
    }
    // '$store.state.bi.closePageObj': {
    //   handler(n, o) {
    //     // 
    //     // let params = this.paramsFn(n.url)
    //     // for (let i in this.menu) {
    //     //   if (this.menu[i].id === params.id) {
    //     //     this.menu.splice(i, 1)
    //     //     break
    //     //   }
    //     // }
    //   },
    //   deep: true
    // }
  }
}
</script>

<style scoped>
</style>
