shj
2022-09-06 bd51064081eb9e317e88f20e29607117f090cb99
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
<template>
    <div class="system-user-container">
        <el-card shadow="hover">
            <div class="system-user-search mb15">
                <el-form ref="ruleFormRef" size="default" label-width="80px" :inline="true">
                    <el-row >
                        <el-col :span="5">
                            <el-form-item prop="telephone" label="选择年月">
                                <el-radio-group v-model="params.type" style="width:100%">
                                    <el-radio :label="2">年</el-radio>
                                    <el-radio :label="1">月</el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item v-if="params.type==2" prop="telephone" label="选择年">
                                <el-date-picker
                                        v-model="params.year"
                                        :disabled="disabled"
                                        type="year"
                                        style="width:100%"
                                        value-format="YYYY"
                                        placeholder="选择日期时间"
                                />
                            </el-form-item>
                            <el-form-item v-if="params.type==1" prop="telephone" label="选择月">
                                <el-date-picker
                                        v-model="params.realMonth"
                                        :disabled="disabled"
                                        type="month"
                                        class="w100"
                                         style="width:100%"
                                        value-format="YYYY-MM"
                                        placeholder="选择日期时间"
                                />
                            </el-form-item>
                        </el-col>
                        <el-col :span="3">
                            <el-button size="default" type="primary" class="ml10" @click="emergencySuppliesCount"> 查询</el-button>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="echarts" ref="echarts1">
 
                </div>
            </div>
 
        </el-card>
 
    </div>
</template>
<script lang="ts">
    import { defineComponent, onMounted, ref } from 'vue';
    import * as echarts from 'echarts';
    import { ElMessage } from 'element-plus';
    import { goalManagementApi } from '/@/api/goalManagement';
    import { toNamespacedPath } from 'path/posix';
    export default defineComponent({
        setup() {
            const params = ref({
                level:'',
                type:2,
                year:'2022',
                month:'',
                realMonth:''
            })
            const list = ref([])
//加载数据
            const emergencySuppliesCount = () => {
                if(params.value.type==2){
                    params.value.month=''
                }
                if(params.value.type==1){
                    params.value.year=params.value.realMonth.split('-')[0]
                    params.value.month=params.value.realMonth.split('-')[1]
                }
                goalManagementApi()
                    .accidentReportCount(params.value)
                    .then((res) => {
                        if (res.data.code == 200) {
                            var newList = []
                            for(var a = 0;a<res.data.data.length;a++){
                                newList.push(
                                    {
                                        name:res.data.data[a].name+":"+res.data.data[a].num,
                                        value:res.data.data[a].num,
                                        deathNum: res.data.data[a].deathNum,
                                        economicLoss: res.data.data[a].economicLoss,
                                        minorInjuryNum: res.data.data[a].minorInjuryNum,
                                        seriousInjuryNum: res.data.data[a].seriousInjuryNum
                                    }
                                )
                            }
                            list.value = newList;
                            initPies()
                        } else {
                            ElMessage.error(res.data.msg);
                        }
                    });
            };
            const echarts1 = ref()
            const initPies = () => {
                var myChart = echarts.init(echarts1.value);
                myChart.clear()
                var option = {
                    tooltip: {
                        trigger: 'item',
                        textStyle:{
                            fontSize:18
                        },
                        formatter(params){
                            for(var x in params){
                                return params.data.name.split(':')[0] +":"+params.data.value+'<br />'+
                                    '死亡人数:'+params.data.deathNum+'<br />'+
                                    '轻伤人数:'+params.data.minorInjuryNum+'<br />'+
                                    '重伤人数:'+params.data.seriousInjuryNum+'<br />'+
                                    '经济损失:'+params.data.economicLoss+'<br />'
                            }
 
                        }
                    },
                    legend: {
                        top: '5%',
                        left: 'center',
                        icon: "circle",
                        formatter: function(param){
                            param=param.split(":");
                            return [param[0]+':'+param[1]].join("");
                        },
                    },
                    series: [
                        {
                            name: '事故等级分布',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            itemStyle: {
                                borderRadius: 10,
                                borderColor: '#fff',
                                borderWidth: 2
                            },
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: false,
                                    fontSize: '40',
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            data: list.value
                        }
                    ]
                };
 
                myChart.setOption(option, true);
 
            };
            onMounted(() => {
                emergencySuppliesCount()
            });
            return {
                params,
                list,
                emergencySuppliesCount,
                initPies,
                echarts1
            }
        }
 
    })
</script>
<style scoped>
.echarts{
    width: 500px;
    height: 400px;
}
</style>