<template>
  <div>
    <div>
      <headers :rightDate="rightDate" @menu-click="handleMenuClick"></headers>
    </div>
    <div class="contents">
      <div>
        <sidebar @headerDate="headerDate"></sidebar>
      </div>

      <div class="content">
        <router-view></router-view>
      </div>
    </div>

  </div>
</template>

<script>
import headers from '@/components/header'
import sidebar from '@/components/sidebar'
export default {

  components: {
    headers,
    sidebar
  },
  data() {
    return {
      rightDate: ""
    }
  },

  mounted() {

  },
  methods: {
    // 处理菜单点击事件
    handleMenuClick(item) {
      console.log('获取到这个路由', item);
      if (item.route && this.$route.path !== item.route) { // 增加判断
        this.$router.push(item.route);
      }
    },

    //获取头部的数据
    headerDate(e) {
      console.log('查看数据111', e)
      if (e.name == '财务概览') {
        this.rightDate = [
          {
            name: "经营情况",
            route: '/operate'
          }, {
            name: "年度审计情况",
            route: '/annual'
          },
          { name: "专项审计情况" },
          { name: "企业所得税纳税情况" }]
        if (this.$route.path !== e.route) { // 增加判断
          this.$router.push(e.route);
        }
      } else if (e.name == '企业概况') {

        this.rightDate = [
          {
            name: "数据概览",
            route: '/home'
          }, {
            name: "资料检索",
            route: '/home/dataretrieval'
          },
          {
            name: "企业信息",
            route: '/home/corporateInformation'
          },
        ]
        // 强制跳转到数据概览页面
        if (this.$route.path !== '/home' && !this.$route.path.startsWith('/home/')) {
          this.$router.push('/home');
        } else if (this.$route.path !== '/home') {
          this.$router.push('/home');
        }
      }


      else if (e.name == '人力资源') {
        this.rightDate = [{ name: "组织架构" }, { name: "职工管理" },{ name: "科技专家" }]
      } else if (e.name == '成果管理') {
        this.rightDate = [{ name: "知识产权" }, { name: "论文管理" }, { name: "标准制定" }]
      } else if (e.name == '资质荣誉') {
        this.rightDate = [{ name: "企业资源" }, { name: "企业荣誉" }]
      } else if (e.name == '制度文件') {
        this.rightDate = [{ name: "制度通知" }]
      } else if (e.name == '合同登记') {
        this.rightDate = [{ name: "登记管理" }]
      }
      console.log('头部的数据', e, this.rightDate)

    }
  }
}
</script>

<style scope>
.contents {
  display: flex;
}

.content {
  margin-left: 40px;
  width: 85%;

  margin-top: 20px;
  border-radius: 10px;
}
</style>