Explorar el Código

子目换算-砂浆、混凝土的替换

zhangweicheng hace 6 años
padre
commit
d1ee3efc0e

+ 3 - 0
modules/all_models/ration_coe.js

@@ -20,6 +20,9 @@ var coeListSchema = mongoose.Schema({
     ID: String,                         // 系数ID(流水号ID)
     name: String,                       // 名称
     content: String,                    // 说明
+    original_code:String,               //原人材机编码
+    option_codes:String,                //可选人材机编码
+    select_code:String,
     rationID:String,
     projectID:Number,
     coeID:Number,

+ 2 - 0
modules/all_models/stdRation_coe.js

@@ -23,6 +23,8 @@ const coeListSchema = new Schema({
     serialNo: Number,                  //编号
     name: String,                       // 名称
     content: String,                    // 说明
+    original_code:String,               //原人材机编码
+    option_codes:String,                //可选人材机编码
     coes: [coeSchema]
 }, {versionKey: false});
 

+ 5 - 6
modules/main/facade/ration_facade.js

@@ -310,6 +310,8 @@ async function addRationCoe(std,newRation,compilation) {
                 newCoe.seq = seq;
                 newCoe.name = libCoe.name;
                 newCoe.content = libCoe.content;
+                newCoe.original_code = libCoe.original_code;
+                newCoe.option_codes = libCoe.option_codes;
                 newCoe.isAdjust=0;
                 newCoe.coes = libCoe.coes;
                 newCoe.rationID = newRation.ID;
@@ -488,7 +490,7 @@ async function updateCoeAdjust(data,compilation) {
         }
     }
 
-    let cal_result = await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID});
+    let cal_result = await glj_calculate_facade.calculateQuantity({projectID:data.projectID,rationID:data.rationID},null,true);
     let coe = {
         query:{ID:data.ID,projectID:data.projectID},
         doc:data.doc
@@ -499,16 +501,13 @@ async function updateCoeAdjust(data,compilation) {
     };
     let ration = {
         ID:cal_result.rationID,
-        adjustState:cal_result.adjustState
+        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}
 
 }
 
