@ -532,70 +532,81 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
var checkState = op . checkState || { } ;
var checkState = op . checkState || { } ;
var parentValues = op . parentValues || [ ] ;
var parentValues = op . parentValues || [ ] ;
var selectedValues = op . selectedValues || { } ;
var selectedValues = op . selectedValues || { } ;
function getResult ( parentValues , checkState ) {
var valueMap = { } ;
var valueMap = { } ;
// if (judgeState(parentValues, selectedValues, checkState)) {
// if (judgeState(parentValues, selectedValues, checkState)) {
valueMap = dealWithSelectedValue ( parentValues , selectedValues ) ;
valueMap = dealWithSelectedValue ( parentValues , selectedValues ) ;
// }
// }
var nodes = this . _getChildren ( parentValues ) ;
var nodes = self . _getChildren ( parentValues ) ;
for ( var i = ( times - 1 ) * this . _const . perPage ; nodes [ i ] && i < times * this . _const . perPage ; i ++ ) {
for ( var i = ( times - 1 ) * self . _const . perPage ; nodes [ i ] && i < times * self . _const . perPage ; i ++ ) {
var state = getCheckState ( nodes [ i ] . value , parentValues , valueMap , checkState ) ;
var state = getCheckState ( nodes [ i ] . value , parentValues , valueMap , checkState ) ;
var openState = o . open || nodes [ i ] . open ;
result . push ( {
result . push ( {
id : nodes [ i ] . id ,
id : nodes [ i ] . id ,
pId : nodes [ i ] . pId ,
pId : nodes [ i ] . pId ,
value : nodes [ i ] . value ,
value : nodes [ i ] . value ,
text : nodes [ i ] . text ,
text : nodes [ i ] . text ,
times : 1 ,
times : 1 ,
isParent : nodes [ i ] . getChildrenLength ( ) > 0 ,
isParent : nodes [ i ] . isParent || nodes [ i ] . getChildrenLength ( ) > 0 ,
checked : state [ 0 ] ,
checked : state [ 0 ] ,
halfCheck : state [ 1 ] ,
half : state [ 1 ] ,
open : o . open ,
halfCheck : openState ? false : state [ 1 ] ,
open : openState ,
disabled : nodes [ i ] . disabled ,
disabled : nodes [ i ] . disabled ,
title : nodes [ i ] . title || nodes [ i ] . text ,
title : nodes [ i ] . title || nodes [ i ] . text ,
warningTitle : nodes [ i ] . warningTitle ,
warningTitle : nodes [ i ] . warningTitle ,
} ) ;
} ) ;
if ( openState ) {
getResult ( parentValues . concat ( [ nodes [ i ] . value ] ) , { checked : state [ 0 ] , half : state [ 1 ] } ) ;
}
}
}
// 如果指定节点全部打开
if ( o . open ) {
var allNodes = [ ] ;
// 获取所有节点
BI . each ( nodes , function ( idx , node ) {
allNodes = BI . concat ( allNodes , self . _getAllChildren ( parentValues . concat ( [ node . value ] ) ) ) ;
} ) ;
var lastFind ;
BI . each ( allNodes , function ( idx , node ) {
var valueMap = dealWithSelectedValue ( node . parentValues , selectedValues ) ;
// REPORT-24409 fix: 设置节点全部展开,添加的节点没有给状态
var parentCheckState = { } ;
var find = BI . find ( result , function ( idx , pNode ) {
return pNode . id === node . pId ;
} ) ;
if ( find ) {
parentCheckState . checked = find . halfCheck ? false : find . checked ;
parentCheckState . half = find . halfCheck ;
// 默认展开也需要重置父节点的halfCheck
if ( BI . isNotNull ( lastFind ) && ( lastFind !== find || allNodes . length - 1 === idx ) ) {
lastFind . half = lastFind . halfCheck ;
lastFind . halfCheck = false ;
}
}
lastFind = find ;
var state = getCheckState ( node . value , node . parentValues , valueMap , parentCheckState ) ;
result . push ( {
id : node . id ,
pId : node . pId ,
value : node . value ,
text : node . text ,
times : 1 ,
isParent : node . getChildrenLength ( ) > 0 ,
checked : state [ 0 ] ,
halfCheck : state [ 1 ] ,
open : self . options . open ,
disabled : node . disabled ,
title : node . title || node . text ,
warningTitle : node . warningTitle ,
} ) ;
} ) ;
}
}
getResult ( parentValues , checkState ) ;
// 如果指定节点全部打开
// if (o.open) {
// var allNodes = [];
// // 获取所有节点
// BI.each(nodes, function (idx, node) {
// allNodes = BI.concat(allNodes, self._getAllChildren(parentValues.concat([node.value])));
// });
// var lastFind;
// BI.each(allNodes, function (idx, node) {
// var valueMap = dealWithSelectedValue(node.parentValues, selectedValues);
// // REPORT-24409 fix: 设置节点全部展开,添加的节点没有给状态
// var parentCheckState = {};
// var find = BI.find(result, function (idx, pNode) {
// return pNode.id === node.pId;
// });
// if (find) {
// parentCheckState.checked = find.halfCheck ? false : find.checked;
// parentCheckState.half = find.halfCheck;
// // 默认展开也需要重置父节点的halfCheck
// if (BI.isNotNull(lastFind) && (lastFind !== find || allNodes.length - 1 === idx)) {
// lastFind.half = lastFind.halfCheck;
// lastFind.halfCheck = false;
// }
// }
// lastFind = find;
// var state = getCheckState(node.value, node.parentValues, valueMap, parentCheckState);
// result.push({
// id: node.id,
// pId: node.pId,
// value: node.value,
// text: node.text,
// times: 1,
// isParent: node.getChildrenLength() > 0,
// checked: state[0],
// halfCheck: state[1],
// open: true,
// disabled: node.disabled,
// title: node.title || node.text,
// warningTitle: node.warningTitle,
// });
// });
// }
// 深层嵌套的比较麻烦,这边先实现的是在根节点添加
// 深层嵌套的比较麻烦,这边先实现的是在根节点添加
if ( parentValues . length === 0 && times === 1 ) {
if ( parentValues . length === 0 && times === 1 ) {
result = BI . concat ( self . _getAddedValueNode ( parentValues , selectedValues ) , result ) ;
result = BI . concat ( self . _getAddedValueNode ( parentValues , selectedValues ) , result ) ;
@ -603,17 +614,17 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
BI . nextTick ( function ( ) {
BI . nextTick ( function ( ) {
callback ( {
callback ( {
items : result ,
items : result ,
hasNext : nodes . length > times * self . _const . perPage
hasNext : self . _getChildren ( parentValues ) . length > times * self . _const . perPage
} ) ;
} ) ;
} ) ;
} ) ;
function judgeState ( parentValues , selected _value , checkState ) {
// function judgeState(parentValues, selected_value, checkState) {
var checked = checkState . checked , half = checkState . half ;
// var checked = checkState.checked, half = checkState.half;
if ( parentValues . length > 0 && ! checked ) {
// if (parentValues.length > 0 && !checked) {
return false ;
// return false;
}
// }
return ( parentValues . length === 0 || ( checked && half ) && ! BI . isEmpty ( selected _value ) ) ;
// return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value));
}
// }
function dealWithSelectedValue ( parentValues , selectedValues ) {
function dealWithSelectedValue ( parentValues , selectedValues ) {
var valueMap = { } , parents = ( parentValues || [ ] ) . slice ( 0 ) ;
var valueMap = { } , parents = ( parentValues || [ ] ) . slice ( 0 ) ;
@ -840,6 +851,40 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, {
return this . _getChildren ( parentValues ) . length ;
return this . _getChildren ( parentValues ) . length ;
} ,
} ,
assertSelectedValue : function ( selectedValues , items = [ ] ) {
if ( BI . isPlainObject ( selectedValues ) ) {
return selectedValues ;
}
var tree = BI . Tree . transformToTreeFormat ( items ) ;
var value2ParentMap = { } ;
BI . Tree . traversal ( tree , function ( index , node , pNode ) {
value2ParentMap [ node . value ] = pNode ;
} ) ;
var result = { } ;
BI . each ( selectedValues , function ( index , value ) {
var curr = value ;
var parentPath = [ ] ;
while ( curr ) {
parentPath . unshift ( curr ) ;
curr = value2ParentMap [ curr ] ? . value ;
}
BI . each ( parentPath , function ( index ) {
if ( BI . isNull ( BI . get ( result , parentPath . slice ( 0 , index + 1 ) ) ) ) {
BI . set ( result , parentPath . slice ( 0 , index + 1 ) , { } ) ;
}
} ) ;
// 执行完一条路径,check一下
var lengths = BI . size ( BI . get ( result , parentPath . slice ( 0 , - 1 ) ) ) ;
if ( lengths === value2ParentMap [ value ] ? . children ? . length ) {
BI . set ( result , parentPath . slice ( 0 , - 1 ) , { } ) ;
}
} ) ;
return result ;
} ,
buildCompleteTree : function ( selectedValues ) {
buildCompleteTree : function ( selectedValues ) {
var self = this ;
var self = this ;
var result = { } ;
var result = { } ;