gaoshp
2024-06-11 e87012567c674cd69f7a8f87df7202eac60a8208
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
<!--
 * @Date: 2024-04-18 21:52:18
 * @LastEditors: Sneed
 * @LastEditTime: 2024-05-14 20:42:32
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/components/ShiftAlarm.vue
-->
<template>
    <el-main>
        <el-row>
            <el-col>
                <el-button-group>
                    <el-button size="small" @click="btnListActive = item.id"
                        :type="btnListActive == item.id ? 'primary' : ''" v-for="item in btnList" :key="item.id">{{
                            item.title }}</el-button>
                </el-button-group>
            </el-col>
            <el-col>
                <el-switch v-model="isShowTable" class="mb-2" active-text="数据表" inactive-text="统计图" />
            </el-col>
 
 
        </el-row>
        <el-row v-show="!isShowTable">
            <el-col style="margin-top: 12px;" v-for="item in chartsData" :key="item.shiftIndex">
                <el-card shadow="never">
                    <template #header>
                        <div class="card-header">
                            <span>{{ item.title }}</span>
                        </div>
                    </template>
                    <scEcharts height="300px" :option="item.option"></scEcharts>
                </el-card>
            </el-col>
        </el-row>
        <el-empty description="暂无数据" v-if="tableData.length == 0"></el-empty>
        <el-row v-show="isShowTable" v-for="(item, index) in tableData" :key="index">
            <el-col style="margin-top: 12px;">
                <div>{{ item.title }}</div>
                <el-table ref="table" row-key="id" border :data="item.data" stripe>
                    <el-table-column prop="alarmCode" label="报警代码" />
                    <el-table-column prop="alarmMsg" label="报警信息" />
                    <el-table-column prop="count" label="报警次数" />
                </el-table>
            </el-col>
        </el-row>
    </el-main>
 
</template>
 
<script>
import scEcharts from '@/components/scEcharts';
import moment from 'moment';
export default {
    props: {
        url: {
            default: '',
            type: String,
        },
    },
    components: {
        scEcharts
    },
    data() {
        return {
            sheetUrl: '/api/blade-mdc/alarm/data-shift-sheet',
            isShowTable: false,
            params: {
                enums: "SHIFT",
                month: 0,
                queryTime: "2024-04-18",
                shiftIndex: 1,
                week: 0,
                workstationId: "",
                year: 0,
            },
            btnList: [],
            btnListActive: '',
            tableData: [],
            chartsData: [
            ],
        }
    },
    watch: {
        btnListActive(val) {
            this.queryChart({
                ...this.params,
            })
        }
    },
    methods: {
        init(params) {
            this.btnListActive = ''
            console.log('++++++')
            this.params = {
                ...this.params,
                workstationId: params.workstationId.toString()
            }
            this.getTime({
                endDate: params.endDate,
                startDate: params.startDate,
            }).then(res => {
            })
 
        },
        getTime(data) {
            return new Promise(resolve => {
                let arr = []
                let date = moment(data.startDate)
                arr.push({
                    title: date.format('YYYY-MM-DD'),
                    id: date.format('YYYY-MM-DD')
                })
                while (date.format('YYYY-MM-DD') < data.endDate) {
                    date = date.add(1, 'd')
                    arr.push({
                        title: date.format('YYYY-MM-DD'),
                        id: date.format('YYYY-MM-DD')
                    })
                }
                this.btnList = arr;
                this.btnListActive = arr[0].id
                resolve(arr)
            })
        },
        queryChart(data) {
            let dataSend = {
                ...this.params,
                queryTime: this.btnListActive,
            }
            this.queryTableData(dataSend)
            return this.$HTTP.post(this.url, dataSend, {}).then(res => {
                this.chartsData = res.data.map(item => {
                    return {
                        title: `班次${item.shiftIndex}   ${item.shiftIndexName}`,
                        shiftName: item.shiftName,
                        shiftIndexName: item.shiftIndexName,
                        option: this.setOptions(item.res)
                    }
                })
            })
        },
        setOptions(obj) {
            let source = Object.keys(obj)
            let data = Object.values(obj)
            return {
                legend: {
                    type: 'plain',
                },
                title: {
                    text: '统计图表',
                    subtext: '',
                },
                grid: {
                    top: '80px'
                },
                tooltip: {
                    trigger: 'axis'
                },
                xAxis: {
                    type: 'category',
                    data: source
                },
                yAxis: {
                    type: 'value'
                },
                dataZoom: [
                    { type: 'slider' }
                ],
                series: [{
                    type: 'bar',
                    data
                }]
            }
        },
        queryTableData(data) {
            return this.$HTTP.post(this.sheetUrl, data, {}).then(res => {
                this.tableData = res.data.map(item => {
                    return {
                        title: `班次${item.shiftIndex}`,
                        shiftName: item.shiftName,
                        shiftIndex: item.shiftIndex,
                        data: item.alarmDataSheetVOList
                    }
                })
            })
        }
    }
}
</script>
 
<style lang="scss" scoped></style>