<template>
  <div class="app-main" :id="isApp_main ? 'app-main-id' : ''">
      <keep-alive :include="include">
        <router-view :id="isApp_main ? 'appMain-box' : ''" />
      </keep-alive>
  </div>
</template>

<script>
export default {
  name: 'AppMain',
  data() {
    return {
      include: []
    }
  },
  computed: {
    isApp_main() {
      if (
        this.$store.state.permission.addRoutes.find(
          v => v.name == this.$route.name
        )
      ) {
        return true
      } else {
        return false
      }
    }
  },
  watch: {
    $route(to, from) {
      if (to.meta.keepAlive) {
        !this.include.includes(to.name) && this.include.push(to.name)
      }
      if (to.meta.parentNode && to.meta.parentNode.indexOf(from.name) > -1) {
        !this.include.includes(from.name) && this.include.push(from.name)
      } else if (
        from.meta.parentNode &&
        from.meta.parentNode.indexOf(to.name) > -1
      ) {
        console.log()
      } else {
        if (from.meta.parentNode) {
          let index = this.include.indexOf(from.meta.parentNode)
          index !== -1 && this.include.splice(index, 1)
        }
        if (!from.meta.parentNode) {
          let index = this.include.indexOf(from.name)
          index !== -1 && this.include.splice(index, 1)
        }
      }
    }
  }
}
</script>

<style lang="less" type="text/scss" scoped>
#appMain-box {
  margin: 20px 16px 20px 23px;
  padding: 10px 20px;
  background: #fff;
}
#app-main-id {
  max-height: calc(100vh - 40px);
}
.app-main {
  width: 100%;
  height: 100%;
  position: relative;
  overflow-y: auto;
  flex: 1;
  background: #fff9f9;
}
.fixed-header + .app-main {
  padding-top: 50px;
}
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 15px;
  }
}
</style>
