浏览代码

清单模板,新建清单模板项前,先跟服务器申请ID

MaiXinRong 8 年之前
父节点
当前提交
152f727f4e

+ 11 - 1
modules/templates/controllers/bills_template_controller.js

@@ -27,6 +27,16 @@ module.exports = {
             } else {
                 callback(req, res, err, message, null);
             }
-        })
+        });
+    },
+    getNewBillsTemplateID: function (req, res) {
+        var data = JSON.parse(req.body.data);
+        BillsTemplateData.getNewBillsTemplateID(data.count, function (err, message, data) {
+            if (err === 0) {
+                callback(req, res, err, message, data);
+            } else {
+                callback(req, res, err, message, null);
+            }
+        });
     }
 }

+ 12 - 0
modules/templates/models/bills_template.js

@@ -2,6 +2,8 @@
  * Created by Mai on 2017/4/14.
  * 清单模板,新建项目使用
  */
+var counter = require("../../../public/counter/counter.js");
+
 var mongoose = require('mongoose');
 var dbm = require("../../../config/db/db_manager");
 var templatesDB = dbm.getCfgConnection("templates");
@@ -64,6 +66,16 @@ BillsTemplateDAO.prototype.updateTemplate = function (userID, tempType, datas, c
             }
         }
     }
+};
+BillsTemplateDAO.prototype.getNewBillsTemplateID = function (count, callback) {
+    counter.counterDAO.getIDAfterCount(counter.moduleName.template_bills, count, function (err, result) {
+        var highID = result.value.sequence_value;
+        if (!err) {
+            callback(0, '', {lowID: highID - count + 1, highID: highID});
+        } else {
+            callback(1, '获取主键失败', null);
+        }
+    });
 }
 
 module.exports = new BillsTemplateDAO();

+ 1 - 0
modules/templates/routes/bills_template_router.js

@@ -8,5 +8,6 @@ var billsTemplateController = require('./../controllers/bills_template_controlle
 
 billsTemplateRouter.post('/getBillsTemplate', billsTemplateController.getBillsTemplate);
 billsTemplateRouter.post('/updateBillsTemplate', billsTemplateController.updateBillsTemplate);
+billsTemplateRouter.post('/getNewBillsTemplateID', billsTemplateController.getNewBillsTemplateID);
 
 module.exports = billsTemplateRouter;

+ 1 - 1
public/web/idTree.js

@@ -411,7 +411,7 @@ var idTree = {
             if (this.rangeNodeID() === -1) {
                 return this.maxNodeID() + 1;
             } else {
-                if (this.maxNodeID() >= this.rangeNodeID()) {
+                if (this.maxNodeID() < this.rangeNodeID()) {
                     return this.maxNodeID() + 1;
                 } else {
                     return -1;

+ 18 - 11
web/templates/js/bills.js

@@ -84,7 +84,6 @@ $(document).ready(function () {
             controller.refreshTreeNode([node], false);
         });
     });
-
     billsSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, function (e, info) {
         var node, iRow, iCol, curRow, curCol, datas = [], data, fieldName, updateData;
         for (iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
@@ -119,16 +118,24 @@ $(document).ready(function () {
     });
 
     $('#insert').click(function () {
-        var selected = controller.tree.selected, updateData;
-        if (selected) {
-            updateData = FormatUpdateData(controller.tree.getInsertData(selected.getParentID(), selected.getNextSiblingID()));
-        } else {
-            updateData = FormatUpdateData(controller.tree.getInsertData());
-        }
-        PostData('/template/bills/updateBillsTemplate', updateData, function (data) {
-            controller.insert();
-            RefreshBillsData(data);
-            controller.showTreeData();
+        PostData('/template/bills/getNewBillsTemplateID', {count: 1}, function (data) {
+            var selected = controller.tree.selected, updateData;
+            controller.tree.maxNodeID(data.lowID - 1);
+            controller.tree.rangeNodeID(data.highID);
+            if (selected) {
+                updateData = FormatUpdateData(controller.tree.getInsertData(selected.getParentID(), selected.getNextSiblingID()));
+            } else {
+                updateData = FormatUpdateData(controller.tree.getInsertData());
+            }
+            if (updateData.updateData.length > 0) {
+                PostData('/template/bills/updateBillsTemplate', updateData, function (data) {
+                    controller.insert();
+                    RefreshBillsData(data);
+                    controller.showTreeData();
+                });
+            } else {
+                alert('新增节点失败, 请重试.');
+            }
         });
     });
     $('#delete').click(function () {