<!-- 人员登记列表 --> <script name="RegisterList" lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { IListQuery, IStaffBasicInfo } from './person-regitster' import { batchImport, deleteStaff, getAuthorizeStream, getHoldCertificateStream, getStaffList, getVerifierStream, staffListExport } from '@/api/resource/register' import type { TableColumn } from '@/components/NormalTable/table_interface' import useTemplateDownload from '@/utils/useTemplateDownload' import { exportFile } from '@/utils/exportUtils' // 定义变量 const { proxy } = getCurrentInstance() as any const router = useRouter() const searchQuery = ref<IListQuery>({ name: '', deptName: '', rankExperience: '', // 军衔/时间 titleExperience: '', // 职称职务/时间 treatmentExperience: '', // 待遇等级时间 offset: 1, limit: 20, }) const loadingTable = ref<boolean>(false) // 表格loading const total = ref<number>(0) // 数据总条数 const columns = ref<Array<TableColumn>>([ { text: '姓名', value: 'staffName', align: 'center' }, { text: '出生日期', value: 'birthday', align: 'center', width: '160' }, { text: '军官/文职证号', value: 'officerNo', align: 'center', width: '160' }, { text: '工作部门', value: 'deptName', align: 'center' }, { text: '军衔/时间', value: 'rankExperience', align: 'center' }, { text: '待遇级别/时间', value: 'treatmentExperience', align: 'center' }, { text: '职称职务/时间', value: 'titleExperience', align: 'center' }, ]) // 表头 const list = ref<Array<IStaffBasicInfo>>([]) // 表格数据 const listSelected = ref<Array<IStaffBasicInfo>>([]) // 表格多选 // 逻辑 const addStaff = () => { router.push({ query: { type: 'create', }, path: 'register/detail', }) } // 获取数据列表 const fetchData = (isNowPage = false) => { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } getStaffList(searchQuery.value).then((res) => { if (res.code === 200) { list.value = res.data.rows total.value = Number(res.data.total) } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } const search = () => { fetchData(true) } const clearList = () => { searchQuery.value = { name: '', deptName: '', rankExperience: '', // 军衔/时间 titleExperience: '', // 职称职务/时间 treatmentExperience: '', // 待遇等级时间 offset: 1, limit: 20, } fetchData() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.value.limit = val.size } if (val && val.page) { searchQuery.value.offset = val.page } fetchData(true) } // 导出 const batchExportStaffList = () => { const ids: string[] = [] listSelected.value.forEach((item: IStaffBasicInfo) => { ids.push(item.id!) }) loadingTable.value = true if (ids.length === 0) { // 没有选择导出所有 staffListExport(searchQuery.value).then((res) => { exportFile(res.data, `人员列表-${dayjs(new Date()).format('YYYYMMDDHHmmss')}.xlsx`) }) } else { staffListExport({ ids }).then((res) => { exportFile(res.data, `人员列表-${dayjs(new Date()).format('YYYYMMDDHHmmss')}.xlsx`) }) } loadingTable.value = false } // 持证参数 const batchExportStaffParams = () => { const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) getVerifierStream({ ids: listSelected.value.map(item => item.id), pdf: true }).then((res) => { exportFile(res.data, '参数持证.pdf') loading.close() }) } // 人员持证 const batchExportStaffCerts = () => { const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) getHoldCertificateStream({ ids: listSelected.value.map(item => item.id), pdf: true }).then((res) => { exportFile(res.data, '人员持证.pdf') loading.close() }) } // 导出授权人员参数 const batchExportStaffAuthParams = () => { const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) getAuthorizeStream({ ids: listSelected.value.map(item => item.id), pdf: true }).then((res) => { exportFile(res.data, '授权人员参数.pdf') loading.close() }) } // 多选改变 const staffRecordSelected = (e: any) => { listSelected.value = e } // 查看详情信息 const detail = (row: any) => { sessionStorage.setItem('staffBasicInfo', JSON.stringify(row)) router.push({ query: { type: 'detail', id: row.id, }, path: 'register/detail', }) } // 编辑人员基本信息 const update = (row: any) => { sessionStorage.setItem('staffBasicInfo', JSON.stringify(row)) router.push({ query: { type: 'update', id: row.id, }, path: 'register/detail', }) } // 删除人员信息 const deleteStaffById = (staffId: string, staffName: string) => { ElMessageBox.confirm(`是否删除人员 ${staffName}`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { deleteStaff({ id: staffId }).then((res) => { if (res.code === 200) { ElMessage.success(`人员 ${staffName} 删除成功`) fetchData(true) } else { ElMessage.error(`人员 ${staffName} 删除失败: ${res.message}`) } }) }) } // ----------------------------------------批量导入------------------------------------------- const fileRef = ref() // 文件上传input const onFileChange = (event: any) => { // 原生上传 if (event.target.files?.length !== 0) { // 创建formdata对象 const fd = new FormData() fd.append('file', event.target.files[0]) const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) // 调批量导入接口 batchImport(fd).then((res) => { ElMessage.success('上传成功') fileRef.value.value = '' loading.close() fetchData(true) loading.close() }).catch(() => { loading.close() }) } } // 批量导入 const handleBatchImport = () => { fileRef.value.click() } // -------------------------------------------------------------------------------------------- onMounted(() => { search() }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="clearList"> <search-item> <el-input v-model="searchQuery.name" placeholder="姓名" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.deptName" placeholder="工作部门" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.rankExperience" placeholder="军衔/时间" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.treatmentExperience" placeholder="待遇级别/时间" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.titleExperience" placeholder="职称职务/时间" clearable /> </search-item> </search-area> <!-- 表格数据展示 --> <table-container> <!-- 表头区域 --> <template #btns-right> <icon-button v-if="proxy.hasPerm(`/resource/person/register/add`)" icon="icon-add" title="新建" @click="addStaff" /> <icon-button v-if="proxy.hasPerm(`/resource/person/list/import`)" icon="icon-import" title="批量导入" @click="handleBatchImport" /> <icon-button v-if="proxy.hasPerm(`/resource/person/list/import`)" icon="icon-template" title="模板下载" @click="useTemplateDownload('人员登记')" /> <icon-button icon="icon-export" title="导出" @click="batchExportStaffList" /> <icon-button icon="icon-params" title="导出参数持证" @click="batchExportStaffParams" /> <icon-button icon="icon-cert" title="导出人员持证" @click="batchExportStaffCerts" /> <icon-button icon="icon-auth-params" title="导出授权人员参数" @click="batchExportStaffAuthParams" /> </template> <input ref="fileRef" style="display: none;" type="file" accept="*" @change="onFileChange"> <!-- 表格区域 --> <normal-table id="registerTabel" :data="list" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" :is-showmulti-select="true" @multi-select="staffRecordSelected" @change="changePage" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column fixed="right" label="操作" align="center" width="130"> <template #default="{ row }"> <el-button v-if="proxy.hasPerm(`/resource/person/register/edit`)" size="small" type="primary" link @click="update(row)"> 编辑 </el-button> <el-button size="small" type="primary" link @click="detail(row)"> 详情 </el-button> <el-button v-if="proxy.hasPerm(`/resource/person/register/del`)" size="small" type="danger" link @click="deleteStaffById(row.id, row.staffName)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>