Преглед изворни кода

bugs 替换人材机类型

zhangweicheng пре 6 година
родитељ
комит
047f2a06b2

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

@@ -475,17 +475,24 @@ async function deleteSubListByQuery(delete_query) {
 }
 
 async function updateCoeAdjust(data,compilation) {
-    let newGLJs = [];
+    let replace = [];
     await ration_coe.update({ID:data.ID},data.doc);
     //添加单个工料机的情况
-    if (data.add.length > 0) newGLJs = await ration_glj_facade.insertAddTypeGLJ(data.add,compilation);
+    if (data.add.length > 0)   await ration_glj_facade.insertAddTypeGLJ(data.add,compilation);
     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 cal_result = await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID});
     let coe = {
         query:{ID:data.ID,projectID:data.projectID},
         doc:data.doc
-    }
+    };
     let ration_glj ={
         quantityRefresh:true,
         glj_result:cal_result.glj_result
@@ -494,7 +501,7 @@ async function updateCoeAdjust(data,compilation) {
         ID:cal_result.rationID,
         adjustState:cal_result.adjustState
     };
-    return {coe:coe,ration_glj:ration_glj,ration:ration,add:data.add,delete:data.delete}
+    return {coe:coe,ration_glj:ration_glj,ration:ration,add:data.add,delete:data.delete,replace:replace}
 
 }
 

+ 9 - 2
modules/ration_glj/facade/ration_glj_facade.js

