performanceStatus.vue 5.13 KB
<!-- 业绩状况 -->
<template>
  <div class="performance-status">
    <div class="header">
      业绩状况({{
        queryData.scene == 1 ? "延保" : queryData.scene == 2 ? "轻改" : "权益"
      }})
    </div>
    <div class="tabs">
      <div
        :class="{
          'tabs-item': true,
          'tabs-item-active': index === activeIndex
        }"
        v-for="(item, index) in timeData"
        :key="index"
        @click="handleClick(index)"
      >
        {{ item.text }}
      </div>
    </div>
    <div class="content">
      <!-- 产值 -->
      <div class="content-item">
        <div class="title">个人产值(元)</div>
        <echart-bar
          title="个人产值"
          class="echart"
          id="Output"
          :rate="'outputChangeRatio'"
          :dataRate="performanceItemInfo"
          :xData="xData"
          :yData="yOutputData"
        ></echart-bar>
      </div>
      <div class="content-item">
        <div class="title">转化率(%)</div>
        <echart-line
          title="转化率"
          class="echart"
          id="Conversion"
          :rate="'conversionChangeRatio'"
          :dataRate="performanceItemInfo"
          :xData="xData"
          :yData="yConversionData"
        ></echart-line>
      </div>
      <div class="content-item">
        <div class="title">客单价(元)</div>
        <echart-bar
          title="客单价"
          class="echart"
          id="AverageOrderValue"
          :rate="'aovChangeRatio'"
          :dataRate="performanceItemInfo"
          :xData="xData"
          :yData="yAverageOrderValueData"
        ></echart-bar>
      </div>
    </div>
  </div>
</template>
<script>
import EchartLine from "./echartLine"
import EchartBar from "./echartBar"
export default {
  components: {
    EchartLine,
    EchartBar
  },

  name: "performanceStatus",
  data() {
    return {
      xData: [],
      yOutputData: [], //产值
      yConversionData: [], //转化率
      yAverageOrderValueData: [], //客单价
      activeIndex: 0,
      activeType: "week",
      timeData: [
        {
          text: "近4周",
          value: "week"
        },
        {
          text: "近4月",
          value: "month"
        }
      ],
      performanceItemInfo: [],
      queryData: {}
    }
  },
  watch: {
    performanceInfo: {
      handler(val) {
        console.log(val, "业绩状况")
        this.initData()
      },
      deep: true,
      immediate: true
    }
  },
  props: {
    performanceInfo: {
      type: Array,
      default: () => []
    }
  },
  created() {
    this.queryData = this.$route.query
  },
  methods: {
    initData() {
      this.performanceInfo.forEach((item) => {
        if (item.timeUnit == this.activeType) {
          this.performanceItemInfo = item.data
          this.handleData(item.data)
        }
      })
    },
    handleData(data) {
      let xData = [],
        yOutputData = [],
        yConversionData = [],
        yAverageOrderValueData = []
      //近四周
      if (this.activeIndex == 0) {
        data.forEach((item) => {
          // let timeStr = item.startTime + "-" + item.endTime
          xData.push(item.endTime)
          yOutputData.push(item.personalOutput ? item.personalOutput : 0)
          // yOutputDataRate
          yConversionData.push(item.conversionRate ? item.conversionRate : 0)
          yAverageOrderValueData.push(
            item.averageOrderValue ? item.averageOrderValue : 0
          )
        })
      } else {
        //近四月
        data.forEach((item) => {
          // let timeStr = item.startTime + "-" + item.endTime
          xData.unshift(item.endTime.substring(0, 7))
          yOutputData.unshift(item.personalOutput ? item.personalOutput : 0)
          // yOutputDataRate
          yConversionData.unshift(item.conversionRate ? item.conversionRate : 0)
          yAverageOrderValueData.unshift(
            item.averageOrderValue ? item.averageOrderValue : 0
          )
        })
      }

      this.xData = xData
      this.yOutputData = yOutputData
      this.yConversionData = yConversionData
      this.yAverageOrderValueData = yAverageOrderValueData
    },
    handleClick(index) {
      this.activeIndex = index
      this.activeType = this.timeData[index].value
      this.initData()
    }
  }
}
</script>
<style scoped lang="scss">
.performance-status {
  .header {
    color: #111111;
    font-size: 16px;
    font-weight: 500;
    padding: 8px 20px;
    border-bottom: 1px solid #e5e5e5;
  }
  .tabs {
    margin: 12px 0 16px 20px;
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 2px;
    .tabs-item {
      padding: 6px 20px;
      cursor: pointer;
      font-size: 12px;
      font-weight: 400;
      color: #1d1d1d;
      border: 1px solid #dbdbdb;
    }
    .tabs-item-active {
      color: #ffffff;
      background: #2a58ad;
    }
  }
  .content {
    margin: 20px;
    display: flex;
    height: 238px;
    width: 100%;
    .content-item {
      flex: 1;
      .echart {
        width: 100%;
        height: 100%;;
      }
      .title {
        color: #333333;
        font-size: 14px;
        font-weight: 400;
        margin-bottom: 12px;
      }
    }
  }
}
</style>