|
|
|
@ -105,6 +105,7 @@ |
|
|
|
} |
|
|
|
}); |
|
|
|
this.dataDep = res.result; |
|
|
|
this.syncSelectedTitle(); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
@ -183,14 +184,49 @@ |
|
|
|
this.$emit("on-clear"); |
|
|
|
}, |
|
|
|
setData(ids, title) { |
|
|
|
this.shopAreaTitle = title; |
|
|
|
if (this.multiple) { |
|
|
|
this.shopArea = ids; |
|
|
|
this.shopArea = Array.isArray(ids) ? ids : (ids ? [ids] : []); |
|
|
|
} else { |
|
|
|
this.shopArea = []; |
|
|
|
this.shopArea.push(ids); |
|
|
|
if (ids) { |
|
|
|
this.shopArea.push(ids); |
|
|
|
} |
|
|
|
} |
|
|
|
this.shopAreaTitle = title || ""; |
|
|
|
this.syncSelectedTitle(); |
|
|
|
this.emitChange(); |
|
|
|
}, |
|
|
|
emitChange() { |
|
|
|
if (this.multiple) { |
|
|
|
this.$emit("on-change", this.shopArea); |
|
|
|
} else { |
|
|
|
this.$emit("on-change", this.shopArea[0] || ""); |
|
|
|
} |
|
|
|
this.$emit("on-change", this.shopArea); |
|
|
|
}, |
|
|
|
syncSelectedTitle() { |
|
|
|
if (this.shopAreaTitle || !this.shopArea.length || !this.dataDep.length) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const selectedIds = this.shopArea.map(item => String(item)); |
|
|
|
const titles = []; |
|
|
|
const findTitles = (list) => { |
|
|
|
list.forEach((item) => { |
|
|
|
if (selectedIds.includes(String(item.id))) { |
|
|
|
titles.push(item.title); |
|
|
|
} |
|
|
|
if (item.children && item.children.length) { |
|
|
|
findTitles(item.children); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
findTitles(this.dataDep); |
|
|
|
this.shopAreaTitle = titles.join("、"); |
|
|
|
}, |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
rootId() { |
|
|
|
this.searchKey = ""; |
|
|
|
this.initShopAreaData(); |
|
|
|
}, |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
|