Browse Source

造价计算效率优化

zhangweicheng 4 years ago
parent
commit
5702c3ea0b

+ 29 - 11
public/web/gljUtil.js

@@ -218,9 +218,16 @@ let gljUtil = {
             let p =0;
             for(let ratio of glj.ratio_data){
                 let rIndex = gljUtil.getIndex(ratio);
-                let tem =  _.find(projectGLJDatas.gljList,function(item){
-                    return rIndex == gljUtil.getIndex(item)
-                });
+                let tem = null;
+                if(projectGLJDatas.gljMap){
+                    tem = projectGLJDatas.gljMap[rIndex]
+                }
+                if(!tem){
+                    tem =  _.find(projectGLJDatas.gljList,function(item){
+                        return rIndex == gljUtil.getIndex(item)
+                    });
+                }
+              
                 if(tem){
                     let tem_marketPrice = this.getMarketPrice(tem,projectGLJDatas,calcOptions,decimalObj,true,_,scMathUtil);  //let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
                     let temP = scMathUtil.roundForObj(
@@ -282,9 +289,15 @@ let gljUtil = {
             let p =0;
             for(let ratio of glj.ratio_data){
                 let rIndex = gljUtil.getIndex(ratio);
-                let tem =  _.find(projectGLJDatas.gljList,function(item){
-                    return rIndex == gljUtil.getIndex(item);
-                });
+                let tem = null;
+                if(projectGLJDatas.gljMap){
+                    tem = projectGLJDatas.gljMap[rIndex]
+                }
+                if(!tem){
+                    tem =  _.find(projectGLJDatas.gljList,function(item){
+                        return rIndex == gljUtil.getIndex(item);
+                    });
+                }
                 if(tem){
                     let priceData=this.getGLJPrice(tem,projectGLJDatas,calcOptions,labourCoeDatas,decimalObj,true,_,scMathUtil);
                     let temP = scMathUtil.roundForObj(priceData.adjustPrice*scMathUtil.roundForObj(ratio.consumption,quantity_decimal),process_decimal);
@@ -318,12 +331,17 @@ let gljUtil = {
         let t_index = '';
         let k_arr = [];
         if(!pops) pops = this.gljKeyArray;
-        for (let p of pops) {
-            let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
-            k_arr.push(tmpK);
+        if(pops.length === 5){
+            return `${obj[pops[0]]}|-|${obj[pops[1]]}|-|${obj[pops[2]]}|-|${obj[pops[3]]}|-|${obj[pops[4]]}`
+        }else{
+            for (let p of pops) {
+                let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
+                k_arr.push(tmpK);
+            }
+            t_index = k_arr.join("|-|");
+            return t_index;
         }
-        t_index = k_arr.join("|-|");
-        return t_index;
+        
     },
     getGljTypeSeq:function () {
         let gljType = this.gljType;

+ 35 - 9
public/web/scMathUtil.js

@@ -170,19 +170,44 @@ let scMathUtil = {
     isNumber : function (obj) {
         return obj === +obj;
     },
+
+    floatLength:function(num){
+        let lenght = 0;
+        let str =`${num}`;//me.isNumber(num)?num+"":num;
+        let sub = str.split(".")
+        if(sub.length == 2){
+            return sub[1].length;
+        }
+        return lenght
+    },
+
+    innerRound:function(num,lenght,decimal){
+        let value;
+        let pre = 1;
+        if(lenght === 0) return num;
+        if(num<0) pre = -1;//负数的时候先变成正数
+        num = num*pre;
+        let n = Math.pow(10,lenght);
+        value = Math.round(num * n)
+        if(lenght <= decimal){
+            return value/n*pre
+        }else{
+            value = Math.round(value/Math.pow(10,lenght-decimal))
+            return value/Math.pow(10,decimal)*pre
+        }
+    },
+
     roundForObj:function(obj,decimal){
         let me = this;
-        let value;
         if(obj === undefined || obj === null || isNaN(obj)) return 0;
-        let n = Math.pow(10,decimal);
+        let lenght = 10;
+        let value;
         if(me.isNumber(obj)){
-          value = Math.round(obj * n) / n;
-          //value = me.roundTo(obj,-decimal)
-        }else {
-          value = Math.round(Number(obj) * n) / n;
-          //value = me.roundTo(Number(obj),-decimal);
+            value =  me.innerRound(obj,lenght,decimal);
+        }else{
+            value = me.innerRound(Number(obj),lenght,decimal);
         }
-        return value
+        return value;
     },
     roundToString:function(obj,decimal){
         let me = this;
@@ -222,5 +247,6 @@ Number.prototype.toDecimal = function (ADigit) {
     // var s = scMathUtil.roundTo(this, digit);
     // console.log('Number: ' + this + '   Digit: ' + digit + '    Result: ' + s);
     // return parseFloat(s);
-    return scMathUtil.roundTo(this, digit);
+    //scMathUtil.roundTo(this, digit);
+    return scMathUtil.roundForObj(this, -digit); 
 };

+ 8 - 2
web/building_saas/main/js/main.js

@@ -30,10 +30,16 @@ $(function () {
         //refreshSubSpread();
     });
 
-    $('#tab_report').on('shown.bs.tab', function(e){
-        projectObj.project.calcProgram.doTenderCalc();   // 进入报表前先自动调价计算一遍
+    $('#tab_report').on('shown.bs.tab', function(e){   
         sessionStorage.setItem('mainTab', '#tab_report');
         autoFlashHeight();
+        $.bootstrapLoading.start();
+        setTimeout(function(){
+            projectObj.project.calcProgram.doTenderCalc();   // 进入报表前先自动调价计算一遍
+            $.bootstrapLoading.end();
+        }, 100);
+       
+    
     });
     let mainResizeEles = getMainResizeEles();
     SlideResize.verticalSlide(mainResizeEles.eleObj, mainResizeEles.limit, function(){

+ 8 - 0
web/building_saas/main/js/models/project_glj.js

@@ -1,3 +1,5 @@
+
+
 /**
  * 工料机汇总相关数据
  *
@@ -82,6 +84,11 @@ ProjectGLJ.prototype.refreshByDatas = function(datas){
 
 ProjectGLJ.prototype.loadToCache = function (data) {
     this.datas = data;
+    this.datas.gljMap =  {};
+    for(let g of this.datas.gljList){
+       this.datas.gljMap[gljUtil.getIndex(g)]=g;
+    }
+
 }
 
 /**
@@ -1001,6 +1008,7 @@ ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新
     let uIndex = gljUtil.getIndex(data.unit_price);
     if(!unitPriceMap[uIndex])  unitPriceMap[uIndex] = data.unit_price;
     this.datas.gljList.push(data);
+    this.datas.gljMap[gljUtil.getIndex(data)]= data;
     IDMap[data.id] = data;
     return data;
 };

+ 1 - 1
web/building_saas/main/js/models/ration_glj.js

@@ -102,7 +102,7 @@ let ration_glj = {
                 }
             }
 
-            result = gljOprObj.combineWithProjectGlj(result);
+            result = gljOprObj.combineWithProjectGlj(result,false);
 
             if (!needOneBill) return result;
 

+ 10 - 3
web/building_saas/main/js/views/glj_view.js

@@ -855,9 +855,16 @@ var gljOprObj = {
         var temRationGLJs = [];
         for (var i = 0; i < mixRatioList.length; i++) {
             let mIndex = gljOprObj.getIndex(mixRatioList[i],gljKeyArray);
-            var pg = _.find(projectGljs, function (item) {
-                return gljOprObj.getIndex(item,gljKeyArray) == mIndex
-            });//改关联关系
+            let pgljMap = projectObj.project.projectGLJ.datas.gljMap;
+            let pg = null;
+            if(pgljMap){
+                pg = pgljMap[mIndex];
+            }
+            if(!pg){//兼容旧数据,以防万一
+                pg = _.find(projectGljs, function (item) {
+                    return gljOprObj.getIndex(item,gljKeyArray) == mIndex
+                });//改关联关系
+            }
             if(pg){
                 let tem = {
                     mixRatioId:mixRatioList[i].id,

+ 6 - 1
web/building_saas/main/js/views/project_view.js

@@ -1761,7 +1761,12 @@ var projectObj = {
                     name: '造价计算',
                     icon: 'fa-calculator',
                     callback: function () {
-                        project.calcProgram.calcAllNodesAndSave();
+                        $.bootstrapLoading.start();
+                        setTimeout(function(){
+                            project.calcProgram.calcAllNodesAndSave();
+                            $.bootstrapLoading.end();
+                        },100)
+                        
                     },
                     disabled: function () {
                         if (projectReadOnly) {