Browse Source

组成物批量更新

zhangweicheng 7 years ago
parent
commit
a30a39deb8

+ 47 - 0
modules/glj/controllers/glj_controller.js

@@ -660,6 +660,53 @@ class GLJController extends BaseController {
         }
         res.json(result);
     }
+    async batchUpdateConsumption(req,res){
+        let result={
+            error:0
+        };
+        try {
+            let data = req.body.data;
+            data = JSON.parse(data);
+            let mixTasks = [],parent = null;
+            for(let d of data){
+                if(d.type == 'mix_ratio'){
+                    let task = {updateOne:{filter:d.query, update :d.doc}};
+                    mixTasks.push(task);
+                }else if(d.type =='parent'){
+                    parent = d;
+                }
+            }
+            if(mixTasks.length > 0){
+                let mixRatioModel = new MixRatioModel().model;
+                await mixRatioModel.bulkWrite(mixTasks);
+            }
+            if(parent){
+                let indexList = ['code','name','specs','unit','type'];
+                let keyList = parent.connect_key.split("|-|");
+                let condition = {unit_price_file_id: parent.unit_price_file_id};
+                for(let i = 1;i<keyList.length;i++){
+                    if(keyList[i]!='null'){
+                        condition[indexList[i]]=keyList[i];
+                    }
+                }
+                let unitPriceUpdate = {
+                    base_price: parent.base_price,
+                    market_price: parent.market_price
+                };
+                let unitPriceModel = new UnitPriceModel();
+                let unitPriceResult = await unitPriceModel.updatePrice(condition, unitPriceUpdate);
+                if (!unitPriceResult) {
+                    throw '更新单价数据失败';
+                }
+            }
+            result.data = "ok";
+        }catch (err){
+            logger.err(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        res.json(result);
+    }
     async modifyKeyValue(req,res){//修改工料机关键的属性:名称、类型、规格、型号等
         let result={
             error:0

+ 1 - 0
modules/glj/routes/glj_router.js

@@ -25,6 +25,7 @@ router.post('/save-as', gljController.init, gljController.unitPriceSaveAs);
 router.post('/get-composition', gljController.init, gljController.getComposition);
 router.post('/updatePrice', gljController.init, gljController.updateUnitPrice);
 router.post('/batchUpdatePrices', gljController.init, gljController.batchUpdatePrices);
+router.post('/batchUpdateConsumption', gljController.init, gljController.batchUpdateConsumption);
 router.post('/modifyKeyValue',gljController.init, gljController.modifyKeyValue);
 
 router.get('/test', gljController.init, gljController.test);

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

@@ -352,10 +352,43 @@ ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,callback) {
             $.bootstrapLoading.end();
         });
     }
+};
 
+ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
+    let me = this;
+    $.bootstrapLoading.start();
+    CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
+        let parent = updateData[updateData.length - 1];
+        let parentGlj = me.getByConKey(parent.connect_key);
+        for(let u of updateData){
+            if(u.type == 'mix_ratio'){
+                let tem = updateMap[u.query.id];
+                tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
+                let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
+                if(subData){
+                    subData.consumption = u.doc.consumption;
+                }
+                let m_list = me.datas.mixRatioMap[parent.connect_key];
+                let m_ratioData = _.find(m_list,{"id":u.query.id});
+                if(m_ratioData){
+                    m_ratioData.consumption = u.doc.consumption;
+                }
+            }
+        }
+        parentGlj.unit_price.market_price =  parent.market_price;
+        parentGlj.unit_price.base_price =  parent.base_price;
+        me.calcQuantity();
+
+        if(callback){
+            callback();
+        }
+        $.bootstrapLoading.end();
+    },function () {
+        $.bootstrapLoading.end();
+    })
 
-};
 
+};
 
 ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
     let me = this;

+ 91 - 14
web/building_saas/main/js/views/project_glj_view.js

