浏览代码

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/YangHuCost

zhongzewei 6 年之前
父节点
当前提交
bfc2149954

+ 31 - 12
modules/ration_glj/facade/glj_calculate_facade.js

@@ -66,7 +66,7 @@ async function calculateQuantity(query,noNeedCal,refreshRationName = false){
              }
          }
          for(let glj of gljList){//先把混凝土,砂浆,配合比有自定义消耗的挑出来
-             if(gljUtil.isConcreteType(glj.type)&& !noCustomQuantiyt(glj)) await getMixRatioMap(glj,mixRatioMap);
+             if(gljUtil.isConcreteType(glj.type)&& !noCustomQuantiyt(glj)) await getMixRatioMap(glj,gljList,coeList,assList,mixRatioMap);
          }
 
         gljList = sortRationGLJ(gljList);
@@ -140,11 +140,11 @@ function sortRationGLJ(list) {
     return list;
 }
 
-function sortBeforeCalc(list) {
-    list = _.sortByAll(list, [function (item) {
-       return gljUtil.isConcreteType(item.type)?1:2;
-    }]);
-    return list;
+async function calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList) {
+    let quantity = glj.rationItemQuantity ? scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal):0;
+    quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
+    quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
+    return quantity;
 }
 
 
@@ -164,9 +164,11 @@ async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,m
     try {
         if(noNeedCal==null){//计算顺序:辅助定额,附注条件,自定义消耗(如果有就不用前计算两项),自定义乘系数
             if(noCustomQuantiyt(glj)){
-                quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal);
-                quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
-                quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
+                quantity = await calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList);
+                let mIndex = gljUtil.getIndex(glj);
+                if(mixRatioMap[mIndex]){//组成物
+                    quantity = calcQuantityForMix(quantity,mixRatioMap[mIndex],decimal);
+                }
             }else {//对于有自定义消耗量的,并且是混凝土,浆砂,配合比 这三种类型,其组成物的消耗量要跟据自定义消耗量做相应的换算
                 quantity = glj.customQuantity;
                 result.doc.customQuantity = glj.customQuantity;
@@ -176,6 +178,7 @@ async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,m
                 quantity = scMathUtil.roundToString(quantity,decimal);
                 quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj,decimal);
             }
+            if(quantity < 0) quantity = 0;
             result.doc.quantity =scMathUtil.roundToString(quantity,decimal);
             //2019-01-03 需求修改中间过程的价格不参与计算
             //glj.quantity = quantity;//这里保存中间过程计算出来的消耗量,后面处理“+*”操作符时要用到
@@ -187,16 +190,32 @@ async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,m
     }
 }
 
-async function getMixRatioMap(glj,mixRatioMap) {//生成组成物对应的父工料机的映射表
+function calcQuantityForMix(quantity,plist,decimal) {
+    for(let pglj of plist){
+        let consumption = scMathUtil.roundForObj(pglj.consumption,decimal);
+        let customQuantity = scMathUtil.roundForObj(pglj.customQuantity,decimal);
+        let temQuantity =  scMathUtil.roundForObj(consumption * pglj.assCoeQuantity,6);
+        let pcustomQuantity = scMathUtil.roundForObj(consumption * customQuantity,6);
+        quantity = scMathUtil.roundForObj(quantity - temQuantity,6);
+        quantity = scMathUtil.roundForObj(quantity + pcustomQuantity,decimal);
+    }
+    return quantity;
+}
+
+
+async function getMixRatioMap(glj,gljList,coeList,assList,mixRatioMap) {//生成组成物对应的父工料机的映射表
+    let decimalObject = await decimal_facade.getProjectDecimal(glj.projectID);
+    let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
+    let assCoeQuantity = await calcWhenNoCustomQuantiyt(decimal,glj,gljList,coeList,assList);//计算要用父工料机经过辅助子目换算后的量
     let unitPriceFileId = await ProjectModel.getUnitPriceFileId(glj.projectID);
     let connect_key = gljUtil.getIndex(glj);
     let mixList =  await mixRatioModel.find({"unit_price_file_id":unitPriceFileId,'connect_key':connect_key})
     for(let m of mixList){
         let mkey = gljUtil.getIndex(m);
         if(mixRatioMap[mkey]){
-            mixRatioMap[mkey].push({customQuantity:glj.customQuantity,rationItemQuantity:glj.rationItemQuantity,consumption:m.consumption});
+            mixRatioMap[mkey].push({customQuantity:glj.customQuantity,assCoeQuantity:assCoeQuantity,consumption:m.consumption});
         }else {
-            mixRatioMap[mkey] = [{customQuantity:glj.customQuantity,rationItemQuantity:glj.rationItemQuantity,consumption:m.consumption}];
+            mixRatioMap[mkey] = [{customQuantity:glj.customQuantity,assCoeQuantity:assCoeQuantity,consumption:m.consumption}];
         }
     }
 }

+ 3 - 4
public/web/sheet/sheet_common.js

@@ -109,7 +109,7 @@ var sheetCommonObj = {
             area.vAlign(GC.Spread.Sheets.VerticalAlign.center);
         }
     },
