funnel.vue 5.39 KB
<!-- 选择商品弹窗 -->
<template>
  <div>
    <div ref="funnelCon" class="chart-container flex_cc">
      <div class="funnel_box">
        <div class="h13_title">发券总数:{{ chartInfo.getTotal || 0 }}(张)</div>
        <div class="h13_title">核销总数:{{ chartInfo.usedTotal || 0 }}(张)</div>
        <div class="h13_title">转化订单数:{{ chartInfo.upgradeTotal || 0 }}(笔)</div>
      </div>
      <img class="funnel_icon" src="../../assets/funnel_icon.png" />
      <div class="funnel_box2">
        <div class="wrapper">
          <p class="h13_title">核销转化率:{{ chartInfo.usedPer || 0 }}%</p>
          <p class="h13_title spc">同行平均转化率:{{ chartInfo.totalUsedPer || 0 }}%</p>
        </div>
        <div class="wrapper spcP">
          <p class="h13_title">精品升级转化率:{{ chartInfo.upgradePer || 0 }}%</p>
          <p class="h13_title spc">同行平均转化率:{{ chartInfo.totalUpgradePer || 0 }}%</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import { couponsTotal } from '../../api/modules/rules'
import { converterApi } from '../../api/modules/converter'
import utils from '../../util/util'
export default {
  name: '',
  data() {
    return {
      nodata: false,
      chartInfo: {
        getTotal: 0,
        usedTotal: 0,
        upgradeTotal: 0,
        usedPer: 0,
        totalUsedPer: 0,
        upgradePer: 0,
        totalUpgradePer: 0
      }
    }
  },

  props: {
    echartId: {
      type: String,
      default: ''
    }
  },

  mounted() {
    this.initTIme()
  },
  methods: {
    getOptions(res) {
      var chartDom = document.getElementById(this.echartId)
      var myChart = echarts.init(chartDom)
      var option = {
        color: ['#5850FF', '#9191FF', '#CBCBFF'],
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}'
        },
        series: [
          {
            name: '券统计',
            type: 'funnel',
            left: 'center',
            top: 60,
            bottom: 60,
            width: '60%',
            min: 0,
            max: 100,
            minSize: '50%',
            maxSize: '100%',
            sort: 'descending',
            gap: 15,
            orient: 'vertical',
            label: {
              show: true,
              position: 'left',
              // formatter: '{b}: {c}(张)',
              textStyle: {
                fontSize: 14
              },
              color: '#333'
            },
            labelLine: {
              length: 20,
              lineStyle: {
                width: 1,
                type: 'solid'
              }
            },
            itemStyle: {
              borderColor: '#fff',
              borderWidth: 1,
              height: 37
            },
            data: [
              { value: res.getTotal || 0, name: `发券总数:${res.getTotal || 0}(张)` },
              { value: res.usedTotal || 0, name: `核销总数:${res.usedTotal || 0}(张)` },
              { value: res.upgradeTotal || 0, name: `转化订单数:${res.upgradeTotal || 0}(笔)` }
            ]
          }
        ]
      }
      option && myChart.setOption(option)
    },
    // 初始化时间
    initTIme() {
      let openInfo = JSON.parse(localStorage.getItem('openInfo'))
      let startDate = utils.dateFormat(openInfo.openDate)
      // let startDate = this.$defaultStartDate
      let endDate = utils.dateFormat(new Date())
      this.couponsChartData(startDate, endDate)
    },
    // 券统计
    couponsChartData(startDate, endDate) {
      let method = couponsTotal()
      let para = {
        routerMethod: method,
        startDate,
        endDate
      }
      converterApi(para).then(res => {
        if (!res.getTotal && !res.usedTotal && !res.upgradeTotal) {
          this.nodata = true
          return
        }
        res.usedPer = utils.decimal(res.usedPer, 2)
        res.totalUsedPer = utils.decimal(res.totalUsedPer, 2)
        res.upgradePer = utils.decimal(res.upgradePer, 2)
        res.totalUpgradePer = utils.decimal(res.totalUpgradePer, 2)
        this.chartInfo = res
        // this.getOptions(res)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.chart-container {
  height: 258px;
  overflow: hidden;
}
.image_wrap {
  // width: 660px;
  width: calc(31.4% * 3);
  height: 135px;
  position: relative;
  .text_box {
    position: absolute;
    left: 9.5%;
    top: 10px;
  }
  .text_box1 {
    position: absolute;
    left: 13%;
    top: 61px;
  }
  .text_box2 {
    position: absolute;
    left: 14.7%;
    top: 112px;
  }
  .text_box3 {
    position: absolute;
    right: 2.5%;
    top: 27px;
  }
  .text_box4 {
    position: absolute;
    right: 7%;
    top: 90px;
  }
}

.funnel_icon {
  // width: 31.4%;
  width: 220px;
  height: 135px;
  position: relative;
  z-index: 20;
}
.funnel_box {
  // width: 31.4%;
  height: 135px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  > div {
    height: 37px;
    line-height: 37px;
    margin-bottom: 15px;
    white-space: nowrap;
  }
}
.funnel_box2 {
  // width: 31.4%;
  height: 135px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  .wrapper {
    box-sizing: border-box;
    > p {
      line-height: 20px;
      white-space: nowrap;
    }
  }
  .spcP {
    padding-top: 20px;
  }
}
.spc {
  font-size: 14px;
  font-weight: 400;
  color: #888888;
}
</style>