<template>
  <div class="page-content corporate-customers">
    <transition-group
      :name="transitionName"
      appear
      class="transition-group"
      tag="div"
    >
      <!--   表格页面   -->
      <table-page
        v-show="componentName === 'TablePage'"
        key="TablePage"
        :componentName="componentName"
        @changePage="changePage"
      />
      <!-- 巡检记录页面 -->
      <resultListPage
        ref="resultListPage"
        key="ResultListPage"
        v-show="componentName === 'ResultListPage'"
        :componentName="componentName"
        @changePage="changePage"
      ></resultListPage>

      <!-- 异常记录 -->
      <abnormalListPage
        ref="abnormalListPage"
        key="AbnormalListPage"
        v-show="componentName === 'AbnormalListPage'"
        :componentName="componentName"
        @changePage="changePage"
      ></abnormalListPage>
    </transition-group>
  </div>
</template>

<script>
import TablePage from './components/TablePage/index'
import ResultListPage from './components/ResultListPage/index.vue'
import AbnormalListPage from './components/AbnormalListPage/index.vue'
import PubSub from 'pubsub-js'

export default {
  name: 'videoInspectionResults',
  components: {TablePage, ResultListPage, AbnormalListPage},
  data() {
    return {
      componentName: 'TablePage',
      pubSub: null,
      transitionName: '',
    }
  },
  mounted() {
    // 添加自定义面包屑pub-sub
    this.pubSub = PubSub.subscribe('breadcrumb-click', (_, item) => {
      if (item.isCurrentRoute) {
        // this.clearVideoPage()
        this.componentName = 'TablePage'
      }
    })
  },
  methods: {
    // pageName显示页面标识符 done回调函数，保证页面挂载后执行的逻辑
    /**
     * @param {String} pageName 显示页面标识符(必传)
     * @param {Function} done 回调函数(非必传)
     * @param {String} type 面包屑标题(非必传)
     * */
    changePage(pageName = '', done, type = '') {
      this.componentName = pageName
      this.transitionName =
        this.transitionName === 'fold-right' ? 'fold-left' : 'fold-right'
      done && done()
      switch (pageName) {
        case 'TablePage':
          PubSub.publish('go-back')
          break
        case 'ResultListPage':
          PubSub.publish('add-custom-breadcrumb', '巡检记录')
          break
        case 'AbnormalListPage':
          PubSub.publish('add-custom-breadcrumb', '上报记录')
      }
    },
  },
  beforeDestroy() {
    // 在组件销毁之前 清除订阅消息
    PubSub.unsubscribe(this.pubSub)
  },
}
</script>

<style lang="scss" scoped></style>
