楼层左侧楼层浮动菜单

<template>
  <div class="float-storey" v-if="visibleMenu">
    <a-button
      v-for="(item, index) in menuArray"
      :key="index"
      :class="[checkLevel(index) == index ? 'float-storey-active' : '']"
      size="large"
      @click="onItemClick(index)"
    >
      <b>{{ index + 1 }}</b>层
      <a-divider type="horizontal" />
      {{ item.templateName }}
    </a-button>
  </div>
</template>
<script>
/**
 * Created by Pan zhenyu.
 *
 * 首页左边楼层浮动菜单
 *
 */
export default {
  name: 'FloatStorey',
  props: {
    menuArray1:{
      type:Array,
    }
  },
  components: {},
  data() {
    return {
      visibleMenu: false,
      pageScrollY: 0,
      offsetValue: 156,
      activeLevel: -1,
      menuArray: [],
      storeData: {},
    }
  },
  created() {
    this.storeData = this.$store.getters.getStoreData || {}
    // this.menuArray = [
    //   { title: "中药", pageY: 0 },
    //   { title: "西药", pageY: 0 },
    //   { title: "特惠", pageY: 0 },
    //   { title: "调理", pageY: 0 },
    //   { title: "活动", pageY: 0 },
    // ];
    this.menuArray1.forEach(element => {
     return element.pageY = 0
    });
    this.menuArray = this.menuArray1
    console.log(this.menuArray);
    // this.menuLength = this.menuArray.length
    // 获取楼层数据
    // this.getShopFloor()
  },
  mounted() {
    this.getLevelHeight()
    window.addEventListener('scroll', () => {
      this.pageScrollY = window.scrollY || window.pageYOffset
      if (
        this.menuArray.length > 0 &&
        this.pageScrollY >= this.menuArray[0].pageY - 400
      ) {
        this.visibleMenu = true
      } else {
        this.visibleMenu = false
      }
    })
  },
  methods: {
    // 获取楼层列表
    // getShopFloor() {
    //   let params = { storeId: this.storeData.id }
    //   this.$http('GET', 'specialList', params)
    //     .then((res) => {
    //       if (res.data && res.data.length > 0) {
    //         this.menuArray = res.data
    //         // console.log('333',res);
    //         this.menuArray.forEach((element) => {
    //           element.pageY = 0
    //         })
    //         // this.pageData = res.data
    //         console.log('====================================');
    //         console.log(this.menuArray);
    //         console.log('====================================');
    //       }
    //     })
    //     .catch((err) => {
    //       this.$message.error('提示:' + err.msg || '')
    //     })
    // },
    getLevelHeight() {
      let length = this.menuArray.length
      for (let i = 1; i <= length; i++) {
        let levelItem = document.getElementById(`level_${i}`)
        if (levelItem) {
          this.menuArray[i - 1].pageY = levelItem.offsetTop
        }
      }
    },
    checkLevel(i) {
      this.activeLevel = -1
      if (!this.menuArray.length) {
        this.activeLevel = -1
        return -1
      }
      if (
        i === this.menuArray.length - 1 &&
        this.pageScrollY + this.offsetValue >= this.menuArray[i].pageY
      ) {
        this.activeLevel = i
        return i
      }
      if (
        this.pageScrollY + this.offsetValue >= this.menuArray[i].pageY &&
        this.pageScrollY + this.offsetValue < this.menuArray[i + 1].pageY
      ) {
        this.activeLevel = i
        return i
      }
      return -1
    },
    onItemClick(index) {
      let levelItem = document.getElementById(`level_${index + 1}`)
      if (levelItem) {
        window.scrollTo({
          top: levelItem.offsetTop - this.offsetValue,
          behavior: 'smooth',
        })
      }
      // levelItem.scrollIntoView({
      //   behavior: "smooth",
      // });
    },
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
.float-storey {
  width: 30px;
  position: fixed;
  left: 30px;
  top: 40vh;
  z-index: 200;

  .float-storey-active {
    color: @theme-color!important;
  }

  .ant-btn {
    width: 130px;
    height: 60px;
    margin-bottom: 5px;
    line-height: 0;
    background-color: white;
    // border-radius: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-color: white;
    &:focus {
      color: rgba(0, 0, 0, 0.65);
    }
    &:hover {
      background-color: lighten(white, 25%);
    }
    .ant-divider-horizontal {
      margin: 12px 0;
    }
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值