DigitalMarketingRight.vue 6.6 KB
<template>
  <div class="marketing-right">
    <PullDownSelect ref="rightDownSelect" v-show="!switchShow" :selectList="selectList" @selectVal="selectVal"></PullDownSelect>
    <div class="patch-title" v-show="switchShow">活动订单金额分布</div>
    <inner-tab ref="innerTabRef" class="inner-tab" :list="tabList" :width="tabWidth" :itemPadding="0.5" @changeTab="changeTab"></inner-tab>
    <!-- 1.3售后众筹显示占比和价格区间切换 -->
    <div class="switch-box" v-if="switchShow">
      <div class="text">收入占比:{{ ratio }}%</div>
      <PriceSwitch :selectList="priceList" @selectPrice="selectPrice"></PriceSwitch>
    </div>
    <BarChart ref="merchantChartRef" domId="merchantChart" :label="barChartLabel" :height="barchartHeight" :colorList="colorList" :barWidth="'50'" :valueName="valueName"></BarChart>
  </div>
</template>

<script>
import PullDownSelect from './PullDownSelect.vue'
import BarChart from './BarChart.vue'
import PriceSwitch from './PriceSwitch.vue'
import { digitalMarketingPriceObj, digitalMarketingRightSelectList } from './constant'
export default {
  name: 'DigitalMarketingRight',
  components: {
    PullDownSelect,
    BarChart,
    PriceSwitch
  },
  data() {
    return {
      tabList: ['门店数', '总金额'],
      tabWidth: 7.3,
      priceList: digitalMarketingPriceObj.merchantOrderlist,
      selectList: digitalMarketingRightSelectList[0],
      selectType: '',
      marketingDistributionList: [],
      colorList: ['#22D8FF', '#223FA9', '#061422'],
      barchartHeight: '16vh',
      switchShow: false,
      valueName: 'outputMerchantNum',
      downSelectNum: 0,
      ratio: '',
      digitalMarketingTab: 0,
      barChartLabel: 'statYear',
      marketingCrowdFundingDistr: [],
      startPrice: '',
      endPrice: '',
      crowfundDistrType: ''
    }
  },

  created() {
    // :门店订单金额分布 && 门店订单量分布
    this.getMarketingDistribution()
  },

  mounted() {
    this.$bus.$on('digitalMarketingTabChange', data => {
      this.digitalMarketingTab = data
      this.tabShow = false
      this.selectList = digitalMarketingRightSelectList[data]
      switch (data) {
        case 0:
          this.switchShow = false
          this.tabWidth = 7.3
          this.tabList = ['门店数', '总金额']
          this.valueName = 'outputMerchantNum'
          this.barChartLabel = 'statYear'
          this.getMarketingDistribution()
          break
        case 1:
          this.switchShow = true
          this.tabWidth = 10.8
          this.tabList = ['门店数', '订单数', '总金额']
          this.valueName = 'num'
          this.barChartLabel = 'statDate'
          this.getMarketingCrowdFundingDistr('merData')
          break
      }
    })
  },

  methods: {
    selectVal(val) {
      this.$refs.innerTabRef.tabActive = 0
      switch (val.val) {
        case 'outputMerchantNum':
          this.tabWidth = 7.3
          this.tabList = ['门店数', '总金额']
          this.valueName = 'outputMerchantNum'
          this.downSelectNum = 0
          this.$nextTick(() => {
            this.$refs.merchantChartRef.drawBar(this.marketingDistributionList)
          })
          break
        case 'orderMerchantNum':
          this.tabList = ['门店数', '总订单数']
          this.tabWidth = 8.1
          this.valueName = 'orderMerchantNum'
          this.downSelectNum = 1
          this.$nextTick(() => {
            this.$refs.merchantChartRef.drawBar(this.marketingDistributionList)
          })
          break
      }
    },
    changeTab(val) {
      console.log(val)
      switch (val) {
        case 0:
          // 1.1精品升级
          if (this.digitalMarketingTab === 0) {
            this.valueName = this.downSelectNum === 0 ? 'outputMerchantNum' : 'orderMerchantNum'
            this.$refs.merchantChartRef.drawBar(this.marketingDistributionList)
          } else {
            // 1.3售后众筹
            this.crowfundDistrType = 'merData'
            this.marketingDistributionList = this.marketingCrowdFundingDistr.merData.trendData
            this.ratio = this.marketingCrowdFundingDistr.merData.ratio
          }
          break
        case 1:
          // 1.1精品升级
          if (this.digitalMarketingTab === 0) {
            this.valueName = this.downSelectNum === 0 ? 'outputMoney' : 'orderMoney'
            this.$refs.merchantChartRef.drawBar(this.marketingDistributionList)
          } else {
            // 1.3售后众筹
            this.crowfundDistrType = 'orderData'
            this.marketingDistributionList = this.marketingCrowdFundingDistr.orderData.trendData
            this.ratio = this.marketingCrowdFundingDistr.merData.ratio
          }
          break
        case 2:
          // 只有1.3售后众筹
          this.crowfundDistrType = 'incomeData'
          this.marketingDistributionList = this.marketingCrowdFundingDistr.incomeData.trendData
          this.ratio = this.marketingCrowdFundingDistr.merData.ratio
          break
      }
      this.$nextTick(() => {
        this.$refs.merchantChartRef.drawBar(this.marketingDistributionList)
      })
    },
    async getMarketingDistribution() {
      const _data = await this.api.internal.getMarketingDistribution()
      const _dataList = _data.data.dataList
      this.marketingDistributionList = _dataList
      this.$refs.merchantChartRef.drawBar(_dataList)
    },
    // 活动订单金额分布
    async getMarketingCrowdFundingDistr(queryItem) {
      const params = {
        startPrice: this.startPrice,
        endPrice: this.endPrice
      }
      const _data = await this.api.internal.getMarketingCrowdFundingDistr(params)
      const _queryItem = queryItem || this.crowfundDistrType
      const _dataList = _data.data.dataList[0][_queryItem].trendData
      this.marketingCrowdFundingDistr = _data.data.dataList[0]
      this.marketingDistributionList = _dataList
      this.ratio = _data.data.dataList[0][_queryItem].ratio
      this.$refs.merchantChartRef.drawBar(_dataList)
    },
    selectPrice(val) {
      if (val.label === '全部') {
        this.startPrice = ''
        this.endPrice = ''
        this.getMarketingCrowdFundingDistr()
        return
      }
      this.startPrice = val.startPrice
      this.endPrice = val.endPrice
      this.getMarketingCrowdFundingDistr()
    }
  }
}
</script>

<style lang="scss" scoped>
.marketing-right {
  width: 22.78vw;
  height: 25vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .inner-tab {
    /deep/.tab-item-box {
      margin: 0;
    }
  }
  .switch-box {
    display: flex;
    justify-content: space-between;
    .text {
      font-weight: 600;
      font-size: 10px;
      color: #ffffff;
    }
  }
}
</style>