/**
 * @author fanguozhu
 */
$(function()
{
	var tab = new TabPanel("tab",true);
	var f_tree = new Fieldset("f_tree","公司列表",{
		state: Fieldset.OPEN_STATE,
		topdown: false
	});
	
	var mytree = new PorTreeT("tree", "-1", "手机公司",{isDefaultClick:0} );
    var dw = new DataWrapper();
	dw.service("PRtree");
	mytree.dataWrapper(dw);
	
	tab.dataWrapper(dw);
	
	tab.addChangeObserver(function(src, msg){
		var dw = this.dataWrapper();
		if (!dw) return;
		var label = msg.data.label;
		var name = msg.data.name;
		for (var i=1;i<=3;i++) {
			if (label) {
				this.setTitle(i,"["+name+"]公司产品["+i+"]");
			} else {
				this.setTitle(i,"全部公司产品["+i+"]");
			}
		}
		
	},PorMessage.MSG_TREE_ONCLICK);
	
	var dw1 = new DataWrapper();
	dw1.service("PR02");
	var dw2 = new DataWrapper();
	dw2.service("PR02");
	var dw3 = new DataWrapper();
	dw3.service("PR02");
	
	var dg1 = new DataGrid("grid_1",{autoDraw:true,readonly:true});
	dg1.dataWrapper(dw1);
	
	var dg2 = new DataGrid("grid_2",{autoDraw:true,readonly:true});
	dg2.dataWrapper(dw2);
	
	var dg3 = new DataGrid("grid_3",{autoDraw:true,readonly:true});
	dg3.dataWrapper(dw3);
		
	var mapping = {
		master:["label"],
		sub:["company"]
	};
	
	PorUtil.linkTreeAndGrid( dw,[{
		sub:dw1,
		mapping:mapping,
		tabs:{
			tab:[0,1]		//配置在'tab'的第1个tab页需要加载
		}
	},{
		sub:dw2,
		mapping:mapping,
		tabs:{
			tab:[2]		//配置在'tab'的第2个tab页需要加载
		}
	},{
		sub:dw3,
		mapping:mapping,
		tabs:{
			tab:[3]		//配置在'tab'的第3个tab页需要加载
		}
	}]);

	mytree.init();
});
