Bläddra i källkod

Adjust Bills Calculate

MaiXinRong 7 år sedan
förälder
incheckning
43de7d72b1

+ 40 - 17
web/building_saas/main/js/calc/bills_calc.js

@@ -40,7 +40,10 @@ let nodeCalcObj = {
     sumTotalFee: function() {
         let result = 0, child;
         for (child of this.node.children) {
-            result += this.getFee(child.data, this.field.totalFee);
+            let value = this.getFee(child.data, this.field.totalFee);
+            if (Object.prototype.toString.apply(value) === "[object String]") {
+                result += parseFloat(this.getFee(child.data, this.field.totalFee));
+            }
         }
         return result;
     },
@@ -48,6 +51,9 @@ let nodeCalcObj = {
         let result = 0, child, qty;
         result = this.sumTotalFee(this.field);
         qty = this.getFee(this.node.data, 'quantity');
+        if (Object.prototype.toString.apply(qty) === "[object String]") {
+            qty = parseFloat(qty);
+        }
         if (qty !== 0) {
             result = result / qty;
         }
@@ -58,11 +64,22 @@ let nodeCalcObj = {
     },
     rationContentUnitFee: function () {
         let result = 0, child, qty = this.getFee(this.node.data, 'quantity');
+        if (Object.prototype.toString.apply(qty) === "[object String]") {
+            qty = parseFloat(qty);
+        }
         if (qty === 0) {
             qty = 1;
         }
         for (child of this.node.children) {
-            result += (this.getFee(child.data, this.field.unitFee) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
+            let childUnitFee = this.getFee(child.data, this.field.unitFee);
+            if (Object.prototype.toString.apply(childUnitFee) === "[object String]") {
+                childUnitFee = parseFloat(childUnitFee);
+            }
+            let childQuantity = this.getFee(child.data, 'quantity');
+            if (Object.prototype.toString.apply(childQuantity) === "[object String]") {
+                childQuantity = parseFloat(childQuantity);
+            }
+            result += (childUnitFee * childQuantity / qty).toDecimal(this.digit);
         }
         return result;
     }
@@ -220,21 +237,26 @@ class BillsCalcHelper {
     constructor (project, CalcFlag) {
         this.project = project;
         this.CalcFlag = CalcFlag;
-        switch (this.CalcFlag) {
-            case rationContent:
-                this.calcField = rationContentCalcFields;
-                break;
-            case rationPrice:
-                this.calcField = rationPriceCalcFields;
-                break;
-            case rationPriceConverse:
-                this.calcField = rationPriceConverseCalcFields;
-                break;
-            case billsPrice:
-                this.calcField = billsPriceCalcFields;
-                break;
-            default:
-                this.calcField = [];
+        this.calcField = JSON.parse(JSON.stringify(feeType));
+        for (let field of this.calcField) {
+            // unitFeeCalcFlag
+            if (this.calcFlag === rationContent) {
+                field.unitFeeFlag = rationContentUnitFeeFlag;
+            } else if ( this.calcFlag === billsPrice) {
+                field.unitFeeFlag = billsPriceUnitFeeFlag;
+            } else {
+                field.unitFeeFlag = averageQtyUnitFeeFlag;
+            }
+            // totalFeeCalcFlag
+            if (field.type === 'common') {
+                if (this.CalcFlag === rationPriceConverse) {
+                    field.totalFeeFlag = sumTotalFeeFlag;
+                } else {
+                    field.totalFeeFlag = totalFeeFlag;
+                }
+            } else {
+                field.totalFeeFlag = sumTotalFeeFlag;
+            }
         }
         this.InitFields(this.calcField);
     };
@@ -287,6 +309,7 @@ class BillsCalcHelper {
                     node.data.feesIndex[field.type].totalFee = 0;
             }
         }
+        console.log(node.data);
     };
     calcVolumePriceLeaf (node, fields) {
 

+ 1 - 10
web/building_saas/main/js/controllers/project_controller.js

@@ -104,18 +104,9 @@ ProjectController = {
         }
     },
     calculateAll: function (project, sheetController, CalcType) {
-        let date0 = new Date();
-        let ration_calc = new RationCalcHelper(project);
-        ration_calc.calculateAll();
-        let date1 = new Date();
-        console.log(date1 - date0);
         let calc = new BillsCalcHelper(project, CalcType);
         calc.calcAll();
-        calc = null;
-        let date2 = new Date();
-        console.log(date2 - date1);
         sheetController.showTreeData();
-        let date3 = new Date();
-        console.log(date3 - date1);
+        calc = null;
     }
 }

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

@@ -139,4 +139,4 @@ $('#column').on('hide.bs.modal', function () {
     }
     SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
     projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
-})
+});