Bläddra i källkod

工料机汇总定额价修改、定额工料机编辑是否暂估

zhangweicheng 7 år sedan
förälder
incheckning
b579e9b1a1

+ 29 - 2
web/building_saas/glj/js/project_glj.js

@@ -26,6 +26,7 @@ let usedTenderList = [];
 let otherFileData = {};
 let currentTag = '';
 let isChanging = false;
+let initPage = false;
 $(document).ready(function () {
     $('#tab_gongliaoji').on('show.bs.tab', function (e) {
         $(e.relatedTarget.hash).removeClass('active');
@@ -225,7 +226,7 @@ $(document).ready(function () {
  */
 function init() {
     projectObj.project.projectGLJ.loadData(function (data) {
-        if (jsonData.length <= 0) {
+        if (initPage==false||jsonData.length <= 0) {
             // 赋值
             jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
             jsonData = filterProjectGLJ(jsonData);
@@ -245,6 +246,7 @@ function init() {
             unitPriceFileInit();
 
             setTimeout(spreadInit, 1);
+            initPage=true;
         } else {
             projectObj.project.projectGLJ.loadCacheData();
         }
@@ -325,7 +327,7 @@ function getUsedTenderInfo() {
  * @param {object} info
  * @return {void}
  */
-function successTrigger(field, info) {
+function successTrigger(field, info,id) {
     let updateData = {};
     switch (field) {
         case 'unit_price.market_price':
@@ -339,6 +341,9 @@ function successTrigger(field, info) {
             // 供货方式更改成功后
             projectGLJSpread.changeSupplyType(info);
             break;
+        case 'is_evaluate':
+            changeIsEvaluate(id);
+            break;
     }
     // 重新加载数据到缓存
     projectObj.project.projectGLJ.loadData(function () {
@@ -350,6 +355,28 @@ function successTrigger(field, info) {
     gljOprObj.refreshView();
 }
 
+//更新是否暂估
+function changeIsEvaluate (id){
+    let projectGLJ = projectObj.project.projectGLJ
+    let datas = projectGLJ.datas;
+    let gljList = datas.gljList;
+    let glj = _.find(gljList, {'id': id});
+    if(glj){
+        let con_key = gljOprObj.getIndex(glj,gljKeyArray);
+        let pratioM =datas.mixRatioConnectData[con_key];//找到父key
+        let conditions = [];
+        if(pratioM&&pratioM.length>0){
+            for(let p_key in pratioM ){
+                conditions.push(gljOprObj.getConditionByKey(p_key));
+            }
+        }
+        let gljs = projectGLJ.getProjectGLJs(conditions,false);
+        gljs.push(glj);
+        let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
+        projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
+    }
+}
+
 /**
  * socket.io相关初始化
  *

+ 30 - 15
web/building_saas/glj/js/project_glj_spread.js

@@ -48,7 +48,7 @@ ProjectGLJSpread.prototype.init = function () {
         {name: 'ID', field: 'id', visible: false},
         {name: '类型', field: 'unit_price.type', visible: false},
         {name: '总消耗量', field: 'quantity', visible: true,width:100,decimalField:'glj.quantity'},
-        {name: '定额价', field: "base_price", visible: true,width:70,decimalField:"glj.unitPrice"},
+        {name: '定额价', field: "base_price", visible: true,width:70,decimalField:"glj.unitPrice",validator: 'number'},//这里feiedID设置是为了在计不计取价差的时候做显示用
         {name: '调整价', field: 'adjust_price', visible: true,width:70,decimalField:"glj.unitPrice"},
         {name: '市场价', field: "unit_price.market_price", visible: true, validator: 'number',width:70,decimalField:"glj.unitPrice"},
         {
@@ -112,6 +112,7 @@ ProjectGLJSpread.prototype.init = function () {
     this.sheetObj.setStyle(-1, supplyQuantity, rightStyleSetting);
 
     // 设置可编辑列
+    this.sheetObj.setColumnEditable(basePriceColumn);
     this.sheetObj.setColumnEditable(marketPriceColumn);
     this.sheetObj.setColumnEditable(isEvaluateColumn);
     this.sheetObj.setColumnEditable(isAdjustPriceColumn);
@@ -198,7 +199,7 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
 
     // 直接在前端计算后传值后台改
     let extend = {};
-    let updateRecord = jsonData[row];
+/*    let updateRecord = jsonData[row];  这时修改成在后端计算后直接更新,因为还要重新计算受影响的清单节点
     let parentMarketPrice = projectGLJSpread.compositionCalculate(updateRecord);
     if (parentMarketPrice !== null && Object.keys(parentMarketPrice).length > 0) {
         for (let activeCode in parentMarketPrice) {
@@ -207,7 +208,7 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
             };
             extend[activeCode] = tmpObject;
         }
-    }
+    }*/
 
     // 如果是供货方式则需要处理数据
     if (field === 'supply') {
@@ -217,10 +218,17 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
     if(field === 'supply_quantity'){//修改数量需做4舍5入
         value= value.toDecimal(getDecimal('glj.quantity'));
     }
-    if(field === 'unit_price.market_price'){
-        value= value.toDecimal(getDecimal('glj.unitPrice'));
+    if(field === 'unit_price.market_price'||field === 'base_price'){
+        value= scMathUtil.roundForObj(value,getDecimal('glj.unitPrice'));//修改市场价和修改定额价时需要重新记算很多受影响的树节点,现在改成与定字额工料机那里调相同的方法。
+        let editField = field === 'base_price'?field:"market_price";
+        projectObj.project.projectGLJ.updatePrice(jsonData[row],editField,value);
+        return;
     }
     extend = Object.keys(extend).length > 0 ?  JSON.stringify(extend) : '';
+    this.postUpdate(id,field,value,info,extend,callback);
+};
+
+ProjectGLJSpread.prototype.postUpdate=function (id,field,value,info,extend,callback) {
     $.bootstrapLoading.start();
     $.ajax({
         url: '/glj/update',
@@ -237,22 +245,25 @@ ProjectGLJSpread.prototype.updateProjectGLJField = function(info, callback) {
         success: function(response) {
             isChanging = false;
             // 修改失败则恢复原值
-            if (response.err !== 0) {
-                activeSheet.setValue(row, column, info.oldValue);
+            if (response.err !== 0&&info.fromRG!=true) {
+                projectGLJSheet.getSheet().setValue(info.row, info.col, info.oldValue);
                 alert('更改数据失败!');
             } else {
                 // 成功则触发相应事件
-                if (parentMarketPrice !== null) {
-                    info.parentMarketPrice = parentMarketPrice;
-                }
-                if(field !== 'supply'){ //供货方式需做转换才能直接设置值, 这里设置值是为了早点更新数据,等getdata返回数据再刷新的话会有比较大的延时
-                    activeSheet.setValue(row, column, value);
+                /* if (parentMarketPrice !== null) {
+                 info.parentMarketPrice = parentMarketPrice;
+                 }*/
+                if(field !== 'supply'&&info.fromRG!=true){ //供货方式需做转换才能直接设置值, 这里设置值是为了早点更新数据,等getdata返回数据再刷新的话会有比较大的延时
+                    projectGLJSheet.getSheet().setValue(info.row, info.col, value);
                 }
-                callback(field, info);
+                callback(field, info,id);
             }
         }
     });
-};
+
+
+}
+
 
 /**
  * 设置特殊单元格数据
@@ -314,11 +325,15 @@ ProjectGLJSpread.prototype.specialColumn = function (sourceData) {
             this.firstMachineRow = this.firstMachineRow === -1 && data.unit_price.type === GLJTypeConst.GENERAL_MACHINE ?
                 rowCounter : this.firstMachineRow;
             // 锁定该单元格
-            if (data.ratio_data  && data.ratio_data.length > 0){//有组成物时,市场单价不可修改
+            if (data.ratio_data  && data.ratio_data.length > 0){//有组成物时,市场单价、定额价不可修改
                 activeSheet.getCell(rowCounter, marketPriceColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
+                activeSheet.getCell(rowCounter, basePriceColumn, GC.Spread.Sheets.SheetArea.viewport).locked(true);
             }
             activeSheet.getCell(rowCounter, supplyColumn,  GC.Spread.Sheets.SheetArea.viewport).locked(true);
         }
+        if(data.unit_price.is_add!=1){//如果不是新增,定额价不可修改。
+            activeSheet.getCell(rowCounter, basePriceColumn, GC.Spread.Sheets.SheetArea.viewport).locked(true);
+        }
 
         // 处理数据
         if (data.ratio_data !== undefined && data.ratio_data.length > 0) {

+ 34 - 23
web/building_saas/main/js/models/project_glj.js

@@ -132,7 +132,7 @@ ProjectGLJ.prototype.updateData = function (id, data) {
  *
  * @return {void}
  */
-ProjectGLJ.prototype.loadCacheData = function () {
+ProjectGLJ.prototype.loadCacheData = function (resort) {
     // 加载工料机数据
     let data = this.datas === null ? null : this.datas;
     if (data === null) {
@@ -141,16 +141,18 @@ ProjectGLJ.prototype.loadCacheData = function () {
     jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
     jsonData = filterProjectGLJ(jsonData);
     jsonData = sortProjectGLJ(jsonData);
-    projectGLJSheet.setData(jsonData);
-    projectGLJSpread.specialColumn(jsonData);
+    if(projectGLJSheet&&projectGLJSpread){
+        projectGLJSheet.setData(jsonData);
+        projectGLJSpread.specialColumn(jsonData);
+    }
 };
 
 ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval) {
     if (updateField == 'marketPrice') {
-        this.updateBasePriceFromRG(recode, "market_price", newval);
+        this.updatePrice(recode, "market_price", newval,"rg");
     }
     if (updateField == 'basePrice') {
-        this.updateBasePriceFromRG(recode, "base_price", newval);
+        this.updatePrice(recode, "base_price", newval,"rg");
     }
 };
 
@@ -223,11 +225,11 @@ ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
 
 }
 
-ProjectGLJ.prototype.updateBasePriceFromRG = function (recode, updateField, newval) {
+ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from) {
     let me = this;
     let projectGljs = this.datas.gljList;
-    let glj = _.find(projectGljs, {'id': recode.projectGLJID});
-    console.log(glj);
+    let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
+    let glj = _.find(projectGljs, {'id': pgljID});
     if (glj) {
         let data = {id: glj.unit_price.id, field: updateField, newval: newval};
         let callback = function (data) {
@@ -237,12 +239,14 @@ ProjectGLJ.prototype.updateBasePriceFromRG = function (recode, updateField, newv
             } else {
                 glj.unit_price.market_price = newval;
             }
-            //更新项目工料机价格
-            me.refreshProjectGLJPrice(data);
+            //更新回传的父节点项目工料机价格
+           let gljs = me.getProjectGLJs(data);
             me.refreshRationGLJPrice(glj);//刷新定额工料机列表的记录
+            projectObj.project.projectGLJ.loadCacheData();//更新工料机汇总缓存和显示
             gljOprObj.showRationGLJSheetData();
             me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
-            let nodes = me.getImpactRationNodes(glj);//取到因为改变工料机价格而受影响的定额
+            gljs.push(glj);
+            let nodes = me.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
             projectObj.project.calcProgram.calcRationsAndSave(nodes);//触发计算程序
             $.bootstrapLoading.end();
         }
@@ -254,8 +258,10 @@ ProjectGLJ.prototype.updateBasePriceFromRG = function (recode, updateField, newv
         gljOprObj.showRationGLJSheetData();
     }
 }
+
+
 ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
-    if ((data.unit_price.type = gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
+    if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
         var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
             if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
                 tem.data.marketUnitFee = data.unit_price.market_price;
@@ -268,21 +274,24 @@ ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
 }
 
 //根据工料机,取得所有受影响的定额节点
-ProjectGLJ.prototype.getImpactRationNodes = function (glj) {
+ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
     let nodes = [];
     let rationMap = {};
+    let idArray = _.map(gljs,'id');
+    let priceArray = _.map(gljs,'unit_price');
     //先根据项目工料机ID,找到受影响定额的ID
     let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
     for (let rg of ration_glj_list) {
-        if (rg.projectGLJID == glj.id) {
+        if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
             rationMap[rg.rationID] = true;  //取所有定额ID,用MAP方式去重
         }
     }
     for (let item of projectObj.project.mainTree.items) {
         if (item.sourceType == ModuleNames.ration) {
             if (item.data.type == rationType.gljRation) {//取定额类型的工料机
-                if (item.data.projectGLJID == glj.id) {
-                    item.data.marketUnitFee = glj.unit_price.market_price; //更新市场单价
+                let idx = _.indexOf(idArray,item.data.projectGLJID);
+                if (idx != -1) {
+                    item.data.marketUnitFee = priceArray[idx].market_price; //更新市场单价
                     nodes.push(item);
                 }
             } else if (rationMap[item.data.ID] == true) {  //受影响的定额
@@ -306,11 +315,11 @@ ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
 
 }
 
-ProjectGLJ.prototype.refreshProjectGLJPrice = function (data) {
+ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
     let parentGlj = [];
     //
     let projectGljs = this.datas.gljList;
-    let indexList = ['code', 'name', 'specs', 'unit', 'type'];
+    let indexList = gljKeyArray;
     for (let d of data) {
         if (d) {
             let condition = {};
@@ -321,11 +330,13 @@ ProjectGLJ.prototype.refreshProjectGLJPrice = function (data) {
             }
             let glj = _.find(projectGljs, condition);
             if (glj) {
-                glj.unit_price.base_price = d.base_price;
-                glj.unit_price.market_price = d.market_price;
-                this.setAdjustPrice(glj);
-                this.refreshRationGLJPrice(glj);
-                this.refreshTreeNodePriceIfNeed(glj);
+                if(refreshPrice==true){
+                    glj.unit_price.base_price = d.base_price;
+                    glj.unit_price.market_price = d.market_price;
+                    this.setAdjustPrice(glj);
+                    this.refreshRationGLJPrice(glj);
+                    this.refreshTreeNodePriceIfNeed(glj);
+                }
                 parentGlj.push(glj);
             }
         }

+ 29 - 6
web/building_saas/main/js/views/glj_view.js

@@ -390,19 +390,18 @@ var gljOprObj = {
         }
     },
     onCheckBoxClick: function (sender, args) {
-        if (args.sheetName == 'ration_glj') {
-            return;
-        }
         var checkboxValue = args.sheet.getCell(args.row, args.col).value();
         var newval = 0;
         if (checkboxValue) {
             newval = 0;
             args.sheet.getCell(args.row, args.col).value(newval);
         } else {
-            newval = 1
+            newval = 1;
             args.sheet.getCell(args.row, args.col).value(newval);
         }
-        if (args.sheetName == 'ration_coe') {
+        if (args.sheetName == 'ration_glj') {
+            gljOprObj.updateIsEstimate(args,newval);
+        } else if (args.sheetName == 'ration_coe') {
             gljOprObj.updateRationCoe(args, newval)
         } else if (args.sheetName == 'quantity_detail') {
             projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
@@ -804,7 +803,7 @@ var gljOprObj = {
                 var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
                 if (glj) {
                     let typeString = ration_gljs[i].type + "";
-                    if (typeString.indexOf("2") != -1) {//只有材料类型才显示是否暂估
+                    if (typeString.indexOf("2") != -1||typeString=='4'||typeString=='5') {//只有材料类型才显示是否暂估
                         ration_gljs[i].isEstimate = glj.is_evaluate;
                     }
                     ration_gljs[i].isAdd = glj.unit_price.is_add;
@@ -857,6 +856,16 @@ var gljOprObj = {
         t_index = k_arr.join("|-|");
         return t_index;
     },
+    getConditionByKey(conKey){//将连接字符串转换成对象
+        let valueArray = conKey.split("|-|");
+        let obj ={};
+        for(let i = 0;i<valueArray.length;i++){
+            if(valueArray[i]!='null'){
+                obj[gljKeyArray[i]]=valueArray[i];
+            }
+        }
+        return obj;
+    },
     getMixRationShowDatas: function (mixRatioList, projectGljs) {
         var temRationGLJs = [];
         for (var i = 0; i < mixRatioList.length; i++) {
@@ -1036,6 +1045,20 @@ var gljOprObj = {
         var recode = me.coeSheetData[args.row];
         projectObj.project.ration_coe.adjustCoeClick(recode, newval);
     },
+    updateIsEstimate:function (args, newval) {
+        var me = gljOprObj;
+        if(me.setting.header[args.col].dataCode=="isEstimate"){
+            var pspread= new ProjectGLJSpread();
+            var recode = me.sheetData[args.row];
+            let projectGljs = projectObj.project.projectGLJ.datas.gljList;
+            let glj = _.find(projectGljs, {'id': recode.projectGLJID});
+            if(glj){
+                glj["is_evaluate"]=newval;
+                args.fromRG=true;
+                pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
+            }
+        }
+    },
     numberValueChecking: function (val) {
         var newval = Number(val);
         if (number_util.isNumber(newval)) {