lost.vue
3.69 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!--
* @Description: 客户流失
* @Author: huyue
* @Date: 2022-06-23 15:05:21
* @LastEditors: huyue
* @LastEditTime: 2022-06-23 17:22:34
-->
<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="lostChart" :dataList.sync="dataList" :storeOrBrandTxt="storeOrBrandTxt" :queryType="queryType" :tooltipFormatterObj="tooltipFormatterObj"></LineChart>
</div>
</div>
</template>
<script>
import { changeMixin } from '@/mixins'
export default {
name: 'Lost',
mixins: [changeMixin],
props: {
height: {
type: String,
default: '19.8vh'
}
},
data() {
return {
isEmpty: true,
storeOrBrandTxt: '品牌',
queryType: 0,
dataList: [],
tooltipFormatterObj: [
{
label: '流失数',
attrName: 'num'
},
{
label: '流失率',
attrName: 'rate',
addSymbol: '%'
},
{
label: '环比',
attrName: 'hrate',
addSymbol: '%'
},
{
label: '同比',
attrName: 'trate',
addSymbol: '%'
}
]
}
},
mounted() {},
methods: {
init(val) {
this.isEmpty = true
this.queryType = +this.watchReportParams.reportType
var params = {
req: {
queryItem: 'loss',
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 || 0
}
}
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].rate ? topTempList[item].rate.toFixed(2) + '%' : '- -'
})
})
Object.keys(lastTempList).forEach(item => {
lastList.push({
label: item,
value: lastTempList[item].rate ? lastTempList[item].rate.toFixed(2) + '%' : '- -'
})
})
this.dataList.push({
num: item.num || 0,
rate: item.rate.toFixed(2) || 0,
hrate: item.hrate.toFixed(4) || 0,
trate: item.trate.toFixed(4) || 0,
statDate: item.statDate,
topList: topList,
lastList: lastList
})
})
}
}
}
</script>