fix: 修复编辑用户部门默认不选中bug
修复编辑用户部门默认不选中bug
This commit is contained in:
@@ -135,15 +135,10 @@
|
||||
label="上级部门"
|
||||
prop="parentId"
|
||||
>
|
||||
<TreeSelect
|
||||
:treeProps="dataMap.props"
|
||||
<tree-select
|
||||
:options="dataMap.deptOptions"
|
||||
placeholder="选择上级部门"
|
||||
:originOptions="dataMap.originOptions"
|
||||
:defalut="dataMap.formVal.parentId"
|
||||
:user="true"
|
||||
@callBack="getDeptId"
|
||||
:disabled="dataMap.disabled"
|
||||
v-model:value="dataMap.formVal.parentId"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="部门名称" prop="name">
|
||||
@@ -296,25 +291,10 @@ function resetQuery() {
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
function flatten(origin: any) {
|
||||
let result: any = []
|
||||
for (let i = 0; i < origin.length; i++) {
|
||||
const item = origin[i]
|
||||
if (Array.isArray(item.children)) {
|
||||
result = result.concat(flatten(item.children))
|
||||
result.push(item)
|
||||
} else {
|
||||
result.push(item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/** 查询部门下拉树结构 */
|
||||
function getTreeselect() {
|
||||
getDeptSelectList().then(response => {
|
||||
dataMap.deptOptions = response.data
|
||||
dataMap.originOptions = flatten(response?.data) as any
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +264,7 @@
|
||||
width="600px"
|
||||
append-to-body
|
||||
@opened="showDialog"
|
||||
@closed="cancel"
|
||||
>
|
||||
<el-form
|
||||
ref="addForm"
|
||||
@@ -288,14 +289,10 @@
|
||||
label="归属部门"
|
||||
prop="deptId"
|
||||
>
|
||||
<Treeselect
|
||||
:treeProps="dataMap.props"
|
||||
<tree-select
|
||||
:options="dataMap.deptOptions"
|
||||
placeholder="请选择归属部门"
|
||||
:originOptions="dataMap.originOptions"
|
||||
:defalut="dataMap.formVal.deptId"
|
||||
:user="true"
|
||||
@callBack="getDeptId"
|
||||
v-model:value="dataMap.formVal.deptId"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -428,7 +425,7 @@
|
||||
import {listUser, getUser, delUser, addUser, updateUser, patch} from '@/api/system/user'
|
||||
|
||||
import {getDeptSelectList} from '@/api/system/dept'
|
||||
import Treeselect from '@/components/TreeSelect/Index.vue'
|
||||
import TreeSelect from '@/components/TreeSelect/Index.vue'
|
||||
import {listRoles} from '@/api/system/role'
|
||||
import {Search, Plus, Edit, Refresh, Delete} from '@element-plus/icons'
|
||||
|
||||
@@ -666,11 +663,7 @@ function handleSelectionChange(selection: any) {
|
||||
|
||||
/** 新增按钮操作 */
|
||||
function handleAdd() {
|
||||
console.log(dataMap.formVal)
|
||||
dataMap.addformFlag = true
|
||||
resetForm()
|
||||
dataMap.originOptions = []
|
||||
// loadDeptOptions()
|
||||
dataMap.open = true
|
||||
dataMap.title = '添加用户'
|
||||
dataMap.formVal.password = "123456"
|
||||
@@ -696,15 +689,12 @@ function resetForm() {
|
||||
|
||||
/** 修改按钮操作 */
|
||||
async function handleUpdate(row: { [key: string]: any }) {
|
||||
resetForm()
|
||||
const userId = row.id || dataMap.ids
|
||||
const response = await getUser(userId);
|
||||
dataMap.formVal = response.data
|
||||
console.log(response.data)
|
||||
dataMap.title = '修改用户'
|
||||
dataMap.formVal.password = ''
|
||||
dataMap.formVal.deptId = 1
|
||||
// dataMap.formVal.deptId = parseInt(response.data.deptId)
|
||||
dataMap.formVal.deptId =response.data.deptId
|
||||
dataMap.open = true
|
||||
}
|
||||
|
||||
@@ -754,9 +744,6 @@ function cancel() {
|
||||
resetForm()
|
||||
}
|
||||
|
||||
function getParentValue(event: any) {
|
||||
console.log(event)
|
||||
}
|
||||
|
||||
function getDeptId(e: any) {
|
||||
dataMap.formVal.deptId = e
|
||||
@@ -787,6 +774,7 @@ onMounted(() => {
|
||||
|
||||
function showDialog() {
|
||||
loadDeptOptions()
|
||||
loadRoleOptions()
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user