Newer
Older
smartwell_front / src / views / home / alarm / count / components / alarmStatistics.vue
lyg on 12 Sep 4 KB 反馈问题修改
<!--
  Description: 报警统计-各类报警统计
  Author: 李亚光
  Date: 2023-07-08
 -->
<script lang="ts" setup name="AlarmCount">
import layout from './layout.vue'
import { getAlarmType } from '@/api/home/alarm/count'
const listQuery = ref({
  timeType: '2',
  ledgerType: '',
  deptid: '',
  begTime: '',
  endTime: '',
})
const selectTimeType = (type: string) => {
  listQuery.value.timeType = type
}
// 类别
const ledgerTypeList = ref<{ id: string; name: string; value: string }[]>([
  {
    name: '闸井',
    id: '1',
    value: '1',
  },
  {
    name: '场站',
    id: '2',
    value: '2',
  },
  {
    name: '管线',
    id: '3',
    value: '3',
  },
])
const xAxisData = ref([])
const data = ref([])
const list = ref([])
const loading = ref(true)
// 开始结束时间
const datetimerange = ref()
// 默认当天
watch(() => datetimerange.value, (newVal) => {
  listQuery.value.begTime = ''
  listQuery.value.endTime = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.value.begTime = `${newVal[0]}`
      listQuery.value.endTime = `${newVal[1]}`
    }
  }
})
// setTimeout(() => {
//   xAxisData.value = [
//     '闸井浓度超限', '场站浓度超限', '场站火焰报警', '疑似第三方破坏', '场站烟雾报警',
//   ]
//   data.value = [
//     {
//       name: '报警数量',
//       data: [1, 3, 5, 1, 4],
//     },
//   ]
//   list.value = xAxisData.value.map((item, index) => ({
//     alarmType: item,
//     value: data.value[0].data[index],
//   }))
// }, 1000)
const fetchData = () => {
  loading.value = true
  getAlarmType(listQuery.value).then((res) => {
    console.log(res.data, '各类报警统计')
    loading.value = false
  }).catch(() => {
    loading.value = false
  })
}
onMounted(() => {
  fetchData()
})
</script>

<template>
  <layout title="各类报警统计">
    <!-- 查询条件 -->
    <template #search>
      <div class="search">
        <el-button
          :class="listQuery.timeType === '2' ? 'active' : ''" round size="small" style="margin: 0 5px;"
          @click="selectTimeType('2')"
        >
          本周
        </el-button>
        <el-button
          :class="listQuery.timeType === '3' ? 'active' : ''" round size="small" style="margin: 0 5px;"
          @click="selectTimeType('3')"
        >
          本月
        </el-button>
        <el-select v-model="listQuery.ledgerType" placeholder="全部类别" clearable style="width: 180px;margin: 0 5px;">
          <el-option v-for="item in ledgerTypeList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <dept-select
          v-model="listQuery.deptid" placeholder="管理单位" :clearable="true"
          style="width: 220px;margin: 0 5px;"
        />
        <el-date-picker
          v-model="datetimerange" type="datetimerange" format="YYYY-MM-DD HH:mm:ss"
          style="width: 340px;margin: 0 5px;" value-format="YYYY-MM-DD HH:mm:ss" range-separator="至"
          start-placeholder="报警开始时间" end-placeholder="报警结束时间" clearable
        />
        <el-button type="primary" style="margin: 0 5px;" @click="fetchData">
          搜索
        </el-button>
      </div>
    </template>
    <template #content>
      <div v-loading="loading" class="alarm-count">
        <div class="bar">
          <bar-chart-vertical
            v-show="xAxisData.length"
            :x-axis-data="xAxisData" :bar-coner="0" :data="data" :colors="[]" :bar-width="15"
            :legend="{ itemWidth: 8, itemHeight: 8, type: 'scroll', orient: 'horizontal', icon: 'roundRect', right: '0', top: '10' }"
            :grid="{
              top: 50,
              left: 30,
              right: 30,
              bottom: 20,
              containLabel: true, // 是否包含坐标轴的刻度标签
            }"
          />
          <el-empty v-show="!xAxisData.length" description="暂无数据" />
        </div>
        <div class="table">
          <el-table border :data="list" stripe style="width: 100%;" :height="440">
            <el-table-column label="报警类型" prop="alarmType" align="center" />
            <el-table-column label="报警数量" prop="value" align="center" />
          </el-table>
        </div>
      </div>
    </template>
  </layout>
</template>

<style lang="scss" scoped>
.active {
  color: #3d7eff;
  border-color: #c5d8ff;
  outline: none;
  background-color: #ecf2ff;
}

.search {
  display: flex;
  align-items: center;
}

.alarm-count {
  display: flex;

  .bar {
    width: 60%;
    height: 450px;
  }

  .table {
    width: 38%;
    padding: 10px;
    margin-left: 20px;
  }
}
</style>