소스 검색

bug fixed

zhangweicheng 6 년 전
부모
커밋
aa3aa8034b

+ 0 - 1
modules/ration_glj/controllers/ration_glj_controller.js

@@ -85,7 +85,6 @@ async function replaceGLJ(req, res){
     try {
         let data = req.body.data;
         data = JSON.parse(data);
-        console.log(data);
         let rdata= await ration_glj_facade.replaceGLJ(data);
         result.data=rdata;
     }catch (err){

+ 31 - 6
modules/ration_glj/facade/glj_calculate_facade.js

@@ -30,14 +30,14 @@ let stateSeq ={
 };
 
 
-async function calculateQuantity(query,noNeedCal){
+async function calculateQuantity(query,noNeedCal,refreshRationName = false){
     try {
          let  result ={
              glj_result:[],
              rationID:query.rationID
          };
          let impactRation = await ration.findOne({projectID:query.projectID,ID:query.rationID,deleteInfo:null});
-         let gljList = await ration_glj.find(query)//{projectID:query.projectID,rationID:query.rationID}
+         let gljList = await ration_glj.find(query);//{projectID:query.projectID,rationID:query.rationID}
          let coeList = await ration_coe.find({projectID:query.projectID,rationID:query.rationID}).sort('seq').exec();
          let assList=[];
          let assRation = null;
@@ -55,19 +55,25 @@ async function calculateQuantity(query,noNeedCal){
                  }
              }
          }
-        gljList = sortRationGLJ(gljList);
+         gljList = sortRationGLJ(gljList);
          for(let i =0;i<gljList.length;i++ ){
              let r = await calculateQuantityPerGLJ(gljList[i],i,coeList,assList,adjustState,noNeedCal);
              result.glj_result.push(r);
          }
 
-        if(noNeedCal==null){
+         if(noNeedCal==null){
             await ration_glj.bulkWrite(generateUpdateTasks(result.glj_result));
-        }
+         }
          adjustState= _.sortByOrder(adjustState, ['index'], ['asc']);
          adjustState=_.map(adjustState, _.property('content'));
          let adjustStateString = adjustState.join(';');
-         await ration.update({projectID:query.projectID,ID:query.rationID,deleteInfo: null},{adjustState:adjustStateString});
+         let setData = {adjustState:adjustStateString};
+         if(refreshRationName == true){//需要更新定额名称
+             let newName = generateRationName(impactRation,gljList);
+             setData.name = newName;
+             result.rationName = newName;
+         }
+         await ration.update({projectID:query.projectID,ID:query.rationID,deleteInfo: null},setData);
          result.adjustState=adjustStateString;
          return result;
     }catch (err){
@@ -76,6 +82,25 @@ async function calculateQuantity(query,noNeedCal){
     }
 }
 
+function generateRationName(ration,gljList) {
+    let caption = ration.caption ? ration.caption:ration.name;
+    if(ration.rationAssList && ration.rationAssList.length > 0){
+        let ass = ration.rationAssList[0];
+        if(ass.actualValue != null && ass.actualValue != undefined ){
+            caption =  caption.replace('%s',ass.actualValue);
+        }
+    }
+
+    for(let g of gljList){
+        //glj._doc.createType=='replace'&&glj.rcode!=glj.code
+        if(g.createType=='replace'&&g.rcode!=g.code){ //是替换工料机
+            caption = caption + ' '+g.name;
+            if(!_.isEmpty(g.specs)) caption = caption + ' '+g.specs
+        }
+    }
+    return caption;
+}
+
 function generateUpdateTasks(result) {
     let tasks = [];
     for(let i =0;i<result.length;i++){

+ 3 - 3
modules/ration_glj/facade/ration_ass_facade.js

@@ -58,7 +58,7 @@ function update_ration_ass(user_id,datas) {
                         stateRefresh:true,
                         rationID:result.cal_result.rationID,
                         adjustState:result.cal_result.adjustState,
-                        name:datas.doc.name
+                        name:result.cal_result.rationName
                     }
                 };
                 callback(null,[newObject,ration_glj_data,ration_data]);
@@ -73,10 +73,10 @@ async function doRationAssAdjust(ration,doc) {
     let result ={
         err:null,
         cal_result:[]
-    }
+    };
     try{
         await rationModel.update({projectID:ration.projectID,ID:ration.ID,deleteInfo: null},doc);
-        let cal_result = await glj_calculate_facade.calculateQuantity({projectID:ration.projectID,rationID:ration.ID});
+        let cal_result = await glj_calculate_facade.calculateQuantity({projectID:ration.projectID,rationID:ration.ID},null,true);
         result.cal_result=cal_result;
         return result;
     }catch (err){

+ 6 - 4
modules/ration_glj/facade/ration_glj_facade.js

@@ -644,9 +644,10 @@ async function replaceGLJ(data) {
     let stateResult = await glj_calculate_facade.calculateQuantity({
         projectID: data.projectID,
         rationID: data.rationID
-    }, true);
+    }, true,true);
     rdata.data = data;
     rdata.adjustState = stateResult.adjustState;
+    rdata.name = stateResult.rationName;
     return rdata;
 }
 async function mReplaceGLJ(data) {
@@ -724,8 +725,9 @@ async function doRationGLJUpdate(data) {
     let stateResult = await glj_calculate_facade.calculateQuantity({
         projectID: data.query.projectID,
         rationID: data.query.rationID
-    });
+    },null,true);
     resutl.adjustState = stateResult.adjustState;
+    resutl.name = stateResult.rationName;
     return resutl;
 }
 
@@ -800,9 +802,9 @@ async function changAdjustState(data, rationList) {
         let stateResult = await glj_calculate_facade.calculateQuantity({
             projectID: data.query.projectID,
             rationID: r
-        }, true);
+        }, true,true);
         if(stateResult){
-            stateList.push({rationID: r, adjustState: stateResult.adjustState});
+            stateList.push({rationID: r, adjustState: stateResult.adjustState,name:stateResult.rationName});
         }
     }
     return stateList;

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

