#I24D3P后台-系统管理-部门管理,编辑最上级部门,提示“上级部门不能为空”
This commit is contained in:
@ -113,23 +113,83 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getDeptDatas(tree, treeNode, resolve) {
|
||||||
|
const params = { pid: tree.id }
|
||||||
|
setTimeout(() => {
|
||||||
|
crudDept.getDepts(params).then(res => {
|
||||||
|
resolve(res.content)
|
||||||
|
})
|
||||||
|
}, 100)
|
||||||
|
},
|
||||||
// 新增与编辑前做的操作
|
// 新增与编辑前做的操作
|
||||||
[CRUD.HOOK.afterToCU](crud, form) {
|
[CRUD.HOOK.afterToCU](crud, form) {
|
||||||
|
if (form.pid !== null) {
|
||||||
|
form.isTop = '0'
|
||||||
|
} else if (form.id !== null) {
|
||||||
|
form.isTop = '1'
|
||||||
|
}
|
||||||
form.enabled = `${form.enabled}`
|
form.enabled = `${form.enabled}`
|
||||||
// 获取所有部门
|
if (form.id != null) {
|
||||||
crudDept.getDepts({ enabled: true }).then(res => {
|
this.getSupDepts(form.id)
|
||||||
this.depts = res.content
|
} else {
|
||||||
|
this.getDepts()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getSupDepts(id) {
|
||||||
|
crudDept.getDeptSuperior(id).then(res => {
|
||||||
|
const date = res.content
|
||||||
|
this.buildDepts(date)
|
||||||
|
this.depts = date
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
buildDepts(depts) {
|
||||||
|
depts.forEach(data => {
|
||||||
|
if (data.children) {
|
||||||
|
this.buildDepts(data.children)
|
||||||
|
}
|
||||||
|
if (data.hasChildren && !data.children) {
|
||||||
|
data.children = null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getDepts() {
|
||||||
|
crudDept.getDepts({ enabled: true }).then(res => {
|
||||||
|
this.depts = res.content.map(function(obj) {
|
||||||
|
if (obj.hasChildren) {
|
||||||
|
obj.children = null
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 获取弹窗内部门数据
|
||||||
|
loadDepts({ action, parentNode, callback }) {
|
||||||
|
if (action === LOAD_CHILDREN_OPTIONS) {
|
||||||
|
crudDept.getDepts({ enabled: true, pid: parentNode.id }).then(res => {
|
||||||
|
parentNode.children = res.content.map(function(obj) {
|
||||||
|
if (obj.hasChildren) {
|
||||||
|
obj.children = null
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
callback()
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
// 提交前的验证
|
// 提交前的验证
|
||||||
[CRUD.HOOK.afterValidateCU]() {
|
[CRUD.HOOK.afterValidateCU]() {
|
||||||
if (!this.form.pid) {
|
if (this.form.pid !== null && this.form.pid === this.form.id) {
|
||||||
this.$message({
|
this.$message({
|
||||||
message: '上级部门不能为空',
|
message: '上级部门不能为空',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (this.form.isTop === '1') {
|
||||||
|
this.form.pid = null
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
// 改变状态
|
// 改变状态
|
||||||
@ -156,5 +216,14 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||||
|
::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
|
||||||
|
height: 30px;
|
||||||
|
line-height: 30px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||||
|
::v-deep .el-input-number .el-input__inner {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user