Bladeren bron

子目关联相关功能

zhangweicheng 6 jaren geleden
bovenliggende
commit
433d20e457

+ 2 - 4
modules/all_models/compleRation_ration.js

@@ -56,11 +56,9 @@ const compleRationSchema = new Schema({
     rationAssList: [compleRationAssItemSchema],
     rationInstList: [rationInstSchema],
     rationTemplateList : [new Schema({
+        rationID:Number,
         type: String,
-        code: String,
-        name: String,
-        billsLocation: String,
-        unit:String
+        billsLocation: String
     }, { _id: false })],
     deleteInfo: deleteSchema
 }, {versionKey: false});

+ 2 - 4
modules/all_models/stdRation_ration.js

@@ -48,11 +48,9 @@ const rationItemSchema = new Schema({
     rationAssList: [rationAssItemSchema],
     rationInstList: [rationInstSchema],
     rationTemplateList : [new Schema({
+        rationID:Number,
         type: String,
-        code: String,
-        name: String,
-        billsLocation: String,
-        unit:String
+        billsLocation: String
     }, { _id: false })]
 
 });

+ 9 - 10
modules/main/controllers/ration_controller.js

@@ -54,20 +54,19 @@ let controller = {
     applyTemplate:async function(req){
         let data = req.body.data;
         data = JSON.parse(data);
-        let rationResult = [],billsResult = [],updateDatas =[];
-        //先生成新定额
-        if(data.rations.create.length > 0){
-            rationResult = await ration_facade.addMultiRation(data.rations.create,req.session.sessionCompilation);
-        }
-        //再生成清单
-        if(data.bills.create.length > 0){
-            billsResult =  await bill_facade.createNewBills(data.bills.create)
-        }
+        let updateDatas =[];
+        let applyTasks = [
+            ration_facade.addMultiRation(data.rations.create,req.session.sessionCompilation),//先生成新定额
+            bill_facade.createNewBills(data.bills.create),
+        ];
         //整理更新的数据,调用一个方法更新
         updateDatas.push(data.ration_template);
         if(data.rations.update.length > 0)  prepareUpdateNodes(data.rations.update,updateDatas,"ration");
         if(data.bills.update.length > 0)  prepareUpdateNodes(data.bills.update,updateDatas,"bills");
-        await project_facade.updateNodes(updateDatas);
+        applyTasks.push(project_facade.updateNodes(updateDatas));
+        let [rationResult,billsResult,updates] = await Promise.all(applyTasks);
+
+
         return {rationResult:rationResult,billsResult:billsResult,updateDatas:updateDatas};
     }
 };

+ 17 - 17
modules/main/facade/ration_facade.js

@@ -258,18 +258,21 @@ async function addRationTemplate(std,newRation) {
     let templateList = [];
     if(std.hasOwnProperty('rationTemplateList') && std.rationTemplateList.length > 0){
         for(let tem of std.rationTemplateList){
-            let template = {
-                billID:"",
-                fxID:"",
-                quantity:"0",
-                coe:"0"
-            };
-            template.code = tem.code;
-            template.name = tem.name;
-            template.type = tem.type;
-            template.unit = tem.unit;
-            template.billsLocation = tem.billsLocation;
-            templateList.push(template)
+            let re_ration = await rationItemModel.findOne({rationRepId:std.rationRepId,ID:tem.rationID});
+            if(re_ration){
+                let template = {
+                    billID:"",
+                    fxID:"",
+                    quantity:"0",
+                    coe:"0"
+                };
+                template.code = re_ration.code;
+                template.name = re_ration.name;
+                template.type = tem.type;
+                template.unit = re_ration.unit;
+                template.billsLocation = tem.billsLocation;
+                templateList.push(template)
+            }
         }
     }
     if(templateList.length > 0){
@@ -418,9 +421,6 @@ async function addRationGLJ(std,newRation,compilation) {
                     std_glj.basePrice =  std_glj.priceProperty[ext.priceField];
                 }
             }
-            console.log("================================get std glj=============================================");
-            console.log(std_glj);
-            let std_gljTime = +new Date();
             if(std_glj){
                 newGLJ.name = std_glj.name;
                 newGLJ.code = std_glj.code;
@@ -442,8 +442,8 @@ async function addRationGLJ(std,newRation,compilation) {
                 newRationGLJList.push(newGLJ);
                 rationGLJShowList.push(info);
             }
-            let InfoFromProjectGLJ = +new Date();
-            console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
+            //let InfoFromProjectGLJ = +new Date();
+            //console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
         }
     }
     let before = +new Date();

