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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<template>
<CellWrapper title="大客户分析" :cellContentHeight="cellContentHeight">
<template v-slot:header>
<span class="el-icon-refresh" title="刷新"></span>
<span class="el-icon-more" title="操作"></span>
</template>
<div class="chart-container">
<div class="chart-operate">
<i class="el-icon-arrow-up"></i>
<i class="el-icon-arrow-down"></i>
</div>
<div class="chartWrapper">
<div class="chart"></div>
</div>
</div>
</CellWrapper>
</template>
<script>
import CellWrapper from "../common/CellWrapper.vue";
import * as echarts from "echarts";
import { busvolume, finamount, expincome } from "~/service/report";
export default {
name: "CustomerAnalyse",
props: ["cellContentHeight"],
components: { CellWrapper },
data() {
return {
echartInstance: null,
//componentIndex
mapping: {
0: "busvol",
1: "iaefts",
2: "expben",
},
category: [],
seriesData : [] ,
seriesData1 : [] ,
seriesData2 : [] ,
};
},
mounted() {
// 仅在整个视图都被渲染之后才会运行的代码
this.$nextTick(async() => {
await this.loadData();
this.loadCharts();
this.loadChartsBind = this.loadCharts.bind(this);
window.addEventListener("resize", this.loadChartsBind);
});
},
methods: {
async loadData() {
//统计 业务量
const volume = await busvolume();
let volumes = Array.from(volume);
//统计 融资量
const amount = await finamount();
let amounts = Array.from(amount);
//统计 费用收益
const income = await expincome();
let incomes = Array.from(income)
let categoryArr = [];
//定义 seriesData数组 金额 category数组 客户名
// let seriesData = [];
// let seriesData1 = [];
// let seriesData2 = [];
// 优先遍历客户名,方便后续的数组匹配
// volume.forEach((v) => {
// console.log(v.nam1)
// category.push(v.nam1);
// console.log(category.toString());
// console.log(category)
// });
for (let i = 0; i < volume.length; i++) {
let v = volume[i].nam1;
// console.log(typeof v);
// console.log(volume[i].nam1);
categoryArr.push(v);
// console.log(category.toString());
// console.log(category);
// console.log(typeof category);
}
this.category = categoryArr;
//存在bug后续要解决
// amount.forEach((v) => {
// for (let i = 0; i < category.length; i++) {
// if (category[i] == v.nam1) {
// continue;
// } else {
// category.push(v.nam1);
// }
// }
// });
//存在bug后续要解决
// income.forEach((v) => {
// for (let i = 0; i < category.length; i++) {
// if (category[i] == v.nam1) {
// continue;
// } else {
// category.push(v.nam1);
// }
// }
// });
const volumeArr = []
volumes.forEach((v) => {
for (let i = 0; i < categoryArr.length; i++) {
if (categoryArr[i] == v.nam1) {
volumeArr.push(v.amount)
break;
}
}
});
this.seriesData = volumeArr;
const amountArr = []
amounts.forEach((v) => {
for (let i = 0; i < categoryArr.length; i++) {
if (categoryArr[i] == v.nam1) {
amountArr.push(v.amount);
break;
}
}
});
this.seriesData1 = amountArr;
const incomeArr = []
incomes.forEach((v) => {
for (let i = 0; i < categoryArr.length; i++) {
if (categoryArr[i] == v.nam1) {
incomeArr.push(v.amount);
break;
}
}
});
this.seriesData2 = incomeArr;
},
//加载图标函数
loadCharts() {
if (this.echartInstance) {
this.echartInstance.dispose();
}
this.echartInstance = echarts.init(
this.$el.querySelector(".chart-container .chartWrapper .chart")
);
const option = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
},
legend: {
bottom: "2%",
},
grid: {
left: "1%",
right: "6%",
top: "1%",
containLabel: true,
},
xAxis: {
type: "value",
boundaryGap: ["10%", "20%"],
},
yAxis: {
type: "category",
data: this.category,
},
series: [
{
name: "业务量金额(美元)",
type: "bar",
data: this.seriesData,
},
{
name: "融资量金额(万美元)",
type: "bar",
data: this.seriesData1,
},
{
name: "费用收益金额(千美元)",
type: "bar",
data: this.seriesData2,
},
],
};
this.echartInstance.setOption(option);
//echart on事件来跳转页面
// this.echartInstance.on(
// 'click',
// function (params) =>{
// alert(params.name);
// this.$router.push('/taskList')
// }
this.echartInstance.on("click", (params) => {
console.log(params);
console.log(params.name);
var name = parseInt(params.name);
let path = params.componentIndex;
// 要使用=>函数使内外的this指向一致
if (path === 0) {
this.$router.push({
path:"/business/Busvol",
query:{name: params.name}
});
} else if (path === 1) {
//{path:"/xxxpath",query:"id:xxx"} router跳转页面传参业务 接受页面用created(){if(this.$route.query){todo}}
this.$router.push({
path:"/business/Iaefts",
query:{name: params.name}
});
} else {
//{path:"/xxxpath",query:"id:xxx"} router跳转页面传参业务 接受页面用created(){if(this.$route.query){todo}}
this.$router.push({
path:"/business/Expben",
query:{name:params.name}
});
}
});
},
destroyed() {
window.removeEventListener("resize", this.loadChartsBind);
},
},
};
</script>
<style>
.chart-container {
height: 100%;
display: flex;
flex-direction: column;
padding: 0 5px;
}
.chart-operate {
margin-left: 20px;
height: 20px;
}
.chart-operate i {
cursor: pointer;
}
.chartWrapper {
flex: 1;
}
.chartWrapper .chart {
width: 100%;
height: 100%;
/* 将指针改变为可以跳转 */
cursor: pointer;
}
</style>