<!-- 分线融合和耦合 --> <script name="Analyse" setup lang="ts"> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { DateModelType } 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 { batchDeleteAnalyse, exportAnalyse, getAnalyseListPage } from '@/api/page/analyse' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getLocation } from '@/api/map' import { exportExcel } from '@/utils/exportXlsx' const $router = useRouter() const { proxy } = getCurrentInstance() as any // 查询条件 const listQuery = ref({ beginDate: '', couplingCode: '', couplingResult: '', endDate: '', offset: 1, limit: 20, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ { text: '风险耦合分析编号', value: 'couplingCode', align: 'center', width: '160' }, { text: '时间', value: 'couplingTime', align: 'center' }, { text: '风险耦合分析结果', value: 'couplingResult', align: 'center' }, { text: '风险经纬度', value: 'loglat', align: 'center' }, { text: '风险详细位置', value: 'position', align: 'center' }, ]) const list = ref([]) // 表格数据 // 筛选时间段数据 const dateRange = ref<[DateModelType, DateModelType]>(['', '']) // 选中的内容 const checkoutList = ref<string[]>([]) // 时间变更 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 } getAnalyseListPage(listQuery.value).then((res) => { console.log(res.data, '风险耦合') list.value = res.data.rows.map((item: any) => ({ ...item, loglat: `${item.longitude},${item.latitude}` })) list.value.forEach((item: any, index: number) => { // if (index > 2) { // return // } getLocation(`${item.longitude.trim()},${item.latitude.trim()}`).then((res) => { if (res.data.info === 'OK') { item.position = res.data.regeocode.formatted_address } else { item.position = '/' } }) }) total.value = parseInt(res.data.total) loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 搜索 const searchList = () => { fetchData(true) } // 重置 const reset = () => { listQuery.value = { beginDate: '', couplingCode: '', couplingResult: '', endDate: '', offset: 1, limit: 20, } dateRange.value = ['', ''] // 时间清空 fetchData(true) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e } // 导出 const exportList = () => { if (!checkoutList.value.length) { ElMessage.warning('请选择需要导出的数据') return } const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) // exportAnalyse({ ids: checkoutList.value }).then((res) => { // exportFile(res.data, '风险耦合记录.xlsx') // loading.close() // }).catch(() => { // loading.close() // }) const titleArr = ['序号', ...columns.value.map((item: any) => item.text)] const json = checkoutList.value.map((item: any, index: number) => { const obj = {} as any columns.value.map((item: any) => item.value).forEach((element: any) => { obj[element] = item[element] }) return { index: index + 1, ...obj, } }) exportExcel({ json, name: '风险耦合记录', titleArr, sheetName: 'sheet1', }) loading.close() } // 删除 const deleteList = () => { if (!checkoutList.value.length) { ElMessage.warning('请选择需要删除的数据') return } ElMessageBox.confirm( '确认删除所选数据吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { batchDeleteAnalyse({ ids: checkoutList.value.map((item: any) => item.id) }).then((res) => { ElMessage.success('操作成功') fetchData(true) // 获取数据 }) }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 = (row: any) => { detailRef.value.initDialog(row) } const analyseResult = ref<dictType[]>([]) // 分析结果 // 查询字典 const getDict = async () => { // 分析结果 getDictByCode('analyseResult').then((response) => { analyseResult.value = response.data }) } onMounted(async () => { await getDict() fetchData(true) // 获取数据 }) </script> <template> <!-- 布局 --> <app-container> <!-- 详情弹窗 --> <detail-dialog ref="detailRef" /> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.couplingCode" placeholder="风险耦合分析编号" class="short-input" clearable /> </search-item> <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-select v-model="listQuery.couplingResult" class="short-input" placeholder="风险耦合分析结果" clearable> <el-option v-for="item in analyseResult" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <!-- <search-item> <el-input v-model.trim="listQuery.recognitionCode" placeholder="风险位置" class="short-input" clearable /> </search-item> --> </search-area> <table-container> <template #btns-right> <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"> <template #default="{ row }"> {{ `${row.longitude},${row.latitude}` }} </template> </el-table-column> <el-table-column label="风险详细位置" align="center"> <template #default="{ row }"> {{ row.position }} </template> </el-table-column> --> <el-table-column label="操作" align="center" fixed="right" width="120"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handler(row)"> 分析详情 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> // 样式 </style>