Browse Source

修复新建一期费用计算式bug

laiguoran 5 years ago
parent
commit
9959a75fb4
1 changed files with 11 additions and 11 deletions
  1. 11 11
      app/lib/material_calc.js

+ 11 - 11
app/lib/material_calc.js

@@ -40,18 +40,18 @@ class MaterialCalculate {
     }
 
     _calculateExpr(expr) {
-        let formula = expr;
-        for (const b of this.bases) {
-            formula = formula.replace(b.reg, b.value);
-        }
-        const percent = formula.match(this.percentReg);
-        if (percent) {
-            for (const p of percent) {
-                const v = math.eval(p.replace('%', '/100'));
-                formula = formula.replace(p, v);
-            }
-        }
         try {
+            let formula = expr;
+            for (const b of this.bases) {
+                formula = formula.replace(b.reg, b.value);
+            }
+            const percent = formula.match(this.percentReg);
+            if (percent) {
+                for (const p of percent) {
+                    const v = math.eval(p.replace('%', '/100'));
+                    formula = formula.replace(p, v);
+                }
+            }
             const value = math.eval(formula);
             return value;
         } catch (err) {