Newer
Older
SpaceIntegration_front / src / views / inspection / task / detail.vue
liyaguang on 30 Oct 2023 7 KB 巡检管理调试
<!-- 巡检任务管理详情 -->
<script name="TaskDetail" lang="ts" setup>
import type { DateModelType } from 'element-plus'
import alarmHandlerDialog from './handlerAlarmDialog.vue'
import alarmVideoDialog from './alarmVideoDialog.vue'
import mapTrajectoryDialog from './trajectoryMap.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { getTaskDetailListPage } from '@/api/page/task'
const $route = useRoute()
const $router = useRouter()
const listQuery = ref({
  alarmCode: '', // 报警编号
  beginDate: '', // 开始时间
  endDate: '', // 结束时间
  gas1: '', // 起始浓度
  gas2: '', // 终止浓度
  isAlarm: '', // 是否告警,1:报警,0:正常
  position: '', // 位置
  taskId: $route.params.id, // 	任务ID
  offset: 1,
  limit: 20,
})
const list = ref()
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
const columns = ref<TableColumn[]>([
  { text: '时间', value: 'ts', align: 'center', width: '160' },
  { text: '气体浓度', value: 'gas', align: 'center' },
  { text: '水平角度', value: 'direction', align: 'center' },
  { text: '垂直角度', value: 'pitch', align: 'center' },
  { text: '是否报警', value: 'isAlarm', align: 'center' },
  { text: '报警编号', value: 'alarmCode', align: 'center' },
  // { text: '报警状态', value: 'modelName', align: 'center' },
  { text: '报警阈值(ppm·m)', value: 'modelName', align: 'center' },
  { text: '车速(km/h)', value: 'speed', align: 'center' },
  { text: '经度', value: 'longitude', align: 'center' },
  { text: '纬度', value: 'lagitude', align: 'center' },
  { text: '位置', value: 'position', align: 'center' },
])
// 筛选时间段数据
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])
// 时间变更
watch(dateRange, (val) => {
  if (val) {
    listQuery.value.beginDate = `${val[0]}`
    listQuery.value.endDate = `${val[1]}`
  }
  else {
    listQuery.value.beginDate = ''
    listQuery.value.endDate = ''
  }
})
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getTaskDetailListPage(listQuery.value).then((res) => {
    console.log(res.data, '巡检总计列表')
    list.value = res.data.rows.map((item: any) => ({ ...item, isAlarm: item.isAlarm === '1' ? '是' : '否' }))
    total.value = parseInt(res.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
fetchData(true)
// 搜索
const searchList = () => {
  fetchData(true)
}
// 重置
const reset = () => {
  listQuery.value = {
    alarmCode: '', // 报警编号
    beginDate: '', // 开始时间
    endDate: '', // 结束时间
    gas1: '', // 起始浓度
    gas2: '', // 终止浓度
    isAlarm: '', // 是否告警,1:报警,0:正常
    position: '', // 位置
    taskId: $route.params.id, // 	任务ID
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', ''] // 时间清空
  fetchData(true)
}

// 选中的内容
const checkoutList = ref<string[]>([])
// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData(true)
}
// 查询字典
const statusMap = ref<dictType[]>()
const getDict = async () => {
  // 是否报警
  getDictByCode('isAlarm').then((response) => {
    statusMap.value = response.data
  })
}
getDict()
// 处理报警
const alarmRef = ref()
const handlerAlarm = (row: any) => {
  alarmRef.value.initDialog(row)
}
// 报警视频
const videoRef = ref()
const alarmVideo = (row: any) => {
  videoRef.value.initDialog({ ...row, type: 'video' })
}
// 轨迹追踪
const mapRef = ref()
const showMap = () => {
  mapRef.value.initDialog()
}
</script>

<template>
  <app-container>
    <!-- 报警处理弹窗 -->
    <alarm-handler-dialog ref="alarmRef" @refresh="searchList" />
    <!-- 报警视频弹窗 -->
    <alarm-video-dialog ref="videoRef" />
    <!-- 轨迹绘制 -->
    <map-trajectory-dialog ref="mapRef" />
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <search-item>
        <el-date-picker
          v-model="dateRange"
          class="short-input"
          type="datetimerange"
          range-separator="至"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          start-placeholder="巡检开始时间"
          end-placeholder="巡检结束时间"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.gas1"
          placeholder="气体浓度起始值"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.gas2"
          placeholder="气体浓度目标值"
          class="short-input"
          clearable
        />
      </search-item>
      <!-- <search-item>
        <el-input
          v-model.trim="listQuery.gas2"
          placeholder="请输入报警阈值"
          class="short-input"
          clearable
        />
      </search-item> -->
      <search-item>
        <el-select v-model="listQuery.isAlarm" class="short-input" placeholder="是否报警" clearable>
          <el-option v-for="item in statusMap" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.alarmCode"
          placeholder="报警编号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.position"
          placeholder="位置"
          class="short-input"
          clearable
        />
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <el-button type="primary" @click="() => { $router.go(-1) }">
          返回
        </el-button>
        <el-button type="primary" @click="showMap">
          轨迹追踪
        </el-button>
        <!-- <icon-button icon="icon-delete" title="删除" type="primary" @click="deleteList" />
        <icon-button icon="icon-export" title="导出" type="primary" @click="exportList" /> -->
      </template>
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable"
        is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column label="操作" align="center" fixed="right" width="180">
            <template #default="{ row }">
              <el-button size="small" link type="primary" :disabled="!(row.alarmCode && row.isAlarm === '是')" @click="alarmVideo(row)">
                报警视频
              </el-button>
              <el-button size="small" type="primary" :disabled="!(row.alarmCode && row.isAlarm === '是')" link @click="handlerAlarm(row)">
                报警处置
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>