mileage.vue 4.39 KB
<!--
 * @Description: 售后车辆里程
 * @Author: huyue
 * @Date: 2022-06-23 15:05:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-07-11 11:00:49
-->
<template>
  <div>
    <div class="title title-icon">
        <span class="icon"></span>
      <span>售后车辆里程</span>
    </div>
    <template v-if="mileageData.length > 0">
      <div class="flex container">
        <pie-chart :id="chart.id" :list="mileageData" :height="height - 5 + 'vh'" :radius="chart.radius" @pieAction="pieAction" :size="chart.size"></pie-chart>
        <div class="ranking-container">
          <div class="ranking-title">
            <div class="ranking-title-brand">{{ this.$store.state.app.reportParams.brand ? '门店' : '品牌' }}</div>
            <div>客户数</div>
          </div>
          <div class="ranking">
            <div class="brand flex" v-for="(item, index) in rankingData.slice(0, 5)" :key="index">
              <span class="brand-num">{{ index + 1 }}</span>
              <marquee class="marquee" :direction="directionTimer" :delay="delayTimer" :text="item.brand" />
              <span>{{ item.value }}</span>
            </div>
          </div>
        </div>
      </div>
    </template>
    <div class="empty" :style="{ height: height - 4.9 + 'vh' }" v-else>
      <img src="../../assets/images/empty.png" alt="" />
    </div>
  </div>
</template>

<script>
import { changeMixin } from '../../mixins/index'
export default {
  name: 'Mileage',
  props: ['height'],
  mixins: [changeMixin],
  data() {
    return {
      mileageData: [],
      distributionRank: '',
      rankingData: [],
      chart: {
        id: 'mileagePie',
        radius: ['60%', '78%'],
        size: '0.8vw'
      },
      delayTimer: 3000,
      directionTimer: 3000,
      brandList: this.list,
      isBrand: false,
      brandName: ''
    }
  },
  mounted() {
    this.getValueType()
  },
  methods: {
    getValueType() {
      let mileageApi = !this.isBrand ? 'aftersaleother' : 'afterMerchantSaleother'
      const params = {
        req: {
          queryItem: 'mileage',

          queryTime: this.getCurrentDate(),
          queryType: this.watchReportParams.reportType
        }
      }
      if (this.isBrand) params.req.brandName = this.brandName
      this.api.afterSales[mileageApi](params).then(res => {
        this.mileageData = []
        this.rankingData = []
        if (res.data.dataList.length > 0) {
          let distribution = JSON.parse(res.data.dataList[0].distribution)
          // console.log()
          const keys = Object.keys(distribution)
          keys.forEach((item, index) => {
            this.mileageData.push({
              name: item,
              value: distribution[item]
            })
          })
          this.distributionRank = JSON.parse(res.data.dataList[0].distributionRank)
        }
      })
    },
    pieAction(data) {
      let distributionRank = this.distributionRank[data.name]
      this.rankingData = []
      for (const key in distributionRank) {
        this.rankingData.push({
          brand: key,
          value: distributionRank[key]
        })
      }
      this.rankingData.sort(function (a, b) {
        return b.value - a.value //倒序
      })
    },
    init(newVal) {
      this.isBrand = false
      if (newVal && newVal.brand) {
        this.isBrand = true
        this.brandName = newVal.brand.name
      }
      this.getValueType()
    }
  }
}
</script>
<style lang="scss" scoped>
.title {
  padding: 1vh 8px;
  height: 4vh;
}
.ranking-container {
  flex: 1;
  margin-left: 0.6vw;
  box-sizing: border-box;
  height: 21.5vh;
  width: 10.8vw;
  background: #262525;
  .ranking-title {
    padding: 0.5vh 1.5vw 0.4vh 1.5vw;
    font-size: 0.833vw;
    color: #eb6001;
    letter-spacing: 0;
    font-weight: 400;
    background: rgba(53, 53, 53, 0.6);
    display: flex;
    align-items: center;
    div {
      white-space: nowrap;
    }
    .ranking-title-brand {
      width: 4.9vw;
      margin-right: 0.6vw;
    }
  }
  .ranking {
    font-size: 0.694vw;
    color: #ffffff;
    letter-spacing: 0;
    font-weight: 400;
    padding: 0.1vh 0 0.4vh 8px;
    height: 18.5vh;
    box-sizing: border-box;
    .brand {
      line-height: 3.6vh;
      .brand-num {
        color: #606266;
        margin-right: 8px;
        display: inline-block;
        width: 0.3vw;
        text-align: center;
      }
      .marquee {
        width: 4.9vw;
        height: 3.6vh;
        margin-right: 0.6vw;
      }
    }
  }
}
</style>