dst.defineClass("com.dst.slms.plan.annualpaymentplan.annualPaymentPlanEdit", dst.framework.coreBillBaseEdit, {
	initalizeDOM:function(){
		com.dst.slms.plan.annualpaymentplan.annualPaymentPlanEdit.superClass.initalizeDOM.call(this);
		
		var billId = $('#id').val();
		var oldId = $('#oldId').val();
		var _self = this;
		$('#editTreeGrid').treegrid({
			url:'getAccountEntryData?id='+billId+'&oldId='+oldId,    
		    idField:'id',    
		    treeField:'name',    
		    cls:'datagrid-simple',
			singleSelect:true,
			rownumbers:true,
			striped:true,
			fit:true,
			editorHeight:30,
			title:'年计划明细',
			rowStyler: function(row,index){
				if(!row.isLeaf){
					return 'background-color:#cbcccd;';
				}
			},
		    columns:[[    
		        {title:'id',field:'id',hidden:true},    
		        {field:'name',title:'科目名称',width:220},    
		        {field:'number',title:'科目编码',width:120},    
		        {field:'amount',title:'合计金额',width:60,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)}},    
		        {field:'one',title:'1月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'two',title:'2月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'three',title:'3月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'four',title:'4月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'five',title:'5月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'six',title:'6月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'seven',title:'7月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'eight',title:'8月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'nine',title:'9月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'ten',title:'10月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'eleven',title:'11月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		        {field:'twelve',title:'12月*',width:100,align:'right',formatter:function(value,rec,index){return _self.fmt_Amount(value)},editor:{type:'numberbox',options:{prompt:'请输入金额',precision:2,groupSeparator:',',min:-9999999999999,max:9999999999999}}},    
		    ]],
		    onClickCell:function(field,row){
		    	debugger;
		    	if('ADDNEW' != _self.getOperateState() && 'EDIT' != _self.getOperateState()){
		    		return;
		    	}
		    	if(_self.gridEditId){
		    		$('#editTreeGrid').treegrid('endEdit',_self.gridEditId);
		    		_self.cacl_runAmount();
		    	}
		    	if(field == 'amount' ){
		    		return;
		    	}
		    	if(!row.isLeaf){
		    		return;
		    	}
		    	$('#editTreeGrid').treegrid('beginEdit',row.id);
		    	_self.gridEditId = row.id;
		    },
		    onLoadSuccess:function(data){
		    	_self.cacl_runAmount();
		    }
		});
	},
	
	cacl_runAmount:function(){
		var rows = $('#editTreeGrid').treegrid('getData');
		var row = null;
		for (var v = 0; v < rows.length; v++) {
			row = rows[v];
			this.calAmount(row);
		}
		if(row && row.children){
			var amount = 0;
			var one = 0;
			var two = 0;
			var three = 0;
			var four = 0;
			var five = 0;
			var six = 0;
			var seven = 0;
			var eight = 0;
			var nine = 0;
			var ten = 0;
			var eleven = 0;
			var twelve = 0;
			
			for (var o = 0; o < row.children.length; o++) {
				var ro = row.children[o];
				amount = Number(amount) + Number(ro.amount);
				one = Number(one) + Number(ro.one);
				two = Number(two) + Number(ro.two);
				three = Number(three) + Number(ro.three);
				four = Number(four) + Number(ro.four);
				five = Number(five) + Number(ro.five);
				six = Number(six) + Number(ro.six);
				seven = Number(seven) + Number(ro.seven);
				eight = Number(eight) + Number(ro.eight);
				nine = Number(nine) + Number(ro.nine);
				ten = Number(ten) + Number(ro.ten);
				eleven = Number(eleven) + Number(ro.eleven);
				twelve = Number(twelve) + Number(ro.twelve);
			}
			$('#editTreeGrid').treegrid('update',{id:row.id,row:{amount:amount,one:one,two:two,three:three,four:four,five:five,
				six:six,seven:seven,eight:eight,nine:nine,ten:ten,eleven:eleven,twelve:twelve}});
		}
	},
	/**
	 * 逐级汇总父节点
	 */
	calAmount:function(rows){
		for (var v = 0; v < rows.children.length; v++) {
			var row = rows.children[v];
			if(row.children){
				var amount = 0;
				var one = 0;
				var two = 0;
				var three = 0;
				var four = 0;
				var five = 0;
				var six = 0;
				var seven = 0;
				var eight = 0;
				var nine = 0;
				var ten = 0;
				var eleven = 0;
				var twelve = 0;
				
				for (var o = 0; o < row.children.length; o++) {
					var ro = row.children[o];
					var tolAmt = Number(ro.one) + Number(ro.two) + Number(ro.three) + Number(ro.four) + Number(ro.five) + Number(ro.six) 
					+ Number(ro.seven) + Number(ro.eight) + Number(ro.nine) + Number(ro.ten) + Number(ro.eleven) + Number(ro.twelve);
					$('#editTreeGrid').treegrid('update',{id:ro.id,row:{amount:tolAmt}});
					
					amount = Number(amount) + Number(ro.amount);
					one = Number(one) + Number(ro.one);
					two = Number(two) + Number(ro.two);
					three = Number(three) + Number(ro.three);
					four = Number(four) + Number(ro.four);
					five = Number(five) + Number(ro.five);
					six = Number(six) + Number(ro.six);
					seven = Number(seven) + Number(ro.seven);
					eight = Number(eight) + Number(ro.eight);
					nine = Number(nine) + Number(ro.nine);
					ten = Number(ten) + Number(ro.ten);
					eleven = Number(eleven) + Number(ro.eleven);
					twelve = Number(twelve) + Number(ro.twelve);
				}
				
				var tolAmt = Number(one) + Number(two) + Number(three) + Number(four) + Number(five) + Number(six) 
				+ Number(seven) + Number(eight) + Number(nine) + Number(ten) + Number(eleven) + Number(twelve);
				
				$('#editTreeGrid').treegrid('update',{id:row.id,row:{amount:amount,one:one,two:two,three:three,four:four,five:five,
					six:six,seven:seven,eight:eight,nine:nine,ten:ten,eleven:eleven,twelve:twelve}});
			}
		}
	},
	
	fmt_Amount:function(value){
		var number = Number(value);
    	if(isNaN(number)) {
    		return ''
    	}else{
    		var source = String(parseFloat(value).toFixed(2)).split(".");
    		source[0] = source[0].replace(new RegExp('(\\d)(?=(\\d{3})+$)','ig'),"$1,");
    		return source.join(".");
    	}
	},
	verify: function() {
		if(this.gridEditId){
    		$('#editTreeGrid').treegrid('endEdit',this.gridEditId);
    	}
		this.cacl_runAmount();
		var rows = $('#editTreeGrid').treegrid('getData');
    	if($('#editTreeGrid_JSON').length==0){
    		$('#id').append('<input id="editTreeGrid_JSON" name="editTreeGrid_JSON" type="hidden">');
    	}
		$('#editTreeGrid_JSON').val(encodeURIComponent(JSON.stringify(rows)));
		return true;
	},
	
	project_DataChange:function(newValue,oldValue){
		var projectId = $('#marketProject').textbox('getBizValue').id;
		dst.remoteCall({
			method : "getOrg",
			async:true,  
			url: this.uipk,
			param : {projectId:projectId},
			success : function(data, textStatus) {
				if(data.admin==null){
					$("#org").textbox("setBizValue","");
				}else{
					$("#org").textbox("setBizValue",data.admin);
				}
			}
		});
	},

//	//可编辑表格值改变事件，可对表格进行值代入、带出操作
//	entry_change:function(datagridTarget,target,index,field,newValue,oldValue){
//		//获取编辑行数据
//		var row = datagridTarget.datagrid('getRows')[index];
//		row[field]=newValue;
//		var v = {};
//		if(field=='jan'||field=='feb'||field=='mar'||field=='apr'||field=='may'||field=='jun'||field=='jul'||field=='aug'||field=='sep'||field=='oct'||field=='nov'||field=='dec'){
//			//计算金额且
//			var a =row["jan"]==undefined?0:row["jan"];
//			var b =row["feb"]==undefined?0:row["feb"];
//			var c =row["mar"]==undefined?0:row["mar"];
//			var d =row["apr"]==undefined?0:row["apr"];
//			var e =row["may"]==undefined?0:row["may"];
//			var f =row["jun"]==undefined?0:row["jun"];
//			var g =row["jul"]==undefined?0:row["jul"];
//			var h =row["aug"]==undefined?0:row["aug"];
//			var i =row["sep"]==undefined?0:row["sep"];
//			var j =row["oct"]==undefined?0:row["oct"];
//			var k =row["nov"]==undefined?0:row["nov"];
//			var l =row["dec"]==undefined?0:row["dec"];
//			var xx= Number(a)+ Number(b)+ Number(c)+ Number(d)+ Number(e)+ Number(f)+ Number(g)+ Number(h)+ Number(i)+ Number(j)+ Number(k)+Number(l);
//			v["amountTotal"]=xx;
//		}
//		//更新行数据
//		datagridTarget.datagrid("updateRow",{index:index,row:v});
//	},

});