zhangweicheng 7 years ago
parent
commit
e4b3a413e8

+ 18 - 0
modules/main/controllers/installation_controller.js

@@ -8,6 +8,7 @@ let logger = require("../../../logs/log_helper").logger;
 module.exports={
     updateInstallationFee:updateInstallationFee,
     updateRationInstallation:updateRationInstallation,
+    applyRuleByIDs:applyRuleByIDs,
     resetToDefault:resetToDefault
 }
 
@@ -28,6 +29,23 @@ async function updateRationInstallation(req, res) {
     res.json(result);
 }
 
+async function applyRuleByIDs(req, res) {
+    let result={
+        error:0
+    }
+    try {
+        let data = req.body.data;
+        data = JSON.parse(data);
+        let datas= await ration_installation_facade.applyRuleByIDs(data);
+        result.data=datas;
+    }catch (err){
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+    }
+    res.json(result);
+}
+
 async function  updateInstallationFee(req, res) {
     let result={
         error:0

+ 12 - 0
modules/main/facade/ration_installation_facade.js

@@ -8,6 +8,7 @@ let projectConsts = consts.projectConst;
 
 module.exports={
     updateRationInstallation:updateRationInstallation,
+    applyRuleByIDs:applyRuleByIDs,
     updateFromInstallationFee:updateFromInstallationFee,
     getData:getData,
     deleteByRation:deleteByRation
@@ -22,6 +23,17 @@ async function updateRationInstallation(data){
     }
 }
 
+async function applyRuleByIDs(data){
+    console.log(data);
+    if(data.projectID&&data.IDs){
+        return rationInstallationModel.update({projectID: data.projectID, ID:{'$in':data.IDs}},{ruleId:data.ruleId,unifiedSetting:0},{multi: true});
+    }else {
+        throw  new Error('项目ID或者ID为空,更新失败!');
+    }
+    //ration.update({projectID: doc.updateData.projectID, ID: doc.updateData.ID}, doc.updateData,{multi: true},cb);
+
+}
+
 async function updateFromInstallationFee(projectID,rationInstallations) {
     let tasks = [];
     for (let ri of rationInstallations){

+ 1 - 0
modules/main/routes/installation_route.js

@@ -10,6 +10,7 @@ module.exports = function (app) {
 
     installationRouter.post('/updateInstallationFee', installationController.updateInstallationFee);
     installationRouter.post('/updateRationInstallation', installationController.updateRationInstallation);
+    installationRouter.post('/applyRuleByIDs', installationController.applyRuleByIDs);
     installationRouter.post('/resetToDefault', installationController.resetToDefault);
     app.use('/installation',installationRouter);
 };

+ 4 - 1
web/building_saas/main/js/models/bills.js

@@ -705,10 +705,13 @@ var Bills = {
                 }
                 controller.m_delete(mainNodes);//删除树节点
                 me.tree.m_delete(idTreeNodes);
+                $.bootstrapLoading.end();
                 //重新计算
                 project.installation_fee.calcInstallationFee(function (isChange) {
                     project.calcProgram.calcAllNodesAndSave();
-                    if(!isChange) project.projectGLJ.loadData();
+                    if(!isChange) {
+                        project.projectGLJ.loadData();
+                    }
                 });
 
                /* project.calcProgram.calcBillsAndSave(parentNodes,function () {

+ 15 - 0
web/building_saas/main/js/models/cache_tree.js

@@ -445,6 +445,21 @@ var cacheTree = {
               this.getAllSubNode(c,nodeArray);
           }
         };
+        Tree.prototype.getLeavesNodes = function (node) {//取该节点下的所有叶子节点
+            let leaves = [];
+            getLeaves(node,leaves);
+            return leaves;
+
+            function getLeaves(node,nodeArr) {
+                if(node.children.length>0){
+                    for(let ch of node.children){
+                        getLeaves(ch,nodeArr);
+                    }
+                }else {
+                    nodeArr.push(node);
+                }
+            }
+        };
         Tree.prototype.getNodeByID = function (ID) {
           let node = this.nodes[this.prefix+ID];
           return node;

+ 38 - 1
web/building_saas/main/js/models/ration_installation.js

@@ -53,8 +53,45 @@ let ration_installation = {
                 return false;
             })
         };
+        ration_installation.prototype.getDataByConditions = function (conditions) {
+            return _.filter(this.datas,function (item) {
+                let match = true;
+                for(let ckey in conditions){
+                    if( Array.isArray(conditions[ckey])){
+                       let isContain =  _.includes(conditions[ckey],item[ckey]);
+                       if(!isContain){//不包含
+                           match = false;
+                           break;
+                       }
+                    }else {
+                        if(conditions[ckey]!=item[ckey]){
+                            match = false;
+                            break;
+                        }
+                    }
+                }
+                return match;
+            })
+        };
+        ration_installation.prototype.applyRuleByIDs = function(projectID,IDs,ruleId,callback){
+            let me = this;
+            $.bootstrapLoading.start();
+            CommonAjax.post('/installation/applyRuleByIDs',{projectID:projectID,IDs:IDs,ruleId:ruleId},function (data) {
+                //更新缓存
+                for(let ID of IDs){
+                    let ri = _.find(me.datas,{'ID':ID});
+                    ri.ruleId = ruleId;
+                    ri.unifiedSetting = 0;
+                }
+                if(callback){
+                    callback();
+                }
+                $.bootstrapLoading.end();
+            },function () {
+                $.bootstrapLoading.end();
+            })
 
-
+        };
         ration_installation.prototype.update = function (updateData,callback) {
             let  me = this;
             $.bootstrapLoading.start();

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

@@ -314,7 +314,7 @@ var gljOprObj = {
         if(selected) {//是主材或者是设备时只读
             if(selected.sourceType == ModuleNames.ration_glj){
                 return true;
-            }else if(selected.sourceType == ModuleNames.bills&&selected.data.type==billType.BX){//是补项时只读
+            }else if(gljOprObj.isInstallationNode(selected)){//是补项或者是安装类型的定额时只读
                 return true;
             }
             return false;

+ 66 - 25
web/building_saas/main/js/views/glj_view_contextMenu.js

@@ -16,11 +16,15 @@ var gljContextMenu = {
                     icon: 'fa-remove',
                     disabled: function () {
                         var sheetData = gljOprObj.sheetData;
-                        var disable = true;
                         if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
-                            disable=  sheetData[gljContextMenu.selectedRow].isMixRatio==true?true:false;
+                            if( sheetData[gljContextMenu.selectedRow].isMixRatio==true){
+                                return true;
+                            }
+                        }
+                        if(gljOprObj.isInstallationNode(projectObj.project.mainTree.selected)){
+                            return true;
                         }
-                        return disable;
+                        return false;
                     },
                     callback: function () {
                         var sheetData = gljOprObj.sheetData;
@@ -35,16 +39,21 @@ var gljContextMenu = {
                     name: '添加工料机',
                     icon: 'fa-sign-in',
                     disabled: function () {
-                        var disable = true;
                         var selected = projectObj.project.mainTree.selected;
                         var sheetData = gljOprObj.sheetData;
-                        if(selected&&selected.sourceType==ModuleNames.ration&&selected.data.type==rationType.ration){
-                            disable=false;
+                        if(selected){
+                            if(selected.sourceType!=ModuleNames.ration){
+                                return true;
+                            }else if(selected.data.type!=rationType.ration){
+                                return true;
+                            }
                         }
                         if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
-                            disable=  sheetData[gljContextMenu.selectedRow].isMixRatio==true?true:false;
+                            if(sheetData[gljContextMenu.selectedRow].isMixRatio==true){
+                                return true;
+                            }
                         }
-                        return disable;
+                        return false;
                     },
                     callback:function () {
                         getGLJData('add');
@@ -58,11 +67,15 @@ var gljContextMenu = {
                     icon: 'fa-sign-in',
                     disabled: function () {
                         var sheetData = gljOprObj.sheetData;
-                        var disable = true;
                         if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
-                            disable=  sheetData[gljContextMenu.selectedRow].isMixRatio==true?true:false;
+                            if(sheetData[gljContextMenu.selectedRow].isMixRatio==true){
+                                return true;
+                            }
                         }
-                        return disable;
+                        if(gljOprObj.isInstallationNode(projectObj.project.mainTree.selected)){
+                            return true;
+                        }
+                        return false;
                     },
                     callback: function () {
                         getGLJData('replace');
@@ -78,9 +91,14 @@ var gljContextMenu = {
                         var sheetData = gljOprObj.sheetData;
                         var disable = true;
                         if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
-                            disable=  sheetData[gljContextMenu.selectedRow].isMixRatio==true?true:false;
+                            if(sheetData[gljContextMenu.selectedRow].isMixRatio==true){
+                                return true;
+                            }
                         }
-                        return disable;
+                        if(gljOprObj.isInstallationNode(projectObj.project.mainTree.selected)){
+                            return true;
+                        }
+                        return false;
                     },
                     callback: function () {
                         getGLJData('m_replace');
@@ -94,12 +112,17 @@ var gljContextMenu = {
                     icon: 'fa-sign-in',
                     disabled: function () {
                         var sheetData = gljOprObj.sheetData;
-                        var disable = true;
                         if(subSpread.getActiveSheetIndex()==0&&sheetData!=null&&sheetData.length>0&&gljContextMenu.selectedRow<sheetData.length){
                             var recode = sheetData[gljContextMenu.selectedRow];
-                            disable= recode.isMixRatio!=true&&recode.isAdd==true?false:true
+                            if(!(recode.isMixRatio!=true&&recode.isAdd==true)){
+                                return true
+                            }
+                          //  disable= recode.isMixRatio!=true&&recode.isAdd==true?false:true
                         }
-                        return disable;
+                        if(gljOprObj.isInstallationNode(projectObj.project.mainTree.selected)){
+                            return true;
+                        }
+                        return false;
                     },
                     callback: function () {
                         var sheetData = gljOprObj.sheetData;
@@ -236,11 +259,17 @@ var gljContextMenu = {
                     name: '应用到当前分项',
                     icon: 'fa-sign-in',
                     disabled: function () {
-                        /* var sheetData = gljOprObj.detailData;
-                         return gljContextMenu.selectedRow>sheetData.length-2;*/
+                        let sheetData = installationFeeObj.rationInstallData;
+                        if(gljContextMenu.selectedRow>sheetData.length-1){
+                            return true;
+                        }
+                        if(sheetData[gljContextMenu.selectedRow].unifiedSetting == 1){
+                            return true;
+                        }
+                        return false;
                     },
                     callback: function () {
-                        //projectObj.project.quantity_detail.moveDown(gljContextMenu.selectedRow);
+                        installationFeeObj.applyRuleTo('FX',gljContextMenu.selectedRow);
                     },
                     visible: function(key, opt){
                         return subSpread.getActiveSheet().name()=='rationInstallSheet';
@@ -250,11 +279,17 @@ var gljContextMenu = {
                     name: '应用到当前分部',
                     icon: 'fa-sign-in',
                     disabled: function () {
-                        /* var sheetData = gljOprObj.detailData;
-                         return gljContextMenu.selectedRow>sheetData.length-2;*/
+                        let sheetData = installationFeeObj.rationInstallData;
+                        if(gljContextMenu.selectedRow>sheetData.length-1){
+                            return true;
+                        }
+                        if(sheetData[gljContextMenu.selectedRow].unifiedSetting == 1){
+                            return true;
+                        }
+                        return false;
                     },
                     callback: function () {
-                        //projectObj.project.quantity_detail.moveDown(gljContextMenu.selectedRow);
+                        installationFeeObj.applyRuleTo('FB',gljContextMenu.selectedRow);
                     },
                     visible: function(key, opt){
                         return subSpread.getActiveSheet().name()=='rationInstallSheet';
@@ -264,11 +299,17 @@ var gljContextMenu = {
                     name: '应用到当前项目',
                     icon: 'fa-sign-in',
                     disabled: function () {
-                        /* var sheetData = gljOprObj.detailData;
-                         return gljContextMenu.selectedRow>sheetData.length-2;*/
+                        let sheetData = installationFeeObj.rationInstallData;
+                        if(gljContextMenu.selectedRow>sheetData.length-1){
+                            return true;
+                        }
+                        if(sheetData[gljContextMenu.selectedRow].unifiedSetting == 1){
+                            return true;
+                        }
+                        return false;
                     },
                     callback: function () {
-                        //projectObj.project.quantity_detail.moveDown(gljContextMenu.selectedRow);
+                        installationFeeObj.applyRuleTo('PJ',gljContextMenu.selectedRow);
                     },
                     visible: function(key, opt){
                         return subSpread.getActiveSheet().name()=='rationInstallSheet';

+ 65 - 6
web/building_saas/main/js/views/installation_fee_view.js

@@ -26,9 +26,15 @@ let installationFeeObj={
                return installationFeeObj.getDisplayText(item);
             },
             forRule:function (item,val) {//
-                let feeRule = projectObj.project.installation_fee.getFeeRuleByID(item.libID,val);
-                if(feeRule){
-                    return feeRule.rule;
+                let install_fee = projectObj.project.installation_fee;
+                let impactRules =install_fee.getFeeRuleBySection({libID:item.libID,ID:item.sectionId});
+                if(_.find(impactRules,{ID:val})){
+                    return val;
+                }else {
+                    let feeRule = projectObj.project.installation_fee.getFeeRuleByID(item.libID,val);
+                    if(feeRule){
+                        return feeRule.rule;
+                    }
                 }
                 return val;
             }
@@ -812,6 +818,9 @@ let installationFeeObj={
         }
         installation_fee.updateFeeRule({position:recode.code,billID:recode.ID},rationInstall.libID,rationInstall.ruleId,function (){
             me.refreshRationInstallationRow(riselection.row);
+            installation_fee.calcInstallationFee(function () {
+                projectObj.project.calcProgram.calcAllNodesAndSave();
+            });
         });
     },
     updateFeeRulePosition:function (recode) {
@@ -866,6 +875,9 @@ let installationFeeObj={
         };
         projectObj.project.ration_installation.update(updateData,function (data) {
             me.refreshRationInstallationRow(ri_row);
+            projectObj.project.installation_fee.calcInstallationFee(function () {
+                projectObj.project.calcProgram.calcAllNodesAndSave();
+            });
         });
     },
     updateFeeItemPosition:function(recode){
@@ -933,6 +945,7 @@ let installationFeeObj={
     },
     onRationInstallValueChange:function (e,info) {
         let me = installationFeeObj;
+        let installation_fee = projectObj.project.installation_fee
         if(info.newValue==info.oldValue){
             return;
         }
@@ -958,8 +971,8 @@ let installationFeeObj={
         }
         if(fieldID=='unifiedSetting'){//勾选统一设置
             updateData.ruleId = '';
-            let feeItem =  projectObj.project.installation_fee.getFeeItemByID(raInstallation.libID,raInstallation.feeItemId);
-            let section = projectObj.project.installation_fee.getInstallSectionByID(raInstallation.libID,raInstallation.sectionId);
+            let feeItem =  installation_fee.getFeeItemByID(raInstallation.libID,raInstallation.feeItemId);
+            let section = installation_fee.getInstallSectionByID(raInstallation.libID,raInstallation.sectionId);
             if(section&&feeItem&&feeItem.isCal == 1){
                 updateData.ruleId = section.feeRuleId;
             }
@@ -967,6 +980,9 @@ let installationFeeObj={
         updateData[fieldID] = info.newValue;
         projectObj.project.ration_installation.update(updateData,function (data) {
             me.refreshRationInstallationRow(info.row);
+            installation_fee.calcInstallationFee(function () {
+                projectObj.project.calcProgram.calcAllNodesAndSave();
+            });
         });
     },
     modifyFeeRuleValueChange:function (e,info) {
@@ -1202,7 +1218,7 @@ let installationFeeObj={
         install_fee.calcInstallationFee(function (isChange) {
             if(isChange){
                 projectObj.project.calcProgram.calcAllNodesAndSave();
-                gljOprObj.refreshView();
+                installationFeeObj.showRationInstallationData(projectObj.project.mainTree.selected);
             }
             console.log("cal end");
         });
@@ -1217,6 +1233,49 @@ let installationFeeObj={
             $("#all_project_calc").prop("checked",false);
             $("#FB_calc").prop("checked",true);
         }
+    },
+    applyRuleTo:function(level,row){//level:FX/FB/PJ
+        let selectRecord = this.rationInstallData[row];
+        let ration_installation = projectObj.project.ration_installation;
+        let rationID = selectRecord.rationID;
+        let condition = {'libID':selectRecord.libID,'feeItemId':selectRecord.feeItemId,'sectionId':selectRecord.sectionId};
+        let rationList = [];
+        let rationNode = projectObj.project.mainTree.getNodeByID(rationID);
+        if(!rationNode){
+            return;
+        }
+        if(level == 'FX'){//应用到分项
+            let children = rationNode.parent.children;//兄弟节点
+            for(let c of children){
+                if(c.data.type == rationType.ration){
+                    rationList.push(c.data.ID);
+                }
+            }
+            condition.rationID = rationList;
+        }else if(level == 'FB'){//应用到分部
+            let FBNode = rationNode.parent.parent;//分部节点
+            let rationNodeList =  projectObj.project.mainTree.getLeavesNodes(FBNode);
+            for(let r of rationNodeList){
+                if(r.data.type == rationType.ration){
+                    rationList.push(r.data.ID);
+                }
+            }
+            condition.rationID = rationList;
+        }
+        //应用到项目的时候就不用加入rationList做判断
+        let riList = ration_installation.getDataByConditions(condition);
+        let IDList = _.map(riList,'ID');
+        ration_installation.applyRuleByIDs(selectRecord.projectID,IDList,selectRecord.ruleId,function () {
+            //计算安装增加费
+            projectObj.project.installation_fee.calcInstallationFee(function (isChange) {
+                if(isChange){
+                    projectObj.project.calcProgram.calcAllNodesAndSave();
+                }
+            });
+        })
+    },
+    getRationByParentID:function () {
+
     }
 };
 

+ 7 - 6
web/building_saas/main/js/views/zlfb_view.js

@@ -68,7 +68,6 @@ let zlfb_object={
         let resort = $('#bill_resort').prop('checked'),recode=$('#bill_recode').prop('checked'),first=$('#bill_first').prop('checked');
         let second =$('#bill_second').prop('checked'), third =$('#bill_third').prop('checked');
         let needSelf = first==true||second==true||third==true;//需要补充分部节点;
-        $.bootstrapLoading.start();
         if(me.sectionInfo){
             let FX_nodes =me.sectionInfo.FX_nodes,fxMap = me.sectionInfo.fxMap,FB_nodes =me.sectionInfo.FB_nodes;
             let codeMap = {},sectionNodeMap={},allNewNode=[],updateData={},newDataMap={};
@@ -145,8 +144,6 @@ let zlfb_object={
                 }
             };
             me.submitRequest(newDataMap,allNewNode,updateData,FBFX,controller);
-        }else {
-            $.bootstrapLoading.end();
         }
     },
     addSubNode:function (parentNode,oldChildren,allNewNode,controller) {
@@ -243,7 +240,9 @@ let zlfb_object={
         }
         updateData.projectID = FBFX.data.projectID;
         updateData.user_id = userID;
+        $.bootstrapLoading.start();
         CommonAjax.post('/bills/reorganizeFBFX',updateData,function (data) {
+            $.bootstrapLoading.end();
             //更新前端缓存
             let billDatas = projectObj.project.Bills.datas;
             let quantity_detail_datas = projectObj.project.quantity_detail.datas;
@@ -278,9 +277,11 @@ let zlfb_object={
                 });
             }
             cbTools.refreshFormulaNodes();
-            //重新计算
-            projectObj.project.Bills.getEngineeringCostNode(controller).changed = true;
-            projectObj.project.calcProgram.calcAllNodesAndSave();
+            projectObj.project.installation_fee.calcInstallationFee(function () {
+                //重新计算
+                projectObj.project.Bills.getEngineeringCostNode(controller).changed = true;
+                projectObj.project.calcProgram.calcAllNodesAndSave();
+            });
         },function () {
             //errorCallback
         });