zhangweicheng 7 years ago
parent
commit
0716ab0dd9

+ 19 - 1
modules/main/controllers/installation_controller.js

@@ -7,7 +7,8 @@ let ration_installation_facade = require('../facade/ration_installation_facade')
 let logger = require("../../../logs/log_helper").logger;
 module.exports={
     updateInstallationFee:updateInstallationFee,
-    updateRationInstallation:updateRationInstallation
+    updateRationInstallation:updateRationInstallation,
+    resetToDefault:resetToDefault
 }
 
 async function updateRationInstallation(req, res) {
@@ -45,4 +46,21 @@ async function  updateInstallationFee(req, res) {
         result.message = err.message;
     }
     res.json(result);
+}
+
+async function  resetToDefault(req, res) {
+    let result={
+        error:0
+    }
+    try {
+        let data = req.body.data;
+        data = JSON.parse(data);
+        let returnData= await installation_facade.resetToDefault(data.projectID,data.installFees);
+        result.data=returnData;
+    }catch (err){
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+    }
+    res.json(result);
 }

+ 62 - 38
modules/main/facade/installation_facade.js

@@ -5,11 +5,12 @@ import {installSectionModel,installFeeItemModel} from "../../complementary_ratio
 import installationFeeModel from "../models/installation_fee";
 import engineeringModel from "../../users/models/schema/engineering_lib";
 const uuidV1 = require('uuid/v1');
