index.vue 2.11 KB
<!-- 费用类目管理 -->
<template>
  <d2-container class="account">
    <div class="header" slot="header">
      <el-tabs v-model="activeName">
        <el-tab-pane label="分账类目" name="ledger" />
        <el-tab-pane label="对账类目" name="reconciliation" />
      </el-tabs>
    </div>
    <div>
      <ledger-list v-if="activeName === 'ledger'" ref="ledgerListRef" />
      <reconciliation-list v-if="activeName === 'reconciliation'" ref="reconciliationListRef" />
    </div>
  </d2-container>
</template>

<script>
import ledgerList from './ledgerList'
import reconciliationList from './reconciliationList'
export default {
  name: 'CostCategoryIndex',
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      activeName: 'ledger'
      // activeName: 'reconciliation'
    }
  },

  components: {
    ledgerList,
    reconciliationList
  },

  mounted() {
    if (this.$route.params.activeName) {
      this.activeName = this.$route.params.activeName
    }
    this.refreshListIfNeeded()
  },

  watch: {
    $route() {
      if (this.$route.params.activeName) {
        this.activeName = this.$route.params.activeName
      }
      this.refreshListIfNeeded()
    }
  },

  methods: {
    /** 从详情/编辑页返回时带 query.listRefresh=1,刷新当前 Tab 列表 */
    refreshListIfNeeded() {
      if (this.$route.name !== 'costCategoryManage' || this.$route.query.listRefresh !== '1') {
        return
      }
      if (this.$route.params.activeName) {
        this.activeName = this.$route.params.activeName
      }
      this.$nextTick(() => {
        if (this.activeName === 'ledger') {
          const child = this.$refs.ledgerListRef
          if (child && child.refreshList) child.refreshList()
        } else {
          const child = this.$refs.reconciliationListRef
          if (child && child.refreshList) child.refreshList()
        }
        this.$router.replace({
          name: 'costCategoryManage',
          params: { activeName: this.activeName },
          query: {}
        })
      })
    }
  }
}

</script>
<style>
.account .el-tabs__header {
  margin: 0;
  padding: 0 20px;
}
</style>