<template>
  <div>
    <!-- 为了解决菜单高亮的问题，暂时的解决方式是将两个页面作为组件写入页面，通过判断显示不同组件 -->
    <!-- 联锁总表 -->
    <template v-if="showPage === 'summary'">
      <!-- IoT TPM相关 修改框架 -->
      <!-- <a-tabs v-if="layoutMode === 'iotmenu'"  type="card" default-active-key="1">
        <a-tab-pane :id="page.fullPath" :key="page.fullPath" v-for="page in iotTpmageList">
          <span slot="tab" :pagekey="page.fullPath">{{ page.meta.title }}</span>
        </a-tab-pane>
      </a-tabs> -->
      <div class="iotmenu-content-header">
        <a-icon type="file-text" />
        <span>联锁总表</span>
      </div>
      <div class="iotmenu-content">
        <u-equipment-tree-drag treeTitle="装置系统" @select="selectEquipment">
          <interlock-summary-list ref="summaryList" @click="summaryListClick"></interlock-summary-list>
        </u-equipment-tree-drag>
      </div>
    </template>
    <!-- 详情 -->
    <interlock-detail-list v-if="showPage === 'detail'" @click="showPage='summary'" ref="summaryDetailRef" :currentData="currentData"></interlock-detail-list>
  </div>
</template>

<script>
  import InterlockSummaryList from './InterlockSummaryList.vue';
  import InterlockDetailList from '../interlockSummaryDetail/InterlockSummaryDetailList.vue';
  import store from '@/store'

  export default({
    components: {
      InterlockSummaryList,
      InterlockDetailList
    },
    data () {
      return {
        showPage: 'summary',
        currentData: {}
      }
    },
    beforeRouteEnter(to, from, next) {
      if(from.path !== '/interLock/summary/set'){
        store.commit('SET_CLICKSYSTEMNODE', {});
        store.commit('SET_TREESELECTKEYS', []);
        store.commit('SET_TREEEXPANDEKEYS', []);
      }
      next()
    },
    created() {
    },
    mounted() {
    },
    // beforeDestroy() {
    //   if(this.$route.path !== '/interLock/summary/set'){
    //     // 除了进入新增编辑页面外，销毁vuex数据
    //     this.$store.commit('SET_CLICKSYSTEMNODE', {});
    //     this.$store.commit('SET_TREESELECTKEYS', []);
    //     this.$store.commit('SET_TREEEXPANDEKEYS', []);
    //   }
    // },
    methods: {
      selectEquipment(){
        this.$refs.summaryList.loadData();
      },
      summaryListClick(data){
        // this.showPage='detail'
        // this.currentData = data
        console.log(data)
        sessionStorage.setItem("detail_sid", data.summaryid)
        sessionStorage.setItem("detail_isid", data.interlockSystemId)
        sessionStorage.setItem("detail_dname", data.detailName)
        this.$router.push({path: "/interLock/detail"})
        // this.$nextTick(()=>{
        //   this.$refs.summaryDetailRef.currentData = data
        //   console.log('ref', this.$refs.summaryDetailRef.currentData)
        // })
      },
    },
  })
</script>