-    showData: function(sheet, setting, data,distTypeTree) {
+    showData: function(sheet, setting, data,distTypeTree,callback) {//这个callback是为了在showdata后还做了引起重画表格的操作,在callback里调用能提高效率
         var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
         sheet.suspendPaint();
         sheet.suspendEvent();
@@ -159,6 +159,7 @@ var sheetCommonObj = {
             }
         }
         this.lockCells(sheet,setting);
+        if(callback) callback();
         sheet.resumeEvent();
         sheet.resumePaint();
         //me.shieldAllCells(sheet);
@@ -569,9 +570,9 @@ var sheetCommonObj = {
                     ctx.fill();//画实心圆
                     ctx.closePath();
                     ctx.restore();
+                    w = w - imageWidth - imageMagin;
                     //这里的左对齐的,当显示的字长度超过空白地方时,要改成右对齐
                     if(style.hAlign == 0){
-                        w = w - imageWidth - imageMagin;
                         if(value){
                             let textWidth = ctx.measureText(value).width;
                             let spaceWidth = w;
@@ -579,8 +580,6 @@ var sheetCommonObj = {
                                 style.hAlign = 2;
                             }
                         }
-                    }else if(style.hAlign == 2){//如果是右对齐的,往左边挪,给按钮留出空间
-                        x = x - imageWidth - imageMagin;
                     }
 
                 }

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

@@ -575,6 +575,7 @@ var gljOprObj = {
         }
     },
     showRationGLJSheetData: function (init) {
+        let me = this;
         let selected = this.sheet.getSelections();
         this.combineWithProjectGlj(this.sheetData);
         this.sheet.setRowCount(0);
@@ -582,16 +583,17 @@ var gljOprObj = {
         this.sumQuantity();//计算总消耗量
         this.addMixRatioToShow();//显示组成物信息
         this.initRationTree(init,this.getUnitPriceCodeMap());
-        sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
-        if(this.mainTreeSelectedChange == true){
-            this.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
-            this.mainTreeSelectedChange = false;
-        }else if(selected){//定位光标到之前的位置
-            this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
-        }
-        //初始选择
-        this.preGljSelection = null;
-        this.sheetInitSelection({row: this.sheet.getActiveRowIndex(), col: this.sheet.getActiveColumnIndex()});
+        sheetCommonObj.showData(this.sheet, this.setting, this.sheetData,null,function () {
+            if(me.mainTreeSelectedChange == true){
+                me.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
+                me.mainTreeSelectedChange = false;
+            }else if(selected){//定位光标到之前的位置
+                me.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
+            }
+            //初始选择
+            me.preGljSelection = null;
+            me.sheetInitSelection({row: me.sheet.getActiveRowIndex(), col: me.sheet.getActiveColumnIndex()});
+        });
 
     },
     getSelectedRationGlj:function () {

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

@@ -1949,7 +1949,7 @@ var projectObj = {
                     w = w - imageWidth - imageMagin;
                 }
             }
-            GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
+             GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
         };
         CommonTotalFeeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
             return {

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

@@ -80,7 +80,7 @@ let quantityEditObj = {
                     ctx.fill();//画实心圆
                     ctx.closePath();
                     ctx.restore();
-                    x = x - imageWidth - imageMagin;
+                    w = w - imageWidth - imageMagin;
                 }
             }
             GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);