| | |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="所属区划" prop="areaCode"> |
| | | <el-select |
| | | <el-tree-select |
| | | class="gd-select gray" |
| | | popper-class="gd-select-popper" |
| | | popper-class="gd-tree-select-popper" |
| | | v-model="searchParams.areaCode" |
| | | :data="regionOptions" |
| | | node-key="id" |
| | | :props="treeSelectProps" |
| | | placeholder="请选择" |
| | | clearable |
| | | filterable |
| | | @change="handleSearch" |
| | | > |
| | | <el-option v-for="item in regionOptions" :key="item.value" :label="item.title" :value="item.value" /> |
| | | </el-select> |
| | | :check-strictly="true" |
| | | /> |
| | | </el-form-item> |
| | | |
| | | <el-form-item class="gd-search-actions"> |
| | |
| | | @close="handleImportClose" |
| | | > |
| | | <el-form class="gd-dialog-form" ref="importFormRef" :model="importParams" :rules="importRules" label-width="140px"> |
| | | |
| | | <el-form-item label="上传文件" prop="file"> |
| | | {{ importFileName }} |
| | | <el-upload class="avatar-uploader" action="" :show-file-list="false" :before-upload="onImportFileBefore"> |
| | |
| | | const regionOptions = ref([]) // 区域选项 |
| | | const dictObj = ref({}) // 字典对象 |
| | | |
| | | // 树形选择器配置 |
| | | const treeSelectProps = { |
| | | value: 'id', |
| | | label: 'name', |
| | | children: 'children' |
| | | } |
| | | |
| | | |
| | | // 导入机构相关 |
| | | const isShowImportView = ref(false) |
| | | const importFileName = ref('') |
| | |
| | | }) |
| | | } |
| | | |
| | | // 获取区域列表 |
| | | function getRegionList() { |
| | | regionLazyTreeApi({parentCode: '360800000000'}).then(res => { |
| | | console.log('区域列表', res.data.data); |
| | | |
| | | regionOptions.value = res.data.data || [] |
| | | }) |
| | | // 递归获取区域树形数据 |
| | | async function getRegionTree(parentCode = '360800000000') { |
| | | try { |
| | | const res = await regionLazyTreeApi({ parentCode }) |
| | | const nodes = res?.data?.data || [] |
| | | |
| | | // 如果节点有子节点,递归获取子节点 |
| | | for (let node of nodes) { |
| | | if (node.hasChildren) { |
| | | node.children = await getRegionTree(node.id) |
| | | } else { |
| | | node.children = [] |
| | | } |
| | | node.name = node.name || node.title || node.label |
| | | // 确保 id 属性存在 |
| | | node.id = node.id || node.value |
| | | } |
| | | return nodes |
| | | } catch (error) { |
| | | console.error('获取区域数据失败:', error) |
| | | return [] |
| | | } |
| | | } |
| | | |
| | | // 获取完整的区域树形数据 |
| | | async function getRegionList() { |
| | | try { |
| | | regionOptions.value = await getRegionTree() |
| | | console.log('区域树形数据:', regionOptions.value) |
| | | } catch (error) { |
| | | ElMessage.error('获取区域数据失败') |
| | | } |
| | | } |
| | | |
| | | // 获取列表 |
| | |
| | | |
| | | // 上传文件前处理 |
| | | function onImportFileBefore(file) { |
| | | // 执行文件上传 |
| | | // 检查文件类型 |
| | | const allowedTypes = ['.xlsx', '.xls'] |
| | | const fileExtension = file.name.substring(file.name.lastIndexOf('.')).toLowerCase() |
| | | if (!allowedTypes.includes(fileExtension)) { |
| | | ElMessage.error('请上传Excel文件(.xlsx 或 .xls)') |
| | | return false |
| | | } |
| | | let data = new FormData() |
| | | data.append('file', file) |
| | | |
| | |
| | | if (valid) { |
| | | importSubmitting.value = true |
| | | try { |
| | | // 这里实际上传文件的逻辑已经在onImportFileBefore中处理了 |
| | | // 这里可以添加额外的验证或逻辑 |
| | | if (!importParams.value.file) { |
| | | ElMessage.error('请先上传文件') |
| | | return |
| | | } |
| | | // 触发上传操作 |
| | | await onImportFileBefore(importParams.value.file) |
| | | } finally { |
| | | importSubmitting.value = false |
| | | } |