Newer
Older
smartwell_front / src / views / home / well / index.vue
<!--
  Description: 闸井监测
  Author: 李亚光
  Date: 2023-07-12
 -->
<script lang="ts" setup name="WellMonitor">
import { ElMessage, ElMessageBox } from 'element-plus'
import { ArrowUpBold } from '@element-plus/icons-vue'
import MapCom from './components/map.vue'
import editDialog from './components/editDialog.vue'
import { getWellList, getWellListPage } from '@/api/home/well/well'
import { getDictByCode } from '@/api/system/dict'
// 表格标识  地图或普通
const mapRef = ref()
const tableFlag = ref('map')
const mapLoading = ref(true)
const mapLoad = ref(false)
// 表格数据
const list = ref([])
const total = ref(0)
// 地图数据
const mapList = ref([])

// 初始展示列
const columns = ref<any>([
  { text: '闸井位号', value: 'tagNumber', align: 'center', width: '110' },
  { text: '闸井编号', value: 'ledgerCode', align: 'center' },
  { text: '闸井名称', value: 'ledgerName', align: 'center' },
  { text: '管理单位', value: 'deptName', align: 'center' },
  { text: '产权单位', value: 'propertyOwner', align: 'center' },
  { text: '管理方式', value: 'manageTypeName', align: 'center', width: '90' },
  { text: '使用状态', value: 'onStateName', align: 'center', width: '90' },
  // { text: '布防状态', value: 'bfztName', align: 'center', width: '90' },
  { text: '状态', value: 'monitorStateName', align: 'center', width: '90' },
  { text: '感知设备', value: 'deviceCount', align: 'center', width: '90' },
  { text: '标签', value: 'marker', align: 'center' },
])
// 最终展示列
const columnsConfig = ref([])
// 修改列
const editColumns = (data: any) => {
  columnsConfig.value = data
}
const loadingTable = ref(true)
//  查询条件
const listQuery = ref({
  limit: 20,
  offset: 1,
  tagNumber: '', // 闸井位号
  ledgerName: '', // 闸井名称
  ledgerCode: '', // 闸井编号
  deptid: '', // 管理单位
  propertyOwner: '', // 产权单位
  manageType: '', // 管理方式
  onState: '', // 使用状态
  bfzt: '', // 布防状态
  monitorState: '', // 监控状态
  marker: '',
} as { [key: string]: string | number })
// 查询数据
const fetchData = () => {
  loadingTable.value = true
  // 判断是否有查询条件(是地图展示20条  否地图展示所有)
  const queryList = [] as Boolean[] // 长度大于2 即为是
  for (const i in listQuery.value) {
    if (listQuery.value[i]) {
      queryList.push(true)
    }
  }
  console.log(queryList.length, 'queryList')
  getWellListPage(listQuery.value).then((res) => {
    list.value = res.data.rows.map((item: any) => ({ ...item, bfztName: item.bfzt === '1' ? '布防' : '撤防' }))
    total.value = res.data.total
    loadingTable.value = false
    if (queryList.length > 2) {
      mapList.value = list.value
      setTimeout(() => {
        if (tableFlag.value === 'map') {
          mapRef.value?.resetDraw()
        }
        mapLoading.value = false
      }, 500)
    }
  }).catch(() => {
    loadingTable.value = false
    mapLoading.value = false
  })
  if (queryList.length > 2 || mapLoad.value) { return }
  // 获取地图全部数据
  mapLoading.value = true
  getWellList(listQuery.value).then((res) => {
    mapList.value = res.data
    mapLoad.value = true
    setTimeout(() => {
      if (tableFlag.value === 'map') {
        mapRef.value?.resetDraw()
      }
      mapLoading.value = false
    }, 500)
  }).catch(() => {
    mapLoading.value = false
  })
}
// 重置查询条件f
const reset = () => {
  mapLoad.value = false
  listQuery.value = {
    limit: 20,
    offset: 1,
    tagNumber: '', // 闸井位号
    ledgerName: '', // 闸井名称
    ledgerCode: '', // 闸井编号
    deptid: '', // 管理单位
    propertyOwner: '', // 产权单位
    manageType: '', // 管理方式
    onState: '', // 使用状态
    bfzt: '', // 布防状态
    monitorState: '', // 监控状态
    marker: '',
  }
  fetchData()
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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()
}

// 获取字典
const manageTypeList = ref<{ id: string; name: string; value: string }[]>([]) // 管理方式
const onStateList = ref<{ id: string; name: string; value: string }[]>([]) // 使用状态
const bfztList = ref<{ id: string; name: string; value: string }[]>([]) // 布防状态
const monitorStateList = ref<{ id: string; name: string; value: string }[]>([]) // 监控状态
const fetchDict = () => {
  // 管理方式
  getDictByCode('manageType').then((res) => {
    manageTypeList.value = res.data
  })
  // 使用状态
  getDictByCode('onState').then((res) => {
    onStateList.value = res.data
  })
  // 布防状态
  getDictByCode('organizeDefenceStatus').then((res) => {
    bfztList.value = res.data
  })
  // 监控状态
  getDictByCode('monitorState').then((res) => {
    monitorStateList.value = res.data
  })
}
onMounted(() => {
  fetchDict()
  fetchData()
})

