<template>
  <div class="shopmallLayout">
    <!-- navbar -->
    <div class="top">
      <navbar :is-show="isShow" />
    </div>
    <!-- body -->
    <div class="bottom">
      <div class="banner_wrap">
        <banner />
      </div>
      <div class="content">
        <div class="left">
          <sidebar v-if="sidebarData.length" :sidebar-data="sidebarData" />
        </div>
        <div class="right">
          <appMain />
        </div>
      </div>
    </div>
    <!-- footerbar -->
    <div class="footer">
      <footerbar />
    </div>
  </div>
</template>

<script>
import { navbar, appMain, banner, sidebar, footerbar } from './shopComponents'
import { getUserMenu } from '@/api/common/loginCenter'

export default {
  name: 'ShopmallLayout',
  components: {
    navbar,
    appMain,
    banner,
    sidebar,
    footerbar
  },
  data() {
    return {
      fixed: false,
      isShow: true,
      sidebarData: []
    }
  },
  watch: {
    '$route'(val) {
      this.$route.path === '/shop/shopHome' ? this.isShow = true : this.isShow = false
      this.getCartNumber()
    },
    '$store.getters.info.currentRol.roleCode'(val) {
      this.getShopmallUserMenu()
    }
  },
  created() {
    this.$route.path === '/shop/shopHome' ? this.isShow = true : this.isShow = false
    this.getShopmallUserMenu()
    this.getCartNumber()
  },
  methods: {
    // 解决进入 /personalCenter 路由下时，购物车数量错误的问题
    getCartNumber() {
    // 调用vuex获取购物车列表方法
      const data = {
        pageNo: 1,
        pageSize: 3
      }
      this.$store
        .dispatch('loadShoppingCart', data)
        .then(() => {})
        .catch(() => {})
    },
    // 获取电商菜单
    getShopmallUserMenu() {
      getUserMenu().then(res => {
        if (res.header.ret === '0') {
          this.sidebarData = res.data
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
@import "~@/assets/style/common/maincommon.less";
.shopmallLayout {
  height: 100vh;
  overflow: auto;
  .top,
  .content {
    max-width: 1366px;
    margin: 0 auto;
  }
  .bottom {
    background-color: #f4f4f4;
    min-height: 100vh;
    padding-bottom: 35px;
    .banner_wrap {
      background-color: @hyacinthine;
      padding: 14px 0;
    }
    .content {
      margin-top: 26px;
      display: flex;
      justify-content: space-between;
      .left {
        width: 11%;
        background: #ffffff;
        height: 620px;
        margin-right: 1%;
      }
      .right {
        width: 89%;
        background: #ffffff;
        font-size: 12px;
      }
    }
  }
  .footer {
    width: 100%;
  }
}
</style>