@@ -40,6 +40,7 @@ module.exports = {
     deleteGLJ:deleteGLJ,
     insertAddTypeGLJ:insertAddTypeGLJ,
     replaceGLJ: replaceGLJ,
+    replaceGLJByData:replaceGLJByData,
     mReplaceGLJ: mReplaceGLJ,
     updateRationGLJByEdit: updateRationGLJByEdit,
     getGLJClass: getGLJClass,
@@ -656,8 +657,7 @@ async function insertAddTypeGLJ(rgList,compilation) {
 }
 
 
-async function replaceGLJ(data,compilation) {
-    let rdata = {};
+async  function replaceGLJByData(data,compilation) {
     let projectGljModel = new GLJListModel();
     let [unitFileId,ext] = await  prepareExtData(data.projectID,compilation);
     let result = await projectGljModel.addList(getGLJSearchInfo(data),unitFileId,ext);
@@ -676,6 +676,13 @@ async function replaceGLJ(data,compilation) {
     if (result.hasOwnProperty('subList') && result.subList.length > 0) {
         data.subList = getMixRatioShowDatas(result.subList);
     }
+    return data;
+}
+
+
+async function replaceGLJ(data,compilation) {
+    let rdata = {};
+    data = await  replaceGLJByData(data,compilation);
     let stateResult = await glj_calculate_facade.calculateQuantity({
         projectID: data.projectID,
         rationID: data.rationID

+ 2 - 2
web/building_saas/main/js/models/quantity_detail.js

@@ -728,7 +728,7 @@ var quantity_detail = {
             node.data.quantityEXP = quantityEXP?quantityEXP:editingText;
             value = scMathUtil.roundForObj(value,getDecimal("quantity",node));
             let newQuantity =  value+"";
-            if(oldQuantityEXP == node.data.quantityEXP && node.data.quantity == newQuantity){ //相当于什么都没改,不用做提交操作
+            if(quantityEXP!="GCLMXHJ"&& oldQuantityEXP == node.data.quantityEXP && node.data.quantity == newQuantity){ //除了修改工程量明细表达式进来的操作,相当于什么都没改,不用做提交操作
                 projectObj.mainController.refreshTreeNode([node]);//这里要再刷新一下,因为工程量要把手工输入的值刷新为转换后的值再显示
                 return;
             }
@@ -801,7 +801,7 @@ var quantity_detail = {
             //value = scMathUtil.roundForObj(value,getDecimal("ration.quantity"));
             value = project.quantity_detail.autoTransformQuantity(value,node);//先转换再4舍5入
             value = scMathUtil.roundForObj(value,decimalObj.decimal("quantity",node));
-            if(oldQuantityEXP == node.data.quantityEXP && node.data.quantity == value){ //相当于什么都没改,不用做提交操作
+            if( quantityEXP!="GCLMXHJ" && oldQuantityEXP == node.data.quantityEXP && node.data.quantity == value){ //除了修改工程量明细表达式进来的操作,相当于什么都没改,不用做提交操作
                 projectObj.mainController.refreshTreeNode([node]);//这里要再刷新一下,因为工程量要把手工输入的值刷新为转换后的值再显示
                 return;
             }

+ 24 - 13
web/building_saas/main/js/models/ration_coe.js

@@ -151,19 +151,40 @@ var ration_coe = {
                     }else {//取消勾选时,要删除添加的工料机记录
                        if(glj && glj.createType == "add") updateData.delete.push(glj.ID);
                     }
-
                 }
                 //替换工料机的情况
+                if(coe.coeType ==  "替换人材机"){
+                    let glj = _.find(gljList,{"rcode":coe.gljCode,'code':coe.replaceCode});//两个条件都满足,则表示已找到对应的记录
+                    if(newval == 1){
+                        if(glj) continue;
+                        let r_glj = _.find(gljList,function (g) {
+                            return (g.code == coe.gljCode && (g.createType===undefined || g.createType == 'normal')) || g.rcode == coe.gljCode //这两个满足一个说明要替换
+                        });
+                        if(r_glj){
+                            replace.push({code:coe.replaceCode,oldData:r_glj});
+                            codesList.push(coe.replaceCode);
+                        }
+                    }
+                    if(newval == 0 && glj){//取消勾选并找到的情况,要恢复成原来的
+                        replace.push({code:coe.gljCode,oldData:glj});
+                        codesList.push(coe.gljCode);
+                    }
+                }
             }
             project.ration_glj.getGLJDataByCodes(codesList,function (gljList) {//统一从后端按编号查找标准工料机信息
                 let gljMap = _.indexBy(gljList, 'code');
-                console.log(gljMap);
                 for(let a of add){
                     if(gljMap[a]){
                         let tem = project.ration_glj.getAddDataByStd(gljMap[a],recode.rationID,project.mainTree.selected.data.billsItemID,recode.projectID);
                         updateData.add.push(tem);
                     }
                 }
+                for(let r of replace){
+                    if(gljMap[r.code]){
+                        let r_tem = project.ration_glj.getReplaceDataByStd(r.oldData,gljMap[r.code]);
+                        updateData.replace.push(r_tem);
+                    }
+                }
                 $.bootstrapLoading.start();
                 CommonAjax.post("/ration/updateCoeAdjust",updateData,function (result) {
                     $.bootstrapLoading.end();
@@ -171,17 +192,7 @@ var ration_coe = {
                     zmhs_obj.refreshAfterUpdate(result,true)
                 })
             });
-
-
-
-
-
-           /* ;*/
-
-
-
-            //var updateData = this.getUpdateData('ut_update',query,doc,'adjustUpdate');
-           // project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
+            
         };
 
         ration_coe.prototype.updateCustomerCoe = function (data) {

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

@@ -187,6 +187,18 @@ let ration_glj = {
                 }
             }
         };
+        ration_glj.prototype.updateGLJNodeAfterReplace = function(data){
+            if (this.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
+                var node = this.findGLJNodeByID(data.ID);
+                if (node) {
+                    this.transferToNodeData(data);
+                    node.source = data;
+                    node.data = data;
+                }
+               return node;
+            }
+        };
+
         ration_glj.prototype.addToMainTree = function (datas) {
             datas = sortRationGLJ(datas);
             for (let data of datas) {
@@ -732,23 +744,16 @@ let ration_glj = {
             }, function () {
                 $.bootstrapLoading.end();
             });
-
-
         };
 
-        ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
-            let allGLJ = gljOprObj.AllRecode;
-            let glj = _.find(allGLJ, function (item) {
-                let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
-                return i_key == selectCode;
-            });
-            if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
-                return callback(null);
-            }
+        ration_glj.prototype.getReplaceDataByStd = function (oldData,glj) {
             if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
                 oldData.rcode = oldData.code;
                 oldData.createType = 'replace';
             }
+            if(oldData.createType == 'replace' && oldData.rcode == glj.code){//如果原数据已经是替换过的,这次替换又恢复成原数据,则把类型改回来
+                oldData.createType = 'normal'
+            }
             oldData.GLJID = glj.ID;
             oldData.name = glj.name;
             oldData.code = glj.code;
@@ -769,6 +774,20 @@ let ration_glj = {
             } else {
                 oldData.from = "std";
             }
+            return oldData;
+        };
+
+
+        ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
+            let allGLJ = gljOprObj.AllRecode;
+            let glj = _.find(allGLJ, function (item) {
+                let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
+                return i_key == selectCode;
+            });
+            if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
+                return callback(null);
+            }
+            oldData = this.getReplaceDataByStd(oldData,glj);
             $.bootstrapLoading.start();
             CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
                 $.bootstrapLoading.end();

+ 3 - 5
web/building_saas/main/js/views/fee_rate_view.js

@@ -354,11 +354,9 @@ var feeRateObject={
             var init=false;
         }
         FeeRateEditCellType.prototype = new ns.CellTypes.Text();
-        FeeRateEditCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
-           // if(value!=null){
-               // ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3);
+        //2018-12-12 按新需求隐藏费率选择按钮
+      /*  FeeRateEditCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
              GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
-           // }
             if(feeRateObject.editingCell && !projectReadOnly){
                 if(feeRateObject.editingCell.row==options.row&&feeRateObject.editingCell.col==options.col){
                     var image = document.getElementById('f_btn'),imageMagin = 3;
@@ -437,7 +435,7 @@ var feeRateObject={
                 hitinfo.sheet.repaint();
                 feeRateObject.pmLeave = true;
             }
-        }
+        }*/
         return new FeeRateEditCellType();
     },
     showSelectModal:function (hitinfo) {

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

@@ -1183,7 +1183,9 @@ var gljOprObj = {
                 glj_list[list_index] = data;
                 project.projectGLJ.loadData(function () {//加载完项目工料机再计算
                     gljOprObj.showRationGLJSheetData();
-                    if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
+                    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);
@@ -1191,7 +1193,7 @@ var gljOprObj = {
                             node.data = data;
                         }
                         node ? nodes.push(node) : "";
-                    }
+                    }*/
                     //project.ration_glj.addToMainTree(data);
                     selected.data.adjustState = result.adjustState;
                     selected.data.name = result.name;

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

@@ -96,19 +96,27 @@ let zmhs_obj = {
         let ration_glj = projectObj.project.ration_glj;
         let calcInstall = false;//是否记录安装增加费
         let nodes = projectObj.project.updateNodesCache([{type:ModuleNames.ration,data:result.ration}]);
-        projectObj.mainController.refreshTreeNode(nodes, false);
         if(result.add && result.add.length > 0){//需添加定额工料机的情况
             ration_glj.datas = ration_glj.datas.concat(result.add);
             gljOprObj.sheetData = gljOprObj.sheetData.concat(result.add);
         }
         if(result.delete && result.delete.length > 0 && this.deleteGLJs(result.delete)) calcInstall = true; //这样保证delete返回值是true的时候才改变变量类型
+        if(result.replace && result.replace.length > 0){ //替换工料机的情况
+            for(let r of result.replace){//替换缓存内容
+                ration_glj.datas.splice(_.findIndex(ration_glj.datas,{'ID': r.ID}),1,r);
+                gljOprObj.sheetData.splice(_.findIndex(gljOprObj.sheetData,{'ID': r.ID}),1,r);
+                let node = ration_glj.updateGLJNodeAfterReplace(r);
+                if(node)  nodes.push(node);
+            }
+        }
+        projectObj.mainController.refreshTreeNode(nodes, false);
 
         let rationID= ration_glj.updateCacheAfterAdjust(result.ration_glj);
         if(reload == true){//有添加、替换、工料机等需重新加载的情况
             $.bootstrapLoading.start();
             projectObj.project.projectGLJ.loadData(function () {
                 $.bootstrapLoading.end();
-                if(result.add && result.add.length > 0) ration_glj.addToMainTree(result.add);
+                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();//如果是删除节点的话,
             });