index.vue
1.58 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
<template>
<div>
<Chart :cdata="cdata" />
</div>
</template>
<script>
import Chart from "./Chart";
import work from "@/api/work";
export default {
data () {
return {
cdata: {
seriesData: [],
},
getdata: [],
};
},
components: {
Chart,
},
mounted () {
this.addhousetotal();
window.addEventListener("resize", () => {
this.getdata = [];
this.addhousetotal();
});
},
methods: {
async addhousetotal () {
if (this.getdata.length == 0) {
this.getdata = [];
try {
let { result: res } = await work.addhousetotal();
res.map((item) => {
return this.cdata.seriesData.push({
name: `${item.fwyt + '(' + item.fwxz})`,
value: item.mj,
});
});
} catch (error) {
console.log("error", error);
}
}
let delarr = this.cdata.seriesData.sort(this.up)
this.setadat(delarr)
},
// 处理数据方法
setadat (delarr) {
this.cdata.seriesData = delarr.splice(0, 6);
let sum = 0
for (var i = 0; i < delarr.length; i++) {
sum = sum + delarr[i].value
}
sum = sum.toFixed(2)
this.cdata.seriesData.push({
name: "其他(其他种类)",
values: "其他种类",
value: sum,
})
},
// 排序方法
up (x, y) { return y.value - x.value }
}
};
</script>
<style lang="scss" scoped></style>