+ 3 - 3
web/building_saas/main/html/main.html

@@ -157,7 +157,7 @@
                               <a class="nav-link px-1 right-nav-link" href="javascript:void(0)" id="stdRationTab" relaPanel="#de">定额库</a>
                           </li>
                           <li class="nav-item dropdown">
-                              <!--<a class="nav-link dropdown-toggle more" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">更多</a>-->
+                             <!-- <a class="nav-link dropdown-toggle more" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">更多</a>-->
                               <div class="dropdown-menu">
                                   <a class="dropdown-item  right-nav-link"  href="javascript:void(0)" id = 'locateTab' relaPanel="#locate">查找定位</a>
                                  <!-- <a class="dropdown-item" data-toggle="tab" href="#sqpz" role="tab">书签批注</a>-->
@@ -213,9 +213,9 @@
                                   <li class="nav-item" id = "TZJNR_div">
                                       <a class="nav-link sub-item" id="linkTZJNR" data-toggle="tab" href="#subSpread" role="tab">特征及内容</a>
                                   </li>
-                                <!--  <li class="nav-item" id="MBZM_div">
+                                  <li class="nav-item" id="MBZM_div">
                                       <a class="nav-link sub-item" id="linkMBZM" data-toggle="tab" href="#subSpread" role="tab">模板子目</a>
-                                  </li>-->
+                                  </li>
                               </ul>
                               <!-- Tab panes -->
                               <div class="tab-content" id="tabCon">

+ 30 - 0
web/building_saas/main/js/controllers/project_controller.js

@@ -233,6 +233,36 @@ ProjectController = {
         } else {
             alert('当前焦点行不是定额,无法替换。');
         }
