file.vue 3.22 KB
<!--
 * @Description: 售后档案客户
 * @Author: huyue
 * @Date: 2022-06-23 15:05:21
 * @LastEditors: huyue
 * @LastEditTime: 2022-06-23 17:21:39
-->
<template>
  <div>
    <div class="title title-icon">
      <span class="icon"></span>
      <span>售后档案客户</span>
    </div>
    <div v-if="!dataList.length" class="empty">
      <img src="../../assets/images/empty.png" alt="" />
    </div>
    <div v-else>
      <div v-if="isEmpty" class="empty">
        <img src="../../assets/images/empty.png" alt="" />
      </div>
      <LineChart v-else ref="lineChartRef" domId="fileChart" :dataList.sync="dataList" :storeOrBrandTxt="storeOrBrandTxt" :queryType="queryType"></LineChart>
    </div>
  </div>
</template>

<script>
import { changeMixin } from '@/mixins'
export default {
  name: 'File',
  mixins: [changeMixin],
  props: {
    height: {
      type: String,
      default: '19.8vh'
    }
  },
  data() {
    return {
      isEmpty: true,
      storeOrBrandTxt: '品牌',
      queryType: 0,
      dataList: []
    }
  },
  mounted() {
    // this.dealList()
  },
  methods: {
    init(val) {
      this.isEmpty = true
      this.queryType = +this.watchReportParams.reportType
      var params = {
        req: {
          queryItem: 'file',
          querystartTime: +this.watchReportParams.reportType === 1 ? this.getNDate(-30) : this.getNMonth(-12),
          queryendTime: +this.watchReportParams.reportType === 1 ? this.getNDate(-1) : this.getNMonth(-1),
          queryType: this.watchReportParams.reportType
        }
      }
      var brandName = val.brand ? val.brand.name : ''
      this.storeOrBrandTxt = brandName ? '门店' : '品牌'
      if (brandName) {
        params.req.brandName = brandName
      }
      this.api.afterSales[brandName ? 'getMerchantAfterSale' : 'getAfterSale'](params).then(res => {
        var { code, data } = res
        switch (+code) {
          case 0:
            this.dataList = []
            if (!data.dataList.map(item => item.num).every(item => item === 0)) {
              this.isEmpty = false
              this.dealList(data.dataList)
              this.$nextTick(() => {
                this.$refs.lineChartRef.drawLine()
              })
            }
            break
        }
      })
    },
    dealList(list) {
      var topList = []
      var lastList = []
      list.forEach(item => {
        const topTempList = item.topList === 'null' ? [] : JSON.parse(item.topList)
        const lastTempList = item.lastList === 'null' ? [] : JSON.parse(item.lastList)
        topList = []
        lastList = []
        Object.keys(topTempList).forEach(item => {
          topList.push({
            label: item,
            value: topTempList[item].num ? this.numAddSymbol(topTempList[item].num) : '- -'
          })
        })
        Object.keys(lastTempList).forEach(item => {
          lastList.push({
            label: item,
            value: lastTempList[item].num ? this.numAddSymbol(lastTempList[item].num) : '- -'
          })
        })
        this.dataList.push({
          num: item.num || 0,
          hrate: item.hrate.toFixed(2) || 0,
          trate: item.trate.toFixed(2) || 0,
          statDate: item.statDate,
          topList: topList,
          lastList: lastList
        })
      })
    }
  }
}
</script>