@@ -523,7 +523,7 @@ let BlockController = {
             temData.ID = newID; //新的清单ID
             if(temData.billsLibId && temData.billsLibId!="" && temData.code.length == 12){//是从清单库来的
                 let value = temData.code.substr(0,9);
-                if (value&&value.length === 9 && /^[\d]+$/.test(value)) {
+                if (value&&value.length === 9) {//&& /^[\d]+$/.test(value) 去掉全数字判断    07-31 zhang
                     temData.code = me.newFormatCode(value);
                 }
             }

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

@@ -730,7 +730,7 @@ var Ration = {
                 if (calcTools.isLeafBill(node)
                     && (node.data.type != billType.DXFY)
                     && (node.data.type != billType.FB)
-                    && !project.Bills.isMeasure(node)) return true;  // 叶子清单项
+                    && project.Bills.isMeasure(node)) return true;  // 叶子清单项
             };
 
             return false;

+ 14 - 11
web/building_saas/main/js/models/ration_glj.js

@@ -430,9 +430,7 @@ var ration_glj = {
                     for (var key in doc) {
                         recode[key] = doc[key];
                     }
-                    if (data.hasOwnProperty('adjustState')) {//更新定额调整状态
-                        me.updateRationAdjustState(data.adjustState, recode.rationID, node);
-                    }
+                    me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
                     if (recode.subList && recode.subList.length > 0) {
                         initShow = true;
                     }
@@ -481,16 +479,19 @@ var ration_glj = {
             var me = this;
             data.glj_result.forEach(function (item) {
                 me.refreshEachItme(item.doc, item.query);
-            })
-            me.updateRationAdjustState(data.adjustState, data.rationID, node);
+            });
+            me.refreshRationAfterEdit(data, data.rationID, node);
         };
-        ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
-            var nodes = [];
-            var node = _.find(projectObj.project.mainTree.items, function (n) {
-                return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
-            })
+        ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
+            let nodes = [];
+            let node = projectObj.project.mainTree.findNode(rationID);
             if (node) {
-                node.data.adjustState = adjustState;
+                if(data.adjustState){
+                    node.data.adjustState = data.adjustState;
+                }
+                if(data.name){
+                    node.data.name = data.name;
+                }
                 nodes.push(node);
             }
             if (rnode) {
@@ -498,6 +499,7 @@ var ration_glj = {
             }
             projectObj.mainController.refreshTreeNode(nodes);
         };