+    },
+    addNewNodes:function (updateData){
+        let controller = projectObj.mainController;
+        let Bill = projectObj.project.Bills;
+        let newAddNode = [];
+        let newRationNodes = [];
+        for(let nb of updateData.bills.add){
+            let newSource = Bill.tree.insertByData(nb, nb.ParentID, -1, true);//按顺序插入的情况下,nextID为-1,树节点
+            let newNode = projectObj.project.mainTree.insert(nb.ParentID, -1, newSource.data.ID);
+            newNode.source = newSource;
+            newNode.sourceType = Bill.getSourceType();
+            newNode.data = newSource.data;
+            controller.sheet.addRows(newNode.serialNo(), 1);
+           // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
+            newAddNode.push(newNode);
+            Bill.datas.push(nb);
+        }
+        for(let nr of updateData.ration.add){
+            let newNode = projectObj.project.mainTree.insert(nr.billsItemID, -1, nr.ID);
+            newNode.source = nr;
+            newNode.sourceType = projectObj.project.Ration.getSourceType();
+            newNode.data = nr;
+            controller.sheet.addRows(newNode.serialNo(), 1);
+           // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
+            newAddNode.push(newNode);
+            newRationNodes.push(newNode);
+            projectObj.project.Ration.datas.push(nr);
+        }
+        TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
+        return newRationNodes;
     }
 /*    addVolumePrice: function (project, sheetController) {
         if (!project || !sheetController) { return null; }

+ 7 - 1
web/building_saas/main/js/models/bills.js

@@ -738,6 +738,9 @@ var Bills = {
                 updateNodes.push(m_node);
                 controller.tree.getAllSubNode(m_node,updateNodes);
             }
+            console.log(mainNodes);
+            let refNodes = mbzm_obj.deleteReferenceRation(mainNodes,updateNodes);//删除子目关联定额节点
+            console.log(mainNodes);
             for(let u_node of updateNodes){
                 if(u_node.sourceType == project.Bills.getSourceType()){
                     billsUpdate[u_node.data.ID] = true;
@@ -777,7 +780,10 @@ var Bills = {
                         project.Ration.deleteSubListOfRation({ID:r_key});
                     }
                 }
-                controller.m_delete(mainNodes);//删除树节点
+                for(let r of refNodes){
+                    controller.m_delete([r],r.serialNo())//这里删除关联子目生成的定额因为是离散的树节点,所以要这样分开处理
+                }
+                controller.m_delete(mainNodes,mainNodes[0].serialNo());//删除树节点
                 me.tree.m_delete(idTreeNodes);
                 $.bootstrapLoading.end();
                 //重新计算

+ 1 - 2
web/building_saas/main/js/models/project.js

@@ -422,16 +422,15 @@ var PROJECT = {
                     temObj = _.find(this[d.type].datas,{"ID":d.data.ID});
                 }
                 if(temObj){
-                    console.log(temObj);
                     for(let key in d.data){
                         if(key == 'ID' || key == 'id'){
                             continue;
                         }
                         this.setValue(temObj,key,d.data[key])
                     }
-                    console.log(temObj);
                 }
             }
+            return refreshNode;
         };
         project.prototype.setValue=function (obj,key,value) {
             let keyArray = key.split('.');

+ 64 - 30
web/building_saas/main/js/views/mbzm_view.js

@@ -117,7 +117,7 @@ let mbzm_obj={
     },
     updatePosition:function (recode) {
         let selection = this.sheet.getSelections()[0];
-        let selectedItem  =(this.datas[selection.row]);
+        let selectedItem =this.datas[selection.row];
         let updateField = $("#createLocation").val()==this.locateMap.INMEASURE?"billID":"fxID";
         if(selectedItem[updateField] == recode.ID) return;
         selectedItem[updateField] = recode.ID;
@@ -132,7 +132,7 @@ let mbzm_obj={
         if(this.datas.length <= 0) return;
         for(let d of this.datas){
             if(gljUtil.isDef(d.quantity)&& parseFloat(d.quantity)>0){
-                if(this.positionChecking(createLocation,d) == false){
+                if(this.positionChecking(createLocation,d) == false){//清单位置检查
                     alert(`请选择${d.code}生成的清单位置`);
                     return;
                 }
@@ -149,15 +149,37 @@ let mbzm_obj={
         console.log(data);
         $.bootstrapLoading.start();
         CommonAjax.post('/ration/applyTemplate',data,function (result) {
-            $.bootstrapLoading.end();
             let refreshNodes = projectObj.project.updateNodesCache(result.updateDatas);//更新要update的前端缓存,并返回要刷新的树节点
+            let nodeDatas = {ration:{add:[]}, bills:{add:[]}};
+            if(result.rationResult){
+                for(let rr of result.rationResult){
+                    nodeDatas.ration.add.push(rr.ration);//定额datas数据的push在addNodes里面做
+                    projectObj.project.Ration.addSubListOfRation(rr);//添加定额子项缓存
+                }
+            }
             //对于新插入的清单:
             if(result.billsResult.length > 0){
-
+                nodeDatas.bills.add = result.billsResult;
             }
-            //对于新插入的定额
-
+            let calRations = ProjectController.addNewNodes(nodeDatas);
+            if(refreshNodes.length > 0){
+                for(let r of refreshNodes){
+                    if(r.sourceType == ModuleNames.ration){
+                        calRations.push(r);
+                        if(r.data.quantityEXP =="MBGCL" ) projectObj.project.quantity_detail.cleanQuantityDetail(r,true);
+                    }
+                }
+                projectObj.mainController.refreshTreeNode(refreshNodes, false);
+            }
+            projectObj.project.projectGLJ.loadData(function () {
+                $.bootstrapLoading.end();
+                cbTools.refreshFormulaNodes();
+                //更新计算程序模板,并进行重新计算
+                projectObj.project.calcProgram.calcNodesAndSave(calRations,function () {
+                    installationFeeObj.calcInstallationFee();
+                });
 
+            });
             console.log(result);
         })
 
@@ -171,7 +193,7 @@ let mbzm_obj={
             }else if(_.isEmpty(data.billsLocation)){
                 validate = false
             }
-        }else {
+        }else if(type == mbzm_obj.locateMap.INFBFX){
             if(_.isEmpty(data.fxID)) {
                 validate = false;
             }else {
@@ -189,6 +211,7 @@ let mbzm_obj={
         let ration = this.getExistRation(data,referenceRationID,type);
         if(ration) {//如果存在,则比较清耗量、工程量表达式是否一致
             let tem =  this.getRationData(ration,data,quantity);//取更新信息
+
             if(tem){//如果不一致,则需要更新
                 rations.update.push(tem);
             }
@@ -204,30 +227,14 @@ let mbzm_obj={
         }else {
             this.createNewRationInFBFX(data,mainRation,quantity,rations,bills);
         }
-
-        /*[
-            {
-                type:'ration',
-                data:{
-                    projectID:1605,
-                    ID:"7b962fb0-1131-11e8-b3da-af725dadd7ae",
-                    name:'testRation'
-                }
-            },
-            {
-                type:'bills',
-                data:{
-                    projectID:1605,
-                    ID:"af9f0081-1127-11e8-99a8-2fc02230b6e7",
-                    name:'安全文明施工专项费用123'
-                }
-            }
-        ]*/
     },
     getRationData:function (ration,data,quantity) {
         let tem = {};
         if (ration.quantity + "" != quantity) tem.quantity = quantity;
-        if (gljUtil.isDef(data.coe) && data.coe != "0") tem.quantityEXP = "MBGCL";
+        if (gljUtil.isDef(data.coe) && data.coe != "0"&&ration.quantityEXP != "MBGCL") {
+            tem.isFromDetail = 0;
+            tem.quantityEXP = "MBGCL";
+        }
         if(!_.isEmpty(tem)) {
             tem.projectID = ration.projectID;
             tem.ID = ration.ID;
@@ -243,7 +250,7 @@ let mbzm_obj={
         if(rations.create.length > 0){
             serialNo = rations.create[rations.create.length -1].newData.serialNo + 1
         }
-        let n_ration = this.createNewRationData(data,newID,mainRation.data.referenceRationID,mainRation.data.billsItemID,serialNo,quantity,mainRation.data.libID);
+        let n_ration = this.createNewRationData(data,newID,mainRation.data.ID,mainRation.data.billsItemID,serialNo,quantity,mainRation.data.libID);
         rations.create.push(n_ration);
         //处理其它兄弟节点的序号
         let br = projectObj.project.Ration.getBillsSortRation();
@@ -287,6 +294,7 @@ let mbzm_obj={
                     ParentID:parentNode.data.ID,
                     NextSiblingID:-1,
                     code:projectObj.project.Bills.newFormatCode(data.billsLocation),
+                    type:billType.BILL,
                     billsLibId:projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id,//projectInfoObj.projectInfo.engineeringInfo.billsGuidance_lib
                     billsLocation : data.billsLocation//这个是用来在后端查找清单信息
                 };
@@ -385,7 +393,6 @@ let mbzm_obj={
         }
         return data.quantity
     },
-
     getExistRation:function (data,referenceRationID,type) {
         let temRation = null;
         //先检查要更新的定额是否已经存在
@@ -421,8 +428,35 @@ let mbzm_obj={
                 }
             }
         }
-
         return temRation;
+    },
+    hasReferenceRation:function (node) {
+        if(node.sourceType == ModuleNames.ration){
+            let  template = projectObj.project.ration_template.getTemplateByRationID(node.data.ID);
+            if(template){
+                let ration = _.find(projectObj.project.Ration.datas,{'referenceRationID':node.data.ID});
+                if(ration) return true;
+            }
+
+        }
+        return false;
+    },
+    deleteReferenceRation:function (mainNodes,updateNodes) {
+        let refNode = [];
+        for(let m of mainNodes){
+            if(this.hasReferenceRation(m)){
+                let  rations = _.filter(projectObj.project.Ration.datas,{'referenceRationID':m.data.ID});
+                for(let r of rations){
+                    let temNode =  projectObj.project.mainTree.getNodeByID(r.ID);
+                    if(temNode && updateNodes.indexOf(temNode) == -1){//能找到该节点,并且节点不在已经删除的列表中
+                        refNode.push(temNode);
+                        updateNodes.push(temNode);
+                        projectObj.mainController.tree.getAllSubNode(temNode,updateNodes)//添加显示到造价书页面的主材、设备节点
+                    }
+                }
+            }
+        }
+        return refNode;
     }
 };
 

