boxChart.vue 6.48 KB
<template>
  <div>
    <div class='component'>
      <div class='titles'>
<!--        <span>展业时间</span>-->
<!--        <span>业务</span>-->
        <span>门店号</span>
        <span>门店名称</span>
        <span>订单数</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.date }}</div>-->
<!--              <div>-->
<!--                {{ item.businessName == '1.1' ? '1.1转化+'-->
<!--                : item.businessName == '1.2' ? '1.2膨胀金' :-->
<!--                  item.businessName == '1.3' ? '1.3众筹'-->
<!--                    : item.businessName == '2.1' ? '2.1车损无忧' : '' }}-->
<!--              </div>-->
              <div>{{ item.merchantId }}</div>
              <div>{{ item.merchantName }}</div>
              <div>{{ item.orderNum }}</div>
              <div>{{ item.orderPrice }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
export default {
  name: 'boxChart',
  components: {},
  props: {},
  data() {
    return {
      totalCount: 10000, // 总数
      scrollContentHeight: 0, // 滚动内容的高度
      scrollBoxHeight: 0, // 滚动父级盒子的高度
      scrollableHeight: 0, // 可以滚动的高度
      scrollTop: 0, // 元素已经滚动的高度
      timer2: null, // 定时器
      boxList: [],
      currentIndex: ''
    }
  },
  computed: {},
  watch: {},
  created() {

  },
  async mounted() {
    await this.getList()
    // this.$nextTick(() => {
    // 窗口大小变化时,重新获取滚动相关元素的高度
    // setTimeout(() => {
    //   window.onresize = this.regainHeight()
    // })
    // 监听元素滚动事件
    // this.$refs.forwardScrollBox.addEventListener('scroll', this.handleScroll, true)
    // })
  },
  destroyed() {
    // 离开时销毁定时器
    clearInterval(this.timer2)
  },
  methods: {
    getList() {
      this.api.springbudAtion.getMerchantNumTrend().then(res => {
        if (res.code == 0) {
          this.boxList = res.data.dataList
          // this.initThirtyDays({
          //   queryItem: 'transwork'
          // })
          this.$nextTick(() => {
            this.regainHeight()
          })
        }
      })
    },

    mouseenterList(item, index) {
      this.currentIndex = index
    },
    // 页面第一次进入或者窗口大小变化时,获取滚动相关元素的高度
    regainHeight() {
      // 获取需要滚动元素的真实高度
      this.scrollContentHeight = this.$refs.forwardContent.getBoundingClientRect().height
      // 获取限制高度滚动容器的真实高度
      this.scrollBoxHeight = this.$refs.forwardScrollBox.getBoundingClientRect().height
      // 可以滚动的高度
      this.scrollableHeight = this.scrollContentHeight - this.scrollBoxHeight
      console.log('内容高度', this.scrollContentHeight, '盒子高度', this.scrollBoxHeight, '可以滚动的高度', this.scrollableHeight)
      this.autoScroll()
    },
    // 自动滚动
    autoScroll() {
      this.timer2 = setInterval(() => {
        if (this.scrollableHeight >= this.scrollTop) {
          // 当为滚动到结尾时滚动
          this.scrollTop = this.$refs.forwardScrollBox.scrollTop += 2
        } else {
          // 滚动结束,清除当前定时器,scrollTop重置为0,继续滚动
          this.scrollTop = 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)
    }

    // initThirtyDays(params, businessName = 'transwork', merchantName = '') {
    //   this.api.springbudAtion.getEveryMerMonthlyTrend(params).then(res => {
    //     if (res.code == 0) {
    //       let thirtyDaysList = res.data.dataList
    //
    //       this.$bus.$emit('thirtyDays', { thirtyDaysList, businessName, merchantName })
    //     }
    //   })
    // },
    // selectData(item) {
    // businessName, merchantId, merchantName
    // const { merchantId } = item
    // this.$bus.$emit('storeDetails', { merchantId })
    // switch (businessName) {
    //   case '1.1':
    //     businessName = 'transwork'
    //     break
    //   case '1.2':
    //     businessName = 'expandedgold'
    //     break
    //   case '1.3':
    //     businessName = 'crowdfunding'
    //     break
    //   case '2.1':
    //     businessName = 'noworries'
    //     break
    // }
    // const params = {
    //   merchantId,
    //   queryItem: businessName
    // }
    // this.$bus.$emit('getMerchantTime', { merchantId, businessName })
    // this.initThirtyDays(params, businessName, merchantName)
    // }
  }
}
</script>
<style lang='scss' scoped>
.component {
  //padding: 1vw 0;
  //padding-bottom: 1vw;
  font-family: Source Han Sans CN, Source Han Sans CN-Regular;
  letter-spacing: 0.1vw;

  .titles {
    //display: flex;
    //justify-content: space-between;
    display: grid;
    //padding: 0 1vw;
    grid-template-columns: 18% 46% 16% 20%;
    font-size: 0.833vw;
  }

  .list_dv::-webkit-scrollbar {
    display: none;
  }
  //针对火狐浏览器隐藏滚动条
  .list_dv {
    scrollbar-width: none
  }
  .list_dv {
    //padding: 0 1vw;
    width: 100%;
    //height: 100%;
    height: 31vh;
    overflow-y: auto;
    font-size: 0.6vw;
    color: #d4eaf6;

    .list_item {

      width: 100%;
      height: 3vh;
      line-height: 3vh;;
      //height: 26px;
      //margin-bottom: 1vw;

      .dataList {
        display: grid;
        grid-template-columns: 18% 46% 16% 20%;
        cursor: pointer;
        //div{
        //  width: 100%;
        //  &:nth-child(2){
        //    width: 70px;
        //  }
        //}
      }

      .selectMerchant {
        background: #6578FF;
      }
    }
  }
}
</style>