Przeglądaj źródła

项目工料机加载优化

zhangweicheng 5 lat temu
rodzic
commit
3b1a841f1e

+ 2 - 1
modules/all_models/project_glj.js

@@ -110,7 +110,8 @@ let modelSchema = {
     transportLossQuantity: Number,    //场外运输损耗量(实际)
     //以下仅普通材料可用
     ratio_data: Schema.Types.Mixed,
-    remark:String
+    remark:String,
+    subList:[Schema.Types.Mixed]
 };
 mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false}));
 

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

@@ -30,9 +30,9 @@ let controller = {
         let start = +new Date();
         let result = await ration_facade.addNewRation(data,req.session.sessionCompilation);
         //合并取项目工料机数据的情求,用于刷新项目工料机数据,当有添加、替换项目工料机的情况,才需要刷新
-        if(result.ration_gljs && result.ration_gljs.length > 0 && data.newData){
+      /*  if(result.ration_gljs && result.ration_gljs.length > 0 && data.newData){
             result.projectGLJDatas =  await getProjectGLJData(data.newData.projectID);
-        }
+        }*/
         let end = +new Date();
         console.log("实际插入时间为-------------------------------"+(end-start));
         return result
@@ -43,9 +43,9 @@ let controller = {
         console.log(data);
         let result = await ration_facade.updateMaterialRation(data,req.session.sessionCompilation);
         //合并取项目工料机数据的情求,用于刷新项目工料机数据,当有添加、替换项目工料机的情况,才需要刷新
-        if(result.ration_gljs && result.ration_gljs.length > 0){
+       /* if(result.ration_gljs && result.ration_gljs.length > 0){
             result.projectGLJDatas =  await getProjectGLJData(data.projectID);
-        }
+        }*/
         return result
     },
     addMultiRation: async function (req) {
@@ -100,9 +100,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
 
     }

+ 10 - 6
modules/main/facade/bill_facade.js

@@ -80,10 +80,11 @@ module.exports={
         let [rationsAndRationGLJ,resultMap] = await Promise.all(pasteTasks);
 
         let gljController = new GLJController();
-        let projectGLJ = await gljController.getProjectGLJsByProjectID(data.projectID);
+        //let projectGLJ = await gljController.getProjectGLJsByProjectID(data.projectID);
         resultMap.rations = rationsAndRationGLJ.rations;
         resultMap.ration_gljs = rationsAndRationGLJ.new_ration_gljs;
-        resultMap.gljData = projectGLJ.data;
+        resultMap.projectGLJList = rationsAndRationGLJ.projectGLJList;
+        //resultMap.gljData = projectGLJ.data;
         return resultMap;
     },
     createNewBills:async function(newDatas){
@@ -163,7 +164,7 @@ async function pasteOtherData(data) {
 
 async function pasteRationsAndRationGLJ (rations,ration_gljs,compilation) {
     let projectGljModel = new GLJListModel();
-    let gljMap = {}, new_ration_gljs=[],projectID=null;
+    let gljMap = {}, new_ration_gljs=[],projectID=null,projectGLJList=[];
     if(rations.length > 0) projectID = rations[0].projectID;
     if(projectID==null && ration_gljs.length > 0) projectID = ration_gljs[0].projectID;
     if(projectID == null) return {rations:rations,new_ration_gljs:new_ration_gljs};
@@ -171,22 +172,24 @@ async function pasteRationsAndRationGLJ (rations,ration_gljs,compilation) {
     //先根据定额类型的工料机,插入到项目工料机中
     for(let r of rations){
         if(r.type == rationType.gljRation){
-            await getProjectGLJ(r,rationKeyArray,gljMap,unitFileId,ext);
+            let tg = await getProjectGLJ(r,rationKeyArray,gljMap,unitFileId,ext);
+            projectGLJList.push(tg)
         }
     }
 
     for(let rg of ration_gljs){
-        await getProjectGLJ(rg,gljKeyArray,gljMap,unitFileId,ext);
+        let tg = await getProjectGLJ(rg,gljKeyArray,gljMap,unitFileId,ext);
         let temRecord = ration_glj_facade.createNewRecord(rg);
         rg.rcode?temRecord.rcode = rg.rcode:'';
         rg.hasOwnProperty("customQuantity")?temRecord.customQuantity = rg.customQuantity:'';
         new_ration_gljs.push(temRecord);
+        projectGLJList.push(tg);
     }
 
     rations.length>0?await insertMany(rations,ration_Model):'';
     new_ration_gljs.length>0?await insertMany(new_ration_gljs,ration_glj_Model):'';
 
-    return {rations:rations,new_ration_gljs:new_ration_gljs};
+    return {rations:rations,new_ration_gljs:new_ration_gljs,projectGLJList:projectGLJList};
 
     async function getProjectGLJ (glj,keyArray,gljMap,unitFileId,ext) {
         let keyIndex = projectGljModel.getIndex(glj,keyArray);
@@ -199,6 +202,7 @@ async function pasteRationsAndRationGLJ (rations,ration_gljs,compilation) {
             gljMap[keyIndex] = pgljResult;
         }
         setResult(glj,pgljResult);
+        return pgljResult;
     }
 
 

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

@@ -40,6 +40,7 @@ const projectDao = require('../../pm/models/project_model').project;
 
 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){
@@ -85,7 +86,8 @@ async function calcInstallationFee(data) {
     if(data.ration.add.length>0){//新增的安装子目要增加对应的工料机
         for(let nr of data.ration.add){
             for(let tkey in nr.glj){
-                newGljList.push(await addInstallationGLJ(nr.glj[tkey]));
+                let [newRecode,projectGLJ] = await addInstallationGLJ(nr.glj[tkey]);
+                newGljList.push(newRecode);
             }
         }
     }
@@ -99,9 +101,9 @@ async function calcInstallationFee(data) {
 
 async function addInstallationGLJ(glj) {
     glj.ID = uuidV1();
-    let info = await ration_glj_facade.getInfoFromProjectGLJ(glj);
+    let [info,projectGLJ ] = await ration_glj_facade.getInfoFromProjectGLJ(glj);
     let newRecode  = ration_glj_facade.createNewRecord(info);
-    return newRecode;
+    return [newRecode,projectGLJ];
 }
 
 

+ 20 - 14
modules/main/facade/ration_facade.js

@@ -96,14 +96,14 @@ async function deleteMaterialRation(data) {
 async function modifyMaterialRation(data,compilation) {
     let model = data.type == "freight"?freightCalcModel:originaltCalcModel;
     if(data.field == "code"){
-        let [newRation,ration_gljs] = await getNewMaterialRationDatas(data,compilation);
+        let [newRation,ration_gljs,projectGLJList] = await getNewMaterialRationDatas(data,compilation);
         let quantity = data.rations[data.row].quantity;
         newRation.quantity = quantity;
         data.rations[data.row] = newRation;
         _.remove(data.ration_gljs,{rationID:data.rationID});
         data.ration_gljs = data.ration_gljs.concat(ration_gljs);
         await  model.update({'ID':data.parentID},{rations:data.rations,ration_gljs:data.ration_gljs});
-        return {ration:newRation,ration_gljs:ration_gljs}
+        return {ration:newRation,ration_gljs:ration_gljs,projectGLJList:projectGLJList}
     }else {
         let doc = {},pre = "rations.$.";
         let field = pre+data.field;
@@ -125,10 +125,10 @@ async function modifyMaterialRation(data,compilation) {
 }
 
 async function addMaterialRation(data,compilation) {
-    let [newRation,ration_gljs] = await getNewMaterialRationDatas(data,compilation);
+    let [newRation,ration_gljs,projectGLJList] = await getNewMaterialRationDatas(data,compilation);
     let model = data.type == "freight"?freightCalcModel:originaltCalcModel;
     await model.update({ID:data.parentID},{$push:{rations:newRation,ration_gljs:{$each:ration_gljs}}});
-    return{ration:newRation,ration_gljs:ration_gljs};
+    return{ration:newRation,ration_gljs:ration_gljs,projectGLJList:projectGLJList};
 }
 
 async function getNewMaterialRationDatas(data,compilation){
@@ -137,8 +137,8 @@ async function getNewMaterialRationDatas(data,compilation){
     if(!stdRation) throw  "找不到指定的定额!";//new Error("找不到指定的定额!");
 
     let newRation = await createNewMaterialRation(stdRation,data.quantityDecimal,data.projectID);
-    let ration_gljs = await addRationGLJ(stdRation,newRation,compilation,true,data.connect_key);
-    return [newRation,ration_gljs];
+    let [ration_gljs,projectGLJList] = await addRationGLJ(stdRation,newRation,compilation,true,data.connect_key);
+    return [newRation,ration_gljs,projectGLJList];
 }
 
 
@@ -296,7 +296,7 @@ async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuanti
 
 async function addRationSubList(stdRation,newRation,needInstall,compilation,cleanzmhs=false) {
     let startTime = +new Date();
-    let ration_gljs = await addRationGLJ(stdRation,newRation,compilation);
+    let [ration_gljs,projectGLJList] = await addRationGLJ(stdRation,newRation,compilation);
     let addRationGLJTime = +new Date();
     console.log("添加定额工料机时间-----"+(addRationGLJTime - startTime));
     let ration_coes = await addRationCoe(stdRation,newRation,compilation);
@@ -313,7 +313,7 @@ async function addRationSubList(stdRation,newRation,needInstall,compilation,clea
         //添加定额模板子目
         ration_template = await addRationTemplate(stdRation,newRation);
     }
-    return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installations:ration_installations,ration_templates:ration_template?[ration_template]:[]};
+    return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installations:ration_installations,ration_templates:ration_template?[ration_template]:[],projectGLJList:projectGLJList};
 }
 
 async function addRationInstallFee(std,newRation) {
@@ -480,6 +480,7 @@ function getExtendData(property,compilation) {
 async function addRationGLJ(std,newRation,compilation,isMaterial,connect_key) {
     let newRationGLJList = [];
     let rationGLJShowList = [];
+    let projectGLJList = [];
     let unitPriceFileId = 0;
     let property = await projectDao.getProjectProperty(newRation.projectID);
     if(property){
@@ -526,10 +527,11 @@ async function addRationGLJ(std,newRation,compilation,isMaterial,connect_key) {
             let std_glj = getStdGlj(sub,stdGLJMap,cptGLJMap,{},ext);
             if(std_glj){
                 ration_glj_facade.setPropertyFromStd(newGLJ,std_glj);
-                let info =  await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
+                let [info,projectGLJ] =  await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId,ext);
                 newGLJ = ration_glj_facade.createNewRecord(info);
                 newRationGLJList.push(newGLJ);
                 rationGLJShowList.push(info);
+                projectGLJList.push(projectGLJ);
             }
             //let InfoFromProjectGLJ = +new Date();
             //console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
@@ -537,7 +539,7 @@ async function addRationGLJ(std,newRation,compilation,isMaterial,connect_key) {
     }
     let before = +new Date();
     console.log("总查询时间为-------------------------------"+(before-first));
-    if(isMaterial == true) return newRationGLJList;//如果是材料计算的工料机,这里返回就可以了
+    if(isMaterial == true) return [newRationGLJList,projectGLJList];//如果是材料计算的工料机,这里返回就可以了
 
     if(newRationGLJList.length>0){
         await ration_glj.insertMany(newRationGLJList);
@@ -545,7 +547,7 @@ async function addRationGLJ(std,newRation,compilation,isMaterial,connect_key) {
     let after = +new Date();
     console.log("实际插入时间为-------------------------------"+(after-before));
     console.log("总操作时间为-------------------------------"+(after-first));
-    return rationGLJShowList;
+    return [rationGLJShowList,projectGLJList];
 }
 
 function getStdGlj(sub,stdGLJMap,cptGLJMap,newGLJ,ext) {
@@ -585,10 +587,13 @@ 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);
 
     //替换工料机的情况
@@ -596,6 +601,7 @@ async function updateCoeAdjust(data,compilation) {
         for(let r of data.replace){
             let r_result = await  ration_glj_facade.replaceGLJByData(r,compilation);
             replace.push(r_result.data) ;
+            projectGLJList.push(r_result.projectGLJ);
             if(r_result.newRecodes.length > 0) data.add = data.add.concat(r_result.newRecodes);
             if(r_result.deleteList.length > 0) data.delete = data.delete.concat(r_result.deleteList);
         }
@@ -614,7 +620,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}
 
 }
 

+ 12 - 7
modules/ration_glj/facade/ration_glj_facade.js

@@ -145,10 +145,10 @@ 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);
-                        tem.showData = info;
+                        tem.newRecode = createNewRecord(info[0]);
+                        tem.showData = info[0];
                         result.datas.push(tem);
                         cb(null, result);
                     } else {
@@ -207,7 +207,7 @@ async function getInfoFromProjectGLJ(ration_glj,unitPriceFileId,ext) {
         if (result.hasOwnProperty('subList') && result.subList.length > 0) {
             ration_glj.subList = getMixRatioShowDatas(result.subList);
         }
-        return ration_glj;
+        return [ration_glj,result];
     } catch (err) {
         logger.err(err);
         return null;
@@ -654,12 +654,13 @@ function setPropertyFromStd(newGLJ,std_glj) {
 
 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 = {
+        projectGLJList:projectGLJList,
         newRecodes: newRecodes,
         showData: rgList,
         adjustState: stateResult.adjustState
@@ -669,6 +670,7 @@ async function addGLJ(rgList,compilation) {
 
 async function insertAddTypeGLJ(rgList,compilation) {
     let newRecodes = [],GLJMap=null;
+    let projectGLJList = [];
     let [unitFileId,ext] = await  prepareExtData(rgList[0].projectID,compilation);
 
     for (let g of rgList) {
@@ -696,9 +698,10 @@ async function insertAddTypeGLJ(rgList,compilation) {
             }
         }
         newRecodes.push(createNewRecord(g));
+        projectGLJList.push(result);
     }
     await ration_glj.insertMany(newRecodes);
-    return newRecodes;
+    return [newRecodes,projectGLJList];
 }
 
 async function deleteRationGLJ(data){
@@ -792,7 +795,7 @@ async  function replaceGLJByData(data,compilation) {
         let updateResult = await ration_glj.findOneAndUpdate({ID: data.ID, projectID: data.projectID}, data);//更新定额工料机
     }
 
-    return {data:data,newRecodes:newRecodes,deleteList:deleteList};
+    return {data:data,newRecodes:newRecodes,deleteList:deleteList,projectGLJ:result};
 }
 
 
@@ -853,6 +856,7 @@ async function replaceGLJ(data,compilation) {
         rationID: data.rationID
     }, null,true);
     rdata.data = data;
+    rdata.projectGLJ = r_result.projectGLJ;
     rdata.adjustState = stateResult.adjustState;
     rdata.name = stateResult.rationName;
     rdata.newRecodes = r_result.newRecodes;
@@ -911,6 +915,7 @@ async function mReplaceGLJ(data,compilation) {
     mresult.newRecodes = mixResult?mixResult.newRecodes:[];
     mresult.deleteList = mixResult?mixResult.deleteList:[];
     mresult.glj_result = glj_result;
+    mresult.projectGLJ = result;
     return mresult
 }
 

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

@@ -355,9 +355,9 @@ let BlockController = {
                 }
             }
         }
-        //更新项目工料机模块信息-计算消耗量
-        project.projectGLJ.datas = result.gljData;
-        project.projectGLJ.calcQuantity();
+        //更新项目工料机模块信息-计算消耗量 ---修改了加载方式
+       /* project.projectGLJ.datas = result.gljData;
+        project.projectGLJ.calcQuantity();*/
         for(let r of result.rations){
             if(r.type == rationType.gljRation){//对于工料机类型的定额,要重新设置下市场单价
                 gljOprObj.setGLJPrice(r);

+ 14 - 8
web/building_saas/main/js/models/project_glj.js

@@ -816,7 +816,7 @@ ProjectGLJ.prototype.updateMaterialRation = async function (datas){
         let lists = datas.type == "freight"?this.datas.freightList:this.datas.originalList;
         $.bootstrapLoading.start();
         let result =  await ajaxPost('/ration/updateMaterialRation',datas);
-        if(datas.actionType=="add" && result.projectGLJDatas) this.refreshByDatas(result.projectGLJDatas);//这一步已经更新了运费和原价数据
+        if(datas.actionType=="add" && result.projectGLJList) this.loadNewProjectGLJToCaches(result.projectGLJList,true);//这一步已经更新了运费和原价数据
         if(datas.actionType == "delete"){
            let parent = _.find(lists,{ID:datas.parentID}) ;
            if(parent){
@@ -828,8 +828,8 @@ ProjectGLJ.prototype.updateMaterialRation = async function (datas){
             let parent = _.find(lists,{ID:datas.parentID}) ;
             let ration = parent?_.find(parent.rations,{ID:datas.rationID}):null;
             if(ration){
-                if(datas.field == "code" && result.projectGLJDatas){
-                    this.refreshByDatas(result.projectGLJDatas);
+                if(datas.field == "code" && result.projectGLJList){
+                    this.loadNewProjectGLJToCaches(result.projectGLJList,true);
                 }else {
                     ration[datas.field] = datas.value;
                     if(datas.ext){
@@ -1705,18 +1705,23 @@ ProjectGLJ.prototype.calcTenderQuantity  = function (){
     gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
 };
 
-ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas) {
+ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas,calquantity = false) {
+    if(!datas) return;
+    let gljIDMap = {};
     for (let d of datas){
-        this.loadNewProjectGLJToCache(d);
+        if(d) this.loadNewProjectGLJToCache(d,gljIDMap);
     }
+    if(datas.length > 0 &&  calquantity)  this.calcQuantity();
 };
 
-ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data) {//把新插入的项目工料机数据增加至缓存中
+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;
     let mixRatioConnectData = this.datas.mixRatioConnectData;
-    let tem =  _.find(project_gljs,{'id':data.id});
+    let IDMap = tIDMap?tIDMap:_.indexBy(project_gljs,'id');
+    let tem =  IDMap[data.id];
     if(tem) return tem; //判断该工料机是否已经存在,是的话不用再次添加
     //查看是否有组成物,有组成物的话先添加组成物信息
     data.ratio_data=[];
@@ -1727,7 +1732,7 @@ ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data) {//把新插入
             mixRatioMap[ratio.connect_key]?mixRatioMap[ratio.connect_key].push(ratio):mixRatioMap[ratio.connect_key] = [ratio];
             let rIndex = gljUtil.getIndex(ratio);
             mixRatioConnectData[rIndex]?mixRatioConnectData[rIndex].push(ratio.connect_key):mixRatioConnectData[rIndex] = [ratio.connect_key];
-            this.loadNewProjectGLJToCache(s);
+            this.loadNewProjectGLJToCache(s,IDMap);
         }
         delete data.subList;
     }
@@ -1735,5 +1740,6 @@ ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data) {//把新插入
     let uIndex = gljUtil.getIndex(data.unit_price);
     if(!unitPriceMap[uIndex])  unitPriceMap[uIndex] = data.unit_price;
     this.datas.gljList.push(data);
+    IDMap[data.id] = data;
     return data;
 };

+ 32 - 36
web/building_saas/main/js/models/ration.js

@@ -426,19 +426,16 @@ var Ration = {
                        project.ration_glj.removeNodeByRation(recode.ration,projectObj.mainController);
                        project.Ration.deleteSubListOfRation(recode.ration,cleanzmhs);//删除旧定额下的相关记录
                        //添加新的记录
-                       project.Ration.addSubListOfRation(recode);
-
-
+                       project.Ration.addSubListOfRation(recode,false);
                        project.ration_glj.addToMainTree(recode.ration_gljs);
                    }
                 }
-                project.projectGLJ.loadData(function () {
-                    mbzm_obj.nodeChanged = true;//子目模板关联刷新
-                    gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected,"-111111111");//这里第二个参数是为了使改前和改后selectedID不一样,删除了的话下方的定额工料机不会刷新
-                    project.calcProgram.calcNodesAndSave(refershNodes);
-                    projectObj.mainController.refreshTreeNode(refershNodes, true);
-                    $.bootstrapLoading.end();
-                });
+                project.projectGLJ.calcQuantity();
+                mbzm_obj.nodeChanged = true;//子目模板关联刷新
+                gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected,"-111111111");//这里第二个参数是为了使改前和改后selectedID不一样,删除了的话下方的定额工料机不会刷新
+                project.calcProgram.calcNodesAndSave(refershNodes);
+                projectObj.mainController.refreshTreeNode(refershNodes, true);
+                $.bootstrapLoading.end();
 
                 if(data.length < nodeInfo.length && nodeInfo[data.length].newCode!=null){//说明有部分定额编号没找到记录
                     alert('当前库中找不到定额"' + nodeInfo[data.length].newCode + '"');
@@ -512,7 +509,7 @@ var Ration = {
                     //更新缓存
                     for(let data of rstData){
                         me.datas.push(data.ration);
-                        me.addSubListOfRation(data);
+                        me.addSubListOfRation(data,false);
                         //插入树节点
                         newSource = data.ration;
                         newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
@@ -523,29 +520,28 @@ var Ration = {
                         newNode.data = newSource;
                         ProjectController.syncDisplayNewNode(sheetController, newNode);
                     }
-                    project.projectGLJ.loadData(function () {
-                        for(let data of rstData){
-                            project.ration_glj.addToMainTree(data.ration_gljs);
-                        }
-                        projectObj.mainController.refreshTreeNode(newNodes, false);
-                        if(project.Bills.isFBFX(newNodes[0])) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
-                            project.installation_fee.calcInstallationFee(function (isChange,rations) {
-                                if(isChange){
-                                    rations = rations.concat(newNodes);
-                                    project.calcProgram.calcNodesAndSave(rations);
-                                }else {
-                                    project.calcProgram.calcNodesAndSave(newNodes);
-                                }
-                            });
-                        }else {
-                            project.calcProgram.calcNodesAndSave(newNodes);
-                        }
-                        if(callback){
-                            callback();
-                        }
-                        showLoding = false;
-                        $.bootstrapLoading.end();
-                    });
+                    project.projectGLJ.calcQuantity();
+                    for(let data of rstData){
+                        project.ration_glj.addToMainTree(data.ration_gljs);
+                    }
+                    projectObj.mainController.refreshTreeNode(newNodes, false);
+                    if(project.Bills.isFBFX(newNodes[0])) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
+                        project.installation_fee.calcInstallationFee(function (isChange,rations) {
+                            if(isChange){
+                                rations = rations.concat(newNodes);
+                                project.calcProgram.calcNodesAndSave(rations);
+                            }else {
+                                project.calcProgram.calcNodesAndSave(newNodes);
+                            }
+                        });
+                    }else {
+                        project.calcProgram.calcNodesAndSave(newNodes);
+                    }
+                    if(callback){
+                        callback();
+                    }
+                    showLoding = false;
+                    $.bootstrapLoading.end();
                 })
             }
         };
@@ -614,7 +610,6 @@ var Ration = {
                         syncNodeOper(data);
                         if(callback) callback(newNode);
                     }else {
-                        if(data.projectGLJDatas) projectObj.project.projectGLJ.refreshByDatas(data.projectGLJDatas);
                         syncNodeOper(data);
                         if (newNode.parent.data.calcFlag)  newNode.parent.updateData.calcFlag = null;    // 删除定额时不用改Flag,反正添加定额时已经改好了。
                         project.calcProgram.calcAndSave(newNode,function () {
@@ -720,12 +715,13 @@ var Ration = {
                 projectObj.project.ration_template.deleteByRation(ration);
             }
         };
-        ration.prototype.addSubListOfRation = function (data) {
+        ration.prototype.addSubListOfRation = function (data,calquantity = true) {
              project.ration_glj.addDatasToList(data.ration_gljs);
              project.ration_coe.addDatasToList(data.ration_coes);
              project.ration_installation.addDatasToList(data.ration_installations);
              project.ration_template.addDatasToList(data.ration_templates);
              project.quantity_detail.addDatasToList(data.quantity_details);
+            if(data.projectGLJList ) projectObj.project.projectGLJ.loadNewProjectGLJToCaches(data.projectGLJList,calquantity);
         };
 
         ration.prototype.replaceRation = function (ration, std) {

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

@@ -752,23 +752,21 @@ let ration_glj = {
                     let data = result.data;
                     let rationNode = projectObj.project.mainTree.findNode(data.rationID);
                     let nodes =  [rationNode];
-                    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) : "";
+                    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();
@@ -781,6 +779,7 @@ let ration_glj = {
             let list_index = _.findIndex(me.datas, {'ID': result.data.ID});
             if(result.data) me.datas[list_index] = result.data;
             me.refreshQuantityAfterCalResult(result.glj_result);
+            if(result.projectGLJ) project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
         };
 
         ration_glj.prototype.addAndDeleteDatas = function (newRecodes,deleteList) {

+ 30 - 33
web/building_saas/main/js/views/glj_view.js

@@ -1167,13 +1167,12 @@ 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);//组成物不会显示到造价书页面
-                        project.calcProgram.calcAndSave(selected);
-                        projectObj.mainController.refreshTreeNode([selected]);
-                        gljOprObj.refreshView();
-                        $.bootstrapLoading.end();
-                    });
+                    project.projectGLJ.loadNewProjectGLJToCaches(result.projectGLJList,true);
+                    project.ration_glj.addToMainTree(result.showData);//组成物不会显示到造价书页面
+                    project.calcProgram.calcAndSave(selected);
+                    projectObj.mainController.refreshTreeNode([selected]);
+                    gljOprObj.refreshView();
+                    $.bootstrapLoading.end();
                 }
             });//doc.rationID=selected.data.ID;
         }
@@ -1215,26 +1214,24 @@ var gljOprObj = {
                 project.ration_glj.setDatasAfterReplace(result);
                 let data = result.data;
                 let nodes = [selected];
-                project.projectGLJ.loadData(function () {//加载完项目工料机再计算
-                    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);
-                    gljOprObj.refreshView();
-                    $.bootstrapLoading.end();
-                });
+                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);
+                gljOprObj.refreshView();
+                $.bootstrapLoading.end();
             }
         })
     },
@@ -1272,12 +1269,12 @@ var gljOprObj = {
                     me.updateProperty(t,quantityMap[t.ID]);
                 }
             })
-            project.projectGLJ.loadData(function () {
-                var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
-                project.calcProgram.calcNodesAndSave(rationNodes);
-                me.refreshView();
-                $.bootstrapLoading.end();
-            });
+            project.projectGLJ.loadNewProjectGLJToCaches([result.projectGLJ],true);
+            var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
+            project.calcProgram.calcNodesAndSave(rationNodes);
+            me.refreshView();
+            $.bootstrapLoading.end();
+
         })
     },
     updateProperty: function (obj, doc) {

+ 9 - 9
web/building_saas/main/js/views/mbzm_view.js

@@ -157,7 +157,7 @@ let mbzm_obj={
             if(result.rationResult){
                 for(let rr of result.rationResult){
                     nodeDatas.ration.add.push(rr.ration);//定额datas数据的push在addNodes里面做
-                    projectObj.project.Ration.addSubListOfRation(rr);//添加定额子项缓存
+                    projectObj.project.Ration.addSubListOfRation(rr,false);//添加定额子项缓存
                 }
             }
             //对于新插入的清单:
@@ -174,15 +174,15 @@ let mbzm_obj={
                 }
                 projectObj.mainController.refreshTreeNode(refreshNodes, false);
             }
-            projectObj.project.projectGLJ.loadData(function () {
-                $.bootstrapLoading.end();
-                cbTools.refreshFormulaNodes();
-                //更新计算程序模板,并进行重新计算
-                projectObj.project.calcProgram.calcNodesAndSave(calRations,function () {
-                    installationFeeObj.calcInstallationFee();
-                });
-                mbzm_obj.showApplySuccess();
+            projectObj.project.projectGLJ.calcQuantity();
+            $.bootstrapLoading.end();
+            cbTools.refreshFormulaNodes();
+            //更新计算程序模板,并进行重新计算
+            projectObj.project.calcProgram.calcNodesAndSave(calRations,function () {
+                installationFeeObj.calcInstallationFee();
             });
+            mbzm_obj.showApplySuccess();
+
         })
     },
     showApplySuccess:function () {

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

@@ -262,8 +262,8 @@ let zmhs_obj = {
         projectObj.mainController.refreshTreeNode(nodes, false);
         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();//如果是删除节点的话,

+ 1 - 1
web/building_saas/pm/html/project-management.html

@@ -730,7 +730,7 @@
                 </button>
             </div>
             <div class="modal-body" id="welcomeBody">
-                <div class="modal-fixed-height" style="overflow-y:auto">
+                <div style="max-height:465px">
                      <%- context %>
                 </div>
             </div>