<template>
  <div class="wrapper">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
    <div class="footer">
      <router-link class="btn-marketing" :to="{path: defaultNav || '/partner'}" replace>
        <img src="./image/tab_xiaoshou_nor@2x.png" alt="" v-show="$route.name === 'partnerMine'">
        <img src="./image/tab_xiaoshou_sel@2x.png" alt="" v-show="$route.name !== 'partnerMine'">
        <span>销售</span>
      </router-link>
      <router-link class="btn-mine" :to="{path: '/partner/mine'}" replace>
        <img src="./image/tab_wode_nor@2x.png" alt="" v-show="$route.name !== 'partnerMine'">
        <img src="./image/tab_wode_sel@2x.png" alt="" v-show="$route.name === 'partnerMine'">
        <span>我的</span>
      </router-link>
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'

export default {
  name: 'home',
  computed: {
    ...mapGetters({
      userInfo: 'partnerMine/userInfo',
      defaultNav: 'business/defaultNav'
    })
  },
  methods: {
    ...mapActions({
      fetchUserInfo: 'partnerMine/fetchUserInfo'
    })
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      const { id } = vm.userInfo
      if (!id) {
        vm.fetchUserInfo()
      }
    })
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100%;
}

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  border-radius: 10px 10px 0 0;
  box-shadow: 0 2px 24px 0 rgba(0, 0, 0, 0.04);
  background: #fff;
}

.btn-marketing,
.btn-mine {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;

  img {
    width: 29px;
    height: 28px;
  }

  span {
    margin-top: 1px;
    line-height: 14px;
    font-size: 10px;
    color: #999;
  }
}
</style>
