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

    <div class="item">
      <el-popover placement="left" width="180" trigger="hover">
        <div>
          <img
            style="width: 150px; height: 150px"
            src="@/assets/xcxqrcode.jpg"
            alt=""
          />
          <div style="text-align: center" class="text">小程序二维码</div>
        </div>
        <div slot="reference">
          <img src="@/assets/qr.png" class="img" alt="" />
          <div class="text">
            小程序
            <div></div>
            二维码
          </div>
        </div>
      </el-popover>
    </div>

    <div class="item">
      <el-popover placement="left" width="180" trigger="hover">
        <div style="height: 100px; text-align: center">
          <img
            style="width: 26px; height: 25px; margin-top: 10px"
            src="@/assets/phone.png"
            alt=""
          />
          <div
            style="
              font-size: 16px;
              font-family: Microsoft YaHei;
              font-weight: bold;
              color: #3f8dfd;
              line-height: 16px;
            "
          >
            020-87085982
          </div>
          <div
            style="
              font-size: 12px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              color: #999999;
              line-height: 24px;
              margin-top: 10px;
            "
          >
            报名电话
          </div>
        </div>
        <div slot="reference">
          <img src="@/assets/contact.png" class="img" alt="" />
          <div class="text">报名咨询</div>
        </div>
      </el-popover>
    </div>
    <div class="item" @click="scollTop">
      <img src="@/assets/top.png" class="img" alt="" />
      <div class="text">返回顶部</div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from "vuex";
export default {
  name: "ToolBar",
  computed: {
    ...mapGetters(["userInfo", "cartCount"]),
  },
  data() {
    return {
      scrollTimer: null,
    };
  },
  mounted() {
    if (this.$tools.isLogin()) {
      this.getCartCount();
    }
  },
  methods: {
    ...mapMutations(["getCartCount"]),
    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 3px 6px 0px rgba(213, 218, 224, 0.8);
  border-radius: 10px;
  padding: 4px;
  position: fixed;
  right: 0;
  top: 380px;
  background: #fff;
  display: flex;
  flex-direction: column;
  z-index: 9999;
  .item {
    cursor: pointer;
    width: 56px;
    height: 80px;
    border-bottom: 1px solid #eeeeee;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #3f8dfd;
    position: relative;

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

    .img {
      width: 24px;
      font-size: 24px;
      height: 24px;
      display: block;
      margin: 0 auto 5px;
    }

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

    .blue {
      font-weight: bold;
      font-size: 14px;
      color: #3f8dfd;
    }

    .el-badge {
      text-align: center;
    }
  }
}
</style>
