Переглянути джерело

定额工料机,组成物增删,修改

zhangweicheng 5 роки тому
батько
коміт
caf8860ba0

+ 18 - 0
modules/glj/controllers/glj_controller.js

@@ -63,6 +63,24 @@ class GLJController extends BaseController {
             callback(result.err,consts.projectConst.PROJECTGLJ,result.data);
         })
     }
+    async updateRatio(request, response) {
+      let data = JSON.parse(request.body.data);
+      let model = new MixRatioModel();
+      if(data.type == 'delete'){
+        await model.deleteById(data.id);
+      }else{
+        await model.updateById(data.id, data.doc);
+      }
+      let unitPriceUpdate = {
+        base_price: data.base_price,
+          market_price: data.market_price
+      };
+      let unitPriceModel = new UnitPriceModel();
+      let unitPriceResult = await unitPriceModel.updatePrice({id:data.pid}, unitPriceUpdate);
+      response.json(unitPriceResult);
+    }
+
+
 
     /**
      * 更新数据

+ 1 - 0
modules/glj/routes/glj_router.js

@@ -15,6 +15,7 @@ let gljController = new GLJController();
 // action定义区域
 router.post('/getData', gljController.init, gljController.getGljList);
 router.post('/update', gljController.init, gljController.updateData);
+router.post('/updateRatio', gljController.init, gljController.updateRatio);
 router.post('/get-ratio', gljController.init, gljController.getRatio);
 router.post('/delete-ratio', gljController.init, gljController.deleteMixRatio);
 router.post('/add-ratio', gljController.init, gljController.addMixRatio);

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

@@ -21,7 +21,7 @@ let gljCol = {
             {headerName: "调后消耗量", headerWidth: 80, dataCode: "tenderQuantity", dataType: "Number", hAlign: "right", visible: false}
         ],
         view: {
-            lockColumns: [ "adjustPrice", "rationItemQuantity", "quantity", "totalQuantity", "isEstimate",
+            lockColumns: [ "adjustPrice", "quantity", "totalQuantity", "isEstimate",
                 "tenderPrice", "tenderQuantity"],//这里以后改成dataCode好一点
             rowHeaderWidth:25
         },

+ 107 - 6
web/building_saas/main/js/views/glj_view.js

@@ -454,9 +454,10 @@ var gljOprObj = {
         if(me.sheet.getTag(args.row,args.col)=="locked") return false;//如果是双击树节点编号里设置了锁定标记,不能编辑
         if (_.includes(me.setting.view.lockColumns, args.col))  return false;//如果是锁定的列,不能编辑
         if(recode != undefined){
-            if(recode.isMixRatio){//对于组成物列
-               return dataCode == 'marketPrice'//允许修改组成物市单价,其它的不可以
+            if(recode.isMixRatio){//对于组成物列 - 可修改市场价和
+              return dataCode == 'marketPrice' || dataCode == 'rationItemQuantity'
             }else {
+                if(dataCode == 'rationItemQuantity') return false;
                 if (dataCode && dataCode == 'marketPrice') {
                     return !me.marketPriceReadOnly({data:me.sheetData[args.row]});
                 }
@@ -775,7 +776,7 @@ var gljOprObj = {
                     ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
                     let connect_index = this.getIndex(glj, gljKeyArray);
                     if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
-                        let mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
+                        let mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs,glj);
                         ration_gljs[i].subList = mixRatios;
                     }
                     if(ration) gljOprObj.getTotalQuantity(ration_gljs[i], ration);
@@ -843,7 +844,7 @@ var gljOprObj = {
         }
         return obj;
     },
-    getMixRationShowDatas: function (mixRatioList, projectGljs) {
+    getMixRationShowDatas: function (mixRatioList, projectGljs,parentGLJ) {
         var temRationGLJs = [];
         for (var i = 0; i < mixRatioList.length; i++) {
             let mIndex = gljOprObj.getIndex(mixRatioList[i],gljKeyArray);
@@ -852,6 +853,7 @@ var gljOprObj = {
             });//改关联关系
             if(pg){
                 let tem = {
+                    mixRatioId:mixRatioList[i].id,
                     projectGLJID: pg.id,
                     code: pg.code,
                     name: pg.name,
@@ -868,7 +870,8 @@ var gljOprObj = {
                     //isEstimate: pg.is_evaluate,
                     isMixRatio: true,
                     isAdd: pg.unit_price.is_add,
-                    GLJID: pg.glj_id
+                    GLJID: pg.glj_id,
+                    parentGLJ:parentGLJ
                 };
                 if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
                     tem.isEstimate =  pg.is_evaluate;
@@ -924,7 +927,7 @@ var gljOprObj = {
             if (args.editingText == null) {
                 updateField == 'marketPrice' ? newval = 0 : newval = "";
             } else {
-                var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
+                var decimal = updateField == 'customQuantity'||updateField == 'rationItemQuantity'  ? getDecimal("glj.quantity") : 6;//对于市场价和定额价,这里只是中间的小数位数,后面更新前会根据有没有组成物再取值
                 newval = number_util.checkNumberValue(args.editingText, decimal);
                 if (newval == null) {
                     me.sheet.getCell(args.row, args.col).value(recode[updateField]);
@@ -956,6 +959,9 @@ var gljOprObj = {
             projectObj.project.ration_glj.updateRationGLJByChangeCode(recode, updateField, newval);
         }else if(me.setting.navigationRightCol.indexOf(updateField) != -1){//对于名称、规格、单位先跳到下一列,保存至缓存
             me.setToEditCache(recode,updateField, newval,args);
+        }else if(updateField == 'rationItemQuantity'){//修改组成物的消耗量
+            me.updateRatio(recode,{consumption:newval})
+            console.log(recode);
         } else {
             projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
         }
@@ -986,6 +992,100 @@ var gljOprObj = {
         }
        return false;
     },
+    getParentPrice:function(subList,value,radio,type = 'modify'){
+      let marketPrice = 0,basePrice=0; 
+      let decimal = getDecimal('glj.unitPrice');
+      for(let s of subList){
+        let c = parseFloat(s.consumption);
+        if(s.mixRatioId == radio.mixRatioId) c = value;
+        if(type == 'delete' && s.mixRatioId == radio.mixRatioId) continue;
+        let m = scMathUtil.roundForObj(s.marketPrice *  c,decimal);
+        let b = scMathUtil.roundForObj(s.basePrice *  c,decimal);
+        marketPrice += m;
+        basePrice +=b;
+      }
+      return [scMathUtil.roundForObj(marketPrice,decimal),scMathUtil.roundForObj(basePrice,decimal)]
+    },
+    deleteRatio:async function(row){
+      let ratio = this.sheetData[row];
+      let pgljData = projectObj.project.projectGLJ.datas;
+      for(let rg of  this.sheetData){
+        if(rg.projectGLJID == ratio.parentGLJ.id) {
+          subList = rg.subList;
+          break;
+        }
+      }  
+      let [marketPrice,basePrice] = this.getParentPrice(subList,0,ratio,"delete");
+      try {
+        $.bootstrapLoading.start()
+        projectData = await ajaxPost('/glj/updateRatio', {id: ratio.mixRatioId,type:'delete',pid:ratio.parentGLJ.id,market_price: marketPrice,base_price: basePrice});
+
+        //更新缓存
+        let pk = gljUtil.getIndex(ratio.parentGLJ);
+        if(pgljData.mixRatioMap && pgljData.mixRatioMap[pk]){
+          _.remove(pgljData.mixRatioMap[pk],{"id":ratio.mixRatioId});
+        }
+        for(let r of ratio.parentGLJ.ratio_data){
+          _.remove(ratio.parentGLJ.ratio_data,{"id":ratio.mixRatioId});
+        }
+        ratio.parentGLJ.unit_price.market_price = marketPrice;
+        ratio.parentGLJ.unit_price.base_price = basePrice;
+        //重新计算消耗量
+        projectObj.project.projectGLJ.calcQuantity();
+        let priceData = {};
+        priceData =this.setGLJPrice(priceData,ratio.parentGLJ);
+        projectGljObject.updateParentNodes(ratio.parentGLJ.id,priceData.marketPrice);
+        projectGljObject.onUnitFileChange(ratio);
+      } catch (error) {
+        console.log(error)
+      }finally{
+        $.bootstrapLoading.end()
+      }
+    },
+    updateRatio:async function(ratio,doc){
+      let pgljData = projectObj.project.projectGLJ.datas;
+      let subList = [];
+      for(let rg of  this.sheetData){
+        if(rg.projectGLJID == ratio.parentGLJ.id) {
+          subList = rg.subList;
+          break;
+        }
+      }  
+      let [marketPrice,basePrice] = this.getParentPrice(subList,doc.consumption,ratio);
+
+      try {
+        $.bootstrapLoading.start()
+        projectData = await ajaxPost('/glj/updateRatio', {id: ratio.mixRatioId, doc:doc,pid:ratio.parentGLJ.id,market_price: marketPrice,base_price: basePrice});
+
+        //更新缓存
+        let pk = gljUtil.getIndex(ratio.parentGLJ);
+        if(pgljData.mixRatioMap && pgljData.mixRatioMap[pk]){
+          for(let m of pgljData.mixRatioMap[pk]){
+            if(m.id == ratio.mixRatioId) gljUtil.setProperty(m,doc);
+          } 
+        }
+        for(let r of ratio.parentGLJ.ratio_data){
+          if(r.id == ratio.mixRatioId) gljUtil.setProperty(r,doc);
+        }
+        ratio.parentGLJ.unit_price.market_price = marketPrice;
+        ratio.parentGLJ.unit_price.base_price = basePrice;
+      
+
+        //重新计算消耗量
+        projectObj.project.projectGLJ.calcQuantity();
+        let priceData = {};
+        priceData =this.setGLJPrice(priceData,ratio.parentGLJ);
+        projectGljObject.updateParentNodes(ratio.parentGLJ.id,priceData.marketPrice);
+        projectGljObject.onUnitFileChange(ratio);
+      } catch (error) {
+        console.log(error)
+      }finally{
+        $.bootstrapLoading.end()
+      }
+      
+    },
+
+
     updateRationTypeGLJ: function (value, node, fieldName,editingText) {
         let newval;
         let updatePrice = false;
@@ -1637,6 +1737,7 @@ $(function () {
     $('#glj_tree_div').on('hidden.bs.modal', function () {
         // 清空搜索框
         $('#gljSearchKeyword').val('');
+        projectGljObject.subList = [];
     });
     $('#glj_tree_div').on('shown.bs.modal', function (e) {
         if (gljOprObj.gljLibSpresd == undefined) {

+ 59 - 1
web/building_saas/main/js/views/glj_view_contextMenu.js

@@ -114,7 +114,65 @@ var gljContextMenu = {
                         return subSpread.getActiveSheet().name()=='ration_glj';
                     }
                 },
-                "add_to_lib": {
+                "addMixRatio": {
+                  name: '添加组成物',
+                  icon: 'fa-sign-in',
+                  disabled: function () {
+                      let sheetData = gljOprObj.sheetData;
+                      const selected = projectObj.project.mainTree.selected;
+                      if(gljOprObj.isInstallationNode(selected) || OVER_HEIGHT.isOverHeight(selected)){
+                          return true;
+                      }
+                      if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
+                          if(sheetData[gljContextMenu.selectedRow].isMixRatio == true) return false;
+                          if(!sheetData[gljContextMenu.selectedRow].subList)  return true;
+                          return false;
+                      }
+                      return true;
+                  },
+                  callback: function () {
+                      let t = gljOprObj.sheetData[gljContextMenu.selectedRow];
+                      if(t.isMixRatio){
+                        projectGljObject.selectedProjectGLJ = t.parentGLJ;
+                        for(let rg of  gljOprObj.sheetData){
+                          if(rg.projectGLJID == t.parentGLJ.id) {
+                            projectGljObject.subList = rg.subList;
+                            break;
+                          }
+                        } 
+
+                      }else{
+                        projectGljObject.selectedProjectGLJ = t;
+                        projectGljObject.subList = t.subList;
+                      }
+                      getGLJData('addMix');
+                  },
+                  visible: function(key, opt){
+                      return subSpread.getActiveSheet().name()=='ration_glj';
+                  }
+                },
+                "deleteMixRatio": {
+                  name: '删除组成物',
+                  icon: 'fa-sign-in',
+                  disabled: function () {
+                      let sheetData = gljOprObj.sheetData;
+                      const selected = projectObj.project.mainTree.selected;
+                      if(gljOprObj.isInstallationNode(selected) || OVER_HEIGHT.isOverHeight(selected)){
+                          return true;
+                      }
+                      if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
+                          if(sheetData[gljContextMenu.selectedRow].isMixRatio == true) return false;
+                      }
+                      return true;
+                  },
+                  callback: function () {
+                     gljOprObj.deleteRatio(gljContextMenu.selectedRow);
+                  },
+                  visible: function(key, opt){
+                      return subSpread.getActiveSheet().name()=='ration_glj';
+                  }
+                },
+               "add_to_lib": {
                     name: '保存到我的人材机库',
                     icon: 'fa-sign-in',
                     disabled: function () {

+ 42 - 33
web/building_saas/main/js/views/project_glj_view.js

@@ -41,6 +41,7 @@ let projectGljObject={
     mixRatioSpread:null,
     mixRatioSheet:null,
     mixRatioData:[],
+    subList:[],//定额工料机,添加组成物时临时保存组成物信息的位置
     usedTenderList:[],
     usedUnitPriceInfo:null,
     displayTypeMap:[
@@ -178,7 +179,9 @@ let projectGljObject={
     },
     addMixRatio:function () {
         let me = this, projectGLJ = projectObj.project.projectGLJ;
-        for(let mix of me.mixRatioData){
+        let tdatas = me.mixRatioData;
+        if(me.subList.length > 0) tdatas = me.subList;
+        for(let mix of tdatas){
             let m_key = gljOprObj.getIndex(mix, gljKeyArray);
             let t_index = gljOprObj.GLJSelection.indexOf(m_key);
             t_index != -1?gljOprObj.GLJSelection.splice(t_index,1):'';
@@ -194,6 +197,7 @@ let projectGljObject={
     },
     showMixRatioData:function () {
         let me = this,gljId = null,gljType = null;
+        if(!me.projectGljSpread) return;
         let sheet = me.projectGljSpread.getActiveSheet();
         let oldSel = me.mixRatioSheet.getSelections()[0];
         if(sheet.name() == 'projectGljSheet'){//projectGljSheet/materialSheet 工料机汇总和三材汇总表
@@ -510,6 +514,7 @@ let projectGljObject={
 
     },
     showProjectGljData:function () {
+        if(!this.projectGljSpread) return;
         this.projectGljSpread.setActiveSheetIndex(0);
         let sel = this.projectGljSheet.getSelections()[0];
         let oldData = sel.row<this.projectGljSheetData.length?this.projectGljSheetData[sel.row]:"";
@@ -593,7 +598,7 @@ let projectGljObject={
             me.showMaterialTreeData();
         }else {
             me.showProjectGljData();
-            me.showMixRatioData();
+            me.showMixRatioData(); 
         }
     },
     createMaterialTree:function (gljList) {
@@ -847,38 +852,42 @@ let projectGljObject={
 
         // 更新组成物缓存
         projectObj.project.composition.loadData();
-        //先查找使用了父项目工料机的定额工料机
-        let updateNodes=[];
-        let ration_gljs = _.filter(projectObj.project.ration_glj.datas,{'projectGLJID':pid});
-        for(let rg of ration_gljs){
-            let node = projectObj.project.mainTree.getNodeByID(rg.rationID);
-            if(node){
-                updateNodes.push(node);
-            }
-        }
-        //或者是使用了父项目工料机的工料机类型的定额
-        let rations = _.filter(projectObj.project.Ration.datas,{'type':3,'projectGLJID':pid});
-        for(let r of rations){
-            let r_node = projectObj.project.mainTree.getNodeByID(r.ID);
-            if(r_node){
-                r_node.data.marketUnitFee = parantData?parantData.marketPrice:'';//parentMarketPrice;//这里用显示的价格
-                updateNodes.push(r_node);
-            }
-        }
-        if(sid){
-            let subRations = calcTools.getRationsByProjectGLJ(sid);
-            updateNodes = updateNodes.concat(subRations);
-        }
-        if(updateNodes.length>0){
-            projectObj.project.calcProgram.calcNodesAndSave(updateNodes,async function () {
-                projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
-                installationFeeObj.calcInstallationFee();//计算安装增加费
-               await OVER_HEIGHT.reCalcOverHeightFee();
-                await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(updateNodes);
-            });
-        }
-        gljOprObj.refreshView();
+        me.updateParentNodes(pid,parantData.marketPrice,sid);
+    },
+    updateParentNodes:function(pid,marketPrice,sid){
+      //先查找使用了父项目工料机的定额工料机
+      let updateNodes=[];
+      let ration_gljs = _.filter(projectObj.project.ration_glj.datas,{'projectGLJID':pid});
+      for(let rg of ration_gljs){
+          let node = projectObj.project.mainTree.getNodeByID(rg.rationID);
+          if(node){
+              updateNodes.push(node);
+          }
+      }
+      //或者是使用了父项目工料机的工料机类型的定额
+      let rations = _.filter(projectObj.project.Ration.datas,{'type':3,'projectGLJID':pid});
+      for(let r of rations){
+          let r_node = projectObj.project.mainTree.getNodeByID(r.ID);
+          if(r_node){
+              r_node.data.marketUnitFee = marketPrice;//parentMarketPrice;//这里用显示的价格
+              updateNodes.push(r_node);
+          }
+      }
+      if(sid){
+          let subRations = calcTools.getRationsByProjectGLJ(sid);
+          updateNodes = updateNodes.concat(subRations);
+      }
+      if(updateNodes.length>0){
+          projectObj.project.calcProgram.calcNodesAndSave(updateNodes,async function () {
+              projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
+              installationFeeObj.calcInstallationFee();//计算安装增加费
+              await OVER_HEIGHT.reCalcOverHeightFee();
+              await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(updateNodes);
+          });
+      }
+      gljOprObj.refreshView();
     },
+
     onUnitFileChange:function (data) {
         projectObj.project.markUpdateProject({projectID:projectObj.project.ID(),'unitFileID':socketObject.getUnitFileRoomID()},"unitFile",function(){
             //socket.emit('unitFileChangeNotify', JSON.stringify(data));