conversionLeft.vue 6.32 KB
<template>
  <div class='conversion-left'>
    <view-sub-title :title='diffsTitle[copyBussinessType]' />
    <div class='component' v-if='boxList'>
      <div class='titles'>
        <span>订单月份</span>
        <span>{{ copyBussinessType == 'expandedGold' ? '活动名称' : '商品名称' }}</span>
        <span>订单数</span>
      </div>
      <div
        ref='forwardScrollBox'
        class='list_dv'
        @mouseenter='mouseenter'
        @mouseleave='mouseleave'
      >
        <div ref='forwardContent' class='scroll_dv'>
          <div v-for='(item, index) in boxList' :key='index' class='list_item dfac'>
            <!--            @click='selectData(item)'-->
            <div
              class='dataList'
              :class="currentIndex === index? 'selectMerchant' : ''"
              @mouseleave="currentIndex = ''"
              @mouseenter='mouseenterList(item,index)'>
              <div>{{ item.statMonth }}</div>
              <div>{{ item[diffsGoodsName[copyBussinessType]] }}</div>
              <div>{{ item[diffsNum[copyBussinessType]] }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ConversionLeft',
  data() {
    return {
      diffsTitle: {
        'transWork': '各月各商品订单量排名',
        'expandedGold': '各月各活动订单量排名',
        'crowdFunding': '各月各商品订单量排名',
        'noWorries': '各月各商品订单量排名'
      },
      diffsGoodsName: {
        'transWork': 'goodsName',
        'expandedGold': 'activityName',
        'crowdFunding': 'goodsName',
        'noWorries': 'goodsName'
      },
      diffsNum:{
        'transWork': 'orderNum',
        'expandedGold': 'totalNum',
        'crowdFunding': 'totalNum',
        'noWorries': 'totalNum'
      },
      totalCount: 10000, // 总数
      scrollContentHeight: 0, // 滚动内容的高度
      scrollBoxHeight: 0, // 滚动父级盒子的高度
      scrollableHeight: 0, // 可以滚动的高度
      scrollTop: 0, // 元素已经滚动的高度
      timer2: null, // 定时器
      boxList: [],
      currentIndex: '',
      copyBussinessType: ''
    }
  },
  async mounted() {
    await this.getGoodsOrderinfoMonthly()

    this.$bus.$on('orderinfoMonthly', data => {
      this.copyBussinessType = data.bussinessType
      this.getGoodsOrderinfoMonthly(data.bussinessType)
    })

    this.$bus.$on('changeMonths', data => {
      this.getGoodsOrderinfoMonthly(this.copyBussinessType, data.month)
    })

    this.$bus.$on('changeBussiness', data => {
      clearInterval(this.timer2)
    })
  },
  destroyed() {
    // 离开时销毁定时器
    clearInterval(this.timer2)
  },
  methods: {
    getGoodsOrderinfoMonthly(val = 'transWork', month = '') {
      this.copyBussinessType = val
      // let getmonth = month
      // if (!getmonth) {
      //   const date = new Date() // 获取时间
      //   const year = date.getFullYear() // 获取年
      //   const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1// 获取月
      //   getmonth = year + '-' + month
      // }
      const params = month ? {
        month
      } : ''
      this.api[val].getGoodsOrderinfoMonthly(params).then(res => {
        if (res.code == 0) {
          this.boxList = res.data.dataList
          this.$nextTick(() => {
            this.regainHeight()
          })
        }
      })
    },

    mouseenterList(item, index) {
      this.currentIndex = index
    },
    // 页面第一次进入或者窗口大小变化时,获取滚动相关元素的高度
    regainHeight() {
      // 获取需要滚动元素的真实高度
      this.scrollContentHeight = this.$refs.forwardContent ? this.$refs.forwardContent.getBoundingClientRect().height : ''
      // 获取限制高度滚动容器的真实高度
      this.scrollBoxHeight = this.$refs.forwardContent ? this.$refs.forwardScrollBox.getBoundingClientRect().height : ''
      // 可以滚动的高度
      this.scrollableHeight = this.scrollContentHeight - this.scrollBoxHeight
      this.autoScroll()
    },
    // 自动滚动
    autoScroll() {
      clearInterval(this.timer2)
      this.timer2 = setInterval(() => {
        if (this.scrollableHeight >= this.scrollTop) {
          // 当为滚动到结尾时滚动
          this.scrollTop = this.$refs.forwardScrollBox ? this.$refs.forwardScrollBox.scrollTop += 1 : ''
        } else {
          // 滚动结束,清除当前定时器,scrollTop重置为0,继续滚动
          this.scrollTop = this.$refs.forwardScrollBox ? this.$refs.forwardScrollBox.scrollTop = 0 : ''
          clearInterval(this.timer2)
          this.autoScroll()
        }
      }, 100)
    },
    // 鼠标移入时停止滚动
    mouseenter() {
      clearInterval(this.timer2)
    },
    // 鼠标移开继续滚动
    mouseleave() {
      this.autoScroll()
    },
    // 滚动元素滚动时的方法
    handleScroll(e) {
      console.log(e.target.scrollTop)
    }

  }
}
</script>

<style scoped lang='scss'>
.conversion-left {
  background-image: url('./../../../assets/images/bg-1.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  //background: forestgreen;
  padding: 0 1.2vw;
  width: 35vw;
  height: 85vh;

  .component {
    //padding: 0.5vw 0;
    //font-family: Source Han Sans CN, Source Han Sans CN-Regular;
    letter-spacing: 0.1vw;

    .titles {
      //display: flex;
      //justify-content: space-between;
      display: grid;
      grid-template-columns:28% 54% 18%;
      font-size: 0.9vw;
    }

    .list_dv::-webkit-scrollbar {
      display: none;
    }

    .list_dv {
      width: 100%;
      height: 77vh;
      overflow-y: auto;
      font-size: 0.6vw;
      color: #d4eaf6;

      .list_item {
        width: 100%;
        height: 3.5vh;
        line-height: 3.5vh;
        //height: 26px;
        //margin-bottom: 1vw;

        .dataList {
          display: grid;
          grid-template-columns: 28% 54% 18%;
          cursor: pointer;
          div{
            width: 100%;
            &:nth-child(2){
              width: 93%;
              overflow: hidden;  //超出隐藏
              white-space: nowrap; //不折行
              text-overflow: ellipsis; //溢出显示省略号

            }
          }
        }

        .selectMerchant {
          background: #6578FF;
        }
      }
    }
  }
}

</style>