<template>
  <!-- 底部横条 -->
  <div class="nav-bar van-hairline--top">
    <ul class="nav-list">
      <router-link class="nav-list-item active" to="home">
        <div class="nbicon">
          <van-image class="navIconImage dailyImage" :src="homeUrl"/>
          <van-image class="navIconImage activeImage" :src="homeActiveUrl"/>
        </div>
        <span>{{$t('navBar.homePage')}}</span>
      </router-link>
      <router-link class="nav-list-item" to="device">
        <div class="nbicon">
          <van-image class="navIconImage dailyImage" :src="deviceUrl"/>
          <van-image class="navIconImage activeImage" :src="deviceActiveUrl"/>
        </div>
        <span>{{$t('navBar.deviceInformation')}}</span>
      </router-link>
      <router-link class="nav-list-item" to="robotranking">
        <div class="nbicon">
          <van-image class="navIconImage dailyImage" :src="rankingUrl"/>
          <van-image class="navIconImage activeImage" :src="rankingActiveUrl"/>
        </div>
        <span>{{$t('navBar.machineRanking')}}</span>
      </router-link>
      <router-link class="nav-list-item" to="user">
        <div class="nbicon">
          <van-image class="navIconImage dailyImage" :src="userUrl"/>
          <van-image class="navIconImage activeImage" :src="userActiveUrl"/>
        </div>
        <span>{{$t('navBar.personalCenter')}}</span>
      </router-link>
    </ul>
  </div>
</template>

<script>
import { onMounted, computed } from "vue";
import { useStore } from "vuex";
import homeUrl from "@/assets/navbarLogo/home.png";
import homeActiveUrl from "@/assets/navbarLogo/homeActive.png";
import deviceUrl from "@/assets/navbarLogo/device.png";
import deviceActiveUrl from "@/assets/navbarLogo/deviceActive.png";
import rankingUrl from "@/assets/navbarLogo/ranking.png";
import rankingActiveUrl from "@/assets/navbarLogo/rankingActive.png";
import userUrl from "@/assets/navbarLogo/user.png";
import userActiveUrl from "@/assets/navbarLogo/userActive.png";

export default {
  setup() {
    // const route = useRoute()
    const store = useStore();
    onMounted(() => {
      // const token = getLocal('token')
      // const path = route.path
      // if (token && !['/home', '/category'].includes(path)) {
      //   store.dispatch('updateCart')
      // }
    });
    const count = computed(() => {
      return store.state.cartCount;
    });

    return {
      count,
      homeUrl,
      homeActiveUrl,
      deviceUrl,
      deviceActiveUrl,
      rankingUrl,
      rankingActiveUrl,
      userUrl,
      userActiveUrl
    };
  },
};
</script>

<style lang="less" scoped >
@import "../common/style/mixin";
.nav-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  padding: 5px 0;
  z-index: 1000;
  background: #fff;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  .nav-list {
    width: 100%;
    .fj();
    flex-direction: row;
    padding: 0;
    .navIconImage { width: 22px; height: 22px; }
    .dailyImage { display: inline-block; }
    .activeImage { display: none; }
    .nav-list-item {
      display: flex;
      flex: 1;
      flex-direction: column;
      text-align: center;
      color: #666;
      &.router-link-active {
        color: rgba(77,106,221,1);
        .dailyImage { display: none; }
        .activeImage { display: inline-block; }
      }
      i {
        text-align: center;
        font-size: 22px;
      }
      span {
        font-size: 12px;
      }
      .van-icon-shopping-cart-o {
        margin: 0 auto;
        margin-bottom: 2px;
      }
    }
  }
}
</style>
