flow.vue 8.63 KB
<!--
 * @Description: 客流转化
 * @Author: huyue
 * @Date: 2022-06-23 15:05:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-06-29 19:45:27
-->
<template>
  <div>
    <div v-if="hasData" class="flow-box">
      <div class="flow-left">
        <div class="title inline" style="padding-left: 0">客流转化</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="changeRank(1)" :class="isActive == 1 ? 'active' : ''">前5{{ isBrand ? '门店' : '品牌' }}</div>
          <div @click="changeRank(2)" :class="isActive == 2 ? 'active' : ''">后5{{ isBrand ? '门店' : '品牌' }}</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>
    <div v-else>
      <div class="title">客流转化</div>
      <div class="empty">
        <img src="../../assets/images/empty.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { changeMixin } from '@/mixins'
import datas from '../../utils/data'
import * as echarts from 'echarts'
export default {
  name: 'Flow',
  mixins: [changeMixin],
  props: ['height'],
  data() {
    return {
      directionTimer: datas.DefaultData.directionTimer,
      delayTimer: datas.DefaultData.delayTimer,
      flowData: [],
      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: '',
      hasData: true,
      paramsData: {},
      topList: [],
      lastList: [],
      isBrand: false
    }
  },
  mounted() {
    this.echartsFunnel = echarts.init(document.getElementById('flow'))
    // resize
    window.addEventListener('resize', () => {
      this.echartsFunnel.resize()
    })
    this.init()
  },
  methods: {
    init(val) {
      this.paramsData = this.$store.state.app.reportParams
      this.isBrand = this.paramsData.brand && this.paramsData.brand.name
      this.getSaletTotal(this.paramsData)
      this.getSaleTrans(this.paramsData)
    },
    getSaletTotal(val) {
      const params = {
        req: {
          corporateGroupName: '集团1',
          queryTime: '2022-06-23',
          queryType: val.reportType
        }
      }
      let api = 'saleTotal'
      if (val.brand && val.brand.name) {
        params.req.brandName = '品牌1'
        api = 'storeTotal'
      }
      this.api.sales[api](params).then(res => {
        if (res.code === '0') {
          res.data.dataList[0].num.forEach((item, index) => {
            this.funnelData[index].value = item
          })
          this.hasData = res.data.dataList[0].num.every(i => i != 0)
          if (this.hasData) 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)'],
        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 => {
        this.getSaleTrans(this.paramsData, data.data.type)
      })
    },
    getSaleTrans(val, queryItem = 'enter') {
      const params = {
        req: {
          corporateGroupName: '集团1',
          queryItem: queryItem,
          queryTime: '2022-06-23',
          queryType: val.reportType
        }
      }
      let api = 'saleTrans'
      if (val.brand && val.brand.name) {
        params.req.brandName = '品牌1'
        api = 'storeSaleTrans'
      }
      this.api.sales[api](params).then(res => {
        const { topList, lastList } = res.data.dataList[0]
        this.topList = topList ? JSON.parse(topList) : []
        this.lastList = lastList ? JSON.parse(lastList) : []
        // this.topList = [
        //   {
        //     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
        //   }
        // ]
        // this.lastList = [
        //   {
        //     id: 1,
        //     name: '广汇集团BI数据看板-前端-交互',
        //     num: 3323425
        //   },
        //   {
        //     id: 2,
        //     name: '广汇集团BI数据看板-前端-交互广汇集团BI数据看板-前端-交互',
        //     num: 9999999
        //   },
        //   {
        //     id: 3,
        //     name: 'fsdfasdg',
        //     num: 33234
        //   },
        //   {
        //     id: 4,
        //     name: '广汇集团BI数据看板-前端-交互',
        //     num: 33234
        //   },
        //   {
        //     id: 5,
        //     name: '广汇集团BI数据看板-前端-交互',
        //     num: 33234
        //   }
        // ]
        this.flowData = this.topList
      })
    },
    // 切换品牌排序
    changeRank(val) {
      this.isActive = val
      this.flowData = val == 1 ? this.topList : this.lastList
    }
  }
}
</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>