Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

vian 5 лет назад
Родитель
Сommit
dc413e2884

+ 2 - 2
modules/main/controllers/ration_controller.js

@@ -87,9 +87,9 @@ let controller = {
         data = JSON.parse(data);
         let result = await ration_facade.updateCoeAdjust(data,req.session.sessionCompilation);
         //合并取项目工料机数据的情求,用于刷新项目工料机数据,当有添加、替换项目工料机的情况,才需要刷新
-        if(result.add.length > 0 || result.replace.length > 0){
+     /*   if(result.add.length > 0 || result.replace.length > 0){
             result.projectGLJDatas =  await getProjectGLJData(data.projectID);
-        }
+        }*/
         return result;
     }
 };

+ 3 - 0
modules/main/facade/project_facade.js

@@ -47,6 +47,7 @@ const billsLibDao = require("../../bills_lib/models/bills_lib_interfaces");
 
 async function calcInstallationFee(data) {
     let result={};
+    let projectGLJList = [];
     let billTasks  = generateTasks(data.bills,data.useID);
     let rationTasks = generateTasks(data.ration,data.useID);
     if(billTasks.length>0){
@@ -93,6 +94,7 @@ async function calcInstallationFee(data) {
             for(let tkey in nr.glj){
                 let [newRecode,projectGLJ] = await createRationGLJData(nr.glj[tkey])
                 newGljList.push(newRecode);
+                projectGLJList.push(projectGLJ);
             }
         }
     }
@@ -101,6 +103,7 @@ async function calcInstallationFee(data) {
     }
     result.update = updateList;
     result.add = newGljList;
+    result.projectGLJList = projectGLJList;
     return result;
 }
 

+ 9 - 4
modules/main/facade/ration_facade.js

@@ -505,16 +505,21 @@ async function deleteSubListByQuery(delete_query,cleanzmhs=false) {
 }
 
 async function updateCoeAdjust(data,compilation) {
-    let replace = [];
+    let replace = [],projectGLJList=[];
     await ration_coe.update({ID:data.ID},data.doc);
     //添加单个工料机的情况
-    if (data.add.length > 0)   await ration_glj_facade.insertAddTypeGLJ(data.add,compilation);
+    if (data.add.length > 0){
+      let [tg,pl] =  await ration_glj_facade.insertAddTypeGLJ(data.add,compilation);
+      if(pl.length > 0) projectGLJList = projectGLJList.concat(pl);
+    }
     if(data.delete.length > 0) await ration_glj_facade.deleteGLJ(data.delete);
 
     //替换工料机的情况
     if (data.replace.length > 0){
         for(let r of data.replace){
-            replace.push(await  ration_glj_facade.replaceGLJByData(r,compilation)) ;
+            let [rg,pg] = await  ration_glj_facade.replaceGLJByData(r,compilation);
+            replace.push(rg) ;
+            projectGLJList.push(pg);
         }
     }
 
@@ -532,7 +537,7 @@ async function updateCoeAdjust(data,compilation) {
         adjustState:cal_result.adjustState,
         name:cal_result.rationName
     };
-    return {coe:coe,ration_glj:ration_glj,ration:ration,add:data.add,delete:data.delete,replace:replace}
+    return {coe:coe,ration_glj:ration_glj,ration:ration,add:data.add,delete:data.delete,replace:replace,projectGLJList:projectGLJList}
 
 }
 

+ 13 - 8
modules/ration_glj/facade/ration_glj_facade.js

