salesMixin.js 1.56 KB
import { changeMixin } from './index'
export default {
  data() {
    return {
      salesData: [],
      brandList: [],
      typeRanking: '',
      isBrand: false,
      brandName: ''
    }
  },
  mixins: [changeMixin],
  created() {
    // this.getSalesData()
  },
  methods: {
    getSalesData() {
      let salesApi = !this.isBrand ? 'getSales' : 'getMerchantSales'
      const params = {
        req: {
          queryItem: this.type,
          queryTime: this.getCurrentDate(),
          queryType: this.watchReportParams.reportType
        }
      }
      if (this.isBrand) params.req.brandName = this.brandName
      this.api.sales[salesApi](params).then(res => {
        this.salesData = []
        this.typeRanking = ''
        this.brandList = []
        if (res.data.dataList.length > 0) {
          let typeNum = JSON.parse(res.data.dataList[0].typeNum)
          Object.keys(typeNum).forEach((item, index) => {
            this.salesData.push({
              name: item,
              value: typeNum[item]
            })
          })

          this.typeRanking = JSON.parse(res.data.dataList[0].typeRanking)
        }
      })
    },
    init(newVal) {
      this.isBrand = false
      if (newVal.brand) {
        this.isBrand = true
        this.brandName = newVal.brand.name
      }
      this.getSalesData()
    },
    pieAction(data) {
      this.brandList = []
      let array = this.typeRanking && this.typeRanking[data.name]
      if (array&&array.length > 0) {
        for (let i of array) {
          this.brandList.push(i && Object.keys(i)[0])
        }
      }
    }
  }
}