Newer
Older
SpaceIntegration_front / src / views / main / undergroundCavity / index.vue
<!-- 地下空洞管理 -->
<script name="UndergroundCavity" setup lang="ts">
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import detailDialog from './detail.vue'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import { exportFile } from '@/utils/exportUtils'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { batchDeleteHole, exportHole, getHoleListPage, importHole, templateHole } from '@/api/page/undergroundCavity'
const $router = useRouter()
const { proxy } = getCurrentInstance() as any

// 查询条件
const listQuery = ref({
  holeCode: '', // 空洞编号
  abnormolWave: '', // 异常波形
  detectionDistance: '', // 探测距离
  holeSize: '', // 空洞大小
  holeType: '', // 空洞类型
  detectionTime: '', // 探测时间
  riskLevel: '', // 风险等级
  position: '', // 空洞位置
  isHandle: '', // 是否进行治理
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
// 表头
const columns = ref<TableColumn[]>([
  { text: '地下空洞编号', value: 'holeCode', align: 'center', width: '160' },
  { text: '异常波形', value: 'abnormolWave', align: 'center' },
  { text: '探测距离', value: 'detectionDistance', align: 'center' },
  { text: '空洞大小', value: 'holeSize', align: 'center' },
  { text: '空洞类型', value: 'holeType', align: 'center' },
  // { text: '空洞图片', value: 'holePicture', align: 'center' },
  { text: '探测时间', value: 'detectionTime', align: 'center' },
  { text: '风险等级', value: 'riskLevel', align: 'center' },
  { text: '空洞经纬度', value: 'lnglat', align: 'center' },
  { text: '空洞位置', value: 'position', align: 'center' },
  { text: '是否进行治理', value: 'isHandle', align: 'center' },
])
const list = ref([]) // 表格数据
// 选中的内容
const checkoutList = ref<string[]>([])
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getHoleListPage(listQuery.value).then((res) => {
    console.log(res.data, '地下空洞')
    list.value = res.data.rows.map((item: any) => {
      return {
        ...item,
        lnglat: `${item.longitude},${item.latitude}`,
        isHandle: item.isHandle === '1' ? '是' : '否',
      }
    })
    total.value = parseInt(res.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const reset = () => {
  listQuery.value = {
    holeCode: '', // 空洞编号
    abnormolWave: '', // 异常波形
    detectionDistance: '', // 探测距离
    holeSize: '', // 空洞大小
    holeType: '', // 空洞类型
    detectionTime: '', // 探测时间
    riskLevel: '', // 风险等级
    position: '', // 空洞位置
    isHandle: '', // 是否进行治理
    offset: 1,
    limit: 20,
  }
  fetchData(true)
}

// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}

// 导出
const exportList = () => {
  if (!checkoutList.value.length) {
    ElMessage.warning('请选择需要导出的数据')
    return
  }
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  exportHole({ ids: checkoutList.value }).then((res) => {
    exportFile(res.data, '地下空洞列表.xlsx')
    loading.close()
  }).catch(() => {
    loading.close()
  })
}
// 删除
const deleteList = () => {
  if (!checkoutList.value.length) {
    ElMessage.warning('请选择需要删除的数据')
    return
  }
  batchDeleteHole({ ids: checkoutList.value }).then((res) => {
    ElMessage.success('操作成功')
    fetchData(true)
  })
}
// 模板下载
const templateDownload = () => {
  templateHole({}).then((res) => {
    exportFile(res.data, '地下空洞模板')
  })
}
// 导入
const importRef = ref()
const importList = () => {
  importRef.value.click()
}
const onFileChange = (event: any) => {
  if (event.target.files?.length !== 0) {
    // 创建formdata对象
    const fd = new FormData()
    fd.append('file', event.target.files[0])
    // fd.append('equipmentType', $props.equipmentType)
    const loading = ElLoading.service({
      lock: true,
      background: 'rgba(255, 255, 255, 0.8)',
    })
    importHole(fd).then((res) => {
      // 清空上传缓存
      importRef.value.value = ''
      if (res.code === 200) {
        ElMessage.success('上传成功')
        loading.close()
        fetchData(true)
      }
      else {
        loading.close()
      }
    }).catch(() => {
      // 清空上传缓存
      importRef.value.value = ''
      loading.close()
    })
  }
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 detailRef = ref()
const handler = (type: string, row: any) => {
  detailRef.value.initDialog(type, row)
}

// 查询字典
const riskLevelList = ref<dictType[]>([]) // 风险等级
const handlerList = ref<dictType[]>([]) // 是否治理
const getDict = async () => {
  // 风险等级
  getDictByCode('holeRiskLevel').then((response) => {
    riskLevelList.value = response.data
  })
  getDictByCode('isAlarm').then((response) => {
    handlerList.value = response.data
  })
}

onMounted(async () => {
  await getDict()
  fetchData(true) // 获取数据
})
</script>

<template>
  <!-- 布局 -->
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <!-- 编辑弹窗 -->
      <detail-dialog ref="detailRef" @refresh="searchList" />
      <search-item>
        <el-input
          v-model.trim="listQuery.holeCode"
          placeholder="地下空洞编号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.abnormolWave"
          placeholder="异常波形"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.detectionDistance"
          placeholder="探测距离"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.holeSize"
          placeholder="空洞大小"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.holeType"
          placeholder="空洞类型"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="listQuery.detectionTime"
          type="date"
          placeholder="探测时间"
          style="width: 100%;"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD HH:mm:ss"
        />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.riskLevel" class="short-input" placeholder="风险等级" clearable>
          <el-option v-for="item in riskLevelList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.position"
          placeholder="空洞位置"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.isHandle" class="short-input" placeholder="是否进行治理" clearable>
          <el-option v-for="item in handlerList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-add" title="新增" type="primary" @click="handler('create', {})" />
        <icon-button icon="icon-delete" title="删除" type="primary" @click="deleteList" />
        <icon-button icon="icon-template" title="模板下载" type="primary" @click="templateDownload" />
        <icon-button icon="icon-import" title="导入" type="primary" @click="importList" />
        <input ref="importRef" style="display: none;" type="file" accept=".xls,.xlsx" @change="onFileChange">
        <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="120">
            <template #default="{ row }">
              <el-button size="small" link type="primary" @click="handler('detail', row)">
                详情
              </el-button>
              <el-button size="small" link type="primary" @click="handler('update', row)">
                编辑
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
// 样式
</style>