@@ -141,7 +141,7 @@ function get_lib_glj_info(ration_glj) {
                 ration_glj.repositoryId = glj.repositoryId;
                 ration_glj.adjCoe = glj.adjCoe;
                 getInfoFromProjectGLJ(ration_glj).then(function (info) {
-                    if (info) {
+                    if (info &&info.length>0) {
                         let tem = {};
                         tem.newRecode = createNewRecord(info[0]);
                         tem.showData = info[0];
@@ -635,13 +635,14 @@ async function prepareExtData(projectID,compilation) {
 
 async function addGLJ(rgList,compilation) {
     if (rgList.length <= 0) return {};
-    let newRecodes = await insertAddTypeGLJ(rgList,compilation);
+    let [newRecodes,projectGLJList] = await insertAddTypeGLJ(rgList,compilation);
     let stateResult = await glj_calculate_facade.calculateQuantity({
         projectID: rgList[0].projectID,
         rationID: rgList[0].rationID
     });
     let result = {
         newRecodes: newRecodes,
+        projectGLJList:projectGLJList,
         showData: rgList,
         adjustState: stateResult.adjustState
     };
@@ -650,6 +651,7 @@ async function addGLJ(rgList,compilation) {
 
 async function insertAddTypeGLJ(rgList,compilation) {
     let newRecodes = [];
+    let projectGLJList = [];
     let [unitFileId,ext] = await  prepareExtData(rgList[0].projectID,compilation);
     for (let g of rgList) {
         let projectGljModel = new GLJListModel();
@@ -668,9 +670,10 @@ async function insertAddTypeGLJ(rgList,compilation) {
             g.subList = getMixRatioShowDatas(result.subList);
         }
         newRecodes.push(createNewRecord(g));
+        projectGLJList.push(result);
     }
     await ration_glj.insertMany(newRecodes);
-    return newRecodes;
+    return [newRecodes,projectGLJList];
 }
 
 
@@ -693,20 +696,21 @@ async  function replaceGLJByData(data,compilation) {
     if (result.hasOwnProperty('subList') && result.subList.length > 0) {
         data.subList = getMixRatioShowDatas(result.subList);
     }
-    return data;
+    return [data,result];
 }
 
 
 async function replaceGLJ(data,compilation) {
     let rdata = {};
-    data = await  replaceGLJByData(data,compilation);
+    let [tdata,projectGLJ] = await  replaceGLJByData(data,compilation);
     let stateResult = await glj_calculate_facade.calculateQuantity({
-        projectID: data.projectID,
-        rationID: data.rationID
+        projectID: tdata.projectID,
+        rationID: tdata.rationID
     }, true,true);
-    rdata.data = data;
+    rdata.data = tdata;
     rdata.adjustState = stateResult.adjustState;
     rdata.name = stateResult.rationName;
+    rdata.projectGLJ = projectGLJ;
     return rdata;
 }
 async function mReplaceGLJ(data,compilation) {
@@ -739,6 +743,7 @@ async function mReplaceGLJ(data,compilation) {
     data.doc = newDoc;
     mresult.data = data;
     mresult.stateList = stateList;
+    mresult.projectGLJ = result;
     return mresult
 }
 

+ 1 - 1
web/building_saas/main/js/controllers/block_controller.js

@@ -361,7 +361,7 @@ let BlockController = {
                 }
             }
         }
-        //更新项目工料机模块信息-计算消耗量
+        //更新项目工料机模块信息-计算消耗量 ---修改了加载方式
       //  project.projectGLJ.datas = result.gljData;
       //  project.projectGLJ.calcQuantity();
         for(let r of result.rations){

+ 6 - 6
web/building_saas/main/js/models/installation_fee.js

@@ -345,13 +345,13 @@ var installation_fee = {
                     setTreeSelection(selectedNode);
                     let endTime =  +new Date();
                     console.log(`计算安装增加费时间——${endTime - startTime}`);
-                    projectObj.project.projectGLJ.loadData(function () {
-                        cbTools.refreshFormulaNodes();
-                        if(callback){
-                            callback(true,calRations);
-                        }
+                    projectObj.project.projectGLJ.loadNewProjectGLJToCaches(data.projectGLJList,true);
+                    cbTools.refreshFormulaNodes();
+                    if(callback){
+                        callback(true,calRations);
+                    }
                         $.bootstrapLoading.end();
-                    });
+
                 });
             }else {
                 if(callback) callback(false);

+ 5 - 2
web/building_saas/main/js/models/project_glj.js

@@ -925,14 +925,16 @@ ProjectGLJ.prototype.calcTenderQuantity  = function (){
 };
 
 ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas,calquantity = false) {
+    if(!datas) return;
     let gljIDMap = {};
     for (let d of datas){
-        this.loadNewProjectGLJToCache(d,gljIDMap);
+       if(d) this.loadNewProjectGLJToCache(d,gljIDMap);
     }
-    if(calquantity)  this.calcQuantity();
+    if(datas.length > 0 &&  calquantity)  this.calcQuantity();
 };
 
 ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新插入的项目工料机数据增加至缓存中
+    if(!data) return;
     let project_gljs = this.datas.gljList;
     let unitPriceMap = this.datas.unitPriceMap;
     let mixRatioMap = this.datas.mixRatioMap;
@@ -958,6 +960,7 @@ ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新
     if(!unitPriceMap[uIndex])  unitPriceMap[uIndex] = data.unit_price;
     this.datas.gljList.push(data);
     IDMap[data.id] = data;
+    return data;
 };
 
 class EvaluateList {

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

@@ -762,7 +762,7 @@ var Ration = {
              project.ration_installation.addDatasToList(data.ration_installations);
              project.ration_template.addDatasToList(data.ration_templates);
              project.quantity_detail.addDatasToList(data.quantity_details);
-             if(data.projectGLJList && data.projectGLJList.length > 0)  projectObj.project.projectGLJ.loadNewProjectGLJToCaches(data.projectGLJList,calquantity);
+             if(data.projectGLJList ) projectObj.project.projectGLJ.loadNewProjectGLJToCaches(data.projectGLJList,calquantity);
         };
 
         ration.prototype.replaceRation = function (ration, std) {

+ 16 - 16
web/building_saas/main/js/models/ration_glj.js

@@ -774,23 +774,23 @@ let ration_glj = {
                     let rationNode = projectObj.project.mainTree.findNode(data.rationID);
                     let nodes =  [rationNode];
                     glj_list[list_index] = data;
-                    project.projectGLJ.loadData(function () {//加载完项目工料机再计算
-                        gljOprObj.refreshView();
-                        if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
-                            let node = project.ration_glj.findGLJNodeByID(data.ID);
-                            if (node) {
-                                project.ration_glj.transferToNodeData(data);
-                                node.source = data;
-                                node.data = data;
-                            }
-                            node ? nodes.push(node) : "";
+                    project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
+                    gljOprObj.refreshView();
+                    if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
+                        let node = project.ration_glj.findGLJNodeByID(data.ID);
+                        if (node) {
+                            project.ration_glj.transferToNodeData(data);
+                            node.source = data;
+                            node.data = data;
                         }
-                        rationNode.data.adjustState = result.adjustState;
-                        rationNode.data.name = result.name;
-                        projectObj.mainController.refreshTreeNode(nodes);
-                        project.calcProgram.calcAndSave(rationNode);
-                        $.bootstrapLoading.end();
-                    });
+                        node ? nodes.push(node) : "";
+                    }
+                    rationNode.data.adjustState = result.adjustState;
+                    rationNode.data.name = result.name;
+                    projectObj.mainController.refreshTreeNode(nodes);
+                    project.calcProgram.calcAndSave(rationNode);
+                    $.bootstrapLoading.end();
+
                 }
             }, function () {
                 $.bootstrapLoading.end();

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

@@ -1275,13 +1275,13 @@ var gljOprObj = {
                     //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
                     project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
                     gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
-                    project.projectGLJ.loadData(function () {
-                        project.ration_glj.addToMainTree(result.showData);
-                        gljOprObj.showRationGLJSheetData();
-                        project.calcProgram.calcAndSave(selected);
-                        projectObj.mainController.refreshTreeNode([selected]);
-                        $.bootstrapLoading.end();
-                    });
+                    project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);
+                    project.ration_glj.addToMainTree(result.showData);
+                    gljOprObj.showRationGLJSheetData();
+                    project.calcProgram.calcAndSave(selected);
+                    projectObj.mainController.refreshTreeNode([selected]);
+                    $.bootstrapLoading.end();
+
                 }
             });//doc.rationID=selected.data.ID;
         }
@@ -1302,29 +1302,29 @@ var gljOprObj = {
                 let nodes = [selected];
                 gljOprObj.sheetData[index] = data;
                 glj_list[list_index] = data;
-                project.projectGLJ.loadData(function () {//加载完项目工料机再计算
-                    gljOprObj.showRationGLJSheetData();
-                    let node = project.ration_glj.updateGLJNodeAfterReplace(data);
-                    if(node) nodes.push(node);
-                    /*if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
-                        var node = project.ration_glj.findGLJNodeByID(data.ID);
-                        if (node) {
-                            project.ration_glj.transferToNodeData(data);
-                            node.source = data;
-                            node.data = data;
-                        }
-                        node ? nodes.push(node) : "";
-                    }*/
-                    //project.ration_glj.addToMainTree(data);
-                    selected.data.adjustState = result.adjustState;
-                    selected.data.name = result.name;
-                    projectObj.mainController.refreshTreeNode(nodes);
-                    project.calcProgram.calcAndSave(selected, async function () {
-                       await OVER_HEIGHT.reCalcOverHeightFee();
-                        await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes([selected]);
-                    });
-                    $.bootstrapLoading.end();
+                project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
+                gljOprObj.showRationGLJSheetData();
+                let node = project.ration_glj.updateGLJNodeAfterReplace(data);
+                if(node) nodes.push(node);
+                /*if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
+                    var node = project.ration_glj.findGLJNodeByID(data.ID);
+                    if (node) {
+                        project.ration_glj.transferToNodeData(data);
+                        node.source = data;
+                        node.data = data;
+                    }
+                    node ? nodes.push(node) : "";
+                }*/
+                //project.ration_glj.addToMainTree(data);
+                selected.data.adjustState = result.adjustState;
+                selected.data.name = result.name;
+                projectObj.mainController.refreshTreeNode(nodes);
+                project.calcProgram.calcAndSave(selected, async function () {
+                   await OVER_HEIGHT.reCalcOverHeightFee();
+                    await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes([selected]);
                 });
+                $.bootstrapLoading.end();
+
             }
         })
     },
@@ -1353,15 +1353,15 @@ var gljOprObj = {
                     }
                 }
             })
