소스 검색

改名字,使清单定额通用计算程序。

Chenshilong 8 년 전
부모
커밋
f45c05a113

+ 18 - 19
public/calc_util.js

@@ -4,11 +4,11 @@
  */
 
 let executeObj = {
-    ration: null,
+    treeNode: null,
     at: function(ID) {
         let me = executeObj,
             rst = 0;
-        rst = me.ration.data.calcTemplate.compiledTemplate[ID].unitFee;
+        rst = me.treeNode.data.calcTemplate.compiledTemplate[ID].unitFee;
         rst = parseFloat(rst);
         return rst;
     },
@@ -18,7 +18,7 @@ let executeObj = {
 
         if (base != null) {
             let price = 0, tmpSum = 0;
-            for (let glj of me.ration.data.gljList) {
+            for (let glj of me.treeNode.data.gljList) {
                 if (base.gljTypes.indexOf(glj.type) >= 0) {
                     if (base.calcType == baseCalc){ price = glj["basePrice"];}
                     else if (base.calcType == adjustCalc){price = glj["adjustPrice"];}
@@ -159,17 +159,17 @@ class Calculation {
         }
     };
 
-    calculate($RATION){         // 参数$RATION也可以是清单
+    calculate($treeNode){
         let me = this;
-        let template = $RATION.data.calcTemplate;
+        let template = $treeNode.data.calcTemplate;
 
-        if ($RATION && template.hasCompiled) {
+        if ($treeNode && template.hasCompiled) {
             let $CE = executeObj;
-            $CE.ration = $RATION;
+            $CE.treeNode = $treeNode;
 
-            if (!$RATION.fees) {
-                $RATION.fees = [];
-                $RATION.feesIndex = {};
+            if (!$treeNode.fees) {
+                $treeNode.fees = [];
+                $treeNode.feesIndex = {};
             };
 
             for (let idx of template.compiledSeq) {
@@ -182,11 +182,13 @@ class Calculation {
                     calcItem.feeRate = feeRate;
                 };
                 calcItem.unitFee = eval(calcItem.compiledExpr) * feeRate * 0.01;   // 如果eval()对清单树有影响,就换成小麦的Expression对象再试
-                calcItem.totalFee = calcItem.unitFee * 3;     // AAAAAA 测试值,因目前定额无数量(保存不上) $RATION.data.Quantity
+                let quantity = $treeNode.data.quantity;
+                if (!quantity) quantity = 0;
+                calcItem.totalFee = calcItem.unitFee * quantity;
 
                 // 费用同步到定额
                 // 引入小麦的字段检测后,快速切换定额出现计算卡顿现象,过多的循环造成。这里把她的代码拆出来,减少微循环。
-                if (!$RATION.feesIndex[calcItem.fieldName]){
+                if (!$treeNode.feesIndex[calcItem.fieldName]){
                     let fee = {
                         'fieldName': calcItem.fieldName,
                         'unitFee': calcItem.unitFee,
@@ -194,17 +196,14 @@ class Calculation {
                         'tenderUnitFee': 0,
                         'tenderTotalFee': 0
                     };
-                    $RATION.fees.push(fee);
-                    $RATION.feesIndex[calcItem.fieldName] = fee;
+                    $treeNode.fees.push(fee);
+                    $treeNode.feesIndex[calcItem.fieldName] = fee;
                 }
                 else{
-                    $RATION.feesIndex[calcItem.fieldName].unitFee = calcItem.unitFee;
-                    $RATION.feesIndex[calcItem.fieldName].totalFee = calcItem.totalFee;
+                    $treeNode.feesIndex[calcItem.fieldName].unitFee = calcItem.unitFee;
+                    $treeNode.feesIndex[calcItem.fieldName].totalFee = calcItem.totalFee;
                 }
             }
         }
     }
 }
-
-
-//module.exports = new calculation();

+ 5 - 5
web/building_saas/main/js/models/calc_program.js

@@ -3592,7 +3592,7 @@ let calcLabourCoes = [
     }
 ];
 
-class RationProgram {
+class CalcProgram {
     constructor(project){
         this.project = project;
         this.calc = new Calculation();
@@ -3608,9 +3608,9 @@ class RationProgram {
        this.calc.compile(calcTemplate, calcFeeRates, calcLabourCoes);
     };
 
-    calculate(ration){
-        ration.data.gljList = this.project.ration_glj.getGljArrByRation(ration.data.ID);
-        ration.data.calcTemplate = calcTemplates[0];  // AAAAAA = getCalcTemplate($RATION.calcTemplateID);
-        this.calc.calculate(ration);
+    calculate(treeNode){
+        treeNode.data.gljList = this.project.ration_glj.getGljArrByRation(treeNode.data.ID);
+        treeNode.data.calcTemplate = calcTemplates[0];  // AAAAAA = getCalcTemplate($RATION.calcTemplateID);
+        this.calc.calculate(treeNode);
     };
 }

+ 1 - 1
web/building_saas/main/js/views/calc_program_view.js

@@ -235,7 +235,7 @@ let calcProgramObj = {
     showData: function (treeNode) {
         var me = this;
         me.treeNode = treeNode;
-        projectObj.project.rationProgram.calculate(treeNode);
+        projectObj.project.calcProgram.calculate(treeNode);
         me.datas = me.treeNode.data.calcTemplate.calcItems;
         //me.sheet.setRowCount(me.datas.length);
         sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);

+ 2 - 2
web/building_saas/main/js/views/project_view.js

@@ -168,8 +168,8 @@ var projectObj = {
 
             }
         });
-        this.project.rationProgram = new RationProgram(this.project);
-        this.project.rationProgram.compileAllTemps();
+        this.project.calcProgram = new CalcProgram(this.project);
+        this.project.calcProgram.compileAllTemps();
     },
     loadMainSpreadContextMenu: function () {
         var project = this.project, spread = this.mainSpread, controller = this.mainController;