suerprisePlus
2024-07-30 e5e65bb50cbfb973f98191993ab559767eff7a53
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
<template>
    <Popup ref="pop" top="20px" :title="title" @close="close(true)" width="1000px" :maxHeight="'700px'"
        @cancel="close(false)">
        <div class="menuBox">
            <div class="serachContent">
                <el-select v-model="linesName" @change="setEchartChange" placeholder="请选择">
                    <el-option v-for="(item, key) in linesOption" :key="key" :label="item.line" :value="item.line">
                    </el-option>
                </el-select>
            </div>
            <div class="echartContent">
                <div id="myEchart" class="myChart"> </div>
            </div>
        </div>
    </Popup>
</template>
 
<script>
import Popup from '@/components/Tool/Popup.vue';
import { zhangzitou_selectInfos } from "@/api/mapView/map.js"
import mapData from '@/assets/js/mapSdk/mapData';
import * as echarts from 'echarts';
export default {
    name: 'dataAnalysis',
    components: { Popup },
    data() {
        return {
            title: '数据统计',
            allLines: [],
            linesOption: [],
            linesName: '',
            myChart: null,
        };
    },
    methods: {
        // 关闭弹窗
        close(isCloseBtn, removeLayer = true) {
            //   removeLayer && this.removeImageLayer();
            // 重置data值
            Object.assign(this.$data, this.$options.data());
            !isCloseBtn && this.$refs.pop.close();
        },
        // 打开弹窗
        open() {
            this.close(true);
            this.$refs.pop.open();
            this.getAllLines();
        },
        getAllLines() {
            zhangzitou_selectInfos().then(response => {
                if (response.data.code != 200) {
                    return this.close();
                }
                this.setAllLinses(response.data.result)
            })
        },
        setAllLinses(res) {
            this.allLines = res;
            this.linesOption = this.allLines.filter((item, index, self) =>
                index === self.findIndex((t) => t.line === item.line)
            );
            this.linesName = this.linesOption[0].line;
            this.setEchartChange();
        },
        setEchartChange() {
            zhangzitou_selectInfos({
                line: this.linesName
            }).then(response => {
                if (response.data.code != 200) return
                const result = response.data.result;
 
                const objData = []
                result.filter(item => {
                    const type = mapData.dataStatistics[item.type];
                    if (type) {
                        item.type = type
                    }
                    objData.push({
                        value: item.count, name: item.type
                    })
                })
                this.setEchartShow(objData)
            })
 
        },
 
        setEchartShow(res) {
 
            let option = {
                title: {
 
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: this.linesName,
                        type: 'pie',
                        radius: '50%',
                        data: res,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            if (!this.myChart) {
 
                this.myChart = echarts.init(document.getElementById("myEchart"));
            }
 
 
            this.myChart.setOption(option);
            window.addEventListener("resize", () => {
                this.myChart.resize();
            });
        },
    },
};
</script>
 
<style lang="scss" scoped>
.menuBox {
    position: relative;
    height: 660px;
    width: calc(100% - 0px);
    padding: 10px;
    display: flex;
    flex-direction: column;
 
    .serachContent {
        display: flex;
    }
 
    .echartContent {
        flex: 1;
 
 
        .myChart {
            margin-top: 10px;
            width: 100%;
            height: calc(100% - 10px);
        }
    }
 
}
</style>