<template>
  <el-container style="height:100vh;background:#fff" direction="vertical">
    <base-header :currentModule="currentModule" :moduleList="moduleList"></base-header>
    <el-container>
      <base-aside :menuList="menuList"></base-aside>
      <el-main style="padding:0;max-height:calc(100vh - 60px)">
        <el-main style="padding:0">
          <router-view></router-view>
        </el-main>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import baseHeader from './header';
import baseAside from './aside';
import { getRequest } from '@/api/api';
import { generatorMenuList, getFirstMenu } from '@/utils';

export default {
  name: 'index',
  props: {
    moduleName: {
      type: String,
      required: true,
    }
  },
  data() {
    return {
      menuList: [],
      currentModule: {},
      moduleList: []
    };
  },
  created() {
    this.getMenuList();
  },
  methods: {
    getMenuList() {
      let para = {
        requestProject: this.requestProject
      };
      getRequest('/gic-authcenter/loginuser', para).then(res => {
        let resData = res.data;
        if (resData.errorCode == '0') {
          this.entranceList = [];
          let entranceList = resData.result.menuList ? generatorMenuList(resData.result.menuList) : [];
          let menu = entranceList.find(el => el.code === this.moduleName);
          this.menuList = menu.children;
          this.currentModule = menu;
          this.moduleList = entranceList;
          let firstMenu = getFirstMenu(this.menuList);
          if(this.$route.path === '/') {
            this.$router.replace({path: firstMenu.uri, query: { tabCode: firstMenu.code }});
          }
        } else {
          this.$message.error(resData.message);
        }
      }).catch(function(error) {
        throw error
      });
    }
  },
  components: {
    baseHeader,
    baseAside
  }
};
</script>

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