|  | @@ -99,6 +99,8 @@ let defaultBillTemplate = {
 | 
	
		
			
				|  |  |      ]
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  class CalcProgram {
 | 
	
		
			
				|  |  |      constructor(project){
 | 
	
		
			
				|  |  |          this.project = project;
 | 
	
	
		
			
				|  | @@ -144,83 +146,80 @@ class CalcProgram {
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    calculate(treeNode){
 | 
	
		
			
				|  |  | +    // 计算本节点(默认同时递归计算所有父节点,可选)
 | 
	
		
			
				|  |  | +    calculate(treeNode, calcParents = true){
 | 
	
		
			
				|  |  |          let me = this;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        me.calc.calculate(treeNode);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 还原,防止出现混乱影响下次计算
 | 
	
		
			
				|  |  | -        delete treeNode.data.baseTotalPrice;
 | 
	
		
			
				|  |  | -        delete treeNode.data.gatherType;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        // 存储、刷新本结点、所有父结点
 | 
	
		
			
				|  |  | -        if (treeNode.changed) {
 | 
	
		
			
				|  |  | -            me.saveAndCalcParents(treeNode);
 | 
	
		
			
				|  |  | -            delete treeNode.changed;
 | 
	
		
			
				|  |  | -        };
 | 
	
		
			
				|  |  | -    };
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    saveAndCalcParents(treeNode) {
 | 
	
		
			
				|  |  | -        if (treeNode.parent) {
 | 
	
		
			
				|  |  | -            projectObj.converseCalculateBills(treeNode.parent);
 | 
	
		
			
				|  |  | -        };
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        let data = {ID: treeNode.data.ID, projectID: projectObj.project.ID(), fees: treeNode.data.fees};
 | 
	
		
			
				|  |  | -        let newDta = {'updateType': 'ut_update', 'updateData': data};
 | 
	
		
			
				|  |  | -        let newDataArr = [];
 | 
	
		
			
				|  |  | -        newDataArr.push(newDta);
 | 
	
		
			
				|  |  | -        projectObj.project.pushNow('', treeNode.sourceType, newDataArr);
 | 
	
		
			
				|  |  | -        projectObj.mainController.refreshTreeNode([treeNode]);
 | 
	
		
			
				|  |  | -    };
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    getCalcDatas(treeNode){
 | 
	
		
			
				|  |  | -        let me = this;
 | 
	
		
			
				|  |  | -        let rst = [];
 | 
	
		
			
				|  |  |          let isRation = treeNode.sourceType === me.project.Ration.getSourceType();
 | 
	
		
			
				|  |  |          let isBill = treeNode.sourceType === me.project.Bills.getSourceType();
 | 
	
		
			
				|  |  |          let isLeafBill = isBill && treeNode.source.children && treeNode.source.children.length === 0;
 | 
	
		
			
				|  |  |          let isBillPriceCalc = me.project.projSetting.billsCalcMode === billsPrice;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        if (isRation) {
 | 
	
		
			
				|  |  | -            //
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        if (isRation)
 | 
	
		
			
				|  |  | +            treeNode.calcType = treeNodeCalcType.ctRationCalcProgram
 | 
	
		
			
				|  |  |          else if (isLeafBill) {
 | 
	
		
			
				|  |  | -            let ct = '';
 | 
	
		
			
				|  |  |              if (treeNode.children && treeNode.children.length > 0){
 | 
	
		
			
				|  |  |                  if (treeNode.children[0].sourceType == me.project.Ration.getSourceType()){
 | 
	
		
			
				|  |  | -                    ct = childrenType.ration;
 | 
	
		
			
				|  |  | +                    if (isBillPriceCalc)                   // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算
 | 
	
		
			
				|  |  | +                        treeNode.calcType = treeNodeCalcType.ctBillCalcProgram;
 | 
	
		
			
				|  |  | +                    else                                  // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
 | 
	
		
			
				|  |  | +                        treeNode.calcType = treeNodeCalcType.ctGatherRations;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  else if (treeNode.children[0].sourceType == me.project.VolumePrice.getSourceType()){
 | 
	
		
			
				|  |  | -                    ct = childrenType.volumePrice;
 | 
	
		
			
				|  |  | +                    let value = 20000;
 | 
	
		
			
				|  |  | +                    // if (treeNode.data.feesIndex && treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.unitFee != 0)
 | 
	
		
			
				|  |  | +                    //     value = treeNode.data.feesIndex.common.unitFee;
 | 
	
		
			
				|  |  | +                    treeNode.calcType = treeNodeCalcType.ctCalcBaseValue;
 | 
	
		
			
				|  |  | +                    treeNode.calcBaseValue = value;
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            else{
 | 
	
		
			
				|  |  | -                ct = childrenType.formula;
 | 
	
		
			
				|  |  | +            else{                                          // 公式计算
 | 
	
		
			
				|  |  | +                let value = 20000;
 | 
	
		
			
				|  |  | +                // if (treeNode.data.feesIndex && treeNode.data.feesIndex.common && treeNode.data.feesIndex.common.unitFee != 0)
 | 
	
		
			
				|  |  | +                //     value = treeNode.data.feesIndex.common.unitFee;
 | 
	
		
			
				|  |  | +                treeNode.calcType = treeNodeCalcType.ctCalcBaseValue;
 | 
	
		
			
				|  |  | +                treeNode.calcBaseValue = value;
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        else if (isBill)                                 // 父清单:汇总子清单的费用类别
 | 
	
		
			
				|  |  | +            treeNode.calcType = treeNodeCalcType.ctGatherBills;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (ct == childrenType.ration){
 | 
	
		
			
				|  |  | -                if (isBillPriceCalc){                   // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算
 | 
	
		
			
				|  |  | +        me.calc.calculate(treeNode);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                else{                                   // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
 | 
	
		
			
				|  |  | -                    treeNode.data.gatherType = CP_GatherType.rations;
 | 
	
		
			
				|  |  | +        // 计算所有父结点
 | 
	
		
			
				|  |  | +        if (treeNode.changed && calcParents && treeNode.parent) {
 | 
	
		
			
				|  |  | +            me.calculate(treeNode.parent);
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 存储、刷新本节点(默认存储刷新所有父节点,可选)
 | 
	
		
			
				|  |  | +    saveNode(treeNode, saveParent = true) {
 | 
	
		
			
				|  |  | +        if (!treeNode.changed) return;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        let newDataArr = [], nodesArr = [];
 | 
	
		
			
				|  |  | +        let project = projectObj.project;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        project.beginUpdate('');
 | 
	
		
			
				|  |  | +        let curNode = treeNode;
 | 
	
		
			
				|  |  | +        while (curNode) {
 | 
	
		
			
				|  |  | +            if (curNode.changed){
 | 
	
		
			
				|  |  | +                let data = {
 | 
	
		
			
				|  |  | +                    ID: curNode.data.ID,
 | 
	
		
			
				|  |  | +                    projectID: projectObj.project.ID(),
 | 
	
		
			
				|  |  | +                    quantity: curNode.data.quantity,
 | 
	
		
			
				|  |  | +                    fees: curNode.data.fees
 | 
	
		
			
				|  |  |                  };
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else if (ct == childrenType.volumePrice){
 | 
	
		
			
				|  |  | -                let totalPrice = 10000;
 | 
	
		
			
				|  |  | -                treeNode.data.baseTotalPrice = totalPrice;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            else if (ct == childrenType.formula){
 | 
	
		
			
				|  |  | -                let totalPrice = 20000;
 | 
	
		
			
				|  |  | -                treeNode.data.baseTotalPrice = totalPrice;
 | 
	
		
			
				|  |  | +                let newDta = {'updateType': 'ut_update', 'updateData': data};
 | 
	
		
			
				|  |  | +                newDataArr.push(newDta);
 | 
	
		
			
				|  |  | +                nodesArr.push(curNode);
 | 
	
		
			
				|  |  | +                project.push(curNode.sourceType, newDataArr);
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        else if (isBill){                                   // 父清单:汇总子清单的费用类别
 | 
	
		
			
				|  |  | -            treeNode.data.gatherType = CP_GatherType.bills;
 | 
	
		
			
				|  |  | +            if (saveParent) curNode = curNode.parent
 | 
	
		
			
				|  |  | +            else break;
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  | +        project.endUpdate();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        me.calculate(treeNode);
 | 
	
		
			
				|  |  | -        rst = treeNode.data.calcTemplate.calcItems;
 | 
	
		
			
				|  |  | -        return rst;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +        for (let node of nodesArr){delete node.changed;};
 | 
	
		
			
				|  |  | +        projectObj.mainController.refreshTreeNode(nodesArr);
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  |  }
 |