fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
7.5 KiB

7 years ago
/**
* guy
* 二级树
* @class BI.PlatformLevelTree
* @extends BI.Select
*/
BI.PlatformLevelTree = BI.inherit(BI.Widget, {
props: {
baseCls: "platform-level-tree",
itemsCreator: BI.emptyFn
},
render: function () {
var self = this, o = this.options;
this.tree = BI.createWidget({
type: "bi.custom_tree",
element: this,
expander: {
type: "bi.select_tree_expander",
isDefaultInit: false,
el: {},
popup: {
type: "bi.custom_tree"
}
},
itemsCreator: function (op, callback) {
o.itemsCreator(op, function (items) {
7 years ago
callback(self._formatItems(items));
});
7 years ago
},
el: {
type: "bi.loader",
next: false,
el: {
type: "bi.button_tree",
chooseType: 0,
layouts: [{
type: "bi.vertical"
}]
}
}
});
this.tree.on(BI.CustomTree.EVENT_CHANGE, function () {
self.fireEvent(BI.PlatformLevelTree.EVENT_CHANGE, arguments);
7 years ago
});
7 years ago
},
_formatItems: function (nodes) {
var self = this;
BI.each(nodes, function (i, node) {
var extend = {};
if (node.isParent === true || BI.isNotEmptyArray(node.children)) {
switch (i) {
case 0 :
extend.type = "bi.multilayer_select_tree_first_plus_group_node";
break;
case nodes.length - 1 :
extend.type = "bi.multilayer_select_tree_last_plus_group_node";
break;
default :
extend.type = "bi.multilayer_select_tree_mid_plus_group_node";
break;
}
BI.defaults(node, extend);
} else {
switch (i) {
case nodes.length - 1:
extend.type = "bi.multilayer_single_tree_last_tree_leaf_item";
break;
default :
extend.type = "bi.multilayer_single_tree_mid_tree_leaf_item";
}
BI.defaults(node, extend);
}
});
return nodes;
},
populate: function () {
this.tree.populate();
},
getValue: function () {
return this.tree.getValue();
}
});
BI.PlatformLevelTree.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.platform_level_tree", BI.PlatformLevelTree);
BI.DemoLevelTree = BI.inherit(BI.Widget, {
render: function () {
var self = this;
return {
type: "bi.vtape",
items: [{
el: {
type: "bi.platform_level_tree",
ref: function () {
self.tree = this;
},
itemsCreator: function (op, callback) {
7 years ago
if (!op.node) {// 根节点
7 years ago
callback([{
7 years ago
id: 1,
pId: 0,
7 years ago
text: "A",
value: 1,
isParent: true
}, {
7 years ago
id: 2,
pId: 0,
text: "B",
7 years ago
value: 2,
isParent: true,
7 years ago
open: true
7 years ago
}]);
7 years ago
} else {
if (op.node.id == 1) {
callback([
{
7 years ago
id: 11,
pId: 1,
text: "test11",
7 years ago
value: 11,
layer: 1,
isParent: true
},
{
7 years ago
id: 12,
pId: 1,
text: "test12",
7 years ago
value: 12,
7 years ago
layer: 1
7 years ago
},
{
7 years ago
id: 13,
pId: 1,
text: "test13",
7 years ago
value: 13,
7 years ago
layer: 1
7 years ago
},
{
7 years ago
id: 14,
pId: 1,
text: "test14",
7 years ago
value: 14,
layer: 1,
height: 35
},
{
7 years ago
id: 15,
pId: 1,
text: "test15",
7 years ago
value: 15,
7 years ago
layer: 1
7 years ago
},
{
7 years ago
id: 16,
pId: 1,
text: "test16",
7 years ago
value: 16,
7 years ago
layer: 1
7 years ago
},
7 years ago
{id: 17, pId: 1, text: "test17", layer: 1, value: 17}
]);
7 years ago
} else if (op.node.id == 2) {
callback([{
7 years ago
id: 21,
pId: 2,
text: "test21",
7 years ago
value: 21,
7 years ago
layer: 1
7 years ago
},
7 years ago
{
id: 22,
pId: 2,
text: "test22",
value: 22,
layer: 1
}]);
7 years ago
} else if (op.node.id == 11) {
callback([{
7 years ago
id: 111,
pId: 11,
text: "test111",
7 years ago
value: 111,
7 years ago
layer: 2
7 years ago
}]);
7 years ago
}
}
}
}
}, {
el: {
type: "bi.button",
text: "确定",
handler: function () {
BI.Msg.toast(JSON.stringify(self.tree.getValue()));
}
},
height: 25
}]
7 years ago
};
7 years ago
},
mounted: function () {
}
});
BI.shortcut("demo.platform_level_tree", BI.DemoLevelTree);