// 切换地图标识
const switchMode = (type: string) => {
  // if (!mapList.value.length) {
  //   ElMessage.warning('数据正在获取中或无数据')
  //   return
  // }
  tableFlag.value = type
}
// 点击数据行
const rowClick = (data: any) => {
  if (tableFlag.value === 'normal') { return }
  if (!data.lngGaode || !data.latGaode) {
    ElMessage.warning('该数据缺少坐标信息')
    return
  }
  // mapRef.value.map.setZoom(15)
  // 打开地图弹窗
  mapRef.value.openInfoDetail({
    lnglat: [data.lngGaode, data.latGaode],
    id: data.id,
    name: data.ledgerName,
    row: data,
  })
}
// 布防/撤防
const changeDefense = (row: any) => {
  ElMessageBox.confirm(
    `确定要${row.bfzt === '1' ? '撤防' : '布防'}${row.ledgerName}吗?`,
    '确认操作',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
  })
}
// 查看/编辑
const $router = useRouter()
const editRef = ref()
const editRow = (type: string, row: any) => {
  if (type === 'edit') {
    editRef.value.initDialog(type, JSON.parse(JSON.stringify(row)))
    return
  }
  $router.push({
    path: `/well/${type}`,
    query: {
      id: row.id,
      row: JSON.stringify(row),
    },
  })
}
// 表格高度
const tableHeight = ref(window.innerHeight - 60 - 50 - 10 - 350 - 98 - 10 - 52 - 52 - 10)
window.addEventListener('resize', () => {
  tableHeight.value = window.innerHeight - 60 - 50 - 10 - 350 - 98 - 10 - 52 - 52 - 10
})
watch(() => tableFlag.value, (newVal) => {
  if (newVal === 'map') {
    tableHeight.value = window.innerHeight - 60 - 50 - 10 - 350 - 98 - 10 - 52 - 52 - 10
  }
  else if (newVal === 'normal') {
    tableHeight.value = window.innerHeight - 60 - 50 - 10 - 98 - 10 - 52 - 52 - 10
  }
})
const { proxy } = getCurrentInstance() as any
</script>

<template>
  <!-- 布局 -->
  <app-container class="container">
    <edit-dialog ref="editRef" @refresh="fetchData" />
    <!-- 地图 -->
    <map-com v-if="tableFlag === 'map'" ref="mapRef" v-loading="mapLoading" :height="350" :data="mapList" />
    <!-- 收起地图-图标 -->
    <div v-if="tableFlag === 'map'" class="icon" @click="switchMode('normal')">
      <el-icon :size="25">
        <arrow-up-bold />
      </el-icon>
    </div>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="fetchData" @clear="reset">
      <search-item>
        <el-input v-model.trim="listQuery.tagNumber" placeholder="闸井位号" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.ledgerCode" placeholder="闸井编号" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.ledgerName" placeholder="闸井名称" clearable />
      </search-item>
      <search-item>
        <dept-select v-model="listQuery.deptid" placeholder="管理单位" :clearable="true" style="width: 192px;" />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.propertyOwner" placeholder="产权单位" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.manageType" placeholder="管理方式" clearable class="select">
          <el-option v-for="item in manageTypeList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.onState" placeholder="使用状态" clearable class="select">
          <el-option v-for="item in onStateList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <!-- <search-item>
        <el-select v-model="listQuery.bfzt" placeholder="布防状态" clearable class="select">
          <el-option v-for="item in bfztList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item> -->
      <search-item>
        <el-select v-model="listQuery.monitorState" placeholder="监控状态" clearable class="select">
          <el-option v-for="item in monitorStateList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.marker" placeholder="标签" clearable class="select" />
      </search-item>
    </search-area>
    <!-- 表头标题 -->
    <table-container
      :is-config="true" config-title="well-monitor" :columns="columns" :config-columns="columnsConfig"
      :edit="editColumns"
    >
      <template #btns-left>
        <!-- 操作 -->
        <div v-if="tableFlag === 'normal'" style="margin-left: 15px;">
          <el-button type="primary" plain :disabled="loadingTable" @click="switchMode('map')">
            切换地图模式
          </el-button>
        </div>
      </template>
      <template #btns-right>
        <!-- 操作 -->
        <div>
          <el-button v-if="proxy.hasPerm('/well/export')" type="primary">
            导出
          </el-button>
        </div>
      </template>
      <!-- 查询结果Table显示 -->
      <normal-table
        :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable"
        :height="tableHeight" @change="changePage" @rowDbClick="rowClick"
      >
        <template #preColumns>
          <!-- <el-table-column label="选择" width="55" align="center">
              <template #default="scope">
                <el-radio v-model="select" :label="scope.$index + 1" class="radio" />
              </template>
  </el-table-column> -->
          <el-table-column label="序号" width="75" align="center">
            <template #default="scope">
              {{ (listQuery.offset as number - 1) * (listQuery.limit as number) + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <!-- <el-table-column label="布/撤防" align="center" width="80">
            <template #default="scope">
              <el-button type="primary" link size="small" @click="changeDefense(scope.row)">
                {{ scope.row.bfzt === '1' ? '撤防' : '布防' }}
              </el-button>
            </template>
  </el-table-column> -->
          <el-table-column label="操作" align="center" width="120">
            <template #default="scope">
              <el-button v-if="proxy.hasPerm('/well/detail')" type="primary" link size="small" @click="editRow('detail', scope.row)">
                查看
              </el-button>
              <el-button v-if="proxy.hasPerm('/well/update')" type="primary" link size="small" @click="editRow('edit', scope.row)">
                编辑
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
.container {
  position: relative;

  .map {
    position: fixed;
    z-index: 99;
  }

  .icon {
    position: absolute;
    top: 345px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;

    &:hover {
      cursor: pointer;
    }
  }

  .search-area {
    position: fixed;
    z-index: 99;
  }
}
</style>

<style>
.select {
  width: 192px;
}
</style>