-let consts = require('../../main/models/project_consts')
+let consts = require('../../main/models/project_consts');
 
 module.exports={
     copyInstallationFeeFromLib:copyInstallationFeeFromLib,
     updateInstallationFee:updateInstallationFee,
+    resetToDefault:resetToDefault,
     getData:getData
 };
 async function updateInstallationFee(projectID,updateData) {
@@ -64,6 +65,22 @@ function createUpdateQuery(projectID,data) {
     return [query,udoc];
 }
 
+/*[
+    {libID:56,ID:123558}
+]*/
+async function resetToDefault(projectID,installFees) {
+    let newInstallFees = [];
+    for(let inf of installFees){
+        let newInstallationFee = await getInstallationFeeFromLib(inf.libID);
+        if(newInstallationFee){
+          let updateResult =  await installationFeeModel.findOneAndUpdate({projectID:projectID,ID:inf.ID},newInstallationFee,{new: true});
+            newInstallFees.push(updateResult);
+        }
+    }
+    return newInstallFees;
+}
+
+
 async function copyInstallationFeeFromLib(projectID,engineering_id) {
 
     //安装增加费用内嵌文档的方式
@@ -71,37 +88,47 @@ async function copyInstallationFeeFromLib(projectID,engineering_id) {
     let ration_lib = engineering.ration_lib;
     let installationFeeList = [];
     for(let rl of ration_lib){
-       let installFeeItems = await installFeeItemModel.find({'rationRepId':rl.id});
-       let installSections = await installSectionModel.find({'rationRepId':rl.id});
-       let positionMap = {};
-       let newInstallationFee = {
-           libID:rl.id,
-           libName:rl.name,
-           projectID:projectID
-       };
-        newInstallationFee.ID = uuidV1();
-       let create = false;
-       if(installFeeItems && installFeeItems.length > 0) {//费用项
-           create = true;
-           let tem_installFeeItem = [];
-           for(let ifee of installFeeItems){
+        let newInstallationFee = await getInstallationFeeFromLib(rl.id);
+        if(newInstallationFee){
+            newInstallationFee.libID = rl.id;
+            newInstallationFee.libName = rl.name;
+            newInstallationFee.projectID = projectID;
+            newInstallationFee.ID = uuidV1();
+            installationFeeList.push(newInstallationFee);
+        }
+    }
+    if(installationFeeList.length > 0){
+        await installationFeeModel.insertMany(installationFeeList);
+    }
+}
+
+async function getInstallationFeeFromLib(libID) {
+        let installFeeItems = await installFeeItemModel.find({'rationRepId':libID});
+        let installSections = await installSectionModel.find({'rationRepId':libID});
+        let positionMap = {};
+        let create = false;
+        let newInstallationFee={};
+        if(installFeeItems && installFeeItems.length > 0) {//费用项
+            create = true;
+            let tem_installFeeItem = [];
+            for(let ifee of installFeeItems){
                 let tem_fee ={
                     feeItem:ifee.feeItem,
                     feeType:ifee.feeType,
                     position:ifee.position,
                     ID:ifee.ID
                 };
-               positionMap[ifee.ID] = ifee.position;//设置选取位置对应表,为给规项赋值
-               tem_installFeeItem.push(tem_fee);
-           }
-           newInstallationFee.installFeeItem = tem_installFeeItem;
-       }
+                positionMap[ifee.ID] = ifee.position;//设置选取位置对应表,为给规项赋值
+                tem_installFeeItem.push(tem_fee);
+            }
+            newInstallationFee.installFeeItem = tem_installFeeItem;
+        }
 
-       if(installSections && installSections.length > 0){//章节项
-           create = true;
-           let tem_installSections = [];
-           let tem_feeRules = [];
-           for(let isect of installSections){
+        if(installSections && installSections.length > 0){//章节项
+            create = true;
+            let tem_installSections = [];
+            let tem_feeRules = [];
+            for(let isect of installSections){
                 let tem_sec={
                     ID:isect.ID,
                     name:isect.name,
@@ -128,21 +155,18 @@ async function copyInstallationFeeFromLib(projectID,engineering_id) {
                 }else {
                     tem_sec.feeRuleId = "";
                 }
-               tem_installSections.push(tem_sec);
-           }
-           newInstallationFee.installSection = tem_installSections;
-           newInstallationFee.feeRule = tem_feeRules;
-       }
-       if(create==true){
-           installationFeeList.push(newInstallationFee);
-       }
-    }
-    console.log(installationFeeList);
-    if(installationFeeList.length > 0){
-        await installationFeeModel.insertMany(installationFeeList);
-    }
+                tem_installSections.push(tem_sec);
+            }
+            newInstallationFee.installSection = tem_installSections;
+            newInstallationFee.feeRule = tem_feeRules;
+        }
+        if(create == true){
+            return newInstallationFee;
+        }
+        return null;
 }
 
+
 function getData(projectID, callback) {
     installationFeeModel.find({'projectID': projectID}, (err, datas) => {
         if (err) {

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

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

+ 3 - 1
public/web/tree_sheet/tree_sheet_helper.js

@@ -156,7 +156,9 @@ var TREE_SHEET_HELPER = {
                 if (colSetting.data.cellType && Object.prototype.toString.apply(colSetting.data.cellType) !== "[object String]") {
                     cell.cellType(colSetting.data.cellType(node));
                 }
-                if (colSetting.readOnly) {
+                if(gljOprObj.isInstallationNode(node)){//如果是通过安装增加费自动生成的,都是只读类型
+                    cell.locked(true);
+                }else if (colSetting.readOnly) {
                     if (Object.prototype.toString.apply(colSetting.readOnly) === "[object Function]") {
                         cell.locked(colSetting.readOnly(node));
                     } else {

+ 1 - 1
web/building_saas/main/html/main.html

@@ -944,7 +944,7 @@
                     </div>
                 </div>
                 <div class="modal-footer">
-                    <button type="button" class="btn btn-link" >恢复默认值</button>
+                    <button type="button" class="btn btn-link" id="btn_reset_to_default">恢复默认值</button>
                   <!--  <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>-->
                     <button  class="btn btn-primary" id="calc_installation_fee_confirm">确定</button>
                 </div>

+ 22 - 6
web/building_saas/main/js/models/bills.js

@@ -589,10 +589,21 @@ var Bills = {
                 }else if(selected.sourceType==ModuleNames.ration_glj){
                     project.ration_glj.updataOrdelete(selected.source);
                 }
-                if(parent){
-                    projectObj.converseCalculateBills(parent);
-                }else { //删除的是大项费用要重新计算工程造价节点
-                    project.Bills.calcEngineeringCostNode(controller);
+                if(project.Bills.isFBFX(selected)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
+                    project.installation_fee.calcInstallationFee(function (isChange) {
+                        if(isChange){
+                            project.calcProgram.calcAllNodesAndSave();
+                        }else {
+                            if(parent){
+                                projectObj.converseCalculateBills(parent);
+                            }else { //删除的是大项费用要重新计算工程造价节点
+                                project.Bills.calcEngineeringCostNode(controller);
+                            }
+                            project.projectGLJ.loadData();
+                        }
+                    });
+                }else {
+                    project.projectGLJ.loadData();
                 }
             }
         };
@@ -695,9 +706,14 @@ var Bills = {
                 controller.m_delete(mainNodes);//删除树节点
                 me.tree.m_delete(idTreeNodes);
                 //重新计算
-                project.calcProgram.calcBillsAndSave(parentNodes,function () {
-                    project.projectGLJ.loadData();
+                project.installation_fee.calcInstallationFee(function (isChange) {
+                    project.calcProgram.calcAllNodesAndSave();
+                    if(!isChange) project.projectGLJ.loadData();
                 });
+
+               /* project.calcProgram.calcBillsAndSave(parentNodes,function () {
+                    project.projectGLJ.loadData();
+                });*/
             }, function () {
                 $.bootstrapLoading.end();
             });

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

@@ -1074,7 +1074,7 @@ class CalcProgram {
             $.bootstrapLoading.end();
             return;
         };
-
+        $.bootstrapLoading.start();
         me.project.updateNodes(dataArr, function (data) {
             if(callback){
                 callback(data);

+ 34 - 18
web/building_saas/main/js/models/installation_fee.js

@@ -202,15 +202,16 @@ var installation_fee = {
             let FBMap = {};//保存分部下对应的补项
             let usedBXMap = {};//有使用到的补项
             if(engineering!=engineeringType.BUILD_IN){//如果不是安装工程,则不用计算
+                if(callback) callback(false);
                 return;
             }
             for(let bx of BXs){//把补项放入映射表中
-                FBMap[bx.ParentID] =bx;
+                FBMap[bx.ParentID] = bx;
             }
             for(let d of me.datas){
                 for(let item of d.installFeeItem){
                     if(item.isCal == 1){ //勾选了记取的费用项
-                        let rule_ration_map={};//费用规则定额映射表;
+                        let rule_ration_map = {};//费用规则定额映射表;
                         let ra_installs = rationInstallation.getCalcRIByItemID(d.libID,item.ID);//取所有有效的定额安装增加费
                         for(let ri of ra_installs){
                             let rationNode = project.mainTree.getNodeByID(ri.rationID);
@@ -228,11 +229,6 @@ var installation_fee = {
                     }
                 }
             }
-
-            console.log("------------------生成的定额安装费");
-            console.log(rationKeyMap);
-            console.log("------------------新的清单");
-            console.log(newBills);
             let updateData = {
                 bills:{
                     delete:[],
@@ -246,9 +242,7 @@ var installation_fee = {
                 userID: userID
             };
             let oldITypeRations = _.cloneDeep(project.Ration.getAllInstallTypeRation())//取所有旧的安装增加费定额-没有用的要删除
-            let oldRationMap = {};
-            let deleteRationNodes = [];
-            let deleteBillsNodes = [];
+            let oldRationMap = {}, deleteRationNodes = [], deleteBillsNodes = [];
             let isChange = newBills.length>0;//记录数据是否发生了改变;
             for(let o of oldITypeRations){//过滤出要删除的定额
                 if(rationKeyMap[o.installationKey]==undefined){
@@ -285,10 +279,8 @@ var installation_fee = {
                 }
             }
 
-            console.log(updateData);
-            console.log(isChange);
             if(isChange == true){
-                $.bootstrapLoading.start()
+                $.bootstrapLoading.start();
                 CommonAjax.post("/project/calcInstallationFee",updateData,function (data) {
                     //提交后台成功后所做的操作,删除要先删除定额,再删除清单,添加要先添加清单再添加定额
                     console.log(data);
@@ -307,11 +299,13 @@ var installation_fee = {
                     projectObj.project.projectGLJ.loadData(function () {
                         cbTools.refreshFormulaNodes();
                         if(callback){
-                            callback();
+                            callback(true);
                         }
                         $.bootstrapLoading.end();
                     });
                 });
+            }else {
+                if(callback) callback(false);
             }
             function addNewNodes(updateData) {
                 let controller = projectObj.mainController;
@@ -338,13 +332,13 @@ var installation_fee = {
                     newAddNode.push(newNode);
                     project.Ration.datas.push(nr);
                 }
+                console.log("add nodes");
                 TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
             }
 
             function deleteOldNodes(deleteRationNodes,deleteBillsNodes) {
                 let controller = projectObj.mainController, project = projectObj.project;
-                let Bill = project.Bills, Ration = project.Bills.Ration,ration_glj = project.ration_glj;
-             //   let sels = controller.sheet.getSelections();
+                let Bill = project.Bills, Ration = project.Ration,ration_glj = project.ration_glj;
                 for(let rd of deleteRationNodes){
                     controller.sheet.deleteRows(rd.serialNo(),1);
                     controller.tree.delete(rd);
@@ -357,7 +351,8 @@ var installation_fee = {
                     Bill.tree.delete(bd.source);
                     Bill.removeByID(bd.getID());
                 }
-                controller.setTreeSelected(controller.tree.items[1]);
+                let sels = controller.sheet.getSelections();
+                controller.setTreeSelected(controller.tree.items[sels[0].row]);
             }
 
             
@@ -379,7 +374,6 @@ var installation_fee = {
                 }
                 oldRation.glj = gljList;
                 return modify;
-
             }
 
             function calcEachRule(item,libID,ruleID,rations,rationKeyMap,newBills) {
@@ -583,6 +577,7 @@ var installation_fee = {
                 data.name = rule.rule;
                 data.unit = '元';
                 data.quantity = '1';
+                data.contain ='1';
                 data.nextID = nextID;
                 data.glj = {
                     'RGFTZ':{
@@ -666,6 +661,27 @@ var installation_fee = {
             });
 
         };
+        installation_fee.prototype.resetToDefault = function (callback) {
+            let me = this;
+            let installFees = [];
+            for(let d of me.datas){
+                let ins ={
+                    libID:d.libID,
+                    ID:d.ID
+                };
+                installFees.push(ins);
+            }
+            //data.projectID,data.installFees
+            $.bootstrapLoading.start();
+            CommonAjax.post("/installation/resetToDefault",{projectID:project.ID(),installFees:installFees},function (result) {
+                console.log(result)
+                me.datas = result;
+                if(callback){
+                    callback();
+                }
+                $.bootstrapLoading.end();
+            })
+        };
         // 提交数据后返回数据处理
         installation_fee.prototype.doAfterUpdate = function(err, data){
 

+ 23 - 4
web/building_saas/main/js/models/quantity_detail.js

@@ -553,7 +553,6 @@ var quantity_detail = {
                     if(project.quantity_detail.quantityEditChecking(value,node,fieldName)){
                         node.data.isFromDetail=0;
                         project.quantity_detail.cleanQuantityDetail(node,true);
-                        $.bootstrapLoading.start();
                         if(node.sourceType === project.Bills.getSourceType()){
                             me.updateBillQuantity(value,node,null,editingText);
                         }else {
@@ -606,11 +605,23 @@ var quantity_detail = {
                     }
                 }
             }
-            if(needUpdateChildren.length>0){
+            if(needUpdateChildren.length>0){//清单下的定额工程量发生了改变
                 node.changed = true;//本身发生了改变,需要存储。
-                project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
+                /*project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
                     project.projectGLJ.loadData();
+                });*/
+                project.calcProgram.calcRationsAndSave(needUpdateChildren, function () {
+                    if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
+                        project.installation_fee.calcInstallationFee(function (isChange) {
+                            if(isChange){
+                                project.calcProgram.calcAllNodesAndSave();
+                            }
+                        });
+                    }else {
+                        project.projectGLJ.loadData();
+                    }
                 });
+
             }else {
                 node.changed = true;
                 project.calcProgram.calcAndSave(node, function () {
@@ -635,7 +646,15 @@ var quantity_detail = {
             }
             node.changed = true;
             project.calcProgram.calcAndSave(node, function () {
-                project.projectGLJ.loadData();
+                if(project.Bills.isFBFX(node)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
+                    project.installation_fee.calcInstallationFee(function (isChange) {
+                        if(isChange){
+                            project.calcProgram.calcAllNodesAndSave();
+                        }
+                    });
+                }else {
+                    project.projectGLJ.loadData();
+                }
             });
             projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机总消耗量
             gljOprObj.showRationGLJSheetData();

+ 9 - 1
web/building_saas/main/js/models/ration.js

@@ -481,8 +481,16 @@ var Ration = {
                     ProjectController.syncDisplayNewNode(sheetController, newNode);
                     project.projectGLJ.loadData(function () {
                         project.ration_glj.addToMainTree(data.ration_gljs);
-                        project.calcProgram.calcAndSave(newNode);
                         projectObj.mainController.refreshTreeNode([newNode], false);
+                        project.calcProgram.calcAndSave(newNode,function () {
+                            if(project.Bills.isFBFX(newNode)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
+                                project.installation_fee.calcInstallationFee(function (isChange) {
+                                    if(isChange){
+                                        project.calcProgram.calcAllNodesAndSave();
+                                    }
+                                });
+                            }
+                        });
                         $.bootstrapLoading.end();
                     });
                     console.log(data);

+ 5 - 8
web/building_saas/main/js/views/glj_view.js

@@ -361,19 +361,16 @@ var gljOprObj = {
         let me = gljOprObj;
         let selected = projectObj.project.mainTree.selected;
         if(selected){
-            if(me.isInstallationNode()==true){
+            if(me.isInstallationNode(selected)==true){
                 args.cancel = true;
             }
         }else {
             args.cancel = true;
         }
     },
-    isInstallationNode:function(){
-        let selected = projectObj.project.mainTree.selected;
-        if(selected){
-            if((selected.sourceType == ModuleNames.ration&&selected.data.type == rationType.install)||(selected.sourceType == ModuleNames.bills&&selected.data.type==billType.BX)){//是定额安装费类型或者补项
-                return true;
-            }
+    isInstallationNode:function(node){
+        if((node.sourceType == ModuleNames.ration&&node.data.type == rationType.install)||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
+            return true;
         }
         return false
     },
@@ -455,7 +452,7 @@ var gljOprObj = {
         if(args.sheetName == 'rationInstallSheet' && checkboxValue){
             return;
         }
-        if(gljOprObj.isInstallationNode()==true){
+        if(gljOprObj.isInstallationNode(selected)==true){
             return;
         }
         let newval = 0;

+ 32 - 13
web/building_saas/main/js/views/installation_fee_view.js

@@ -506,7 +506,6 @@ let installationFeeObj={
         return feeRules;
     },
 
-
     getDetailRowDataBySection(is,libID){
         let me = this;
         let tem_detail = {
@@ -1200,18 +1199,30 @@ let installationFeeObj={
             }
         }
         $('#calc_installation_fee').modal('hide');
-        install_fee.calcInstallationFee(function () {
-            projectObj.project.calcProgram.calcAllNodesAndSave();
-            gljOprObj.refreshView();
+        install_fee.calcInstallationFee(function (isChange) {
+            if(isChange){
+                projectObj.project.calcProgram.calcAllNodesAndSave();
+                gljOprObj.refreshView();
+            }
             console.log("cal end");
         });
     },
+    initSettingRadio:function () {
+        let installSetting = projectInfoObj.projectInfo.property.installSetting;
+        //radio 值设置
+        if(installSetting==undefined||installSetting=="0"){
+            $("#all_project_calc").prop("checked",true);
+            $("#FB_calc").prop("checked",false);
+        }else {
+            $("#all_project_calc").prop("checked",false);
+            $("#FB_calc").prop("checked",true);
+        }
+    }
 };
 
 
 $(function () {
     $('#calc_installation_fee').on('shown.bs.modal',function () {
-        let installSetting = projectInfoObj.projectInfo.property.installSetting;
         if(installationFeeObj.feeItemSpread == null){//初始化显示
             installationFeeObj.initInstallationFeeSpread();
         }else {
@@ -1219,13 +1230,7 @@ $(function () {
             installationFeeObj.showFeeDetailData();
         }
         //radio 值设置
-        if(installSetting==undefined||installSetting=="0"){
-            $("#all_project_calc").attr("checked","checked");
-            $("#FB_calc").attr("checked",false);
-        }else {
-            $("#all_project_calc").attr("checked",false);
-            $("#FB_calc").attr("checked","checked");
-        }
+        installationFeeObj.initSettingRadio();
 
     });
     $('#calc_position').on('shown.bs.modal',function () {
@@ -1278,7 +1283,21 @@ $(function () {
         }
         me.calcInstallationFee();
     });
-
+    $('#btn_reset_to_default').click(function (){
+        let ifModel =  projectObj.project.installation_fee;
+        let c = confirm("确定恢复系统默认值吗?");
+        if(c){
+            ifModel.resetToDefault(function () {
+                installationFeeObj.showFeeItemData();
+                installationFeeObj.showFeeDetailData();
+            });
+            ifModel.updateInstallSetting("0",function () {
+                installationFeeObj.initSettingRadio();
+            });
+        }
+      /*  installationFeeObj.showFeeItemData();
+        installationFeeObj.showFeeDetailData();*/
+    });
 
     $("input[name='install_setting_radios']").each(function(){
         $(this).click(function(){