-function addGLJByCoe(code,engineerID,rationID,projectID) {//通过单个工料机类型编号添加
-
-}
-
 
 
 async function  updateRation(std,defaultLibID,rationID,billsItemID,projectID,calQuantity) {

+ 37 - 17
modules/ration_glj/facade/glj_calculate_facade.js

@@ -66,8 +66,7 @@ async function calculateQuantity(query,noNeedCal,refreshRationName = false){
          }
          gljList = sortRationGLJ(gljList);
          for(let i =0;i<gljList.length;i++ ){
-             let isLast = i == gljList.length -1;
-             let r = await calculateQuantityPerGLJ(gljList[i],isLast,coeList,assList,adjustState,noNeedCal);
+             let r = await calculateQuantityPerGLJ(gljList[i],gljList,coeList,assList,adjustState,noNeedCal);
              result.glj_result.push(r);
          }
 
@@ -137,7 +136,7 @@ function sortRationGLJ(list) {
     return list;
 }
 
-async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,noNeedCal) {
+async function calculateQuantityPerGLJ(glj,gljList,coeList,assList,adjustState,noNeedCal) {
     let decimalObject =await decimal_facade.getProjectDecimal(glj.projectID);
     let decimal = (decimalObject&&decimalObject.glj&&decimalObject.glj.quantity)?decimalObject.glj.quantity:3;
     let quantity =  scMathUtil.roundTo(parseFloat(glj.quantity),-decimal);
@@ -155,7 +154,7 @@ async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,no
             if(!glj._doc.hasOwnProperty('customQuantity')||glj.customQuantity==null||glj.customQuantity==""){
                 quantity =scMathUtil.roundTo(parseFloat(glj.rationItemQuantity),-decimal);
                 quantity =scMathUtil.roundTo(await calculateAss(quantity,assList,glj),-decimal);
-                quantity = calculateQuantityByCoes(quantity,coeList,glj);
+                quantity = calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal);
             }else {
                 quantity = glj.customQuantity;
                 result.doc.customQuantity = glj.customQuantity;
@@ -163,11 +162,12 @@ async function calculateQuantityPerGLJ(glj,isLast,coeList,assList,adjustState,no
             let customerCoe = _.last(coeList);
             if(customerCoe&&customerCoe.isAdjust==1){
                 quantity = scMathUtil.roundToString(quantity,decimal);
-                quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj);
+                quantity = calculateQuantityByCustomerCoes(quantity,customerCoe,glj,decimal);
             }
             result.doc.quantity =scMathUtil.roundToString(quantity,decimal);
+            glj.quantity = quantity;//这里保存中间过程计算出来的消耗量,后面处理“+*”操作符时要用到
         }
-        generateAdjustState(glj,coeList,adjustState,isLast,result.doc.quantity);
+        generateAdjustState(glj,coeList,adjustState,gljList,result.doc.quantity);
         return result;
     }catch (err){
         throw err;
@@ -199,7 +199,7 @@ async function calculateAss(quantity,assList,glj) {
     return scMathUtil.roundTo(quantity,-6);
 }
 
-function generateAdjustState(glj,coeList,adjustState,isLast,quantity) {
+function generateAdjustState(glj,coeList,adjustState,gljList,quantity) {
    //替换工料机 and 添加工料机
     if(glj._doc.createType=='replace'&&glj.rcode!=glj.code){
         adjustState.push({index:stateSeq.replace,content:glj.rcode+'换'+glj.code});
@@ -214,17 +214,21 @@ function generateAdjustState(glj,coeList,adjustState,isLast,quantity) {
     // to do
 
   //标准附注条件调整 + 自定义乘系数
-    if(isLast){//最后一个工料机的时候才生成,生成一次就可以了
+    if(_.last(gljList).ID == glj.ID){//最后一个工料机的时候才生成,生成一次就可以了
         for(let i=0;i<coeList.length;i++){
             if(coeList[i].isAdjust==1){
                 if(i==coeList.length-1){
                     adjustState.push({index:stateSeq.cusCoe,content:getContent(coeList[i].coes)});//自定义乘系数要去掉倍数为1的
                 }else {
+                    if(coeList[i].select_code && coeList[i].select_code!=""){
+                        _.remove(adjustState,{'content':coeList[i].original_code+'换'+coeList[i].select_code});//去掉替换工料机自动生成的调整状态
+                        adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].original_code+'换'+coeList[i].select_code});
+                    }
                     for(let c of coeList[i].coes){
                         if(c.coeType=='单个工料机') _.remove(adjustState,{'type':"添"+c.gljCode});//如果是单个工料机子目换算类型自动添加的,去掉前面手动生成的调整状态
                         if(c.coeType=='替换人材机') _.remove(adjustState,{'content':c.gljCode+'换'+c.replaceCode});//如果是替换人材机子目换算类型自动添加的,去掉前面手动生成的调整状态
                     }
-                    adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content
+                    if(coeList[i].content) adjustState.push({index:stateSeq.coe,content:"调 : "+coeList[i].content});//coeList[i].content
                 }
             }
         }
@@ -295,28 +299,30 @@ function calculateTimes(ass){
     return scMathUtil.roundTo(times,-6);
 }
 
-function calculateQuantityByCoes(quantity,coeList,glj){
+function calculateQuantityByCoes(quantity,coeList,glj,gljList,decimal){
     let coeQuantity = quantity;
     if(coeList.length>1){
         for(let i=0;i<coeList.length-1;i++){
-            coeQuantity = everyCoe(coeQuantity,coeList[i],glj);
+            coeQuantity = everyCoe(coeQuantity,coeList[i],glj,gljList,decimal);
         }
     }
     return scMathUtil.roundTo(coeQuantity,-6);
 }
 
-function everyCoe(quantity,coe,glj) {
+function everyCoe(quantity,coe,glj,gljList,decimal) {
     let coeQuantity = quantity;
     if(coe.isAdjust==1){
         for(let i=0;i<coe.coes.length;i++){
             if(coe.coes[i].coeType=='单个工料机' &&coe.coes[i].gljCode==glj.code){//if(coe.coes[i].coeType=='单个工料机'&&coe.coes[i].gljCode==glj.code)
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             }else if(coe.coes[i].coeType== "替换人材机" && glj.rcode == coe.coes[i].gljCode && glj.code == coe.coes[i].replaceCode){
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
+            }else if(coe.coes[i].coeType== "所选人材机" && glj.rcode == coe.original_code && glj.code == coe.select_code ){
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             } else if(coe.coes[i].coeType=='定额'){
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             }else if(coeTypeMap[coe.coes[i].coeType]==getRootGLJType(glj.type).ID){
-                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i]);
+                coeQuantity = getCalculateResult(coeQuantity,coe.coes[i],coe,gljList,decimal);
             }
         }
     }
@@ -338,7 +344,15 @@ function calculateQuantityByCustomerCoes(quantify,coe,glj) {
     return quantify
 }
 
-function getCalculateResult(quantify,c) {
+function getCoeSelectedGLJ(gljList,rcode,code) {
+    if(gljList&& code && code !=""){
+        let o_glj = _.find(gljList,{'rcode':rcode,'code':code});
+        return o_glj;
+    }
+    return null;
+}
+
+function getCalculateResult(quantify,c,coe,gljList,decimal) {
     let q = quantify;
     switch (c.operator){
         case '+' :
@@ -353,6 +367,12 @@ function getCalculateResult(quantify,c) {
         case '/' :
             q = q / c.amount;
             break;
+        case '+*' :
+            let o_glj = getCoeSelectedGLJ(gljList,coe.original_code,coe.select_code);
+            if(o_glj){
+              q = q +  c.amount * scMathUtil.roundForObj(o_glj.quantity,decimal);
+            }
+            break;
         case '=' :
              q = c.amount;
             break;

+ 43 - 10
web/building_saas/main/js/models/ration_coe.js

@@ -127,21 +127,25 @@ var ration_coe = {
             updateData.push(newobj);
             return updateData;
         };
-        ration_coe.prototype.adjustCoeClick = function(recode,newval){
+        ration_coe.prototype.adjustCoeClick = function(record,newval,ext){
             let me=this,codesList = [],add=[],replace=[];
+            let doc = ext?ext:{};
+            doc['isAdjust'] = newval;
             var updateData = {
-                'ID':recode.ID,
-                'projectID': recode.projectID,
-                'rationID':recode.rationID,
-                'doc':{
-                    isAdjust:newval
-                },
+                'ID':record.ID,
+                'projectID': record.projectID,
+                'rationID':record.rationID,
+                'doc':doc,
                 add:[],
                 delete:[],
                 replace:[]
             };
-            let gljList = project.ration_glj.getGLJListByRationID(recode.rationID);
-            for(let coe of recode.coes){//做单个、替换等检查
+            let gljList = project.ration_glj.getGLJListByRationID(record.rationID);
+            if(gljUtil.isDef(record.option_codes)&&record.option_codes!=""){ //说明编辑的是下拉选择编号的类型
+                this.prepareDataForOptionType(record,newval,gljList,updateData,replace,codesList,ext);
+            }
+
+            for(let coe of record.coes){//做单个、替换等检查
                 if(coe.coeType == "单个工料机"){ //单个工料机的情况
                     let glj = _.find(gljList,{"code":coe.gljCode});
                     if(newval == 1){ //单个工料机,选中时,如果能找到则不管,如果没找到,则需自动插入
@@ -175,7 +179,7 @@ var ration_coe = {
                 let gljMap = _.indexBy(gljList, 'code');
                 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);
+                        let tem = project.ration_glj.getAddDataByStd(gljMap[a],record.rationID,project.mainTree.selected.data.billsItemID,record.projectID);
                         updateData.add.push(tem);
                     }
                 }
@@ -194,6 +198,35 @@ var ration_coe = {
             });
 
         };
+        ration_coe.prototype.prepareDataForOptionType = function (record,newval,gljList,updateData,replace,codesList,ext) {
+            let select_code = record.select_code;
+            if(ext && gljUtil.isDef(ext.select_code)&&ext.select_code!=""){//是下拉框选择了人材机编号进来的
+                select_code = ext.select_code;
+            }
+            if(gljUtil.isDef(select_code) && select_code!=""){//有选中编号的情况下,才会做这些操作
+                let glj = _.find(gljList,{"rcode":record.original_code,'code':select_code});//两个条件都满足,则表示已找到对应的记录
+                if(newval == 1){
+                    if(!glj){//在没找到的情况下,要替换
+                        let r_glj = _.find(gljList,function (g) {
+                            return (g.code == record.original_code && (g.createType===undefined || g.createType == 'normal')) || g.rcode == record.original_code //这两个满足一个说明要替换
+                        });
+                        if(r_glj){
+                            replace.push({code:select_code,oldData:r_glj});
+                            codesList.push(select_code);
+                        }
+                    }
+                }else {
+                    updateData.doc['select_code'] = ""; //取消勾选,选中值要恢复为空
+                    if(glj){//如果找到工料机,还需要恢复成原来的
+                        replace.push({code:record.original_code,oldData:glj});
+                        codesList.push(record.original_code);
+                    }
+                }
+            }
+        };
+
+
+
 
         ration_coe.prototype.updateCustomerCoe = function (data) {
             var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');

+ 42 - 9
web/building_saas/main/js/views/zmhs_view.js

@@ -11,12 +11,22 @@ let zmhs_obj = {
         header: [
             {headerName: "调整", headerWidth: 35, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
             {headerName: "条件", headerWidth: 250, dataCode: "name", dataType: "String", cellType: "button"},
-            {headerName: "内容", headerWidth: 160, dataCode: "content", dataType: "String", hAlign: "left"}
+            {headerName: "内容", headerWidth: 160, dataCode: "content", dataType: "String", hAlign: "left",getText:'forContent'}
         ],
         view: {
             lockColumns:[0,1,2],
             rowHeaderWidth:25
         },
+        getText:{
+            forContent:function (item) {
+               if(gljUtil.isDef(item.select_code)&&item.select_code!=""){
+                   return item.select_code;
+               }else {
+                   return item.content;
+               }
+
+            }
+        },
         autoFit:true,
         fitRow:['name']
     },
@@ -45,9 +55,12 @@ let zmhs_obj = {
         this.coeSheet.name('ration_coe');
         this.coeSheet.bind(GC.Spread.Sheets.Events.CellClick, this.onCoeCellClick);
         this.coeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onButtonClick);
-        this.coeSheet.bind(GC.Spread.Sheets.Events.EditStarting, function (e,args) {
-            //args.cancel = true;
+        this.coeSheet.bind(GC.Spread.Sheets.Events.ValueChanged,this.onCoeValueChange);
+        this.coeSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e,args) {
+            args.sheet.repaint();
         });
+
+
         this.assSheet = this.assSpread.getSheet(0);
         sheetCommonObj.initSheet(this.assSheet, this.assSetting, 30);
         this.assSheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onAssEditEnded);
@@ -68,17 +81,29 @@ let zmhs_obj = {
         }
         sheetCommonObj.showData(this.coeSheet, this.coeSetting,coeList);
         if (coeList.length > 0) {
-            var cus_index = _.findIndex(coeList, function (item) {
-                return item.coeID == -1;
-            })
-            if (cus_index != -1) {
-                this.coeSheet.getCell(cus_index, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
-                this.coeSheet.setCellType(cus_index, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
+            for(let i =0;i<coeList.length;i++ ){
+                if(gljUtil.isDef(coeList[i].option_codes)&&coeList[i].option_codes!=""){
+                    this.getComboBoxForCodes(coeList[i],i);//设置可选类型的下拉框
+                    //  sheet.setValue(row, col, val, ch);
+                } else if(coeList[i].coeID == -1){ //自定义系数列
+                    this.coeSheet.getCell(i, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+                    this.coeSheet.setCellType(i, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport);
+                }
             }
         }
         this.coeSheetData = coeList;
+    },
+    getComboBoxForCodes:function (coe,i) {
+        this.coeSheet.getCell(i, 2, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+        let options = coe.option_codes.split("|");
+        let combo = sheetCommonObj.getDynamicCombo(true);
+        combo.itemHeight(options.length).items(options);
+        this.coeSheet.setCellType(i, 2, combo, GC.Spread.Sheets.SheetArea.viewport);
+        this.coeSheet.setValue(i, 2, coe.select_code);
 
     },
+
+
     showAssData:function (node) {
         this.assSheet.suspendPaint();
         this.assSheet.suspendEvent();
@@ -302,6 +327,14 @@ let zmhs_obj = {
             zmhs_obj.coeSheet.startEdit();
         }
     },
+    onCoeValueChange:function (e,args) {
+        let fieldID =  zmhs_obj.coeSetting.header[args.col].dataCode;
+        let recode = zmhs_obj.coeSheetData[args.row];
+        if(gljUtil.isDef(recode.option_codes)&&recode.option_codes!=""&& fieldID == 'content'){//说明是选择了下拉框
+            projectObj.project.ration_coe.adjustCoeClick(recode, 1,{'select_code':args.newValue});
+        }
+    },
+
     onAssEditEnded:function (e,args) {
         var me = zmhs_obj;
         if (args.row >= me.assSheetData.length) {