| | |
| | | |
| | | <div class="gd-table-toolbar"> |
| | | <el-button :icon="Plus" color="#4C34FF" type="primary" @click="openForm('add')">新增机构</el-button> |
| | | <el-button :icon="Upload" @click="handleImport">导入机构</el-button> |
| | | <el-button :icon="Download" :loading="exportLoading" :disabled="exportLoading" @click="handleExport">导出机构</el-button> |
| | | <el-button :icon="Upload" @click="handleImport">机构导入</el-button> |
| | | <el-button :icon="Download" :loading="exportLoading" :disabled="exportLoading" @click="handleExport">机构导出</el-button> |
| | | </div> |
| | | |
| | | <div class="gd-table-container" v-loading="loading"> |
| | | <div class="gd-table-content gd-table-content-bg"> |
| | | <el-table class="gd-table" :data="list"> |
| | | <el-table class="gd-table" :data="list" @selection-change="handleSelectionChange"> |
| | | <el-table-column type="selection" width="46" /> |
| | | <el-table-column label="序号" width="80"> |
| | | <template v-slot="{ $index }"> |
| | | {{ $index + 1 }} |
| | |
| | | class="gd-dialog" |
| | | append-to-body |
| | | v-model="isShowImportView" |
| | | title="导入机构" |
| | | :width="pxToRem(600)" |
| | | title="机构导入" |
| | | :width="pxToRem(500)" |
| | | :close-on-click-modal="false" |
| | | :destroy-on-close="true" |
| | | @close="handleImportClose" |
| | |
| | | type="primary" |
| | | @click="handleExportTemplate" |
| | | > |
| | | 点击导出 |
| | | 下载模板 |
| | | </el-button> |
| | | </el-form-item> |
| | | <el-form-item label="上传文件" prop="file"> |
| | | {{ importFileName }} |
| | | |
| | | <el-upload class="avatar-uploader" action="" :show-file-list="false" :before-upload="onImportFileBefore"> |
| | | <el-button type="primary">点击上传</el-button> |
| | | </el-upload> |
| | | <div class="upload-tip"> |
| | | {{ importFileName }} |
| | | </div> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | |
| | | const dialogVisible = ref(false) |
| | | const regionOptions = ref([]) // 区域选项 |
| | | const dictObj = ref({}) // 字典对象 |
| | | const selectedFiles = ref([]) // 勾选的文件列表 |
| | | |
| | | // 树形选择器配置 |
| | | const treeSelectProps = { |
| | |
| | | label: 'name', |
| | | children: 'children' |
| | | } |
| | | |
| | | |
| | | // 导入机构相关 |
| | | const isShowImportView = ref(false) |
| | | const importFileName = ref('') |
| | |
| | | async function loadRegionNode(node, resolve) { |
| | | |
| | | try { |
| | | // 限制只加载两级,当前节点 level >= 1 时不加载子节点 |
| | | if (node.level >= 2) { |
| | | resolve([]) |
| | | return |
| | | } |
| | | |
| | | // 初始化加载时传递 code 参数,加载子节点时传递 parentCode 参数 |
| | | const params = node.data?.id ? { parentCode: node.data.id } : { code: '360800000000' } |
| | | const res = await regionLazyTreeApi(params) |
| | |
| | | } |
| | | } |
| | | |
| | | // 勾选值设置 |
| | | function handleSelectionChange(rows) { |
| | | selectedFiles.value = rows |
| | | } |
| | | |
| | | // 导出模板 |
| | | async function handleExportTemplate() { |
| | | templateExportLoading.value = true |
| | |
| | | |
| | | // 上传文件前处理 |
| | | function onImportFileBefore(file) { |
| | | // 提示请先导出模板 |
| | | // ElMessage.warning('请先导出模板并按模板格式填写数据') |
| | | |
| | | // 检查文件类型 |
| | | const allowedTypes = ['.xlsx', '.xls'] |
| | | const fileExtension = file.name.substring(file.name.lastIndexOf('.')).toLowerCase() |
| | |
| | | ElMessage.error('请上传Excel文件(.xlsx 或 .xls)') |
| | | return false |
| | | } |
| | | let data = new FormData() |
| | | data.append('file', file) |
| | | |
| | | agenciesImportApi(data, { isCovered: importParams.value.isCovered }).then(res => { |
| | | if (res.data.code === 200) { |
| | | ElMessage.success('导入成功') |
| | | // 保存文件名 |
| | | importFileName.value = file.name |
| | | importParams.value.file = file |
| | | isShowImportView.value = false |
| | | getList() |
| | | } else { |
| | | ElMessage.error(res.msg || '导入失败') |
| | | } |
| | | }) |
| | | |
| | | // 保存文件名和文件对象 |
| | | importFileName.value = file.name |
| | | importParams.value.file = file |
| | | ElMessage.success('上传成功') |
| | | |
| | | return false // 阻止组件的默认上传行为 |
| | | } |
| | |
| | | ElMessage.error('请先上传文件') |
| | | return |
| | | } |
| | | // 触发上传操作 |
| | | await onImportFileBefore(importParams.value.file) |
| | | |
| | | // 构建表单数据并调用导入接口 |
| | | let data = new FormData() |
| | | data.append('file', importParams.value.file) |
| | | |
| | | const res = await agenciesImportApi(data, { isCovered: importParams.value.isCovered }) |
| | | if (res.data.code === 200) { |
| | | ElMessage.success('导入成功') |
| | | isShowImportView.value = false |
| | | getList() |
| | | } else { |
| | | ElMessage.error(res.msg || '导入失败') |
| | | } |
| | | } finally { |
| | | importSubmitting.value = false |
| | | } |
| | |
| | | |
| | | // 导出机构 |
| | | async function handleExport() { |
| | | // 检查是否有选中的数据 |
| | | if (selectedFiles.value.length === 0) { |
| | | ElMessage.warning('请选择要导出的机构') |
| | | return |
| | | } |
| | | |
| | | exportLoading.value = true |
| | | try { |
| | | const res = await agenciesExportApi(searchParams.value) |
| | | const params = {} |
| | | params.deptIds = selectedFiles.value.map(i => i.id) |
| | | // 调用导出API |
| | | const res = await agenciesExportApi(params) |
| | | const blob = new Blob([res.data]) |
| | | const url = URL.createObjectURL(blob) |
| | | const a = document.createElement('a') |
| | | a.href = url |
| | | // `机构列表${new Date().getTime()}.xlsx` |
| | | a.download = `机构列表.xlsx` |
| | | // `机构列表${new Date().getTime()}.xlsx` |
| | | const fileName = `机构列表.xlsx` |
| | | a.download = fileName |
| | | |
| | | document.body.appendChild(a) |
| | | a.click() |
| | | document.body.removeChild(a) |
| | |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | .upload-tip { |
| | | margin-left: 5px; |
| | | } |
| | | </style> |