+
         ration_glj.prototype.getGLJData = function (cb) {
             let engineerID = projectInfoObj.projectInfo.property.engineering_id;
             CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
@@ -684,6 +686,7 @@ var ration_glj = {
                             node ? nodes.push(node) : "";
                         }
                         rationNode.data.adjustState = result.adjustState;
+                        rationNode.data.name = result.name;
                         projectObj.mainController.refreshTreeNode(nodes);
                         project.calcProgram.calcAndSave(rationNode);
                         $.bootstrapLoading.end();

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

@@ -8,6 +8,7 @@ var gljOprObj = {
     ration: null,
     sheetData: [],
     checkb: null,
+    mainTreeSelectedChange:false,
     detailSheet: null,
     detailData: [],
     GLJSelection: [],
@@ -519,7 +520,10 @@ var gljOprObj = {
         this.addMixRatioToShow();//显示组成物信息
         this.initRationTree(init,this.getUnitPriceCodeMap());
         sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
-        if(selected){//定位光标到之前的位置
+        if(this.mainTreeSelectedChange == true){
+            this.sheet.setSelection(0,1,1,1);//默认选中第一行,第二列(名称列)
+            this.mainTreeSelectedChange = false;
+        }else if(selected){//定位光标到之前的位置
             this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
         }
     },
@@ -534,7 +538,7 @@ var gljOprObj = {
                    if(codeMap[preCode]) {
                        codeMap[preCode].push({text:code,value:connectKey});
                    }else {
-                       codeMap[preCode]=[{text:code,value:connectKey}];
+                       codeMap[preCode]=[{text:code ,value:connectKey}];
                    }
                 }
             }
@@ -1071,6 +1075,7 @@ var gljOprObj = {
                     }
                     //project.ration_glj.addToMainTree(data);
                     selected.data.adjustState = result.adjustState;
+                    selected.data.name = result.name;
                     projectObj.mainController.refreshTreeNode(nodes);
                     project.calcProgram.calcAndSave(selected);
                     $.bootstrapLoading.end();
@@ -1126,6 +1131,7 @@ var gljOprObj = {
             })
             if (node) {
                 node.data.adjustState = s.adjustState;
+                node.data.name = s.name;
                 nodes.push(node);
                 rationNodes.push(node);
             }

+ 4 - 4
web/building_saas/main/js/views/project_view.js

@@ -35,6 +35,7 @@ var projectObj = {
         if($('#linkComments').hasClass('active')){
             subViewObj.loadComments(node);
         }
+        gljOprObj.mainTreeSelectedChange = true;
         gljOprObj.showDataIfRationSelect(node);
         if (activeSubSheetIsCalcProgram())
             calcProgramObj.refreshCalcProgram(node, 3);
@@ -322,12 +323,12 @@ var projectObj = {
             withinValidFixed = true;
         }
         if(withinValidFixed && (node.data.type==billType.FX||node.data.type==billType.BX||(node.data.type==billType.BILL&&node.source.children.length==0))){//是分项、补项或者叶子清单的情况下才需要查找替换
-            if (value&&value.length === 9 && /^[\d]+$/.test(value)) {
+            if (value&&value.length === 9) {//&& /^[\d]+$/.test(value)  去掉全数字判断    07-31 zhang
                 stdMatchCode = value;
                 formatCode = project.Bills.newFormatCode(stdMatchCode);
                 searchStdBillsAndUpdate(stdMatchCode, formatCode);
                 return;
-            } else if (value&&value.length === 12 && /^[\d]+$/.test(value)) {
+            } else if (value&&value.length === 12 ) {//&& /^[\d]+$/.test(value) 去掉全数字判断    07-31 zhang
                 stdMatchCode = value.substr(0, 9);
                 matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
                 if (matchs.indexOf(value) === -1) {
@@ -484,8 +485,7 @@ var projectObj = {
                 }
                 else if (node.sourceType === project.Ration.getSourceType()) {
                     project.Ration.updateField(node.source, fieldName, value);
-                };
-
+                }
                 if (colSetting.data.wordWrap) {
                     this.mainSpread.getActiveSheet().autoFitRow(node.serialNo());
                 }