Browse Source

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionOperation

TonyKang 8 years ago
parent
commit
1d52183d89

+ 106 - 14
modules/users/controllers/compilation_controller.js

@@ -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});
         }
-
     }
 
 }

+ 9 - 6
modules/users/models/bills_template_model.js

@@ -20,12 +20,13 @@ class BillsTemplateModel extends BaseModel {
     /**
      * 获取计价类别对应的清单模板
      * @param valuationId
+     * @param engineering
      * @returns {*}
      */
-    async getTemplateData (valuationId) {
+    async getTemplateData (valuationId, engineering) {
         // 筛选字段
         let field = {_id: 1, valuationId: 1, ID: 1, ParentID: 1, NextSiblingID: 1, code: 1, name: 1, unit: 1, flags: 1};
-        let data = await this.findDataByCondition({valuationId: valuationId}, field, false);
+        let data = await this.findDataByCondition({valuationId: valuationId, engineering: engineering}, field, false);
 
         return data === null ? [] : data;
     }
@@ -33,20 +34,22 @@ class BillsTemplateModel extends BaseModel {
     /**
      * 新建项目时,获取计价类别对应的清单模板
      * @param valuationId
+     * @param engineering
      * @returns {*}
      */
-    async getTemplateDataForNewProj (valuationId) {
+    async getTemplateDataForNewProj (valuationId, engineering) {
         // 筛选字段
-        let field = {ID: 1, ParentID: 1, NextSiblingID: 1, code: 1, name: 1, unit: 1, flags: 1};
-        let data = await this.findDataByCondition({valuationId: valuationId}, field, false);
+        let field = {_id: 0, ID: 1, ParentID: 1, NextSiblingID: 1, code: 1, name: 1, unit: 1, flags: 1};
+        let data = await this.findDataByCondition({valuationId: valuationId, engineering: engineering}, field, false);
 
         return data === null ? [] : data;
     }
 
-    async updateTemplate (valuationId, datas) {
+    async updateTemplate (valuationId, engineering, datas) {
         try {
             for (let data of datas) {
                 data.data.valuationId = valuationId;
+                data.data.engineering = engineering;
                 let condition = {valuationId: valuationId, ID: data.data.ID}, result;
                 if (data.type === 'update') {
                     result = await this.db.update(condition, data.data);

+ 45 - 42
modules/users/models/compilation_model.js

@@ -73,7 +73,6 @@ class CompilationModel extends BaseModel {
 
         this.setScene('add');
         data.create_time = new Date().getTime();
-        console.log(data);
         result = this.db.create(data);
         return result;
     }
@@ -97,6 +96,7 @@ class CompilationModel extends BaseModel {
             throw '计价规则名称为空';
         }
         if (this.sectionList.indexOf(section) < 0) {
+            console.log('2');
             throw '数据有误';
         }
 
@@ -121,13 +121,7 @@ class CompilationModel extends BaseModel {
         condition[sectionString + "._id"] = valuationId;
 
         let updateData = {};
-        updateData[sectionString + ".$.bill_lib"] = data.bill_lib;
-        updateData[sectionString + ".$.ration_lib"] = data.ration_lib;
-        updateData[sectionString + ".$.glj_lib"] = data.glj_lib;
-        updateData[sectionString + ".$.fee_lib"] = data.fee_lib;
         updateData[sectionString + ".$.name"] = data.name;
-        updateData[sectionString + ".$.engineering"] = data.engineering;
-        updateData[sectionString + ".$.main_tree_col"] = JSON.parse(data.main_tree_col);
 
         let result = await this.db.update(condition, updateData);
 
@@ -163,6 +157,7 @@ class CompilationModel extends BaseModel {
      */
     _filterValuationData(data) {
         if (Object.keys(data).length <= 0) {
+            console.log('3');
             throw '数据有误';
         }
 
@@ -174,46 +169,11 @@ class CompilationModel extends BaseModel {
         if (data.name === undefined || data.name === '') {
             throw '名称不能为空';
         }
-        // 判断工程专业
-        if (data.engineering === undefined || data.engineering === '') {
-            throw '名称不能为空';
-        }
-        data.engineering = parseInt(data.engineering);
-        // 判断标准清单
-        data.bill_lib = this._validLib(data.bill_lib);
-
-        // 判断定额库
-        data.ration_lib = this._validLib(data.ration_lib);
-
-        // 判断工料机库
-        data.glj_lib = this._validLib(data.glj_lib);
-
-        // 判断费率库
-        data.fee_lib = this._validLib(data.fee_lib);
 
         return data;
     }
 
     /**
-     * 校验库数据
-     *
-     * @param {Object} libData
-     * @return {Object}
-     */
-    _validLib(libData) {
-        let result = [];
-        // 判断费率库
-        if (libData === undefined || libData === '') {
-            throw '判断费率库不能为空';
-        }
-        libData = libData instanceof Array ? libData : [libData];
-        for(let tmp in libData) {
-            result[tmp] = JSON.parse(libData[tmp]);
-        }
-        return result;
-    }
-
-    /**
      * 获取计价规则数据
      *
      * @param {String} compilationId
@@ -223,6 +183,7 @@ class CompilationModel extends BaseModel {
      */
     async getValuation(compilationId, id, section) {
         if (this.sectionList.indexOf(section) < 0) {
+            console.log('4');
             throw '数据有误';
         }
         let compilationData = await this.findDataByCondition({_id: compilationId});
@@ -309,6 +270,48 @@ class CompilationModel extends BaseModel {
         return this.updateById(id, updateData);
     }
 
+    /**
+     * 根据专业工程获取对应专业工程标准库id
+     *
+     * @param {String} valuationId
+     * @param {String} section
+     * @param {Number} engineering
+     * @return {Promise}
+     */
+    async getEngineeringLib(valuationId, section, engineering) {
+        let sectionString = section + "_valuation";
+        let condition = {};
+        condition[sectionString + "._id"] = valuationId;
+        condition[sectionString + ".engineering_list.engineering"] = engineering;
+
+        let engineeringLib = await this.findDataByCondition(condition);
+        if (engineeringLib === null) {
+            return engineeringLib;
+        }
+        return engineeringLib[sectionString].length > 0 && engineeringLib[sectionString][0].engineering_list ?
+            engineeringLib[sectionString][0].engineering_list : {};
+    }
+
+    /**
+     * 新增专业工程标准库
+     *
+     * @param {String} valuationId
+     * @param {String} section
+     * @param {Object} data
+     * @return {Promise}
+     */
+    async addEngineeringLib(valuationId, section, data) {
+        let sectionString = section + "_valuation";
+        let condition = {};
+        condition[sectionString + "._id"] = valuationId;
+
+        let insertData = {};
+        insertData[sectionString + ".$.engineering_list"] = data;
+        let result = await this.db.addToSet(condition, insertData);
+
+        return result.ok === 1;
+    }
+
 }
 
 export default CompilationModel;

+ 165 - 0
modules/users/models/engineering_lib_model.js

@@ -0,0 +1,165 @@
+/**
+ * 计价规则标准库业务逻辑
+ *
+ * @author CaiAoLin
+ * @date 2017/8/31
+ * @version
+ */
+import BaseModel from "../../common/base/base_model";
+import EngineeringLibSchema from "./schemas/engineering_lib";
+import CompilationModel from "./compilation_model";
+import {default as EngineeringConst, List as EngineeringList} from "../../common/const/engineering";
+
+class EngineeringLibModel extends BaseModel {
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = EngineeringLibSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取标准库数据
+     *
+     * @param {Object} data
+     * @param {Number} engineering
+     * @return {Promise}
+     */
+    async getLib(data, engineering) {
+        let result = {};
+        if (data.length <= 0) {
+            return result;
+        }
+        let id = '';
+        for(let tmp of data) {
+            if (tmp.engineering === engineering) {
+                id = tmp.engineering_id;
+                break;
+            }
+        }
+        if (id === '') {
+            return result;
+        }
+        let condition = {_id: id};
+        return this.findDataByCondition(condition);
+    }
+
+    /**
+     * 新增标准库
+     *
+     * @param {String} valuationId
+     * @param {Object} data
+     * @return {Promise}
+     */
+    async addLib(valuationId, data) {
+        if (data.main_tree_col) {
+            data.main_tree_col = JSON.parse(data.main_tree_col);
+        }
+
+        let result = false;
+        data = this.filterLibData(data);
+        try {
+            // 查找计价规则表中是否有对应工程专业标准库的数据
+            let compilationModel = new CompilationModel();
+            let engineeringLib = await compilationModel.getEngineeringLib(valuationId, data.section, data.engineering);
+
+            let result = false;
+            if (engineeringLib === null) {
+                // 不存在则插入
+                result = await this.db.create(data);
+            } else {
+                engineeringLib = engineeringLib.length > 0 ? engineeringLib[0] : {};
+                // 存在则直接更新
+                let condition = {_id: engineeringLib.engineering_id};
+                result = await this.db.update(condition, data);
+                result = result.ok === 1;
+            }
+            // 失败直接返回
+            if (!result) {
+                throw '操作失败';
+            }
+
+            // 新增后更新编办数据表中专业工程字段
+            if (result && engineeringLib === null) {
+                let insertData = {
+                    engineering: data.engineering,
+                    engineering_id: result._id
+                };
+                let updateResult = await compilationModel.addEngineeringLib(valuationId, data.section, insertData);
+                if (!updateResult) {
+                    throw '新增编办数据中的专业工程失败!';
+                }
+            }
+        } catch (error) {
+            console.log(error);
+            result = false;
+        }
+
+        return result;
+    }
+
+    /**
+     * 过滤计价数据
+     *
+     * @param {Object} data
+     * @return {Object}
+     */
+    filterLibData(data) {
+        if (Object.keys(data).length <= 0 || data.section === undefined) {
+            console.log('1');
+            throw '数据有误';
+        }
+        // 检测专业工程是否合法
+        data.engineering = parseInt(data.engineering);
+        let match = false;
+        for(let index in EngineeringConst) {
+            if (EngineeringConst[index] === data.engineering) {
+                match = true;
+                break;
+            }
+        }
+        if (!match) {
+            throw '工程专业错误';
+        }
+
+        // 判断标准清单
+        data.bill_lib = this._validLib(data.bill_lib);
+
+        // 判断定额库
+        data.ration_lib = this._validLib(data.ration_lib);
+
+        // 判断工料机库
+        data.glj_lib = this._validLib(data.glj_lib);
+
+        // 判断费率库
+        data.fee_lib = this._validLib(data.fee_lib);
+
+        return data;
+    }
+
+    /**
+     * 校验库数据
+     *
+     * @param {Object} libData
+     * @return {Object}
+     */
+    _validLib(libData) {
+        let result = [];
+        // 判断费率库
+        if (libData === undefined || libData === '') {
+            throw '判断费率库不能为空';
+        }
+        libData = libData instanceof Array ? libData : [libData];
+        for(let tmp in libData) {
+            result[tmp] = JSON.parse(libData[tmp]);
+        }
+        return result;
+    }
+
+}
+
+export default EngineeringLibModel;

+ 3 - 1
modules/users/models/schemas/bills_template.js

@@ -28,7 +28,9 @@ let BillsTemplateSchema = {
         default: []
     },
     // 所属计价ID
-    valuationId: String
+    valuationId: String,
+    // 工程专业
+    engineering: Number
 };
 
 let model = mongoose.model(collectionName, new Schema(BillsTemplateSchema, {versionKey: false, collection: collectionName}));

+ 12 - 22
modules/users/models/schemas/compilation.js

@@ -9,27 +9,22 @@ import mongoose from "mongoose";
 
 let Schema = mongoose.Schema;
 let collectionName = 'compilation';
-let childrenSchema = new Schema({
-    // 计价名称
-    name: String,
-    // 工程专业
+let engineeringListSchema = new Schema({
+    // 工程专业id
     engineering: {
-        type: Number,
-        default: ''
-    },
-    // 标准清单
-    bill_lib: {
-        type: Schema.Types.Mixed,
-        default: []
+        type: Number
     },
-    // 定额库
-    ration_lib: {
+    engineering_id: {
         type: Schema.Types.Mixed,
         default: []
-    },
-    // 工料机库
-    glj_lib: {
-        type: Schema.Types.Mixed,
+    }
+}, {_id: false});
+let childrenSchema = new Schema({
+    // 计价名称
+    name: String,
+    // 工程专业列表
+    engineering_list: {
+        type: [engineeringListSchema],
         default: []
     },
     // 是否启用
@@ -51,11 +46,6 @@ let childrenSchema = new Schema({
             "headRowHeight":[],
             "cols":[]
         }
-    },
-    // 费率标准库
-    fee_lib: {
-        type: Schema.Types.Mixed,
-        default: []
     }
 });
 let modelSchema = {

+ 47 - 0
modules/users/models/schemas/engineering_lib.js

@@ -0,0 +1,47 @@
+/**
+ * 计价规则数据结构
+ *
+ * @author CaiAoLin
+ * @date 2017/8/31
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'engineering_lib';
+let modelSchema = {
+    // 标准清单
+    bill_lib: {
+        type: Schema.Types.Mixed,
+        default: []
+    },
+    // 定额库
+    ration_lib: {
+        type: Schema.Types.Mixed,
+        default: []
+    },
+    // 工料机库
+    glj_lib: {
+        type: Schema.Types.Mixed,
+        default: []
+    },
+    // 列设置
+    main_tree_col: {
+        type: Schema.Types.Mixed,
+        default: {
+            "emptyRows":3,
+            "headRows":0,
+            "treeCol": 0,
+            "headRowHeight":[],
+            "cols":[]
+        }
+    },
+    // 费率标准库
+    fee_lib: {
+        type: Schema.Types.Mixed,
+        default: []
+    }
+};
+let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
+export {model as default, collectionName as collectionName};
+

+ 4 - 2
modules/users/routes/compilation_route.js

@@ -15,15 +15,17 @@ module.exports = function (app) {
     // action定义区域
     router.get('/', compilationController.auth, compilationController.init, compilationController.index);
     router.get('/valuation/:section/:id', compilationController.auth, compilationController.init, compilationController.editValuation);
+    router.get('/:section/:id/:engineering', compilationController.auth, compilationController.init, compilationController.editEngineering);
     router.get('/valuation/:section/delete/:id', compilationController.auth, compilationController.init, compilationController.deleteValuation);
-    router.get('/template/:section/:id', compilationController.auth, compilationController.init, compilationController.template);
+    router.get('/template/:section/:id/:engineering', compilationController.auth, compilationController.init, compilationController.billsTemplate);
 
     router.post('/release', compilationController.auth, compilationController.init, compilationController.release);
     router.post('/add', compilationController.auth, compilationController.init, compilationController.addCompilation);
     router.post('/add-valuation', compilationController.auth, compilationController.init, compilationController.addValuation);
     router.post('/save-valuation', compilationController.auth, compilationController.init, compilationController.saveValuation);
+    router.post('/save-lib', compilationController.auth, compilationController.init, compilationController.saveEngineering);
     router.post('/valuation/:section/enable', compilationController.auth, compilationController.init, compilationController.enableSwitch);
-    router.post('/template/:section/:id/update', compilationController.auth, compilationController.init, compilationController.updateBillsTemplate)
+    router.post('/template/:section/:id/:engineering/update', compilationController.auth, compilationController.init, compilationController.updateBillsTemplate);
 
     app.use("/compilation", router);
 };

+ 5 - 8
web/maintain/std_glj_lib/js/glj.js

@@ -37,8 +37,8 @@ let repositoryGljObj = {
 
         header:[
             {headerName:"编码",headerWidth:120,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
-            {headerName:"名称",headerWidth:260,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
-            {headerName:"规格型号",headerWidth:260,dataCode:"specs", dataType: "String", hAlign: "left", vAlign: "center"},
+            {headerName:"名称",headerWidth:260,dataCode:"name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
+            {headerName:"规格型号",headerWidth:260,dataCode:"specs", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
             {headerName:"计量单位",headerWidth:120,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
             {headerName:"基价单价",headerWidth:120,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
             {headerName:"类型",headerWidth:120,dataCode:"gljType", dataType: "String", hAlign: "center", vAlign: "center"}
@@ -431,7 +431,9 @@ let repositoryGljObj = {
                             if(me.componentGljType.indexOf(me.currentEditingGlj.gljType) !== -1 &&
                                 !(me.currentEditingGlj.gljType === 302 && rObj.gljType === 303) && !(me.currentEditingGlj.gljType === 303 && rObj.gljType === 302)){//修改了原本是组成物的工料机
                                //寻找所有引用了此组成物的工料机,并从组成物中删去此工料机,并重算单价
-                                let updateGljs = me.getUpdateGljs(rObj);
+                                let updateGljs = me.getUpdateGljs(rObj, true);
+                                console.log(rObj);
+                                console.log(updateGljs);
                                 if(updateGljs.updateArr.length > 0 || updateGljs.updateBasePrcArr.length > 0){
                                     for(let i = 0; i < updateGljs.updateArr.length; i++){
                                         updateArr.push(updateGljs.updateArr[i]);
@@ -553,7 +555,6 @@ let repositoryGljObj = {
                                         updateBasePrcArr.push(updateGljs.updateBasePrcArr[i]);
                                     }
                                 }
-                                console.log(updateArr);
                                 removeArr.push(cacheSection[sels[i].row + j].ID);
                                 //tempRemoveArr.push({ID: cacheSection[sels[i].row + j].ID, code: cacheSection[sels[i].row + j].code});
                                 //删除后重新计算引用了此工料机的定额单价
@@ -760,11 +761,7 @@ let repositoryGljObj = {
         return true;
     },
     onClipboardPasting: function(sender, args) {
-        console.log(`oncp`);
         let me = repositoryGljObj;
-        /*if (args.cellRange.colCount != me.setting.header.length || me.gljCurTypeId < 0 || me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
-         args.cancel = true;
-         }*/
         if (me.gljCurTypeId < 0 ) {
             args.cancel = true;
         }

+ 3 - 2
web/maintain/std_glj_lib/js/gljComponent.js

@@ -8,7 +8,7 @@ let gljComponentOprObj = {
         owner: "gljComponent",
         header:[
             {headerName:"编码",headerWidth:50,dataCode:"code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
-            {headerName:"名称",headerWidth:60,dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center"},
+            {headerName:"名称",headerWidth:60,dataCode:"name", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
             {headerName:"计量单位",headerWidth:60,dataCode:"unit", dataType: "String", hAlign: "center", vAlign: "center"},
             {headerName:"单价",headerWidth:50,dataCode:"basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
             {headerName:"消耗量",headerWidth:55,dataCode:"consumeAmt", dataType: "Number", formatter: "0.000", hAlign: "right", vAlign: "center"}
@@ -256,7 +256,8 @@ let gljComponentOprObj = {
             }
         }
         else{
-            args.sheet.setValue(args.row, args.col, '');
+            args.sheet.setValue(args.row, args.col, me.currentEditingComponent[me.setting.header[args.col].dataCode] ?
+            me.currentEditingComponent[me.setting.header[args.col].dataCode]: '');
         }
         if(updateArr.length > 0){
             me.updateComponent(updateArr);

+ 15 - 25
web/users/js/compilation.js

@@ -12,7 +12,7 @@ $(document).ready(function() {
     let id = $("#compilation-id").val();
 
     // 计价规则页面初始化数据
-    if ($("#section").length > 0) {
+    if ($("#save-lib").length > 0) {
         initCompilation();
     }
 
@@ -54,24 +54,6 @@ $(document).ready(function() {
                     name: data[model].name,
                     id: data[model].id
                 };
-                // switch (model) {
-                //     case 'bill':
-                //         addLib.name = standardBillString;
-                //         addLib.id = standardBill;
-                //         break;
-                //     case 'ration':
-                //         addLib.name = rationLibString;
-                //         addLib.id = rationLib;
-                //         break;
-                //     case 'glj':
-                //         addLib.name = gljLibString;
-                //         addLib.id = gljLib;
-                //         break;
-                //     case 'fee':
-                //         addLib.name = gljLibString;
-                //         addLib.id = gljLib;
-                //         break;
-                // }
                 // 判断是否有重复的数据
                 if ($("input:hidden[name='"+ model +"_lib'][data-id='"+ addLib.id +"']").length > 0) {
                     alert('重复添加数据!');
@@ -157,12 +139,16 @@ $(document).ready(function() {
         $("#addcompilation").modal('show');
     });
 
-    // 保存计价规则
-    $("#save-valuation").click(function() {
-        if (validValuation()) {
+    // 保存专业工程标准库
+    $("#save-lib").click(function() {
+        if (validLib()) {
             $("form").submit();
         }
     });
+    // 保存计价规则
+    $("#save-valuation").click(function() {
+        $("form").submit();
+    });
 
     // 移除操作
     $(".bill-list, .ration-list, .glj-list, .fee-list").on("click", ".remove-lib", function() {
@@ -329,7 +315,7 @@ function getAndValidData(model) {
 
     let result = {
         name: name,
-        standardBill: {
+        bill: {
             id: standardBill,
             name: standardBillString
         },
@@ -350,11 +336,11 @@ function getAndValidData(model) {
 }
 
 /**
- * 验证计价规则数据
+ * 验证标准库数据
  *
  * @return {boolean}
  */
-function validValuation() {
+function validLib() {
     let result = false;
     try {
         let valuationName = $("input[name='name']").val();
@@ -375,6 +361,10 @@ function validValuation() {
             throw '请添加定额库';
         }
 
+        if ($("input:hidden[name='fee_lib']").length <= 0) {
+            throw '请添加费率库';
+        }
+
         result = true;
     } catch (error) {
         alert(error);

+ 26 - 113
web/users/views/compilation/add.html

@@ -3,11 +3,8 @@
     <div class="panel-title">
         <div class="title-main">
             <h2>
-                <%= selectedCompilation.name %>
-                <% if(selectedCompilation.is_release) {%>
-                <span class="text-muted" style="margin-left: 5px;">已发布 <%= moment(selectedCompilation.update_time).format('YYYY-MM-DD')%></span>
-                <% } %>
-                <a href="javascript:void(0);" data-id="<%= selectedCompilation._id %>" data-status="<%= selectedCompilation.is_release ? 0 : 1 %>" class="btn btn-primary btn-sm pull-right" id="release"><% if(selectedCompilation.is_release) {%>取消<% }else{ %>发布<% } %>版本</a>
+                <a href="javascript:void(0);" id="save-valuation" class="btn btn-primary btn-sm pull-right">保存</a>
+                <a href="/compilation" class="btn btn-default btn-sm pull-right">返回</a>
             </h2>
         </div>
     </div>
@@ -20,112 +17,40 @@
             </ul>
         </div>
         <div class="c-body">
-            <form method="post" action="/compilation/save-valuation" enctype="application/x-www-form-urlencoded21">
+            <form action="/compilation/save-valuation" method="post" enctype="application/x-www-form-urlencoded">
                 <div class=" row">
                     <div class="col-md-4">
                         <div class="form-group">
                             <label>名称</label>
-                            <div class="input-group">
-                                <input type="text" class="form-control" value="<%= valuationData.name %>" name="name">
-                                <span class="input-group-btn">
-                                     <button class="btn btn-default" type="button" id="save-valuation">保存全部</button>
-                                </span>
-                            </div>
+                            <input type="text" class="form-control" name="name" value="<%= valuationData.name %>">
                         </div>
                     </div>
                     <div class="col-md-12">
                         <legend>
-                            <div class="form-group row">
-                                <label class="col-sm-2 col-form-label">工程专业</label>
-                                <div class="col-sm-3">
-                                    <select class="form-control" name="engineering">
-                                        <option value="">请选择工程</option>
-                                        <% engineeringList.forEach(function(engineering) {%>
-                                        <option value="<%= engineering.value %>" <% if (engineering.value === valuationData.engineering) {%>selected="selected"<% } %>><%= engineering.name %></option>
-                                        <% }) %>
-                                    </select>
-                                </div>
-                            </div>
+                            工程专业
                         </legend>
-                    </div>
-                    <div class="col-md-4">
-                        <div class="form-group">
-                            <label>标准清单</label>
-                            <div class="bill-list">
-                                <% if (valuationData.bill_lib.length > 0) { %>
-                                <% valuationData.bill_lib.forEach(function (bill, index){ %>
-                                <p class="form-control-static">
-                                    <a class="pull-right text-danger remove-lib" data-model="bill" title="移除">
-                                        <span class="glyphicon glyphicon-remove"></span>
-                                    </a>
-                                    <input type="hidden" name="bill_lib" data-id="<%= bill.id %>" value="<%= JSON.stringify({id: bill.id, name: bill.name}) %>">
-                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= bill.name %>
-                                </p>
-                                <% }) %>
-                                <% } %>
-                            </div>
-                            <a class="btn btn-link btn-sm add-compilation" href="javascript:void(0)" data-model="bill">添加</a>
-                        </div>
-                        <div class="form-group">
-                            <label>定额库</label>
-                            <div class="ration-list">
-                                <% if (valuationData.ration_lib.length > 0) { %>
-                                <% valuationData.ration_lib.forEach(function (ration, index){ %>
-                                <p class="form-control-static">
-                                    <a class="pull-right text-danger remove-lib" data-model="ration" title="移除" data-id="<%= ration.id %>">
-                                        <span class="glyphicon glyphicon-remove"></span>
-                                    </a>
-                                    <input type="hidden" name="ration_lib" data-id="<%= ration.id %>" value="<%= JSON.stringify({id: ration.id, name: ration.name}) %>">
-                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= ration.name %>
-                                </p>
-                                <% }) %>
-                                <% } %>
-                            </div>
-                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="ration">添加</a>
-                        </div>
-                        <div class="form-group">
-                            <label>工料机库</label>
-                            <div class="glj-list">
-                                <% if (valuationData.glj_lib.length > 0) { %>
-                                <% valuationData.glj_lib.forEach(function (glj, index){ %>
-                                <p class="form-control-static">
-                                    <a class="pull-right text-danger remove-lib" data-model="glj" title="移除" data-id="<%= glj.id %>">
-                                        <span class="glyphicon glyphicon-remove"></span>
-                                    </a>
-                                    <input type="hidden" name="glj_lib" data-id="<%= glj.id %>" value="<%= JSON.stringify({id: glj.id, name: glj.name}) %>">
-                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= glj.name %>
-                                </p>
-                                <% }) %>
-                                <% } %>
-                            </div>
-                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="glj">添加</a>
-                        </div>
-                        <div class="form-group">
-                            <label>费率库</label>
-                            <div class="fee-list">
-                                <% if (valuationData.fee_lib.length > 0) { %>
-                                <% valuationData.fee_lib.forEach(function (fee, index){ %>
-                                <p class="form-control-static">
-                                    <a class="pull-right text-danger remove-lib" data-model="fee" title="移除" data-id="<%= fee.id %>">
-                                        <span class="glyphicon glyphicon-remove"></span>
-                                    </a>
-                                    <input type="hidden" name="fee_lib" data-id="<%= fee.id %>" value="<%= JSON.stringify({id: fee.id, name: fee.name}) %>">
-                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= fee.name %>
-                                </p>
+                        <table class="table">
+                            <thead>
+                            <tr>
+                                <th>工程名称</th>
+                                <th>标准清单</th>
+                                <th>定额库</th>
+                                <th>工料机库</th>
+                                <th>操作</th>
+                            </tr>
+                            </thead>
+                            <tbody>
+                                <% engineeringList.forEach(function(engineering) {%>
+                                <tr>
+                                    <td><%= engineering.name %></td>
+                                    <td>0</td>
+                                    <td>0</td>
+                                    <td>0</td>
+                                    <td><a href="/compilation/<%= section %>/<%= valuationId %>/<%= engineering.value %>">编辑</a></td>
+                                </tr>
                                 <% }) %>
-                                <% } %>
-                            </div>
-                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="fee">添加</a>
-                        </div>
-                    </div>
-                    <div class="col-md-8">
-                        <legend>
-                            清单模板 / 造价书列
-                            <a href="javascript:void(0)" data-toggle="modal" data-target="#set-column" class="btn btn-primary btn-sm pull-right">设置</a>
-                            <a href="/compilation/template/<%= section %>/<%= valuationId %>" data-toggle="modal" data-target="" class="btn btn-primary btn-sm pull-right" style="margin-right:5px">模板设置</a>
-                        <input type="hidden" name="main_tree_col" value="<%= mainTreeCol %>">
-                        <div id="main-tree-col">
-                        </div>
+                            </tbody>
+                        </table>
                     </div>
                 </div>
                 <input type="hidden" name="section" value="<%= section %>" id="section">
@@ -134,17 +59,5 @@
         </div>
     </div>
 </div>
-<script type="text/javascript">
-    let billList = '<%- billList %>';
-    let rationList = '<%- rationList %>';
-    let gljList = '<%- gljList %>';
-    let mainTreeCol = '<%- mainTreeCol %>';
-    let billsTemplateData = '<%- billsTemplateData %>';
-    let feeRateList = '<%- feeRateList %>';
-    let colSpread = null;
-    let colEditSpread = null;
-</script>
-<script type="text/javascript" src="/public/web/id_tree.js"></script>
-<script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
 <script type="text/javascript" src="/web/users/js/compilation.js"></script>
 <%include ../compilation/modal.html %>

+ 120 - 0
web/users/views/compilation/engineering.html

@@ -0,0 +1,120 @@
+<%include ./common.html %>
+<div class="panel-content">
+    <div class="panel-title">
+        <div class="title-main">
+            <h2>
+                <a href="javascript:void(0);" id="save-lib" class="btn btn-primary btn-sm pull-right">保存</a>
+                <a href="/compilation/valuation/<%= section %>/<%= valuationId %>" class="btn btn-default btn-sm pull-right">返回</a>
+            </h2>
+        </div>
+    </div>
+    <div class="content-wrap">
+        <div class="c-header" style="padding:0">
+            <ul class="nav nav-tabs">
+                <li role="presentation" class="active"><a href="javascript:void(0);"><%= engineeringInfo.name %></a></li>
+            </ul>
+        </div>
+        <div class="c-body">
+            <form method="post" action="/compilation/save-lib" enctype="application/x-www-form-urlencoded21">
+                <div class="row">
+                    <div class="col-md-4">
+                        <div class="form-group">
+                            <label>标准清单</label>
+                            <div class="bill-list">
+                                <% if (Object.keys(libData).length > 0 && libData.bill_lib.length > 0) { %>
+                                <% libData.bill_lib.forEach(function (bill, index){ %>
+                                <p class="form-control-static">
+                                    <a class="pull-right text-danger remove-lib" data-model="bill" title="移除">
+                                        <span class="glyphicon glyphicon-remove"></span>
+                                    </a>
+                                    <input type="hidden" name="bill_lib" data-id="<%= bill.id %>" value="<%= JSON.stringify({id: bill.id, name: bill.name}) %>">
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= bill.name %>
+                                </p>
+                                <% }) %>
+                                <% } %>
+                            </div>
+                            <a class="btn btn-link btn-sm add-compilation" href="javascript:void(0)" data-model="bill">添加</a>
+                        </div>
+                        <div class="form-group">
+                            <label>定额库</label>
+                            <div class="ration-list">
+                                <% if (Object.keys(libData).length > 0 && libData.ration_lib.length > 0) { %>
+                                <% libData.ration_lib.forEach(function (ration, index){ %>
+                                <p class="form-control-static">
+                                    <a class="pull-right text-danger remove-lib" data-model="ration" title="移除" data-id="<%= ration.id %>">
+                                        <span class="glyphicon glyphicon-remove"></span>
+                                    </a>
+                                    <input type="hidden" name="ration_lib" data-id="<%= ration.id %>" value="<%= JSON.stringify({id: ration.id, name: ration.name}) %>">
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= ration.name %>
+                                </p>
+                                <% }) %>
+                                <% } %>
+                            </div>
+                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="ration">添加</a>
+                        </div>
+                        <div class="form-group">
+                            <label>工料机库</label>
+                            <div class="glj-list">
+                                <% if (Object.keys(libData).length > 0 && libData.glj_lib.length > 0) { %>
+                                <% libData.glj_lib.forEach(function (glj, index){ %>
+                                <p class="form-control-static">
+                                    <a class="pull-right text-danger remove-lib" data-model="glj" title="移除" data-id="<%= glj.id %>">
+                                        <span class="glyphicon glyphicon-remove"></span>
+                                    </a>
+                                    <input type="hidden" name="glj_lib" data-id="<%= glj.id %>" value="<%= JSON.stringify({id: glj.id, name: glj.name}) %>">
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= glj.name %>
+                                </p>
+                                <% }) %>
+                                <% } %>
+                            </div>
+                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="glj">添加</a>
+                        </div>
+                        <div class="form-group">
+                            <label>费率标准</label>
+                            <div class="fee-list">
+                                <% if (Object.keys(libData).length > 0 && libData.fee_lib.length > 0) { %>
+                                <% libData.fee_lib.forEach(function (fee, index){ %>
+                                <p class="form-control-static">
+                                    <a class="pull-right text-danger remove-lib" data-model="fee" title="移除" data-id="<%= fee.id %>">
+                                        <span class="glyphicon glyphicon-remove"></span>
+                                    </a>
+                                    <input type="hidden" name="fee_lib" data-id="<%= fee.id %>" value="<%= JSON.stringify({id: fee.id, name: fee.name}) %>">
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= fee.name %>
+                                </p>
+                                <% }) %>
+                                <% } %>
+                            </div>
+                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="fee">添加</a>
+                        </div>
+                    </div>
+                    <div class="col-md-8">
+                        <legend>
+                            清单模板 / 造价书列
+                            <a href="javascript:void(0)" data-toggle="modal" data-target="#set-column" class="btn btn-primary btn-sm pull-right">设置</a>
+                            <a href="/compilation/template/<%= section %>/<%= valuationId %>/<%= engineeringInfo.id%>" data-toggle="modal" data-target="" class="btn btn-primary btn-sm pull-right" style="margin-right:5px">模板设置</a>
+                            <input type="hidden" name="main_tree_col" value="<%= mainTreeCol %>">
+                            <div id="main-tree-col">
+                            </div>
+                    </div>
+                </div>
+                <input type="hidden" name="engineering" value="<%= engineeringInfo.id %>" id="engineering">
+                <input type="hidden" name="section" value="<%= section %>" id="section">
+                <input type="hidden" name="id" value="<%= valuationId %>">
+            </form>
+        </div>
+    </div>
+</div>
+<script type="text/javascript">
+    let billList = '<%- billList %>';
+    let rationList = '<%- rationList %>';
+    let gljList = '<%- gljList %>';
+    let feeRateList = '<%- feeRateList %>';
+    let mainTreeCol = '<%- mainTreeCol %>';
+    let billsTemplateData = '<%- billsTemplateData %>';
+    let colSpread = null;
+    let colEditSpread = null;
+</script>
+<script type="text/javascript" src="/public/web/id_tree.js"></script>
+<script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>
+<script type="text/javascript" src="/web/users/js/compilation.js"></script>
+<%include ../compilation/modal.html %>

+ 1 - 1
web/users/views/compilation/template.html

@@ -53,7 +53,7 @@
 <script>
     let billsTemplateData = '<%- billsTemplateData %>';
     let billsFixedFlagList = '<%- billsFixedFlagList %>';
-    let updateUrl = '/compilation/template/<%= section %>/<%= valuationId %>/update';
+    let updateUrl = '/compilation/template/<%= section %>/<%= valuationId %>/<%= engineering %>/update';
 </script>
 <script type="text/javascript" src="/public/web/id_tree.js"></script>
 <script type="text/javascript" src="/public/web/tree_sheet/tree_sheet_helper.js"></script>