flow.vue 6.11 KB
<!--
 * @Description: 客流转化
 * @Author: huyue
 * @Date: 2022-06-23 15:05:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-06-28 18:41:37
-->
<template>
  <div class="flow-box">
    <div class="flow-left">
      <div class="title inline">客流转化</div>
      <div class="chart-box">
        <div id="flow" :style="{ height: height - 4.1 + 'vh' }"></div>
      </div>
    </div>
    <div class="flow-right">
      <div class="ranking-title">
        <div @click="isActive = 1" :class="isActive == 1 ? 'active' : ''">前5品牌</div>
        <div @click="isActive = 2" :class="isActive == 2 ? 'active' : ''">后5品牌</div>
      </div>
      <div class="ranking-content">
        <div class="ranking-item" v-for="(item, index) in flowData" :key="index">
          <span>{{ item.id }}</span>
          <span class="ranking-name">
            <marquee :direction="directionTimer" :delay="delayTimer" :text="item.name" />
          </span>
          <span class="ranking-text">{{ item.num }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import datas from '../../utils/data'
import * as echarts from 'echarts'
export default {
  name: 'Flow',
  props: ['height'],
  data() {
    return {
      directionTimer: datas.DefaultData.directionTimer,
      delayTimer: datas.DefaultData.delayTimer,
      flowData: [
        {
          id: 1,
          name: '林则徐:苟利国家生死以岂因祸福避趋之',
          num: 3323425
        },
        {
          id: 2,
          name: '林则徐',
          num: 9999999
        },
        {
          id: 3,
          name: 'fg',
          num: 33234
        },
        {
          id: 4,
          name: '售后客户价值分析',
          num: 33234
        },
        {
          id: 5,
          name: '林则徐:苟利国家生死以岂因祸福避趋之',
          num: 33234
        }
      ],
      isActive: 1,
      funnelData: [
        {
          name: '客流',
          type: 'enter',
          value: ''
        },
        {
          name: '留档',
          type: 'stayfile',
          value: ''
        },
        {
          name: '试驾',
          type: 'test',
          value: ''
        },
        {
          name: '订单',
          type: 'placeorder',
          value: ''
        },
        {
          name: '成交',
          type: 'success',
          value: ''
        }
      ],
      option: {},
      echartsFunnel: '',
      funnelDom: ''
    }
  },
  mounted() {
    this.funnelDom = document.getElementById('flow')
    this.echartsFunnel = echarts.init(this.funnelDom)
    // resize
    window.addEventListener('resize', () => {
      this.echartsFunnel.resize()
    })
    this.init()
  },
  methods: {
    init() {
      this.getSaleTrans()
    },
    getSaleTrans() {
      const params = {
        req: {
          corporateGroupName: '集团1',
          queryTime: '2022-06-23',
          queryType: 0
        }
      }
      this.api.sales.saleTotal(params).then(res => {
        console.log(res.data)
        if (res.code === '0') {
          res.data.dataList[0].num.forEach((item, index) => {
            this.funnelData[index].value = item
          })
          this.draw()
        }
      })
    },
    draw() {
      this.option = {
        tooltip: {
          trigger: 'item',
          backgroundColor: 'rgba(68,68,68,0.8)',
          formatter: '{a} <br/>{b} : {c}',
          textStyle: {
            color: '#fff'
          },
          borderWidth: 0
        },
        color: ['rgba(235, 96, 2, 1)', 'rgba(235, 96, 2, .8)', 'rgba(235, 96, 2, .6)', 'rgba(235, 96, 2, .4)', 'rgba(245, 170, 2, .8)'],
        // color: [, , , , ].reverse(),
        series: [
          {
            name: '漏斗图',
            type: 'funnel',
            left: 0,
            top: 8,
            bottom: 8,
            width: '100%',
            min: 0,
            max: 100,
            minSize: '30%',
            maxSize: '100%',
            sort: 'descending',
            gap: 2,
            label: {
              show: true,
              position: 'inside'
            },
            labelLine: {
              length: 10,
              lineStyle: {
                width: 1,
                type: 'solid'
              }
            },
            itemStyle: {
              borderColor: '#fff',
              borderWidth: 0
            },
            emphasis: {
              label: {
                fontSize: 20
              }
            },
            data: this.funnelData
            // data: [
            //   { value: 20, name: 'Order' },
            //   { value: 40, name: 'Inquiry' },
            //   { value: 60, name: 'Visit' },
            //   { value: 80, name: 'Click' },
            //   { value: 100, name: 'Show' }
            // ]
          }
        ]
      }
      this.echartsFunnel.setOption(this.option)
      // 鼠标划入
      this.echartsFunnel.on('mouseover', data => {
        console.log(data.data)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.flow-box {
  display: flex;
  padding: 0 8px 1vh;
  box-sizing: border-box;
  .flow-left {
    padding-bottom: 0.9vh;
    width: 50%;
  }
  .flow-right {
    flex: 1;
    color: #fff;
    font-size: 10px;
    padding: 1vh 0 0.9vh 20px;
    .ranking-title {
      display: flex;
      width: 100%;
      margin-right: 20px;
      cursor: default;
      .active {
        background-color: #eb6001;
        color: #fff;
      }
      div {
        width: 50%;
        text-align: center;
        background-color: #353535;
        line-height: 2.4vh;
      }
    }
    .ranking-content {
      background-color: #262525;
    }
    .ranking-item {
      display: flex;
      width: 100%;
      align-items: center;
      line-height: 2.1vh;
      height: 2.1vh;
      .ranking-name {
        width: calc(100% - 33% - 28px);
      }
      .ranking-text {
        width: 33%;
        padding-left: 4px;
        // width: calc(100% - 50px);
      }
      span {
        display: inline-block;
        &:first-child {
          padding: 0 8px;
        }
      }
    }
  }
}
.chart-box {
  width: 100%;
  box-sizing: border-box;
  // height: 11.7vh;
  background-color: #262525;
  padding: 0 25px;
}
</style>