已选 {{ selectList.length }} 项
@@ -120,40 +119,47 @@ 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 (data.children === undefined) {
+ // 左侧有选择框
+ 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 {// 左侧有选择框 + 单选
+ console.log('左侧有选择框 + 单选')
+ //不添加重复的数据到右边
+ 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 +170,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 +211,10 @@ export default {
cancelButtonText: "取消",
type: "warning"
}).then(() => {
- this.handleCheckChange("1");
if (!this.showCheckbox) {
this.selectList = []
+ }else {
+ this.handleCheckChange("1");
}
});
},
@@ -221,15 +230,15 @@ export default {