@@ -111,6 +111,7 @@ projectGljObject={
         this.mixRatioSheet = this.mixRatioSpread .getSheet(0);
         this.initSheet(this.mixRatioSheet,this.mixRatioSetting);
         this.mixRatioSheet.name('mixRatioSheet');
+        this.mixRatioSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onMixRatioRangeChange);
     },
     initMaterialTreeSheet:function () {
         this.materialTreeSheet = this.projectGljSpread.getSheet(1);
@@ -225,7 +226,8 @@ projectGljObject={
             type:glj.type,
             short_name:projectObj.project.projectGLJ.getShortNameByID(glj.type),
             consumption:glj.ratio_data.consumption,
-            unit_price:glj.unit_price
+            unit_price:glj.unit_price,
+            connect_key:glj.ratio_data.connect_key
         };
         gljOprObj.setGLJPrice(data,glj);
         return data;
@@ -238,7 +240,7 @@ projectGljObject={
             args.cancel = true;
         }
     },
-    projectGljEditChecking:function (row,col) {//return false表示不能编辑
+    projectGljEditChecking:function (row,col,isPaste=false) {//return false表示不能编辑
         let me = projectGljObject;
         let data = null, setting=null;
         let sheet = me.projectGljSpread.getActiveSheet();
@@ -256,7 +258,7 @@ projectGljObject={
             return false;
         }
 
-        if(dataCode=='is_adjust_price'||dataCode=='is_evaluate'||dataCode=='is_main_material'){
+        if(isPaste == false &&(dataCode=='is_adjust_price'||dataCode=='is_evaluate'||dataCode=='is_main_material')){//除了粘贴,拖动填充等操作,其它的都不能编辑
             return false;
         }
         if(dataCode=='basePrice'||dataCode=='marketPrice'||dataCode=='supply'){//有组成物时,市场单价、定额价、供货方式不能修改
@@ -282,7 +284,7 @@ projectGljObject={
     },
     onSelectionChange:function (){
         let me = projectGljObject;
-        me.projectGljRowChang();
+        me.showMixRatioData();
         me.materialTreeSheet.repaint();
     },
     onProjectGljSelectionChange:function (sender, args) {
@@ -296,7 +298,11 @@ projectGljObject={
     },
     projectGljRowChang:function(row){
         let me = projectGljObject;
-        me.mixRatioSheet.getSelections()[0].row = -1;
+        let sel = me.mixRatioSheet.getSelections()[0];
+        sel.row = -1;
+        sel.col = 0;
+        sel.rowCount = 1;
+        sel.colCount = 1;
         me.showMixRatioData();
     },
     rightClickCallback:function (row) {
@@ -312,18 +318,20 @@ projectGljObject={
         let me = projectGljObject;
         let changeInfo=[];
         let canChange = true;
-        if(me.projectGljEditChecking(info.row,info.col) == false){
-            canChange = false;
-        }else if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
-            info.newValue = null;
-            me.onProjectGLJValueChange(sender,info);
-            return ;
+        if(info.action == GC.Spread.Sheets.RangeChangedAction.clear){
+            if(me.projectGljEditChecking(info.row,info.col) == false){
+                canChange = false;
+            }else {
+                info.newValue = null;
+                me.onProjectGLJValueChange(sender,info);
+                return ;
+            }
         }
 
         for(let c of info.changedCells){
             let value=  info.sheet.getCell(c.row, c.col).text();
             changeInfo.push({row:c.row,col:c.col,value:value});
-            if(me.projectGljEditChecking(c.row,c.col)==false){//如果不能编辑
+            if(me.projectGljEditChecking(c.row,c.col,true)==false){//如果不能编辑
                 canChange = false;
             }
             if (canChange==true&&!me.checkData(c.col,me.projectGljSetting,value)) {
@@ -334,18 +342,87 @@ projectGljObject={
         if(canChange == false){//恢复原来的值
             info.sheetName =="materialTreeSheet"?me.showMaterialTreeData():me.showProjectGljData();
         }else if(info.sheetName =="projectGljSheet"){
-            me.batchUpdatePrice(changeInfo);
+            me.batchUpdateProjectGLJ(changeInfo);
         }
     },
-    batchUpdatePrice(changeInfo){
+    onMixRatioRangeChange:function (sender,info){
+        let me = projectGljObject;
+        let canChange = true;
+        let changeInfo=[];
+        if (info.action == GC.Spread.Sheets.RangeChangedAction.clear) {
+            info.newValue = 0;
+            me.onMixRatioValueChange(sender,info);
+            info.sheet.getCell(info.row, info.col).text(0);
+            return ;
+        }
+
+        for(let c of info.changedCells){
+            let value = info.sheet.getCell(c.row, c.col).text();
+            if (!me.checkData(c.col,me.mixRatioSetting,value)) {
+                alert('输入的数据类型不对,请重新输入!');
+                canChange = false;
+                break;
+            }else {
+                changeInfo.push({row:c.row,col:c.col,value:value});
+            }
+        }
+
+        if(canChange == false){//数据类型不对
+            me.showMixRatioData();
+        }
+        if(changeInfo.length > 0){
+            me.batchUpdateConsumption(changeInfo);
+        }
+
+
+    },
+    batchUpdateProjectGLJ:function(changeInfo){
         let projectGLJ = projectObj.project.projectGLJ;
         let me = projectGljObject;
+        me.batchUpdateGLJProperty(changeInfo);
         projectGLJ.batchUpdatePrice(changeInfo,function (impactList) {
             let selected = me.projectGljSheet.getSelections()[0];
             me.showProjectGljData();
             me.projectGljSheet.setSelection(selected.row,selected.col,selected.rowCount,selected.colCount);
         });
     },
+    batchUpdateGLJProperty:function (changeInfo) {
+        console.log(changeInfo)
+    },
+    batchUpdateConsumption:function(changeInfo){
+        let projectGLJ = projectObj.project.projectGLJ;
+        let me = projectGljObject;
+        let updateMap = {},updateData = [],parentBasePrice = 0,parentMarketPrice = 0;
+        let parentKey = '',unit_price_file_id=null;
+        for(let c of changeInfo){
+            let record = me.mixRatioData[c.row];
+            let value = scMathUtil.roundForObj(c.value,getDecimal("glj.quantity"));
+            updateMap[record.mix_ratio_id] = {consumption: value,record:record };
+            updateData.push({type:'mix_ratio',query:{id:record.mix_ratio_id},doc:{consumption:value}});
+            parentKey = record.connect_key;
+            unit_price_file_id = record.unit_price.unit_price_file_id;
+        }
+        for(let sub of me.mixRatioData){
+            let marketPrice = scMathUtil.roundForObj(sub.unit_price.market_price,getDecimal("process"));
+            let basePrice = scMathUtil.roundForObj(sub.unit_price.base_price,getDecimal("process"));
+            let consumption =  updateMap[sub.mix_ratio_id]?updateMap[sub.mix_ratio_id].consumption:scMathUtil.roundForObj(sub.consumption,getDecimal("glj.quantity"));
+            parentMarketPrice = scMathUtil.roundForObj(marketPrice*consumption + parentMarketPrice,getDecimal("process"));
+            parentBasePrice = scMathUtil.roundForObj(basePrice*consumption + parentBasePrice,getDecimal("process"));
+        }
+        parentBasePrice = scMathUtil.roundForObj(parentBasePrice,getDecimal("glj.unitPrice"));
+        parentMarketPrice = scMathUtil.roundForObj(parentMarketPrice,getDecimal("glj.unitPrice"));
+        updateData.push({type:'parent',connect_key:parentKey,base_price:parentBasePrice,market_price:parentMarketPrice,unit_price_file_id:unit_price_file_id});
+        projectGLJ.batchUpdateConsumption(updateData,updateMap,function () {
+            //更新人材机汇总表
+            let parentSheet =  me.projectGljSpread.getActiveSheet();//三材汇总表和工料机汇总表
+            let prow = parentSheet.getActiveRowIndex();//取父机械或组成物的下标
+            let prowData = parentSheet.name() == 'projectGljSheet'?me.projectGljSheetData[prow]:me.materialTree.items[prow].data;
+            me.refreshParentData(prow,prowData.id);
+            me.onUnitFileChange(updateData);
+        });
+
+    },
+
     showProjectGljData:function () {
         this.projectGljSpread.setActiveSheetIndex(0);
         let sel = this.projectGljSheet.getSelections()[0];

+ 0 - 1
web/building_saas/main/js/views/project_info.js

@@ -31,7 +31,6 @@ var projectInfoObj = {
         CommonAjax.post('/pm/api/getProject', {"user_id": userID, "proj_id": scUrlUtil.GetQueryString('project')}, function (data) {
             if (data) {
                 that.projectInfo = data;
-                console.log(that.projectInfo);
                 //init decimal
                 setDecimal(decimalObj, data.property.decimal);
                 billsQuanDecimal.datas = data.property.billsQuantityDecimal || [billsDecimalView.angleDecimal];