<!-- 计量人员列表 --> <script lang="ts" setup name="person"> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { StaffListType, StaffType } from './person-interface' import { exportList, getStaffDelete, getStaffList, uploadList } from '@/api/measure/person' import { getRoleTreeListByUser } from '@/api/system/role' import { roleAssign } from '@/api/system/user' // import { uploadApi } from '@/api/system/notice' import { printJSON } from '@/utils/printUtils' import { getDeptTreeList } from '@/api/system/dept' import { exportFile } from '@/utils/exportUtils' import { getDictByCode } from '@/api/system/dict' import type { dictType } from '@/global' // import type { DeptTreeNode } from '@/views/system/dept/dept-interface' import { toTreeList } from '@/utils/structure' import { keepSearchParams, renewSearchParams } from '@/utils/keepQuery' const { proxy } = getCurrentInstance() as any const $route = useRoute() const $router = useRouter() let searchQuery = reactive<StaffListType>({ staffNo: '', // 人员编号 name: '', // 姓名 deptId: '', // 工作部门 major: '', // 计量专业 verifierCertificateNo: '', // 证书号 certificateStatus: '', // 证书状态 limit: 20, offset: 1, ids: [] as string[], }) // 查询参数 // 页面跳转之前保存参数 onBeforeRouteLeave((to: any) => { keepSearchParams(to.path, 'measure-person', searchQuery) }) // 重新赋值 searchQuery = reactive(renewSearchParams('measure-person') || { staffNo: '', // 人员编号 name: '', // 姓名 deptId: '', // 工作部门 major: '', // 计量专业 verifierCertificateNo: '', // 证书号 certificateStatus: '', // 证书状态 limit: 20, offset: 1, ids: [] as string[], }) const loadingTable = ref<boolean>(false) // 表格loading const total = ref<number>(0) // 数据总条数 const columns = ref([ { text: '人员编号', value: 'staffNo', align: 'center', width: '160' }, { text: '姓名', value: 'name', align: 'center' }, { text: '学历', value: 'education', align: 'center' }, { text: '性别', value: 'sex', align: 'center' }, { text: '工作部门', value: 'deptName', align: 'center' }, { text: '技术职务', value: 'technologyJob', align: 'center' }, { text: '行政职务', value: 'administrationJob', align: 'center' }, { text: '计量专业', value: 'major', align: 'center' }, { text: '证书号', value: 'verifierCertificateNo', align: 'center' }, { text: '证书有效日期', value: 'certificateDate', align: 'center', width: '120' }, { text: '技术考核', value: 'technologyExam', align: 'center' }, ]) // 表格 const list = ref([]) // 表格数据 const measureMajorList = ref<dictType[]>([]) // 计量专业 // 获取字典值 function getDict() { // 获取计量专业 getDictByCode('measureMajor').then((response) => { measureMajorList.value = response.data }) } // 获取所有部门 const deptList = ref([]) const getDeptList = async () => { getDeptTreeList().then((res) => { deptList.value = toTreeList(res.data, '0', true) }) } // 获取数据列表 const getList = () => { loadingTable.value = true getStaffList(searchQuery).then((res) => { if (res.code === 200) { res.data.records = res.data.records.map((item: StaffType) => ({ ...item, sex: item.sex == '1' ? '男' : '女', technologyExam: item.technologyExam == '0' ? '已考核' : '未考核', certificateDate: item.certificateDate.split(' ')[0] })) list.value = res.data.records total.value = Number(res.data.total) } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.limit = val.size } if (val && val.page) { searchQuery.offset = val.page } getList() } // 详情 const detail = (row: StaffType) => { $router.push({ query: { ...row, title: '详情', }, path: '/person/detail', }) } // 编辑 const update = (row: StaffType) => { $router.push({ query: { ...row, title: '编辑', }, path: '/person/detail', }) } // 删除 const remove = (row: StaffType) => { // 当前用户id const userId = row.userId as string ElMessageBox.confirm( `确认删除${row.name}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { getStaffDelete({ id: row.id as string }).then((res) => { if (res.code === 200) { // ElMessage({ // type: 'success', // message: '删除成功', // }) // getList() // 删除用户的 计量人员 角色 // 获取当前用户角色 getRoleTreeListByUser(userId).then((res) => { console.log(res.data, '角色列表') // 当前用户 角色 id let roleIds: string[] = [] // 挑选 计量人员 角色id let metering = '' const data = res.data data.forEach((item: any) => { // 当前用户角色 if (item.checked) { roleIds.push(item.id) } // 计量人员角色 if (item.name === '计量人员') { metering = item.id } }) roleIds = roleIds.filter(item => item !== metering) // 设置当前用户角色 roleAssign(userId, roleIds).then((res) => { console.log('删除计量人员角色成功') ElMessage({ type: 'success', message: '删除成功', }) getList() }) }) } }) }) } // 搜索 const search = () => { getList() } // 重置 const reset = () => { searchQuery.staffNo = '' searchQuery.name = '' searchQuery.deptId = '' searchQuery.major = '' searchQuery.verifierCertificateNo = '' searchQuery.limit = 20 searchQuery.offset = 1 getList() } // 模板下载 const templateDownload = () => { } // 新增 const add = () => { $router.push({ query: { title: '新建', }, path: '/person/detail', }) } // 表格被选中的行 const selectList = ref<StaffType[]>([]) // 表格多选 const multiSelect = (e: any) => { selectList.value = e.map((item: { id: string }) => item.id) } // 导出 const exportExcelBtn = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { const params = { staffNo: searchQuery.staffNo, // 人员编号 name: searchQuery.name, // 姓名 deptId: searchQuery.deptId, // 工作部门 major: searchQuery.major, // 计量专业 verifierCertificateNo: searchQuery.verifierCertificateNo, // 证书号 certificateStatus: searchQuery.certificateStatus, // 证书状态 limit: 20, offset: 1, ids: selectList.value, } exportList(params).then((res) => { const blob = new Blob([res.data]) exportFile(blob, '计量人员列表.xlsx') }) } else { ElMessage.warning('无数据可导出数据') } loading.close() } // 打印 function printList() { const selectIds = selectList.value.map((item: StaffType) => item.id) const properties = columns.value.map((item) => { return { field: item.value, displayName: item.text, } }) if (selectIds.length <= 0 && list.value.length > 0) { printJSON(list.value, properties, '计量人员列表') } else if (selectIds.length > 0) { const printList = list.value.filter((item: StaffType) => selectIds.includes(item.id)) printJSON(printList, properties, '计量人员列表') } else { ElMessage('无可打印内容') } } const deptProps = reactive({ parent: 'pid', value: 'id', label: 'name', children: 'children', }) const fileRef = ref() // 文件上传input const onFileChange = (event: any) => { // 原生上传图片 // console.log(event.target.files) // if (event.target.files[0].type === 'application/pdf') { if (event.target.files?.length !== 0) { // 创建formdata对象 const fd = new FormData() fd.append('multipartFile', event.target.files[0]) uploadList(fd).then((res) => { if (res.code === 200) { ElMessage.success('上传成功') } else { ElMessage.error(res.message) } }) } // } // else { // ElMessage.warning('请上传pdf格式') // } } // 批量导入 const batchImport = () => { fileRef.value.click() } onMounted(async () => { await getDict() getDeptList() getList() }) </script> <template> <div> <!-- 布局 --> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-input v-model="searchQuery.staffNo" placeholder="人员编号" clearable class="w-50 m-2" /> </search-item> <search-item> <el-input v-model="searchQuery.name" placeholder="姓名" clearable class="w-50 m-2" /> </search-item> <search-item> <!-- <el-select v-model="searchQuery.deptId" class="m-2" placeholder="工作部门"> <el-option v-for="item in deptList" :key="item.id" :label="item.name" :value="item.id" /> </el-select> --> <!-- <com-tree-select ref="selectTreeRef" v-model="searchQuery.deptId" :options="deptList" placeholder="工作部门" :tree-props="deptProps" /> --> <dept-select v-model="searchQuery.deptId" :data="deptList" placeholder="工作部门" /> </search-item> <search-item> <el-select v-model="searchQuery.major" style="width: 200px;" placeholder="计量专业" clearable> <el-option v-for="item in measureMajorList" :key="item.value" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-input v-model="searchQuery.verifierCertificateNo" placeholder="证书号" clearable class="w-50 m-2" /> </search-item> </search-area> <table-container> <!-- 表头区域 --> <template #btns-right> <input v-show="(searchQuery.limit === 0)" ref="fileRef" type="file" multiple @change="onFileChange"> <icon-button v-if="proxy.hasPerm(`/measure/person/list/add`)" icon="icon-add" title="新建" @click="add" /> <!-- <icon-button v-if="proxy.hasPerm(`/measure/person/list/import`)" icon="icon-import" title="批量导入" @click="batchImport" /> --> <!-- <icon-button v-if="proxy.hasPerm(`/measure/person/list/mould`)" icon="icon-template" title="模板下载" @click="templateDownload" /> --> <icon-button v-if="proxy.hasPerm(`/measure/person/list/export`)" icon="icon-export" title="导出" @click="exportExcelBtn" /> <icon-button v-if="proxy.hasPerm(`/measure/person/list/print`)" icon="icon-print" title="打印" @click="printList" /> </template> <!-- 表格区域 --> <normal-table id="print" :data="list" :total="total" :columns="columns as any" :is-showmulti-select="true" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" :is-multi="true" @change="changePage" @multi-select="multiSelect" > <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(`/measure/person/list/update`)" size="small" type="primary" link @click="update(row)"> 编辑 </el-button> <el-button v-if="proxy.hasPerm(`/measure/person/list/detail`)" size="small" type="primary" link @click="detail(row)"> 详情 </el-button> <el-button v-if="proxy.hasPerm(`/measure/person/list/delete`)" size="small" type="danger" link @click="remove(row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </div> </template> <style lang="scss" scoped> .normal-input { width: 130px !important; } .normal-date { width: 130px !important; } .normal-select { width: 130px !important; } :deep(.el-table__header) { background-color: #bbb; } </style>