已选 {{ selectList.length }} 项
@@ -102,7 +101,7 @@ export default {
// const jsonb = jsona.replace(/"value"/g, '"deptId"') // 修改成你要的字段
// const jsonc = jsonb.replace(/"label"/g, '"deptName"')
this.deptList = res.data
- console.log("获取部门信息===========", this.deptList);
+ // console.log("获取部门信息===========", this.deptList);
});
},
//通过关键字过滤树节点
@@ -120,40 +119,43 @@ export default {
* @param checked 是否选中
*/
handleCheckChange(data, checked) {
- // 左侧有选择框
- if (this.showCheckbox) {
- // 左侧有选择框 + 多选
- if (this.multiple) {
- //不添加重复的数据到右边
- for (let i = 0; i < this.selectList.length; i++) {
- if (this.selectList[i].value === data.value) {
- this.selectList.splice(i, 1);
- break;
+ // 左侧有选择框
+ if (this.showCheckbox) {
+ // 左侧有选择框 + 多选
+ if (this.multiple ) {
+ //不添加重复的数据到右边
+ for (let i = 0; i < this.selectList.length; i++) {
+ if (this.selectList[i].value === data.value) {
+ this.selectList.splice(i, 1);
+ break;
+ }
}
- }
- if (checked) {
- this.selectList.push(data);
- } else if (data === '1') {
- this.$refs.tree.setCheckedKeys([]);
- this.selectList = [];
- }
- } else {// 左侧有选择框 + 单选
- //不添加重复的数据到右边
- for (let i = 0; i < this.selectList.length; i++) {
- if (this.selectList[i].value === data.value) {
- this.selectList.splice(i, 1);
- break;
+ if (checked) {
+ if(data.children === undefined){
+ this.selectList.push(data);
+ }
+ } else if (data === '1') {
+ this.$refs.tree.setCheckedKeys([]);
+ this.selectList = [];
+ }
+ } else {// 左侧有选择框 + 单选
+ //不添加重复的数据到右边
+ for (let i = 0; i < this.selectList.length; i++) {
+ if (this.selectList[i].value === data.value) {
+ this.selectList.splice(i, 1);
+ break;
+ }
+ }
+ if (checked) {
+ this.$refs.tree.setCheckedNodes([data]);
+ // this.$refs.tree.setCheckedKeys([]);
+ this.selectList = [data];
+ } else if (data === '1') {
+ this.selectList = [];
+ this.$refs.tree.setCheckedKeys([]);
}
- }
- if (checked) {
- this.$refs.tree.setCheckedNodes([data]);
- this.selectList = [data];
- } else if (data === '1') {
- this.$refs.tree.setCheckedKeys([]);
- this.selectList = [];
}
}
- }
this._value = this.selectList
},
@@ -164,19 +166,21 @@ export default {
* @param check checked(checkbox选择框)是否选中
*/
handle(node, check) {
- if (this.multiple) {
- //不添加重复的数据到右边
- for (let i = 0; i < this.selectList.length; i++) {
- if (this.selectList[i].value === node.value) {
- this.selectList.splice(i, 1);
- break;
+ if (check.isLeaf !== false) {
+ if (this.multiple) {
+ //不添加重复的数据到右边
+ for (let i = 0; i < this.selectList.length; i++) {
+ if (this.selectList[i].value === node.value) {
+ this.selectList.splice(i, 1);
+ break;
+ }
}
+ check.checked = true
+ this.selectList.push(node);
+ } else {
+ check.checked = true
+ this.selectList = [node];
}
- check.checked = true
- this.selectList.push(node);
- } else {
- check.checked = true
- this.selectList = [node];
}
this._value = this.selectList
},
@@ -203,9 +207,10 @@ export default {
cancelButtonText: "取消",
type: "warning"
}).then(() => {
- this.handleCheckChange("1");
if (!this.showCheckbox) {
this.selectList = []
+ }else {
+ this.handleCheckChange("1");
}
});
},
@@ -221,15 +226,15 @@ export default {