zmc
2023-12-07 d1ccf7e1835b3c583da16d90a286e749d5e27c84
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<script>
import AreaAndmonitorType from '@/sfc/AreaAndmonitorType.vue'
import { useCommonFunction } from '../../utils/common.js'
import dayjs from 'dayjs'
import ButtonExportExcel from '@/sfc/ButtonExportExcel.vue'
import ButtonClick from '@/sfc/ButtonClick.vue'
import { ElMessage } from 'element-plus'
import MonthSelect from '@/sfc/MonthSelect.vue'
import riskApi from '@/api/risk/riskApi.js'
import riskValue from '@/utils/risk_estimate_common_function/riskValue.js'
export default {
  components: {
    AreaAndmonitorType,
    ButtonExportExcel,
    ButtonClick,
    MonthSelect
  },
  data() {
    return {
      //   表格数据
      tableData: [],
      isNoData: true,
      loading: false,
      // 统计分析按钮加载中
      queryButton: false,
      // 导出按钮加载中
      exportButton: false,
      form: {
        // 站点名称
        name: '',
        // 开始时间
        beginTime: '',
        // // 结束时间
        endTime: '',
 
        // 选择的月份
        month: ''
      },
      bill: {
        min: '',
        max: '',
        avg: '',
        online: '',
        valid: '',
        exceeding: '',
 
        //  典型异常复现率
        exceptionRecurrence: '',
        // 异常类型据聚集度
        exceptionTypeAggregation: ''
      },
 
      // 表格数据
      table: [],
      // 表格高度
      tableHeight: 600,
      currentRow: []
    }
  },
  setup() {
    // 引入 百分号比较大小 导出功能
    const { exportToExcel } = useCommonFunction()
    return { exportToExcel }
  },
  computed: {
    // 计算高中低站点数量
    riskGradeNum() {
      let riskGrade = {}
      if (this.table) {
        let highRisk = 0
        let middleRisk = 0
        let lowRisk = 0
        this.table.forEach((item) => {
          switch (item.riskGrade) {
            case '高风险':
              highRisk++
              break
            case '中风险':
              middleRisk++
              break
            case '低风险':
              lowRisk++
              break
          }
        })
        riskGrade.high = highRisk
        riskGrade.middle = middleRisk
        riskGrade.low = lowRisk
      }
      return riskGrade
    },
    // 高中低风险比例
    riskGradeRate() {
      let rate = {
        high:0,
        middle:0,
        low:0
      }
      if (this.table.length !=0 ) {
        let num = this.table.length
        let highGrade = ((this.riskGradeNum.high / num)*100).toFixed(2)
        let middleGrade = ((this.riskGradeNum.middle / num)*100).toFixed(2)
        let lowGrade = ((this.riskGradeNum.low / num)*100).toFixed(2)
        rate.high = highGrade
        rate.middle = middleGrade
        rate.low = lowGrade
      }
      return rate
    }
  },
  mounted() {
    //
    this.fetch()
    this.calTableHeight()
  },
  methods: {
    /**
     * 将中国标准时间转为指定格式
     * @param:
     * @returns:
     */
    giveMonth(val) {
      //将中国标准时间转为指定格式(该组件返回的标准时间的格式,所以必须的加这个函数)
      this.form.month = dayjs(val).format('YYYY-MM-DD')
      // 同时更新开始和结束时间
      this.form.beginTime = dayjs(this.form.month).startOf().format('YYYY-MM-DD HH:mm:ss')
      this.form.endTime = dayjs(this.form.month).endOf('month').format('YYYY-MM-DD HH:mm:ss')
      console.log(this.form.beginTime, this.form.endTime)
    },
 
    // 功能:改变表格某个单元格的颜色
    tableCellClassName({ row, columnIndex }) {
      // 平均值不满足标准时
      if (columnIndex == 4) {
        if (row.riskValue >= 0.8) {
          return 'warning-row'
        }
      }
    },
    // 功能:表格高度根据内容自适应
    calTableHeight() {
      const h1 = this.$refs.h1.$el.offsetHeight
      // 其中一个40是盒子的总外边距
      this.tableHeight = `calc(100vh - ${h1}px  - 40px - 40px - var(--el-main-padding) * 2`
    },
 
    // 点击风险排名按钮
    fetchData() {
      this.loading = true
      this.queryButton = true
      riskApi.queryRiskValue('', this.form.month, 'month').then((response) => {
        this.loading = false
        this.queryButton = false
        if (response.data.data.length == 0) {
          this.isNoData = true
          return
        }
        
        this.table = riskValue.backComprehensiveRiskTableData(response.data.data)
        this.queryButton = false
        this.isNoData = false
        this.loading = false
        this.$nextTick(() => {
          this.$refs.table.sort('riskValue', 'descending')
        })
      })
    },
 
    /**
     * 初始加载函数
     */
    fetch() {
      // 分析数据
      this.fetchData()
      // 异常数据
      // this.exceptiondataCount()
    },
 
    // 单元格内容换行
    wrapIndex(index) {
      return index.replace(/\n/g, '<br/>')
    },
 
    /**
     * 导出为Excel
 
     */
    exportData() {
      if (this.table.length != 0) {
        const tableColumns = [
          'siteName',
          'region',
          'monitorType',
          'riskValue',
          'riskGrage',
          'riskAdvice',
          'beginTime',
          'endTime'
        ]
        const excelColumns = [
          ['A1', '站点名称'],
          ['B1', '区域'],
          ['C1', '监测类型'],
          ['D1', '风险值'],
          ['E1', '风险等级'],
          ['F1', '管控措施'],
          ['G1', '开始日期'],
          ['H1', '结束日期']
        ]
        this.exportButton = true
        this.exportToExcel(this.table, tableColumns, excelColumns, '综合风险排名.xlsx')
        this.exportButton = false
      } else {
        ElMessage('无数据需要导出')
      }
    },
    openDetail(row) {
      const encodedSiteName = encodeURIComponent(row.siteName)
      const jumpPage = 1 
      this.$router.push(`/exceptionDetail/${encodedSiteName}/${this.form.month}/1/${jumpPage}`)
    }
  }
}
</script>
 
