<!-- 岗位管理 --> <script lang="ts" setup name="ListPost"> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import editDialog from './editDialog.vue' import type { IPostList, IlistQuery } from './post-interface' import { delPost, getPostListPage } from '@/api/system/post' import { exportFile } from '@/utils/exportUtils' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDeptList, getDeptTree } from '@/api/system/dept' import { judgeTree, toTreeList } from '@/utils/structure' const listQuery = reactive<IlistQuery>({ searchId: '', positionName: '', offset: 1, limit: 20, }) const list = ref<IPostList[]>([]) const total = ref(0) const columns = ref<TableColumn[]>([ { text: '所在单位', value: 'companyName', align: 'center' }, { text: '所在部门', value: 'deptName', align: 'center' }, { text: '所在分系统', value: 'subSystemName', align: 'center' }, { text: '岗位名称', value: 'positionName', align: 'center' }, ]) const listLoading = ref(false) const search = () => { listLoading.value = true getPostListPage(listQuery).then((res) => { console.log(res.data) list.value = res.data.rows total.value = Number(res.data.total) listLoading.value = false }) } const reset = () => { listQuery.limit = 20 listQuery.offset = 1 listQuery.positionName = '' listQuery.searchId = '' search() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.limit = val.size } if (val && val.page) { listQuery.offset = val.page } search() } // 表格被选中的行 const selectList = ref<any[]>([]) // 表格多选 const multiSelect = (row: any[]) => { selectList.value = row } search() // 新建编辑 const editRef = ref() const handler = (type: string, row: IPostList | any) => { editRef.value.initDialog(type, JSON.parse(JSON.stringify(row))) } // 删除 const deleteRow = (row: IPostList | any) => { ElMessageBox.confirm( `确认删除${row.positionName}吗`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then((res) => { delPost({ id: row.id }).then((res) => { ElMessage.success('操作成功') search() }) }) } // 导出 const exportList = () => { if (!selectList.value.length) { ElMessage.warning('请选择需要导出的数据') } // const loading = ElLoading.service({ // lock: true, // text: '下载中请稍后', // background: 'rgba(255, 255, 255, 0.8)', // }) // const param = { // ids: selectList.value, // } // exportFileListPage(param).then((res) => { // exportFile(res.data, '文件配置管理') // loading.close() // // searchQuery.ids = [] // }) // .catch((_) => { // loading.close() // }) } const deptList = ref<any[]>([]) const fetchDict = () => { getDeptList({}).then((res) => { const data = res.data.list.filter((item: any) => item.fullName !== '顶级').map((item: any) => ({ ...item, label: item.fullName, value: item.id })) deptList.value = toTreeList(data) }) } fetchDict() </script> <template> <!-- 布局 --> <app-container> <!-- 新建编辑 --> <edit-dialog ref="editRef" @refresh="search" /> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <!-- <dept-select v-model="listQuery.searchId" :need-top="false" placeholder="所在单位/部门/分系统" style="width: 100%;" /> --> <el-tree-select v-model="listQuery.searchId" :data="deptList" check-strictly :render-after-expand="false" placeholder="所在单位/部门/分系统" style="width: 100%;" /> </search-item> <search-item> <el-input v-model.trim="listQuery.positionName" placeholder="岗位名称" clearable class="w-50 m-2" /> </search-item> </search-area> <!-- 查询结果Table显示 --> <table-container> <template #btns-right> <icon-button icon="icon-add" title="新建" type="primary" @click="handler('create', {})" /> <!-- <icon-button icon="icon-export" title="导出" type="primary" @click="exportList" /> --> </template> <div class="table-area"> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :is-multi="true" :is-showmulti-select="true" :list-loading="listLoading" @change="changePage" @multi-select="multiSelect" > <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="操作" width="140" align="center" fixed="right"> <template #default="scope"> <el-button type="primary" link size="small" class="table-text-button" @click="handler('detail', scope.row)"> 查看 </el-button> <el-button type="primary" link size="small" class="table-text-button" @click="handler('update', scope.row)"> 编辑 </el-button> <el-button type="danger" link size="small" class="table-text-button" @click="deleteRow(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </div> </table-container> </app-container> </template>