浏览代码

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

Chenshilong 7 年之前
父节点
当前提交
080e3bad6b

+ 31 - 0
modules/ration_repository/controllers/search_controller.js

@@ -3,6 +3,7 @@
  */
 var rationItem = require('../models/ration_item');
 let rationChapter = require('../models/ration_section_tree');
+let asyncTool = require('async');
 var callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
 };
@@ -32,5 +33,35 @@ module.exports = {
                 callback(req, res, 0, '', rst);
             }
         });
+    },
+    matchRation: function (req, res) {
+        let rId = req.body.rationLibId, code = req.body.code;
+        asyncTool.waterfall([
+            function (callback) {
+                rationItem.matchRation(rId, code, callback);
+            },
+            function (ration, callback) {
+                if (ration) {
+                    rationChapter.getRationChapter(rId, ration.sectionId).then(function(result, err) {
+                        if (!err) {
+                            ration.chapter = JSON.parse(JSON.stringify(result));
+                            callback(err, ration);
+                        } else {
+                            callback(err, ration);
+                        }
+                    }).catch(
+
+                    );
+                } else {
+                    callback(null, ration);
+                }
+            }
+        ], function (err, result) {
+            if (err) {
+                callback(req, res, 1, err, null);
+            } else {
+                callback(req, res, 0, err, result);
+            }
+        });
     }
 };

+ 13 - 2
modules/ration_repository/models/ration_item.js

@@ -113,8 +113,19 @@ rationItemDAO.prototype.findRation = function (repId, keyword, callback) {
         } else {
             callback(false, '', data);
         }