<template>
  <el-row ref="h1">
    <el-col :span="24">
      <el-form :inline="true" :model="form">
        <el-form-item>
          <AreaAndmonitorType></AreaAndmonitorType>
        </el-form-item>
 
        <el-form-item>
          <MonthSelect @submit-value="giveMonth"></MonthSelect>
        </el-form-item>
 
        <el-form-item>
          <ButtonClick
            style="margin-right: 12px"
            content="风险排名"
            type="primary"
            :loading="queryButton"
            @do-search="fetch"
          ></ButtonClick>
          <ButtonExportExcel
            content="导出数据"
            type="success"
            :loading="exportButton"
            @do-export="exportData"
          ></ButtonExportExcel>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="24" class="tag">
 
      <el-tag type="primary"> 参评站点数</el-tag><span class="analysis-info">{{ table.length }}</span>
      <el-tag type="danger"> 高风险数</el-tag>  <span class="analysis-info">{{ riskGradeNum.high }} ({{ riskGradeRate.high }}%)</span>
      <el-tag type="warning"> 中风险数</el-tag>  <span class="analysis-info">{{ riskGradeNum.middle }} ({{ riskGradeRate.middle }}%)</span> 
      <el-tag type="success"> 低风险数</el-tag> <span class="analysis-info">{{ riskGradeNum.low }} ({{ riskGradeRate.low }}%)</span> 
 
 
    </el-col>
  </el-row>
 
 
 
  <el-table
    ref="table"
    :data="table"
    :height="tableHeight"
    v-loading="loading"
    element-loading-text="后台分析中..."
    style="width: 98%"
    :cell-class-name="tableCellClassName"
    :default-sort="{ prop: 'riskValue', order: 'descending' }"
    v-show="!isNoData"
    border
  >
    <el-table-column
      type="index"
      prop="name"
      label="序号"
      fixed
      align="center"
      width="55"
      show-overflow-tooltip
    />
    <el-table-column prop="siteName" label="点位名称" align="center" show-overflow-tooltip>
      <template #default="{ row }">
        <el-button type="primary" text class="table-button" @click="openDetail(row)">{{
          row.siteName
        }}</el-button>
      </template>
    </el-table-column>
 
    <el-table-column prop="region" label="区县" align="center" width="80" show-overflow-tooltip />
    <el-table-column
      prop="monitorType"
      label="检测类型"
      align="center"
      width="80"
      show-overflow-tooltip
    />
    <el-table-column
      prop="riskValue"
      label="风险值"
      sortable
      align="center"
      width="100"
      show-overflow-tooltip
    />
    <el-table-column
      prop="riskGrade"
      label="风险等级"
      align="center"
      width="100"
      show-overflow-tooltip
    />
    <el-table-column prop="riskAdvice" label="管控措施" show-overflow-tooltip>
      <template #default="scope">
        <div v-html="wrapIndex(scope.row.riskAdvice)"></div>
      </template>
    </el-table-column>
    <el-table-column
      prop="beginTime"
      label="日期"
      sortable
      align="center"
      width="160"
      show-overflow-tooltip
    />
    <!-- <el-table-column
      prop="endTime"
      label="结束日期"
      sortable
      align="center"
      width="160"
      show-overflow-tooltip
    /> -->
  </el-table>
  <el-empty v-show="isNoData" :image-size="200" />
</template>
 
<style scoped>
.el-row,
.el-table {
  margin: 10px 0px 0px 10px;
}
 
:deep(.el-table__row .warning-row) {
  background-color: red;
  /* color: rgb(241, 236, 236); */
}
.table-button {
  letter-spacing: 1px;
  text-decoration: underline;
  border-radius: 0px;
}
.el-table {
  color: #333333;
}
.analysis-info {
  margin-right: 20px;
}
.tag{
  margin: 10px 5px 5px 1px;
}
.el-tag {
  font-size: 14px;
  vertical-align: baseline;
}
</style>