clientMixin.js
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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)
// 删掉“未知”
delete distribution['未知']
let keys = Object.keys(distribution)
let total = Object.values(distribution).reduce((prev, next) => prev + next)
keys.forEach((item, index) => {
this.clientData.push({
name: item,
// value: distribution[item]
value: (distribution[item] / total * 100).toFixed(1)
})
})
console.log(this.clientData)
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])
}
}
}
}
}