<a-tree-select labelInValue :value="treeValue3" style="width: 100%" :tree-data="treeDataSalesArea"
:show-checked-strategy="SHOW_PARENT" placeholder="请选择" allowClear :dropdown-style="dropdownStyle"
:searchValue="searchValue3" @search="doSearch3" showSearch @select="treeSelect3" />
/**
* @description 选择节点触发
*/
treeSelect3(nodeValue) {
this.setTitle3(nodeValue.value, this.treeDataSalesArea)
},
/**
* @description 设置当前选中对象
*/
setTitle3(title, treeData) {
this.treeValue3 = undefined
this.treeT = true
this.getSelectedItem(title, treeData)
this.$nextTick(() => {
this.treeValue3 = {
label: this.defaultTitle,
value: title,
param: this.paramVal,
}
})
},
/**
* @description 当前选中对象的title(拼接所有父级title)
*/
getSelectedItem(value, data, title, pid) {
for (let item of data) {
//在根节点找到对应选项
if (!title && item.value === value && this.treeT) {
this.treeT = false
this.defaultTitle = item.title
this.paramVal = item.key
}
//根节点未找到继续递归查找
else if (!title && item.children && this.treeT) {
this.defaultTitle = item.title
this.paramVal = item.key
this.getSelectedItem(value, item.children, this.defaultTitle, this.paramVal);
}
//在子节点找到对应选项
if (title && item.value === value) {
this.treeT = false
this.defaultTitle = title + '/' + item.title
this.paramVal = pid + '^' + item.key
}
//当前子节点未找到继续递归向下查找
else if (title && item.children && this.treeT) {
this.defaultTitle = title + '/' + item.title
this.paramVal = pid + '^' + item.key
this.getSelectedItem(value, item.children, this.defaultTitle, this.paramVal);
}
}
},