Browse Source

update ration type glj

zhangweicheng 7 năm trước cách đây
mục cha
commit
b5ed394765

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

@@ -552,6 +552,25 @@ class GLJController extends BaseController {
         res.json(result);
     }
 
+    async addGlj(req,res){
+        let result={
+            error:0
+        }
+        try {
+            let data = req.body.data;
+            data = JSON.parse(data);
+            let gljListModel = new GLJListModel();
+            // 添加项目工料机
+            let datas = await gljListModel.addList(data);
+            result.data=datas;
+        }catch (err){
+            logger.err(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        res.json(result);
+    }
+
 }
 
 /**

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

@@ -22,6 +22,7 @@ router.post('/change-file', gljController.init, gljController.changeUnitPriceFil
 router.post('/save-as', gljController.init, gljController.unitPriceSaveAs);
 router.post('/get-composition', gljController.init, gljController.getComposition);
 router.post('/updatePrice', gljController.init, gljController.updateUnitPrice);
+router.post('/add',gljController.init, gljController.addGlj)
 
 router.get('/test', gljController.init, gljController.test);
 router.get('/testModify', gljController.init, gljController.testModify);

+ 3 - 0
web/building_saas/main/js/models/project.js

@@ -139,6 +139,9 @@ var PROJECT = {
                 var newNode, br = that.Ration.getBillsSortRation(cacheNode.source.getID()), i;
                 for (i = 0; i < br.length; i++) {
                     newNode = that.mainTree.addNode(cacheNode);
+                    if(br[i].type==rationType.gljRation){
+                        br[i]=  that.ration_glj.combineRationAndGLJ(br[i]);
+                    }
                     newNode.source = br[i];
                     newNode.sourceType = that.Ration.getSourceType();
                     newNode.data = br[i];

+ 32 - 4
web/building_saas/main/js/models/project_glj.js

@@ -169,11 +169,11 @@ ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
             }
             //更新项目工料机价格
             me.refreshProjectGLJPrice(data);
-            me.refreshRationGLJPrice(glj);
+            me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
             gljOprObj.showRationGLJSheetData();
-            me.refreshTreeNodePriceIfNeed(glj);
-            //触发计算
-            projectObj.project.ration_glj.reCalcWhenGLJChange(recode);
+            me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
+            let nodes = me.getImpactRationNodes(glj);//取到因为改变工料机价格而受影响的定额
+            projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
             $.bootstrapLoading.end();
         }
         $.bootstrapLoading.start();
@@ -197,6 +197,31 @@ ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
     }
 }
 
+//根据工料机,取得所有受影响的定额节点
+ProjectGLJ.prototype.getImpactRationNodes = function (glj) {
+    let nodes=[];
+    let rationMap = {};
+    //先根据项目工料机ID,找到受影响定额的ID
+    let ration_glj_list =projectObj.project.ration_glj.datas; //取定额工料机数据
+    for(let rg of ration_glj_list){
+        if(rg.projectGLJID==glj.id){
+            rationMap[rg.rationID] = true;  //取所有定额ID,用MAP方式去重
+        }
+    }
+    for(let item of projectObj.project.mainTree.items){
+        if(item.sourceType==ModuleNames.ration){
+            if(item.data.type==rationType.gljRation){//取定额类型的工料机
+                if(item.data.projectGLJID == glj.id){
+                    item.data.marketUnitFee = glj.unit_price.market_price; //更新市场单价
+                    nodes.push(item);
+                }
+            }else if( rationMap[item.data.ID]==true){  //受影响的定额
+                   nodes.push(item)
+            }
+        }
+    }
+    return nodes;
+};
 ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
     for(let ration_glj of gljOprObj.sheetData){
         if(ration_glj.projectGLJID ==glj.id){
@@ -205,9 +230,12 @@ ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
             ration_glj.adjustPrice=this.getAdjustPrice(glj);
         }
     }
+}
 
+ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
 
 }
+
 ProjectGLJ.prototype.refreshProjectGLJPrice=function(data){
     let projectGljs = this.datas.gljList;
     let indexList = ['code','name','specs','unit','type'];

+ 30 - 3
web/building_saas/main/js/models/ration_glj.js

@@ -476,9 +476,12 @@ var ration_glj = {
             CommonAjax.post("/ration/insertGLJAsRation",postData,function (data) {
                 console.log(data);
                  // 更新兄弟节点的序列号
-                if(selectedSerialNo!=null&&selectedSerialNo<children.length){
-                    for(let i = selectedSerialNo;i<children.length;i++){
-                        children[i].serialNo+=gljList.length;
+                if(selectedSerialNo!=null){
+                    let selectIndex = _.findIndex(children,{"serialNo":selectedSerialNo});
+                    if(selectIndex+1<children.length){
+                        for(let i = selectIndex+1;i<children.length;i++){
+                            children[i].serialNo+=gljList.length;
+                        }
                     }
                 }
                 for(let r_glj of data){
@@ -491,6 +494,9 @@ var ration_glj = {
                     newNode.data = r_glj;
                     ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
                 }
+                let parentNode = project.mainTree.nodes[project.mainTree.prefix+parentNodeID];
+                project.calcProgram.calcLeafBillChildren(parentNode);//计算父级清单的所有子节点
+                //this.nodes[this.prefix + parentID];
                 callback();
                 $.bootstrapLoading.end();
             },function () {
@@ -640,6 +646,27 @@ var ration_glj = {
             data.subType = data.type;
             data.marketUnitFee = data.marketPrice;
         };
+        ration_glj.prototype.combineRationAndGLJ = function (ration) {
+            if(ration){
+                var projectGLJData = projectObj.project.projectGLJ.datas;
+                var projectGljs = projectGLJData.gljList;
+                var mixRatioMap = projectGLJData.mixRatioMap;
+                var glj = _.find(projectGljs,{'id':ration.projectGLJID});
+                if(glj){
+                    ration.marketUnitFee=glj.unit_price.market_price;
+                    //ration_gljs[i].adjustPrice=glj.adjust_price;
+                    ration.isEstimate=glj.is_evaluate;
+                    ration.isAdd=glj.unit_price.is_add;
+                    ration.adjustPrice=projectObj.project.projectGLJ.getAdjustPrice(glj);
+                    var connect_index = gljOprObj.getIndex(glj,['code','name','specs','unit','subType'])
+                    if(mixRatioMap.hasOwnProperty(connect_index)){
+                        var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index],projectGljs);
+                        ration.subList = mixRatios;
+                    }
+                }
+            }
+            return ration;
+        };
         ration_glj.prototype.updateFromMainSpread=function (value,node,fieldName) {
             if(node.data[fieldName]===value){
                 return;

+ 26 - 0
web/building_saas/main/js/views/glj_view.js

@@ -779,6 +779,32 @@ var gljOprObj = {
             projectObj.project.ration_glj.updateRationGLJByEdit(recode,updateField,newval);
         }
     },
+    updateRationTypeGLJ:function (value,node,fieldName) {
+        console.log(fieldName)
+        console.log(value);
+        let newval;
+        let updatePrice = false;
+        if(fieldName=="marketUnitFee"){
+            updatePrice = true;
+            if(value==null){
+                newval=0;
+            }else {
+                var decimal = getDecimal("glj.unitPrice");
+                newval = number_util.checkNumberValue(value,decimal);
+            }
+        }else {
+            if(value!=null){
+                //update
+            }
+        }
+        if(newval&&updatePrice==true){
+            projectObj.project.projectGLJ.updatePriceFromRG(node.data,"marketPrice",newval);
+            return
+        }
+
+        projectObj.mainController.refreshTreeNode([node]);
+    },
+
     updateRationAss:function (args) {
         var me = gljOprObj;
         var newval;