|
@@ -104,6 +104,11 @@ export default {
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ value(val, oldval) {
|
|
|
+ if (val !== oldval) this.initSelected(val);
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted() {
|
|
|
this.getList();
|
|
|
},
|
|
@@ -120,6 +125,7 @@ export default {
|
|
|
return 0;
|
|
|
});
|
|
|
}
|
|
|
+ if (this.value) this.initSelected(this.value);
|
|
|
},
|
|
|
switchOpen() {
|
|
|
if (this.visible) {
|
|
@@ -138,6 +144,46 @@ export default {
|
|
|
this.visible = false;
|
|
|
this.isFocus = false;
|
|
|
},
|
|
|
+ getSelectedData(selectedIds) {
|
|
|
+ let selectedData = [];
|
|
|
+ if (!selectedIds.length) return [];
|
|
|
+
|
|
|
+ const findTree = list => {
|
|
|
+ list.forEach(item => {
|
|
|
+ if (selectedIds.includes(item.id)) {
|
|
|
+ selectedData.push({ ...item });
|
|
|
+ }
|
|
|
+ if (item.children && item.children.length) {
|
|
|
+ findTree(item.children);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ findTree(this.orgs);
|
|
|
+
|
|
|
+ return selectedData;
|
|
|
+ },
|
|
|
+ initSelected(val) {
|
|
|
+ if (!this.orgs.length) return;
|
|
|
+ if (this.multiple) {
|
|
|
+ const selectedIds = val || [];
|
|
|
+ const selectedData = this.getSelectedData(selectedIds);
|
|
|
+ this.selectedOrg = {};
|
|
|
+ this.selectedOrgList = selectedData;
|
|
|
+ } else {
|
|
|
+ const selectedIds = val ? [val] : [];
|
|
|
+ const selectedData = this.getSelectedData(selectedIds);
|
|
|
+ if (selectedData.length) {
|
|
|
+ this.selectedOrg = { ...selectedData[0] };
|
|
|
+ this.selectedOrgList = selectedData;
|
|
|
+ } else {
|
|
|
+ this.selectedOrg = {};
|
|
|
+ this.selectedOrgList = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateSelectOrgIds();
|
|
|
+ this.emitChange();
|
|
|
+ },
|
|
|
nodeClick(data) {
|
|
|
if (!this.multiple) {
|
|
|
this.selectedOrg = { ...data };
|