<template>
  <div class="toolBar">
    <div class="item" v-if="userInfo" @click="go('/cart')">
      <i class="img el-icon-shopping-cart-2"></i>
      <div class="text">购物车</div>
    </div>

    <div class="item">
      <img src="@/assets/qr.png" class="img" alt="" />
      <div class="text">二维码</div>
    </div>

    <div class="item">
      <div class="text blue">02087085982</div>
      <div class="text">报名咨询</div>
    </div>
    <div class="item">
      <img src="@/assets/top.png" class="img" alt="" @click="scollTop" />
      <div class="text">返回顶部</div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "ToolBar",
  computed: {
    ...mapGetters(["userInfo"]),
  },
  data() {
    return {
      scrollTimer: null,
    };
  },
  methods: {
    go(path) {
      this.$router.push({
        path,
      });
    },
    scollTop() {
      clearInterval(this.scrollTimer);
      this.scrollTimer = setInterval(() => {
        const top = document.documentElement.scrollTop;
        const speed = top / 10;
        if (document.documentElement.scrollTop !== 0) {
          document.documentElement.scrollTop -= speed;
        } else {
          clearInterval(this.scrollTimer);
        }
      }, 16);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.toolBar {
  border: 1px solid #eeeeee;
  box-shadow: 0px 0px 7px 1px rgba(7, 82, 208, 0.04);
  border-radius: 10px;
  padding: 4px;
  position: fixed;
  right: 0;
  top: 380px;
  background: #fff;
  display: flex;
  flex-direction: column;
  z-index: 12;
  .item {
    cursor: pointer;
    width: 64px;
    height: 80px;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #3f8dfd;

    &:nth-last-of-type(1) {
      border: 0;
    }

    .img {
      width: 24px;
      font-size: 24px;
      height: 24px;
    }

    .text {
      text-align: center;
      word-break: break-all;
      font-size: 12px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #999999;
      line-height: 24px;
    }

    .blue {
      font-weight: bold;
      font-size: 16px;
      color: #3f8dfd;
    }
  }
}
</style>
