clientMixin.js 1.62 KB
import { changeMixin } from './index'
export default {
  data() {
    return {
      clientData: [],
      brandList: [],
      distributionRank: '',
      isBrand: false,
      brandName: ''
    }
  },
  mixins: [changeMixin],
  created() {
    // this.getClientData()
  },
  methods: {
    getClientData() {
      let clientApi = !this.isBrand ? 'overalldistribution' : 'merchantOveralldistribution'
      const params = {
        req: {
          queryItem: this.type,
          queryTime: this.getCurrentDate()
        }
      }
      if (this.isBrand) params.req.brandName = this.brandName
      this.api.customer[clientApi](params).then(res => {
        this.clientData = []
        this.brandList = []
        this.distributionRank = ''
        if (res.data.dataList.length > 0) {
          let distribution = JSON.parse(res.data.dataList[0].distribution)
          const keys = Object.keys(distribution)
          keys.forEach((item, index) => {
            this.clientData.push({
              name: item,
              value: distribution[item]
            })
          })
          this.distributionRank = JSON.parse(res.data.dataList[0].distributionRank)
        }
      })
    },
    init(newVal) {
      this.isBrand = false
      if (newVal.brand) {
        this.isBrand = true
        this.brandName = newVal.brand.name
      }
      this.getClientData()
    },
    pieAction(data) {
      this.brandList = []
      let array = this.distributionRank && this.distributionRank[data.name]
      if (array&&array.length > 0) {
        for (let i of array) {
          this.brandList.push(i && Object.keys(i)[0])
        }
      }
    }
  }
}