| | |
| | | <el-form-item label="部门名称" prop="deptName"> |
| | | <el-input v-model="form.deptName" placeholder="请输入部门名称" /> |
| | | </el-form-item> |
| | | <el-form-item label="父级部门" prop="parentCode"> |
| | | <el-select v-model="form.parentCode" placeholder="请选择父级部门" style="width: 100%"> |
| | | <el-option label="顶级部门" value="0" /> |
| | | <el-form-item label="上级部门" prop="parentCode"> |
| | | <el-select v-model="form.parentCode" placeholder="请选择上级部门" style="width: 100%"> |
| | | <el-option |
| | | v-for="dept in flatDepartmentList" |
| | | :key="dept.deptCode" |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, computed, onMounted } from 'vue' |
| | | import {ref, reactive, computed, onMounted, nextTick} from 'vue' |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { Plus, Edit, Delete } from '@element-plus/icons-vue' |
| | | import { getDepartmentTree, createDepartment, updateDepartment, deleteDepartment } from '@/api/department' |
| | |
| | | }) |
| | | return result |
| | | } |
| | | return flatten(tableData.value) |
| | | const list = flatten(tableData.value) |
| | | |
| | | // 数据扁平化后,默认选中第一个部门的 deptCode |
| | | nextTick(() => { |
| | | if (list.length > 0) { |
| | | form.parentCode = list[0].deptCode |
| | | } |
| | | }) |
| | | |
| | | return list |
| | | }) |
| | | |
| | | const buildTree = (list) => { |