From 5aaae5a3abddaf30abdf6d5b1057e97148af0e89 Mon Sep 17 00:00:00 2001
From: xuwenbo <717567226@qq.com>
Date: Tue, 17 Nov 2020 10:14:39 +0800
Subject: [PATCH] =?UTF-8?q?#I24D3P=E5=90=8E=E5=8F=B0-=E7=B3=BB=E7=BB=9F?=
=?UTF-8?q?=E7=AE=A1=E7=90=86-=E9=83=A8=E9=97=A8=E7=AE=A1=E7=90=86?=
=?UTF-8?q?=EF=BC=8C=E7=BC=96=E8=BE=91=E6=9C=80=E4=B8=8A=E7=BA=A7=E9=83=A8?=
=?UTF-8?q?=E9=97=A8=EF=BC=8C=E6=8F=90=E7=A4=BA=E2=80=9C=E4=B8=8A=E7=BA=A7?=
=?UTF-8?q?=E9=83=A8=E9=97=A8=E4=B8=8D=E8=83=BD=E4=B8=BA=E7=A9=BA=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/system/dept/index.vue | 77 +++++++++++++++++++++++++++++++--
1 file changed, 73 insertions(+), 4 deletions(-)
diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue
index 6597112..2731b22 100644
--- a/src/views/system/dept/index.vue
+++ b/src/views/system/dept/index.vue
@@ -113,23 +113,83 @@ export default {
}
},
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) {
+ if (form.pid !== null) {
+ form.isTop = '0'
+ } else if (form.id !== null) {
+ form.isTop = '1'
+ }
form.enabled = `${form.enabled}`
- // 获取所有部门
+ if (form.id != null) {
+ this.getSupDepts(form.id)
+ } 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
+ 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]() {
- if (!this.form.pid) {
+ if (this.form.pid !== null && this.form.pid === this.form.id) {
this.$message({
message: '上级部门不能为空',
type: 'warning'
})
return false
}
+ if (this.form.isTop === '1') {
+ this.form.pid = null
+ }
return true
},
// 改变状态
@@ -156,5 +216,14 @@ export default {
}
-
+