Newer
Older
smartwell_front / src / views / home / alarm / count / components / deptCount.vue
<!--
  Description: 报警统计-各单位报警统计
  Author: 李亚光
  Date: 2023-07-09
 -->
<script lang="ts" setup name="AlarmCount">
import layout from './layout.vue'
import { getAlarmCompany } from '@/api/home/alarm/count'
const listQuery = ref({
  begTime: '',
  endTime: '',
  ledgerType: '',
  timeType: '1',
})
const selectTimeType = (type: string) => {
  listQuery.value.timeType = type
}
// 开始结束时间
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]}`
    }
  }
})
const shortcuts = [
  {
    text: '近一周',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setDate(start.getDate() - 7)
      return [start, end]
    },
  },
  {
    text: '近一个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setMonth(start.getMonth() - 1)
      return [start, end]
    },
  },
  {
    text: '近三个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setMonth(start.getMonth() - 3)
      return [start, end]
    },
  },
]
// 类别
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)
// setTimeout(() => {
//   xAxisData.value = [
//     '第一分公司', '第二分公司', '第三分公司', '第四分公司', '第五分公司',
//   ]
//   data.value = [
//     {
//       name: '闸井浓度超限',
//       data: [1, 8, 5, 8, 4],
//     },
//     {
//       name: '场站浓度超限',
//       data: [8, 3, 6, 1, 7],
//     },
//     {
//       name: '疑似第三方破坏',
//       data: [4, 7, 5, 9, 4],
//     },
//   ]
//   list.value = xAxisData.value.map((item, index) => ({
//     dept: item,
//     wellOver: data.value[0].data[index],
//     senceOver: data.value[1].data[index],
//     thirdParty: data.value[2].data[index],
//   }))
// }, 1000)
const resizePage = () => {
  setTimeout(() => {
    const resize = new Event('resize')
    window.dispatchEvent(resize)
  }, 500)
}
const fetchData = () => {
  loading.value = true
  getAlarmCompany(listQuery.value).then((res) => {
    console.log(res.data, '各单位报警统计')
    resizePage()
    loading.value = false
  }).catch(() => {
    loading.value = false
  })
}
onMounted(() => {
  fetchData()
})
</script>

<template>
  <layout title="各单位报警统计">
    <!-- 查询条件 -->
    <template #search>
      <div class="search">
        <el-button
          :class="listQuery.timeType === '1' ? 'active' : ''" round size="small"
          style="margin: 0 5px;"
          @click="selectTimeType('1')"
        >
          今日
        </el-button>
        <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>
        <el-date-picker
          v-model="datetimerange" type="datetimerange" format="YYYY-MM-DD HH:mm:ss"
          style="width: 380px;margin: 0 5px;" value-format="YYYY-MM-DD HH:mm:ss" range-separator="至"
          start-placeholder="报警开始时间" end-placeholder="报警结束时间" clearable :shortcuts="shortcuts"
        />
        <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="dept" align="center" width="200" />
            <el-table-column label="闸井浓度超限" prop="wellOver" align="center" />
            <el-table-column label="场站浓度超限" prop="senceOver" align="center" />
            <el-table-column label="疑似第三方破坏" prop="thirdParty" 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>