analyze.vue
5.12 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!--
* @Description: 售后客户价值分析
* @Author: huyue
* @Date: 2022-06-23 15:05:21
* @LastEditors: huyue
* @LastEditTime: 2022-06-29 19:47:17
-->
<template>
<div>
<div class="title">售后客户价值分析</div>
<template v-if="barData.length > 0">
<div class="analyze-content" :style="{ height: height - 5 + 'vh' }">
<div class="content-left">
<div id="analyzeBar" style="height: 100%"></div>
</div>
<div class="contetn-right">
<pie-chart :id="chart.id" :list="analyzeData" :height="height - 5 + 'vh'" :radius="chart.radius" :size="chart.size"></pie-chart>
</div>
</div>
</template>
<div class="empty" :style="{ height: height - 4.9 + 'vh' }" v-else>
<img src="../../assets/images/empty.png" alt="" />
</div>
</div>
</template>
<script>
import * as echarts from 'echarts'
import datas from '../../utils/data'
import { changeMixin } from '../../mixins/index'
export default {
name: 'Analyze',
props: ['height'],
mixins: [changeMixin],
data() {
return {
analyzeData: [],
chart: {
id: 'analyzePie',
radius: ['60%', '78%'],
size:'0.8vw'
},
barChart: '',
option: {},
barData: [],
key: '重要价值',
isBrand: false,
brandName: ''
}
},
mounted() {},
methods: {
getChart() {
this.barChart = echarts.init(document.getElementById('analyzeBar'))
// resize
window.addEventListener('resize', () => {
this.barChart.resize()
})
this.option = {
grid: {
left: '3%',
right: '4%',
top: '2%',
bottom: '2%',
containLabel: true
},
yAxis: {
type: 'category',
data: datas.Customer.valueType.value.map(item => item.name).reverse(),
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLine: {
show: false
}
},
xAxis: {
type: 'value',
splitLine: {
show: false
},
axisLabel: {
show: false
}
},
series: [
{
// data: [120, 200, 150, 80, 70, 110, 130, 300],
data: this.barData.reverse(),
type: 'bar',
barWidth: 12,
itemStyle: {
normal: {
label: {
show: true,
position: 'center',
textStyle: {
fontSize: '12',
color: '#fff',
height: '12',
padding: [1, 0, 0, 0]
}
},
color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
{
offset: 0,
color: '#F79902'
},
{
offset: 1,
color: '#EB6001'
}
])
}
}
}
]
}
this.barChart.clear()
this.barChart.setOption(this.option)
// 鼠标划入
this.barChart.on('mouseover', data => {
this.initPieData(data.name)
})
},
getValueType() {
let analyzeApi = !this.isBrand ? 'aftersaleother' : 'afterMerchantSaleother'
const params = {
req: {
queryItem: 'valueanalyse',
// queryTime: "2022-06-23",
queryTime: this.getCurrentDate(),
queryType: this.watchReportParams.reportType
}
}
if (this.isBrand) params.req.brandName = this.brandName
this.api.afterSales[analyzeApi](params).then(res => {
this.analyzeData = []
this.barData = []
if (res.data.dataList.length > 0) {
const reqData = JSON.parse(res.data.dataList[0].distribution)
this.distributionRank = JSON.parse(res.data.dataList[0].distributionRank)
this.barData = []
for (let i in reqData) {
this.barData.push(reqData[i])
}
this.$nextTick(() => {
this.getChart()
this.initPieData(this.key)
})
}
})
},
initPieData(name) {
this.analyzeData = []
datas.Customer.valueType.value.map(item => {
if (item.name == name) {
const distributionRank = this.distributionRank[item.value]
Object.keys(distributionRank).forEach(item => {
this.analyzeData.push({
name: item,
value: distributionRank[item]
})
})
}
})
},
init(newVal) {
this.isBrand = false
if (newVal && newVal.brand) {
this.isBrand = true
this.brandName = newVal.brand.name
}
this.getValueType()
}
}
}
</script>
<style lang="scss" scoped>
.title {
padding: 1vh 8px;
height: 4vh;
}
.analyze-content {
display: flex;
padding: 0 8px;
box-sizing: border-box;
.bg {
background-color: #262525;
}
.content-left {
flex: 1;
height: 100%;
}
.contetn-right {
width: 50%;
margin-left: 8px;
}
}
</style>