<!-- 业务看板 --> <script lang="ts" setup name="BoardList"> import { reactive, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox, ItemProps } from 'element-plus' import { exportListApi, getListPage } from '@/api/eqpt/measurementPlan/board' import { exportFile } from '@/utils/exportUtils' import { buildTree, toTreeList } from '@/utils/structure' import { keepSearchParams } from '@/utils/keepQuery' const { proxy } = getCurrentInstance() as any const listQuery = reactive({ deptName: '', // offset: 1, // limit: 20, }) onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'BoardList') }) const columns = ref<any>([ { text: '部门', value: 'deptName', align: 'center', }, { text: '设备总数', value: 'total', align: 'center', }, { text: '本月到期设备', value: 'monthToExpire', align: 'center', }, { text: '已超期设备', value: 'expired', align: 'center', }, { text: '在检设备', value: 'inCheck', align: 'center', }, { text: '年度应检数量', value: 'yearToCheck', align: 'center', }, { text: '年度已检数量', value: 'yearChecked', align: 'center', }, { text: '计量计划完成率', value: 'planFinishRate', align: 'center', }, ]) const list = ref([]) const total = ref(0) const listLoading = ref(true) // 获取数据 const fetchData = (isNowPage = true) => { listLoading.value = true // if (!isNowPage) { // // 是否显示当前页,否则跳转第一页 // listQuery.offset = 1 // } getListPage(listQuery).then((response) => { list.value = toTreeList(response.data.sort((a: any, b: any) => { return a.deptNum - b.deptNum }).map((item: any) => ({ ...item, id: item.deptId })), '0') listLoading.value = false }) } fetchData() // 查询数据 const search = () => { fetchData(false) } // 重置 const reset = () => { listQuery.deptName = '' // listQuery.offset = 1 // listQuery.limit = 20 search() } // // 表格被选中的行 // const selectList = ref<any[]>([]) // // 表格多选 // const multiSelect = (row: any[]) => { // selectList.value = row // } // 导出列表 const exportList = () => { if (list.value.length) { const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(255, 255, 255, 0.8)', }) exportListApi(listQuery).then((res) => { exportFile(res.data, '业务看板') loading.close() }) .catch((_) => { loading.close() }) } else { ElMessage.warning('无可导出内容') } } onActivated(() => { // 从编辑或者新增页面回来需要重新获取列表数据 // $router.options.history.state.forward 上一次路由地址 if (!($router.options.history.state.forward as string || '').includes('detail')) { console.log('需要重新获取列表') fetchData(false) } }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.deptName" placeholder="部门" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button icon="icon-export" title="导出" @click="exportList" /> </template> <!-- 普通表格 --> <!-- <normal-table :data="list" :total="total" :columns="columns as any" :query="listQuery" :list-loading="listLoading" :is-showmulti-select="false" :pagination=" false " :options=" { needIndex: true, // 是否需要序号列 border: true, // 是否需要上方边框 } " > <template #preColumns> <el-table-column label="#" align="center" width="60"> <template #default="props"> {{ props.$index + 1 }} </template> </el-table-column> </template> </normal-table> --> <el-table ref="table" :data="list" row-key="id" border stripe style="width: 100%;" :tree-props="{ children: 'children' }"> <el-table-column v-for="column of columns" :key="column.value" :label="column.text" :prop="column.value" :width="column.width" :align="column.align" /> </el-table> </table-container> </app-container> </template>