<template>
  <content-layout
    :tab-pane-list="currentShowTab"
    @tab-click="handleTabClick"
    @node-click="handleNodeClick"
  >
    <keep-alive :include="keepaliveComponents">
      <component
        :is="currentView[currentActiveTab]"
        :ref="`${currentActiveTab}Table`"
        v-loading="loading"
      ></component>
    </keep-alive>
  </content-layout>
</template>

<script>
  import { mapState } from 'vuex'

  import processClassify from '@/mixins/processClassify.js'
  import fromModule from '@/mixins/fromModule'

  import { TAB_PANE_LIST, COMPONENTS_MAP } from './const'
  export default {
    name: 'NewMatter',
    components: {
      ContentLayout: () => import('@/views/matter/components/ContentLayout'),
      ProcessOverview: () => import('./ProcessOverview'),
      MyCollection: () => import('./MyCollection'),
      MyDraft: () => import('./MyDraft'),
    },
    mixins: [processClassify, fromModule],
    data() {
      return {
        isKeepalive: false,
        currentTabPaneList: TAB_PANE_LIST,
        currentView: COMPONENTS_MAP,
        currentActiveTab: this.$route.query.tabActiveName || 'processOverview',
      }
    },
    computed: {
      ...mapState('user', ['account']),
      keepaliveComponents() {
        return this.isKeepalive ? Object.values(COMPONENTS_MAP) : []
      },
    },
    activated() {
      this.currentActiveTab =
        this.$route.query.tabActiveName || 'processOverview'
    },
    created() {
      if (localStorage.getItem(`keepalive_${this.account}`)) {
        const keepaliveRouteList = JSON.parse(
          localStorage.getItem(`keepalive_${this.account}`)
        )
        if (keepaliveRouteList && keepaliveRouteList.length) {
          this.isKeepalive = keepaliveRouteList
            .map((item) => item.name)
            .includes('NewMatter')
        }
      }
    },
    mounted() {
      this.currentActiveTab =
        this.$route.query.tabActiveName || 'processOverview'
    },
  }
</script>

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