chenshilong 7 years ago
parent
commit
14bbf0d765

+ 41 - 0
web/building_saas/main/js/models/calc_program.js

@@ -192,6 +192,7 @@ let calcTools = {
     },
     // 参数fieldName值: 'common.totalFee'、'equipment.unitFee'
     getFee: function (treeNode, fieldName) {
+        if (!treeNode) return 0;
         let ns = fieldName.split(".");
         if (ns.length != 2)
             return 0
@@ -562,6 +563,46 @@ let analyzer = {
         str = str.replace(/f/g, "F");               // f换成F
         return str;
     },
+    isLegal: function (expr) {
+        let me = this;
+        let stdExpr = me.standard(expr);
+
+        let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]F%]/g;
+        if (invalidChars.test(stdExpr)){
+            alert('表达式中含有无效的字符!');
+            return false;
+        };
+
+        let pattCn = new RegExp(/[\u4E00-\u9FA5]+/gi);
+        let arrCn = stdExpr.match(pattCn);
+        let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
+        let arrBase = stdExpr.match(pattBase);
+        if (arrCn.length != arrBase.length){
+            alert('定额基数必须用“[]”括起来!');
+            return false;
+        };
+
+        for (let base of arrBase){
+            let baseName = base.slice(1, -1);
+            if (!rationCalcBases[baseName]){
+                alert('定额基数“' + baseName + '”末定义!');
+                return false;
+            }
+        };
+
+        let pattF = new RegExp(/F\d+/gi);
+        let arrF = s.match(pattF);
+        for (let F of arrF){
+            let num = F.slice(1);
+            if (num > me.calcTemplate.calcItems.length){
+                alert('表达式中 “F'+ num +'” 引用行号无效!');
+                return false;
+            };
+            let id = me.calcTemplate.calcItems[num - 1].ID;
+        };
+
+        // 循环计算
+    },
 
     analyzeCalcBase: function(expr){
         // 前提:必须无空格、无特殊符号

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

@@ -49,7 +49,7 @@ let MainTreeCol = {
         },
         marketPrice:function (node) {
             if((node.sourceType === projectObj.project.Ration.getSourceType()&&node.data.type!=rationType.ration)||node.sourceType==projectObj.project.ration_glj.getSourceType()){
-                return assistCalcer.uiGLJPrice(node.data.marketUnitFee);
+                return calcTools.uiGLJPrice(node.data.marketUnitFee);
             }
         }
     },