<template>
  <div :class="classObj" class="app-wrapper">
    <!-- <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" /> -->
    <van-nav-bar class="topNavBar" @click-left="onClickLeft" @click-right="onClickRight">
      <slot slot="left" name="left">
        <van-icon name="arrow-left" size="30" />
      </slot>
      <slot slot="title" name="title">{{ title }}</slot>
      <template #right>
        <van-icon name="wap-home" size='30' />
      </template>
    </van-nav-bar>
    <!-- <van-nav-bar title="标题" left-text="返回" right-text="按钮" left-arrow/> -->
    <sidebar class="sidebar-container" />
    <div class="main-container">
      <app-main />
    </div>
    <Footer />
  </div>
</template>

<script>
import { Navbar, Sidebar, AppMain, Footer } from './components'
import ResizeMixin from './mixin/ResizeHandler'

export default {
  name: 'Layout',
  components: {
    Navbar,
    Sidebar,
    AppMain,
    Footer
  },
  mixins: [ResizeMixin],
  data () {
    return {
      title: null
    }
  },
  computed: {
    routes () {
      return this.$router.options.routes
    },
    activeMenu () {
      const route = this.$route
      const { meta, path } = route
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu
      }
      return path
    },
    sidebar () {
      return this.$store.state.app.sidebar
    },
    device () {
      return this.$store.state.app.device
    },
    /* fixedHeader () {
      return this.$store.state.settings.fixedHeader
    }, */
    classObj () {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    }
  },

  created () {
    // console.log(this.$router.currentRoute.matched[0].meta.title,'router.currentRoute')

  },
  mounted () {
    this.title = this.$router.currentRoute.matched[0].meta.title
  },
  methods: {
    handleClickOutside () {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    },
    handleBack () {
      console.log("返回")
    },
    onClickLeft () {
      console.log('返回！')
      // history.back()
      this.$router.go(-1)
    },
    onClickRight () {
      // console.log('返回主页！')
      this.$router.push({ path: "/dashboard" })
    },
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
@import "~@/styles/variables.scss";

.app-wrapper {
  @include clearfix;
  position: relative;
  // height: 100%;

  width: 100%;
  background-color: #f5f5fa;
  &.mobile.openSidebar {
    position: fixed;
    top: 46px;
  }
}
.drawer-bg {
  background: #000;
  opacity: 0.3;
  width: 100%;
  top: 0;
  height: 100%;
  position: absolute;
  z-index: 999;
}

.fixed-header {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 9;
  width: calc(100% - #{$sideBarWidth});
  transition: width 0.28s;
}

.hideSidebar .fixed-header {
  width: calc(100% - 54px);
}

.mobile .fixed-header {
  width: 100%;
}
::v-deep .topNavBar {
  background-color: #5283e7;
  // color: #fff;
  font-size: 26px;
  .van-nav-bar__title {
    color: #fff;
  }
  .van-icon {
    color: #fff;
  }
}
::v-deep .sidebar-container {
  background-color: #fff;
  border-right: 1px solid #ccc;
  // box-shadow: 1px 0px 3px rgba(0, 0, 0, 0.9);
  box-shadow: 5px 0 10px -5px #e2e2e6;

  /* .el-submenu.is-active .el-submenu__title {
    border-left: 3px solid #5283e7;
  } */
  .svg-icon {
    font-size: 18px;
  }
  .el-submenu.is-opened .el-submenu__title {
    border-left: 3px solid #5283e7;
    background-color: #e5edfb;
    .sub-el-icon {
      color: #5283e7;
    }
    .svg-icon {
      color: #5283e7;
    }
  }
  .el-submenu.is-opened .el-menu .nest-menu {
    color: #000;
    .el-menu-item {
      padding-left: 50px;
    }
    .el-menu-item.is-active {
      font-weight: 700;
    }
  }
}
.main-container {
  margin-left: 210px;
  background-color: #ccc;
}
</style>
