shj
2022-08-17 9354b25e495db5365374f222e368a13cbca9b47e
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
<template>
    <div>
        <div class="echart">
            <h2 class="title">距上次应急演练结束{{day}}天</h2>
            <el-form :model="form" label-width="20px">
                <el-row>
                    <!-- <el-col :span="5" :offset="1">
                        <el-form-item>
                            <el-date-picker v-model="form.date" format="YYYY-MM-DD" type="date" placeholder="应急演练时间" style="width: 100%" />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="4" :offset="15">
                        <el-form-item size="default">
                            <el-tree-select v-model="form.deptId" :data="data" @change="eaclick" placeholder="选择部门" :props="propse"  style="width: 100%" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item size="default">
                            <el-select v-model="form.type" placeholder="年/月" @change="eaclick" style="width:100%">
                                <el-option label="年" :value="1" />
                                <el-option label="月" :value="2" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div ref="main" style="width: 100%; height: 400px"></div>
        </div>
    </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 form = ref({
            type:1,
            deptId:1
        });
        //部门
        const department = () => {
            goalManagementApi()
                .getTreedepartment()
                .then((res) => {
                    if (res.data.code == 200) {
                        data.value = res.data.data;
                    } else {
                        ElMessage.error(res.data.msg);
                    }
                });
        };
        const propse = {
            label: 'depName',
            children: 'children',
            value: 'depId',
        };
        const eaclick=()=>{
            listApi()
        }
        onMounted(() => {
             listApi()
            department();
        });
        const day=ref(0)
        const listApi=()=>{
            goalManagementApi().emergencyStat(form.value).then(res=>{
               if(res.data.code==200){
                day.value=res.data.data.days
                let date=[]
                let names=[]
                res.data.data.dataList.forEach(item => {
                    date.push(item.num)
                    names.push(item.name)
                });
                init(date,names)
               }
            })
        }
        const main = ref();
        const init = (data: any,names:any) => {
            var myChart = echarts.init(main.value);
            var option = {
                tooltip: {},
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '5%',
                    containLabel: true,
                },
                xAxis: {
                    type: 'category',
                    data: names,
                },
                yAxis: {
                    type: 'value',
                    name: '次数',
                    nameTextStyle: {
                        color: '#aaa',
                        nameLocation: 'start',
                    },
                },
                color: ['#6394f9'],
                series: [
                    {
                        data: data,
                         barWidth : 40,
                        type: 'bar',
                    },
                ],
            };
 
            myChart.setOption(option);
        };
        const data = ref([])
        return {
            form,
            main,
            init,
            data,
            department,
            propse,
            listApi,
            eaclick,
            day
        };
    },
});
</script>
<style scoped>
.title{
    text-align: center;
    padding: 20px 0;
}
.echart {
    background-color: #fff;
    border-radius: 5px;
}
.el-form {
    padding: 20px 0;
}
</style>