|
|
|
@ -174,6 +174,7 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_reqSelectedTreeNode(op, callback) { |
|
|
|
|
const self = this; |
|
|
|
|
const selectedValues = deepClone(op.selectedValues); |
|
|
|
|
const notSelectedValue = op.notSelectedValue || {}; |
|
|
|
|
const keyword = op.keyword || ""; |
|
|
|
@ -188,7 +189,7 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
dealWithSelectedValues(selectedValues); |
|
|
|
|
callback(selectedValues); |
|
|
|
|
|
|
|
|
|
const dealWithSelectedValues = selectedValues => { |
|
|
|
|
function dealWithSelectedValues(selectedValues) { |
|
|
|
|
let p = parentValues.concat(notSelectedValue); |
|
|
|
|
// 存储的值中存在这个值就把它删掉
|
|
|
|
|
// 例如选中了中国-江苏-南京, 取消中国或江苏或南京
|
|
|
|
@ -197,18 +198,18 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
// 如果搜索的值在父亲链中
|
|
|
|
|
if (isSearchValueInParent(p)) { |
|
|
|
|
// 例如选中了 中国-江苏, 搜索江苏, 取消江苏(干掉了江苏)
|
|
|
|
|
this._deleteNode(selectedValues, p); |
|
|
|
|
self._deleteNode(selectedValues, p); |
|
|
|
|
} else { |
|
|
|
|
const searched = []; |
|
|
|
|
// 要找到所有以notSelectedValue为叶子节点的链路
|
|
|
|
|
const find = search(parentValues, notSelectedValue, [], searched); |
|
|
|
|
if (find && isNotEmptyArray(searched)) { |
|
|
|
|
each(searched, (i, arr) => { |
|
|
|
|
const node = this._getNode(selectedValues, arr); |
|
|
|
|
const node = self._getNode(selectedValues, arr); |
|
|
|
|
if (node) { |
|
|
|
|
// 例如选中了 中国-江苏, 搜索江苏, 取消中国(实际上只想删除中国-江苏,因为搜的是江苏)
|
|
|
|
|
// 例如选中了 中国-江苏-南京,搜索南京,取消中国(实际上只想删除中国-江苏-南京,因为搜的是南京)
|
|
|
|
|
this._deleteNode(selectedValues, arr); |
|
|
|
|
self._deleteNode(selectedValues, arr); |
|
|
|
|
} else { |
|
|
|
|
// 例如选中了 中国-江苏,搜索南京,取消中国(实际上只想删除中国-江苏-南京,因为搜的是南京)
|
|
|
|
|
expandSelectedValue(selectedValues, arr, last(arr)); |
|
|
|
@ -239,14 +240,14 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
// 添加去掉搜索的结果集
|
|
|
|
|
if (result.length > 0) { |
|
|
|
|
each(result, (i, strs) => { |
|
|
|
|
this._buildTree(selectedValues, strs); |
|
|
|
|
self._buildTree(selectedValues, strs); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const expandSelectedValue = (selectedValues, parents, notSelectedValue) => { |
|
|
|
|
function expandSelectedValue(selectedValues, parents, notSelectedValue) { |
|
|
|
|
let next = selectedValues; |
|
|
|
|
const childrenCount = []; |
|
|
|
|
const path = []; |
|
|
|
@ -259,7 +260,7 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
} |
|
|
|
|
if (isEmpty(next)) { |
|
|
|
|
const split = parents.slice(0, i); |
|
|
|
|
const expanded = this._getChildren(split); |
|
|
|
|
const expanded = self._getChildren(split); |
|
|
|
|
path.push(split); |
|
|
|
|
childrenCount.push(expanded.length); |
|
|
|
|
// 如果只有一个值且取消的就是这个值
|
|
|
|
@ -270,7 +271,7 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
) { |
|
|
|
|
for (let j = childrenCount.length - 1; j >= 0; j--) { |
|
|
|
|
if (childrenCount[j] === 1) { |
|
|
|
|
this._deleteNode(selectedValues, path[j]); |
|
|
|
|
self._deleteNode(selectedValues, path[j]); |
|
|
|
|
} else { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -295,16 +296,16 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const search = (parents, current, result, searched) => { |
|
|
|
|
function search(parents, current, result, searched) { |
|
|
|
|
const newParents = clone(parents); |
|
|
|
|
newParents.push(current); |
|
|
|
|
if (this._isMatch(parents, current, keyword)) { |
|
|
|
|
if (self._isMatch(parents, current, keyword)) { |
|
|
|
|
searched && searched.push(newParents); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const children = this._getChildren(newParents); |
|
|
|
|
const children = self._getChildren(newParents); |
|
|
|
|
|
|
|
|
|
const notSearch = []; |
|
|
|
|
let can = false; |
|
|
|
@ -327,9 +328,9 @@ export class AbstractTreeValueChooser extends Widget {
|
|
|
|
|
return can; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const isSearchValueInParent = parentValues => { |
|
|
|
|
function isSearchValueInParent(parentValues) { |
|
|
|
|
for (let i = 0, len = parentValues.length; i < len; i++) { |
|
|
|
|
if (this._isMatch(parentValues.slice(0, i), parentValues[i], keyword)) { |
|
|
|
|
if (self._isMatch(parentValues.slice(0, i), parentValues[i], keyword)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|