+ 2 - 0
web/building_saas/main/js/views/project_view.js

@@ -2474,6 +2474,8 @@ $('#delete_row').on('show.bs.modal', function (e) {//这里用show,在shown之
             showN = true;
             cancelText = "取消";
         }
+    }else if(isSingleSelect()&&mbzm_obj.hasReferenceRation(selected)){//“有模板关联的定额”右键点击删除,弹窗提示“删除主子目时将删除对应的关联子目,是否继续?  是 否” (只有单选中一条定额并且是有模板关联的定额)
+        showinfo = "<label>删除主子目时将删除对应的关联子目,是否继续?</label>";
     }
     $('#delete_showinfo').html(showinfo);
     showN==true? $('#deleteN').show():$('#deleteN').hide();

+ 3 - 0
web/building_saas/main/js/views/quantity_edit_view.js

@@ -184,6 +184,9 @@ let quantityEditObj = {
             $("#quantityEditSpread").hide();
         }
         $("#quantityEXPValue").val(selected.data.quantityEXP);
+        selected.data.quantityEXP == "GCLMXHJ" || selected.data.quantityEXP =="MBGCL"?$("#quantityEXPValue").attr("disabled","disabled"):$("#quantityEXPValue").removeAttr("disabled");
+
+
     },
     checkingAndUpdate(quantityEXP,node){
         let me = this;