浏览代码

造价计算效率优化

zhangweicheng 4 年之前
父节点
当前提交
25c5b3b1cc

+ 29 - 16
public/web/gljUtil.js

@@ -327,9 +327,15 @@ let gljUtil = {
       let constCoe = scMathUtil.roundForObj(projectGLJDatas.constData.machineConstCoe,feeRate_decimal);
       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, labourCoeDatas, decimalObj, true, _, scMathUtil);
           if (ext && ext[tem.id] && this.isDef(ext[tem.id].marketPrice)) { //在修改组成物的价格或消耗量时,影响了父工料机的价格,这时以父工料机的价格应当用组成物的新值来记算
@@ -399,13 +405,16 @@ let gljUtil = {
     } else if (this.notEditType.indexOf(glj.unit_price.type) != -1 && glj.ratio_data.length > 0) { //对于混凝土、配合比、砂浆、机械台班,调整价根据组成物计算得出。
       let p = 0;
       for (let ratio of glj.ratio_data) {
-        let tem = _.find(projectGLJDatas.gljList, {
-          'code': ratio.code,
-          'name': ratio.name,
-          'specs': ratio.specs,
-          'type': ratio.type,
-          'unit': ratio.unit
-        })
+        let rIndex = gljUtil.getIndex(ratio);
+        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);
@@ -438,13 +447,17 @@ let gljUtil = {
   getIndex(obj, pops) {
     let t_index = '';
     let k_arr = [];
-    if (!this.isDef(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) pops = this.gljKeyArray;
+    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;
   },
 
   getMainType: function (type) {

+ 34 - 9
public/web/scMathUtil.js

@@ -170,19 +170,41 @@ let scMathUtil = {
     isNumber : function (obj) {
         return obj === +obj;
     },
+    floatLength:function(num){
+        let lenght = 0;
+        let str =`${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;
@@ -223,5 +245,8 @@ 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);
 };

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

@@ -30,9 +30,14 @@ $(function () {
     });
 
     $('#tab_report').on('shown.bs.tab', function(e){
-        projectObj.project.calcProgram.doTenderCalc();   // 进入报表前先自动调价计算一遍
         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(){

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

@@ -957,7 +957,7 @@
    // 界面显示的工料机数量。参数 quantity 传入一个普通的数量数值即可。
    uiGLJQty: function (quantity) {
      if (quantity)
-       return parseFloat(quantity).toDecimal(decimalObj.glj.quantity)
+       return  scMathUtil.roundForObj(quantity,decimalObj.glj.quantity);//parseFloat(quantity).toDecimal(decimalObj.glj.quantity)
      else return 0;
    },
    hasTargetTotalFee: function (treeNode) { // targetTotalFee 有时为字符串“0”,此种情况会执行if 条件引起逻辑错误。所以这里封闭成方法直接调用。

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

@@ -75,6 +75,10 @@ ProjectGLJ.prototype.synLoadData = function () {
 
 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;
+    }
 }
 
 
@@ -1780,6 +1784,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

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

+ 11 - 4
web/building_saas/main/js/views/glj_view.js

@@ -738,7 +738,7 @@ var gljOprObj = {
                     if(ration) gljOprObj.getTotalQuantity(ration_gljs[i], ration);
                 }else {
                     //计算程序中量价也会放到这里进来,量价是没有对应的项目工料机的
-                    if(ration_gljs[i].type != rationType.volumePrice) console.log("没有找到工料机:"+ration_gljs[i].name)
+                    //if(ration_gljs[i].type != rationType.volumePrice) console.log("没有找到工料机:"+ration_gljs[i].name)
                 }
             }
         }
@@ -801,9 +801,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 = {
                     projectGLJID: pg.id,

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

@@ -1619,7 +1619,11 @@ 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) {