<!-- Description: 台账管理-管线管理 Author: 李亚光 Date: 2024-09-02 --> <script lang="ts" setup name="SyncRecordList"> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import editDialog from './components/editDialog.vue' import { getDictByCode } from '@/api/system/dict' import { exportPipelineList, getPiePleListPage, importPipeline, removePieple, templatePipeline } from '@/api/home/ledger/pipeline' import { exportFile } from '@/utils/exportUtils' import { downloadFile } from '@/utils/download' // 表格数据 const list = ref([]) const total = ref(0) // 初始展示列 const columns = ref<any>([ { text: '管线编号', value: 'pipeCode', align: 'center', isRequired: true }, { text: '管线位置', value: 'position', align: 'center', isRequired: true }, { text: '压力级制', value: 'pressTypeName', align: 'center', isRequired: true, width: '110' }, { text: '材质', value: 'material', align: 'center', width: '110' }, { text: '管径(mm)', value: 'pipeDiameter', align: 'center', width: '110' }, { text: '建设年代', value: 'constructEra', align: 'center', width: '110' }, { text: '管理单位', value: 'deptName', align: 'center', isRequired: true }, { text: '产权单位', value: 'propertyOwner', align: 'center', isRequired: true }, { text: '管理方式', value: 'manageTypeName', align: 'center', isRequired: true, width: '110' }, ]) // 最终展示列 const columnsConfig = ref([]) // 修改列 const editColumns = (data: any) => { columnsConfig.value = data } const loadingTable = ref(true) // 查询条件 const listQuery = ref({ limit: 20, offset: 1, pipeCode: '', // 管线编号 position: '', // 管线位置 pressType: '', // 压力级制 material: '', // 材质 manageType: '', // 管理方式 deptid: '', // 单位 propertyOwner: '', // 单位 constructEra1: '', // 最小建设年代 constructEra2: '', // 最大建设年代 pipeDiameter1: '', // 最小管径 pipeDiameter2: '', // 最大管径 }) // 查询数据 const fetchData = () => { loadingTable.value = true getPiePleListPage(listQuery.value).then((res) => { list.value = res.data.rows total.value = res.data.total loadingTable.value = false }).catch(() => { loadingTable.value = false }) } // 重置查询条件f const reset = () => { listQuery.value = { limit: 20, offset: 1, pipeCode: '', // 管线编号 position: '', // 管线位置 pressType: '', // 压力级制 material: '', // 材质 deptid: '', // 单位 propertyOwner: '', // 单位 manageType: '', // 管理方式 constructEra1: '', // 最小建设年代 constructEra2: '', // 最大建设年代 pipeDiameter1: '', // 最小管径 pipeDiameter2: '', // 最大管径 } 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 removeRow = (row: any) => { ElMessageBox.confirm( '确定要删除该数据吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ).then(() => { removePieple([row.id]).then((response) => { if (response.code === 200) { ElMessage({ message: '删除成功', type: 'success', }) fetchData() } }) }) } // 编辑或者新建 const editRef = ref() const editRow = (type: string, row: any) => { editRef.value.initDialog(type, row) } // 导出列表 const exportList = () => { if (!list.value.length) { ElMessage.warning('暂无导出数据') return } const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) exportPipelineList(listQuery.value).then((res) => { exportFile(res.data, '管线列表.xlsx') loading.close() }).catch(() => { loading.close() }) } const fileRef = ref() // 文件上传input,获取input的引用 const onFileChange = (event: any) => { // 原生上传 // console.log(event.target.files) 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)', }) // export function importDevice(data: object, deviceType: string) { // return request({ // url: `/equipment/info/import?equipmentType=${deviceType}`, // method: 'post', // data, // }) // } importPipeline(fd).then((res) => { if (res.code === 200) { ElMessage.success('导入成功') fileRef.value.value = '' loading.close() fetchData() } else { fileRef.value.value = '' // ElMessage.error(res.message) loading.close() } }).catch(() => { fileRef.value.value = '' // ElMessage.error(err.message) loading.close() }) } } // 导入列表 const importList = () => { fileRef.value.click() } // 模板下载 const downloadTemplate = () => { const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) templatePipeline().then((res) => { if (res.data) { downloadFile(res.data, '管线导入模板.xlsx') } loading.close() }).catch(() => { loading.close() }) } // 获取字典 const pressTypeList = ref<{ id: string; name: string; value: string }[]>([]) // 压力级制 const manageTypeList = ref<{ id: string; name: string; value: string }[]>([]) // 管理方式 const materialList = ref<{ id: string; name: string; value: string }[]>([ { name: 'PE', id: '1', value: 'PE', }, { name: '钢质', id: '2', value: '钢质', }, ]) // 材质 const fetchDict = () => { // 压力级制 getDictByCode('pressType').then((res) => { pressTypeList.value = res.data }) // 管理方式 getDictByCode('manageType').then((res) => { manageTypeList.value = res.data }) } fetchDict() onMounted(async () => { fetchData() }) const { proxy } = getCurrentInstance() as any </script> <template> <!-- 布局 --> <app-container> <edit-dialog ref="editRef" @refresh="fetchData" /> <!-- 筛选条件 --> <search-area :need-clear="true" @search="fetchData" @clear="reset"> <search-item> <el-input v-model="listQuery.pipeCode" placeholder="管线编号" clearable /> </search-item> <search-item> <el-input v-model="listQuery.position" placeholder="管线位置" clearable /> </search-item> <search-item> <el-select v-model="listQuery.pressType" placeholder="压力级制" clearable class="select" style="width: 192px;"> <el-option v-for="item in pressTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <!-- <el-input v-model="listQuery.material" placeholder="材质" clearable /> --> <el-select v-model="listQuery.material" placeholder="材质" clearable class="select" style="width: 192px;"> <el-option v-for="item in materialList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <dept-select v-model="listQuery.deptid" placeholder="管理单位" :clearable="true" style="width: 192px;" /> </search-item> <search-item> <!-- <dept-select v-model="listQuery.propertyOwner" placeholder="产权单位" :clearable="true" style="width: 192px;" /> --> <el-input v-model="listQuery.propertyOwner" placeholder="产权单位" clearable /> </search-item> <search-item> <el-select v-model="listQuery.manageType" placeholder="管理方式" clearable class="select" style="width: 192px;"> <el-option v-for="item in manageTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-input v-model="listQuery.pipeDiameter1" placeholder="管径范围(mm)" clearable type="number" style="width: 135px;" /> ~ <el-input v-model="listQuery.pipeDiameter2" placeholder="管径范围(mm)" clearable type="number" style="width: 135px;" /> </search-item> <search-item> <el-input v-model="listQuery.constructEra1" placeholder="建设年代" clearable type="number" style="width: 135px;" /> ~ <el-input v-model="listQuery.constructEra2" placeholder="建设年代" clearable type="number" style="width: 135px;" /> </search-item> </search-area> <!-- 表头标题 --> <table-container :is-config="true" config-title="pieple-manage" :columns="columns" :config-columns="columnsConfig" :edit="editColumns" > <template #btns-right> <!-- 操作 --> <div> <el-button v-if="proxy.hasPerm('/ledger/pipeline/add')" type="primary" @click="editRow('add', {})"> 新增 </el-button> <el-button v-if="proxy.hasPerm('/ledger/pipeline/down')" type="primary" @click="downloadTemplate"> 模板下载 </el-button> <el-button v-if="proxy.hasPerm('/ledger/pipeline/import')" type="primary" @click="importList"> 批量导入 </el-button> <el-button v-if="proxy.hasPerm('/ledger/pipeline/export')" type="primary" @click="exportList"> 导出 </el-button> <input ref="fileRef" style="display: none;" type="file" accept=".xls,.xlsx" @change="onFileChange"> </div> </template> <!-- 查询结果Table显示 --> <normal-table :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable" @change="changePage" > <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" width="100"> <template #default="scope"> <el-button v-if="proxy.hasPerm('/ledger/pipeline/update')" type="primary" link size="small" @click="editRow('edit', scope.row)"> 编辑 </el-button> <el-button v-if="proxy.hasPerm('/ledger/pipeline/delete')" type="danger" link size="small" @click="removeRow(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template> <style lang="scss" scoped> .circle { width: 18px; height: 18px; border-radius: 50%; margin: 0 auto; } .online { background-color: #95f204; } .offline { background-color: #7f7f7f; } </style>