-    })
-}
+    });
+};
+
+rationItemDAO.prototype.matchRation = function (repId, keyword, callback) {
+    let filter = {
+        'rationRepId': repId,
+        'code': keyword,
+        '$or': [{'isDeleted': {"$exists":false}}, {'isDeleted': null}, {'isDeleted': false}]
+    };
+    rationItemModel.findOne(filter, function (err, data) {
+        callback(err, JSON.parse(JSON.stringify(data)));
+    });
+};
 
 rationItemDAO.prototype.getRationItem = function (repId, code, callback) {
     if (callback) {

+ 1 - 0
modules/ration_repository/routes/ration_front_end_routes.js

@@ -31,6 +31,7 @@ module.exports = function (app) {
 
     apiRouter.post('/getRationItem', searchController.getRationItem);
     apiRouter.post('/findRation', searchController.findRation);
+    apiRouter.post('/matchRation', searchController.matchRation);
 
     app.use("/rationRepository/api", apiRouter);
 };

+ 1 - 2
modules/ration_repository/routes/ration_rep_routes.js

@@ -42,8 +42,7 @@ module.exports = function (app) {
 
     apiRouter.post('/getRationItem', searchController.getRationItem);
     apiRouter.post('/findRation', searchController.findRation);
-
-
+    apiRouter.post('/matchRation', searchController.matchRation);
 };
 
 

+ 16 - 22
web/building_saas/main/js/models/bills.js

@@ -164,7 +164,7 @@ var Bills = {
             var newData = null, that = this;
             insertData.forEach(function (data) {
                 if (data.type === idTree.updateType.new) {
-                    data.data.code = stdBillsData.code;
+                    data.data.code = that.newFormatCode(stdBillsData.code);
                     data.data.name = stdBillsData.name;
                     data.data.unit = stdBillsData.unit;
                     // 工程量计算规则
@@ -285,8 +285,18 @@ var Bills = {
             }
         };
 
-        bills.prototype.formatCode = function (stdCode, formatCode) {
-            let reg = /^stdCode/, matchs= [];
+        bills.prototype.sameStdCode = function (stdCode, filterCode) {
+            let reg = new RegExp('^' + stdCode), matchs= [];
+            for (let data of this.datas) {
+                if (data.code && data.code.length === 12 && reg.test(data.code) && data.code !== filterCode) {
+                    matchs.push(data.code);
+                }
+            }
+            return matchs;
+        }
+
+        bills.prototype.newFormatCode = function (stdCode, filterCode) {
+            let matchs = this.sameStdCode(stdCode, filterCode);
             let format = function (Number) {
                 let s = Number + '';
                 while (s.length < 3) {
@@ -294,27 +304,11 @@ var Bills = {
                 }
                 return s;
             }
-            let getNewFormatCode = function () {
-                for (i = 1; i <= matchs.length + 1; i++) {
-                    let formatCode = stdCode + format(i);
-                    if (matchs.indexOf(formatCode) === -1) {
-                        return formatCode
-                    }
-                }
-            }
-            for (let data of this.datas) {
-                if (data.code && data.code.length === 12 && reg.test(data.code)) {
-                    matchs.push(data.code);
-                }
-            }
-            if (formatCode) {
-                if (matchs.indexOf(formatCode) >= 0) {
-                    return getNewFormatCode();
-                } else {
+            for (i = 0; i <= matchs.length; i++) {
+                let formatCode = stdCode + format(i+1);
+                if (matchs.indexOf(formatCode) === -1) {
                     return formatCode;
                 }
-            } else {
-                return getNewFormatCode();
             }
         };
 

+ 31 - 1
web/building_saas/main/js/models/ration.js

@@ -280,8 +280,38 @@ var Ration = {
             } else {
                 this.project.push(this.getSourceType(), updateData);
             }
-        }
+        };
+
+        ration.prototype.replaceRation = function (ration, std) {
+            this.project.beginUpdate('replaceRation');
+            
+            // delete
+            let ration_glj =projectObj.project.ration_glj;
+            this.project.push(this.project.ration_glj.getSourceType(), this.project.ration_glj.getDeleteDataByRation(ration));
+
+            this.project.ration_glj.deleteByRation(ration);
+            this.project.ration_coe.deleteByRation(ration);
+            this.project.quantity_detail.deleteByRation(ration);
 
+            // insertNewRation
+            let updateData = [];
+            ration.code = std.code;
+            ration.name = std.name;
+            ration.caption = std.caption;
+            ration.unit = std.unit;
+            ration.libID = std.rationRepId;
+            ration.content = std.jobContent;
+            if (std.chapter) {
+                ration.comments = std.chapter.explanation;
+                ration.ruleText = std.chapter.ruleText;
+            }
+            ration.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
+            updateData.push({updateType: 'ut_update', updateData: ration});
+            this.project.push(this.getSourceType(), updateData);
+
+            this.project.endUpdate();
+        };
+        
         return new ration(project);
     }
 };

+ 34 - 9
web/building_saas/main/js/views/project_view.js

@@ -165,9 +165,13 @@ var projectObj = {
     },
     updateBillsCode: function (node, value) {
         let project = projectObj.project;
-        let stdMatchCode, formatCode;
+        let stdMatchCode, formatCode, matchs;
         let searchStdBillsAndUpdate = function (stdCode, formatCode) {
-            if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
+            let orgCode = node.data.code.substr(0, 9);
+            if (stdCode === orgCode || projectInfoObj.projectInfo.engineeringInfo.bill_lib.length === 0) {
+                project.Bills.updateField(node.source, 'code', formatCode, true);
+                projectObj.mainController.refreshTreeNode([node], false);
+            } else if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
                 let libId = projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id;
                 CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
                     if (data) {
@@ -178,26 +182,47 @@ var projectObj = {
                     }
                     projectObj.mainController.refreshTreeNode([node], false);
                 });
-            } else {
-                project.Bills.updateField(node.source, 'code', value, true);
-                projectObj.mainController.refreshTreeNode([node], false);
             }
         }
         if (value.length === 9 && /^[\d]+$/.test(value)) {
             stdMatchCode = value;
-            formatCode = project.Bills.formatCode(stdMatchCode);
+            formatCode = project.Bills.newFormatCode(stdMatchCode);
             searchStdBillsAndUpdate(stdMatchCode, formatCode);
         } else if (value.length === 12 && /^[\d]+$/.test(value)) {
             stdMatchCode = value.substr(0, 9);
-            formatCode = project.Bills.formatCode(stdMatchCode, value);
-            searchStdBillsAndUpdate(stdMatchCode, formatCode);
+            matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
+            if (matchs.indexOf(value) === -1) {
+                searchStdBillsAndUpdate(stdMatchCode, value);
+            } else if (confirm('已存在该编码的清单,是否继续?')) {
+                formatCode = project.Bills.newFormatCode(stdMatchCode, node.data.code);
+                searchStdBillsAndUpdate(stdMatchCode, formatCode);
+            }
         } else {
             project.Bills.updateField(node.source, 'code', value, true);
             this.mainController.refreshTreeNode([node], false);
         } 
     },
     updateRationCode: function (node, value) {
-
+        if (/[\w]{2}[\d]{4}/.test(value)) {
+            if (projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0) {
+                alert('当前项目无定额库,请添加定额库。');
+                this.mainController.refreshTreeNode([node], false);
+            } else {
+                let libId = projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
+                CommonAjax.postRationLib('/rationRepository/api/matchRation', {user_id: userID, rationLibId: libId, code: value}, function (data) {
+                    if (data) {
+                        projectObj.project.Ration.replaceRation(node.source, data);
+                        projectObj.project.ration_glj.addRationGLJ(node.source, data);
+                    } else {
+                        alert('当前库中找不到定额"' + value + '"');
+                    }
+                    projectObj.mainController.refreshTreeNode([node], false);
+                });
+            }
+        } else {
+            alert('输入的定额编码有误,请检查。');
+            this.mainController.refreshTreeNode([node], false);
+        }
     },
     updateCode: function (node, value) {
         let project = projectObj.project;