| 
					
				 | 
			
			
				@@ -14,6 +14,7 @@ import STDFeeRateLibsModel from "../../common/std/std_fee_rate_libs_model"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import {default as EngineeringConst, List as EngineeringList} from "../../common/const/engineering"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import BillsTemplateModel from "../models/bills_template_model"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import {default as BillsFixedFlagConst, List as BillsFixedFlagList} from "../../common/const/bills_fixed.js"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import EngineeringLibModel from "../models/engineering_lib_model"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -113,14 +114,70 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationId = request.params.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let section = request.params.section; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let billList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let rationList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let compilationList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationData = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let compilationModel = new CompilationModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            compilationList = await compilationModel.getCompilationList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 获取对应的计价规则数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            [valuationData, valuationList] = await compilationModel.getValuation(selectedCompilation._id, valuationId, section); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Object.keys(valuationData).length <= 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw '不存在数据'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            console.log(error); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let renderData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            compilationList: compilationList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            engineeringList: EngineeringList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            selectedCompilation: selectedCompilation, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            valuationData: valuationData, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            valuationList: valuationList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            valuationId: valuationId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            section: section, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            layout: 'users/views/layout/layout' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        response.render('users/views/compilation/add', renderData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 编辑工程专业页面 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param {object} request 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param {object} response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return {void} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    async editEngineering(request, response) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let engineering = parseInt(request.params.engineering); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let valuationId = request.params.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let section = request.params.section; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let selectedCompilation = request.session.selectedCompilation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 获取当前工程专业名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let engineeringInfo = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            id: engineering, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            name: '' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for(let tmp of EngineeringList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (tmp.value === engineering) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                engineeringInfo.name = tmp.name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let compilationList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let billList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let rationList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let gljList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let billsTemplateData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let feeRateList = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let libData = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let billsTemplateData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let valuationData = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let valuationList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let compilationModel = new CompilationModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             compilationList = await compilationModel.getCompilationList(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -147,6 +204,10 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 throw '不存在数据'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 获取对应专业工程下的标准库数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let engineeringLibModel = new EngineeringLibModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            libData = await engineeringLibModel.getLib(valuationData.engineering_list, engineering); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 获取清单模板数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             let billsTemplateModel = new BillsTemplateModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billsTemplateData = await billsTemplateModel.getTemplateData(valuationId); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -156,22 +217,51 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let renderData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            section: section, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            valuationId: valuationId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            engineeringInfo: engineeringInfo, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             compilationList: compilationList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            selectedCompilation: selectedCompilation, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            libData: libData, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billList: JSON.stringify(billList), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             rationList: JSON.stringify(rationList), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             gljList: JSON.stringify(gljList), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             feeRateList: JSON.stringify(feeRateList), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            mainTreeCol: JSON.stringify(valuationData.main_tree_col), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billsTemplateData: JSON.stringify(billsTemplateData), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            engineeringList: EngineeringList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            selectedCompilation: selectedCompilation, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            valuationData: valuationData, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            valuationList: valuationList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            valuationId: valuationId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            section: section, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            mainTreeCol: JSON.stringify(valuationData.main_tree_col), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             layout: 'users/views/layout/layout' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        response.render('users/views/compilation/add', renderData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        response.render('users/views/compilation/engineering', renderData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 保存工程专业标准库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param {object} request 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param {object} response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return {void} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    async saveEngineering(request, response) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let valuationId = request.body.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (valuationId === '') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw 'id参数错误'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 先存入工程专业标准库表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let engineeringLibModel = new EngineeringLibModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let result = engineeringLibModel.addLib(valuationId, request.body); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (!result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw '保存失败'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            console.log(error); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        response.redirect(request.headers.referer); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -339,7 +429,7 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param {object} response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return {void} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    async template(request, response) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    async billsTemplate(request, response) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let billList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationList = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationData = {}; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -347,6 +437,7 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let billsTemplateData = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let selectedCompilation = request.session.selectedCompilation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let engineering = request.params.engineering; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationId = request.params.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let section = request.params.section; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -368,6 +459,7 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let renderData = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            engineering: engineering, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billList: JSON.stringify(billList), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billsTemplateData: JSON.stringify(billsTemplateData), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             billsFixedFlagList: JSON.stringify(BillsFixedFlagList), 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -389,19 +481,19 @@ class CompilationController extends BaseController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     async updateBillsTemplate(request, response) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let engineering = request.params.engineering; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let valuationId = request.params.id; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let section = request.params.section; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let data = JSON.parse(request.body.data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let billsTemplateModel = new BillsTemplateModel(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        let result = await billsTemplateModel.updateTemplate(valuationId, data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let result = await billsTemplateModel.updateTemplate(valuationId, engineering, data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             response.json({error: 0, message: '', data: data}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             response.json({error: 1, message: '更新数据错误', data: null}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |