|  | @@ -36,21 +36,30 @@ ProjectController = {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |      addRation: function (project, sheetController, std) {
 | 
	
		
			
				|  |  | -        if (!project || !sheetController) { return null; }
 | 
	
		
			
				|  |  | +        if (!project || !sheetController) { return; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        var selected = project.mainTree.selected;
 | 
	
		
			
				|  |  | -        var newSource = null, newNode = null;
 | 
	
		
			
				|  |  | -        if(selected==null){
 | 
	
		
			
				|  |  | -            return;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
 | 
	
		
			
				|  |  | -            if (std) {
 | 
	
		
			
				|  |  | -                newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
 | 
	
		
			
				|  |  | -                project.ration_glj.addRationGLJ(newSource,std);
 | 
	
		
			
				|  |  | +        let selected = project.mainTree.selected, newSource = null, newNode = null;
 | 
	
		
			
				|  |  | +        if (selected === null) { return; }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
 | 
	
		
			
				|  |  | +            if (selected.source.children.length > 0) {
 | 
	
		
			
				|  |  | +                alert('当前清单已有清单子项,不能套用定额。');
 | 
	
		
			
				|  |  | +            } else if (false) {
 | 
	
		
			
				|  |  | +                alert('当前清单已有公式计算,不能套用定额。');
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  | -                newSource = project.Ration.insertRation(selected.source.getID());
 | 
	
		
			
				|  |  | +                let firstChild = selected.firstChild();
 | 
	
		
			
				|  |  | +                if (firstChild && firstChild.sourceType === project.VolumePrice.getSourceType()) {
 | 
	
		
			
				|  |  | +                    alert('当前位置已有量价,不能套用定额。');
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    if (std) {
 | 
	
		
			
				|  |  | +                        newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
 | 
	
		
			
				|  |  | +                        project.ration_glj.addRationGLJ(newSource,std);
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        newSource = project.Ration.insertRation(selected.source.getID());
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
 | 
	
		
			
				|  |  |          } else if (selected.sourceType === project.Ration.getSourceType()) {
 | 
	
		
			
				|  |  |              if (std) {
 | 
	
		
			
				|  |  |                  newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
 | 
	
	
		
			
				|  | @@ -59,6 +68,8 @@ ProjectController = {
 | 
	
		
			
				|  |  |                  newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
 | 
	
		
			
				|  |  | +        } else if (selected.sourceType === project.VolumePrice.getSourceType()) {
 | 
	
		
			
				|  |  | +            alert('当前位置已有量价,不能套用定额。');
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if (newNode) {
 | 
	
		
			
				|  |  |              newNode.source = newSource;
 |