-            project.projectGLJ.loadData(function () {
-                me.showRationGLJSheetData();
-                var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
-                project.calcProgram.calcNodesAndSave(rationNodes, async function () {
-                    await OVER_HEIGHT.reCalcOverHeightFee();
-                    await  await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(rationNodes);
-                });
-                $.bootstrapLoading.end();
+            project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
+            me.showRationGLJSheetData();
+            var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
+            project.calcProgram.calcNodesAndSave(rationNodes, async function () {
+                await OVER_HEIGHT.reCalcOverHeightFee();
+                await  await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(rationNodes);
             });
+            $.bootstrapLoading.end();
+
         })
     },
     updateProperty: function (obj, doc) {

+ 3 - 1
web/building_saas/main/js/views/item_increase_fee_view.js

@@ -226,6 +226,7 @@ let itemIncreaseFeeObj = {
         let rationGLJMap ={};
         let uniqMap={};
         if(!itemIncreaseSetting) return;
+        if(itemIncreaseSetting.isCalc == false) return;
         for (n of nodes){
             if(n.sourceType == ModuleNames.ration) n = n.parent;
             if(uniqMap[n.data.ID]) continue;//去重复
@@ -233,11 +234,12 @@ let itemIncreaseFeeObj = {
             if(newRefreshNodes.length > 0) refreshNodes = refreshNodes.concat(newRefreshNodes);
             uniqMap[n.data.ID] = true;
         }
-        if(datas || refreshNodes.length > 0){
+        if(datas.length >0 || refreshNodes.length > 0){
             let nodes = await projectObj.project.syncUpdateNodesAndRefresh(datas);
             //重新计算
             cbTools.refreshFormulaNodes();
             projectObj.project.calcProgram.calcNodesAndSave(refreshNodes.concat(nodes));
+
         }
 
     },

+ 2 - 2
web/building_saas/main/js/views/zmhs_view.js

@@ -224,8 +224,8 @@ let zmhs_obj = {
 
         let rationID = result.ration.ID;
         ration_glj.updateCacheAfterAdjust(result.ration_glj);
-        if(result.projectGLJDatas){//有添加、替换、工料机等需重新加载的情况
-            projectObj.project.projectGLJ.refreshByDatas(result.projectGLJDatas);
+        if(result.projectGLJList && result.projectGLJList.length > 0){//有添加、替换、工料机等需重新加载的情况
+            projectObj.project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);
             if(result.add && result.add.length > 0) ration_glj.addToMainTree(result.add);//这个方法有再去项目工料机那里取价格,所以要在回调里调用,不像替换工料的情况
             ration_glj.reCalcWhenGLJChange({rationID:rationID});
             if(result.delete && result.delete.length > 0 && calcInstall) installationFeeObj.calcInstallationFee();//如果是删除节点的话,