<template>
  <div class="home subject-home">
    <div class="home-header">
      <view-header>
        <div class="home-navs" slot="info">
          <ul>
            <li
              :class="{ act: curNav.name === nav.name }"
              v-for="(nav, index) in navs"
              :key="index"
              @click="switchNav(nav)"
            >
              <span class="nav-item-cont">{{ nav.title }}</span>
            </li>
          </ul>
        </div>
      </view-header>
    </div>

    <div class="home-body">
      <div class="home-main">
        <router-view />

        <view-footer></view-footer>
      </div>
    </div>
  </div>
</template>

<script>
import { navs } from "../router";

export default {
  name: "subject-home",
  data() {
    return {
      navs: [],
      curNav: {}
    };
  },
  mounted() {
    this.navs = [{ name: "Overview", title: "首页" }, ...navs];
    this.actCurNav(this.$route);
  },
  methods: {
    switchNav(item) {
      if (item.name === this.curNav.name) return;

      this.curNav = item;
      this.$router.push({
        name: item.name,
        params: {
          workId: this.$route.params.workId
        }
      });
    },
    actCurNav(router) {
      this.curNav = this.navs.find(item => item.name === router.name);
    }
  }
};
</script>
