TonyKang пре 8 година
родитељ
комит
cb0b0b99f4

+ 11 - 2
modules/rationRepository/controllers/rationController.js

@@ -18,7 +18,16 @@ module.exports = {
             }
         });
     },
-    updateRationItems: function(req, res){
-        //
+    mixUpdateRationItems: function(req, res){
+        var sectionId = req.body.sectionID,
+            updateItems = JSON.parse(req.body.updateItems),
+            addItems = JSON.parse(req.body.addItems);
+        rationItem.mixUpdateRationItems(sectionId, updateItems, addItems, function(err, message, rst){
+            if (err) {
+                callback(req, res, err, message, null);
+            } else {
+                callback(req, res, err, message, rst);
+            }
+        });
     }
 }

+ 0 - 9
modules/rationRepository/models/rationChapterTree.js

@@ -67,15 +67,6 @@ rationChapterTreeDAO.prototype.createNewNode = function(repositoryName, lastNode
     }
 },
 
-rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryName,rationTempTree,callback){
-    var db = dbm.getCfgConnection(repositoryName)
-    var rationChapterTreeModel = db.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
-    rationChapterTreeModel.collection.insert(rationTempTree,function(err,data){
-        if(err) callback("插入定额模板错误",false)
-        else callback(false,"ok")
-    })
-}
-
 rationChapterTreeDAO.prototype.removeNodes = function(nodeIds, preNodeId, preNodeNextId, callback){
     var functions = [];
     if (preNodeId != -1) {

+ 37 - 7
modules/rationRepository/models/rationItem.js

@@ -4,7 +4,7 @@
 var mongoose = require("mongoose");
 var dbm = require("../../../config/db/db_manager");
 var db = dbm.getCfgConnection("rationRepository")
-//var async = require("async");
+var async = require("async");
 var Schema = mongoose.Schema;
 
 var rationItemSchema = mongoose.Schema({
@@ -29,10 +29,22 @@ rationItemDAO.prototype.getRationItemsBySection = function(sectionId,callback){
         else callback(false,"获取定额", data);
     })
 };
-rationItemDAO.prototype.updateRationItems = function(updateItems, addItems, callback){
+rationItemDAO.prototype.mixUpdateRationItems = function(sectionId, updateItems, addItems, callback){
     var me = this;
     if (!(updateItems) || updateItems.length == 0) {
-        me.addRationItems(addItems, callback);
+        me.addRationItems(sectionId, addItems, callback);
+    } else {
+        me.updateRationItems(sectionId, updateItems, function(err, results){
+            if (err) {
+                callback(true, "保存定额错误!", false);
+            } else {
+                if (addItems && addItems.length > 0) {
+                    me.addRationItems(sectionId, addItems, callback);
+                } else {
+                    callback(false, "保存定额成功!", results);
+                }
+            }
+        });
     }
 };
 
@@ -40,14 +52,15 @@ rationItemDAO.prototype.getRationItemsByCode = function(code,callback){
     //
 };
 
-rationItemDAO.prototype.addRationItems = function(items,callback){
+rationItemDAO.prototype.addRationItems = function(sectionId, items,callback){
     if (items && items.length > 0) {
-        counter.counterDAO.getIDAfterCount(counter.moduleName.ration, items.length, function(err, result){
+        counter.counterDAO.getIDAfterCount(counter.moduleName.rations, items.length, function(err, result){
             var maxId = result.value.sequence_value;
             var arr = [];
             for (var i = 0; i < items.length; i++) {
                 var obj = new rationItemModel(items[i]);
                 obj.ID = (maxId - (items.length - 1) + i);
+                obj.sectionId = sectionId;
                 arr.push(obj);
             }
             rationItemModel.collection.insert(arr, null, function(err, docs){
@@ -63,8 +76,25 @@ rationItemDAO.prototype.addRationItems = function(items,callback){
     }
 };
 
-rationItemDAO.prototype.updateRationItems = function(items,callback){
-    //
+rationItemDAO.prototype.updateRationItems = function(sectionId, items,callback){
+    var functions = [];
+    for (var i=0; i < items.length; i++) {
+        functions.push((function(doc) {
+            return function(cb) {
+                var filter = {};
+                if (doc.ID) {
+                    filter.ID = doc.ID;
+                } else {
+                    filter.sectionId = sectionId;
+                    filter.code = doc.code;
+                }
+                rationItemModel.update(filter, doc, cb);
+            };
+        })(items[i]));
+    }
+    async.parallel(functions, function(err, results) {
+        callback(err, results);
+    });
 };
 
 module.exports = new rationItemDAO()

+ 1 - 1
modules/rationRepository/routes/rationRepRoutes.js

@@ -21,6 +21,6 @@ apiRouter.post("/updateNodes",rationChapterTreeController.updateNodes);
 apiRouter.post("/deleteNodes",rationChapterTreeController.deleteNodes);
 
 apiRouter.post("/getRationItems",rationController.getRationItemsBySection);
-apiRouter.post("/updateRationItems",rationController.updateRationItems);
+apiRouter.post("/mixUpdateRationItems",rationController.mixUpdateRationItems);
 
 module.exports = apiRouter;

+ 1 - 1
public/counter/counter.js

@@ -20,7 +20,7 @@ const COUNTER_MODULE_NAME = {
     project: 'projects',
     user: 'users',
     bills: 'bills',
-    ration: 'ration',
+    rations: 'rations',
     GLJ: 'glj',
     rationMap: 'rationMaps',
     rationTree: 'rationChapterTrees',

+ 2 - 2
web/rationLibEditor/js/chapterTree.js

@@ -204,8 +204,8 @@ var zTreeOprObj = {
     },
     onClick: function(event,treeId,treeNode) {
         var sectionID = treeNode.ID;
-        if (treeNode.items && treeNode.items.length > 0) {
-            rationOprObj.getRationItems(sectionID)
+        if (!(treeNode.items) || treeNode.items.length == 0) {
+            rationOprObj.getRationItems(sectionID);
         }
     }
 

+ 62 - 15
web/rationLibEditor/js/ration.js

@@ -15,12 +15,12 @@ var rationOprObj = {
     currentSectionId: -1,
     setting: {
         header:[
-            {headerName:"编码",headerWidth:120,data:"code"},
-            {headerName:"名称",headerWidth:300,data:"name"},
-            {headerName:"单位",headerWidth:120,data:"unit"},
-            {headerName:"基价",headerWidth:120,data:"basePrice"},
-            {headerName:"显示名称(以%s表示参数)",headerWidth:350,data:"caption"},
-            {headerName:"取费专业",headerWidth:120,data:"feeType"}
+            {headerName:"编码",headerWidth:120,dataCode:"code"},
+            {headerName:"名称",headerWidth:300,dataCode:"name"},
+            {headerName:"单位",headerWidth:120,dataCode:"unit"},
+            {headerName:"基价",headerWidth:120,dataCode:"basePrice"},
+            {headerName:"显示名称(以%s表示参数)",headerWidth:350,dataCode:"caption"},
+            {headerName:"取费专业",headerWidth:120,dataCode:"feeType"}
         ],
         view:{
             comboBox:[
@@ -33,7 +33,7 @@ var rationOprObj = {
     },
     buildSheet: function(container) {
         var me = this;
-        me.workBook = sheetCommonObj.buildSheet(container, me.setting);
+        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
     },
@@ -58,11 +58,16 @@ var rationOprObj = {
                         itemObj = {};
                     }
                 } else if (info.pasteData.text[i] === "\t" || info.pasteData.text[i] === "\r") {
-                    itemObj[me.setting.header[propId].data] = info.pasteData.text.slice(preStrIdx, i);
+                    itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx, i);
                     propId++;
                     preStrIdx = i + 1;
+                    //if the last copied-cell were empty, should check whether the end of text
+                    if (i == info.pasteData.text.length - 1) {
+                        itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx);
+                        rst.push(itemObj);
+                    }
                 } else if (i == info.pasteData.text.length - 1) {
-                    itemObj[me.setting.header[propId].data] = info.pasteData.text.slice(preStrIdx);
+                    itemObj[me.setting.header[propId].dataCode] = info.pasteData.text.slice(preStrIdx);
                     rst.push(itemObj);
                 }
             }
@@ -73,17 +78,56 @@ var rationOprObj = {
             if (cacheSection) {
                 var hasCacheItem = false;
                 for (var j = 0; j < cacheSection.length; j++) {
-                    if (cacheSection[j][me.setting.header[0].data] == items[i][me.setting.header[0].data]) {
+                    if (cacheSection[j][me.setting.header[0].dataCode] == items[i][me.setting.header[0].dataCode]) {
                         hasCacheItem = true;
+                        items[i]["ID"] = cacheSection[j]["ID"];
                         break;
                     }
                 }
-                if (hasCacheItem) addArr.push(items[i])
-                else updateArr.push(items[i])
+                if (!hasCacheItem) {
+                    addArr.push(items[i]);
+                } else {
+                    updateArr.push(items[i]);
+                }
             } else {
                 addArr.push(items[i])
             }
         };
+        if (updateArr.length > 0 || addArr.length > 0) {
+            $.ajax({
+                type:"POST",
+                url:"api/mixUpdateRationItems",
+                data:{"sectionID": me.currentSectionId, "updateItems": JSON.stringify(updateArr), "addItems": JSON.stringify(addArr)},
+                dataType:"json",
+                cache:false,
+                timeout:5000,
+                success:function(result){
+                    if (result.err) {
+                        alert(err);
+                        me.getRationItems(me.currentSectionId);
+                    } else {
+                        if (!(me.currentRations["_SEC_ID_" + me.currentSectionId])) {
+                            me.currentRations["_SEC_ID_" + me.currentSectionId] = [];
+                            cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
+                        }
+                        if (addArr.length > 0) {
+                            me.currentRations["_SEC_ID_" + me.currentSectionId] = cacheSection.concat(addArr);
+                            cacheSection = me.currentRations["_SEC_ID_" + me.currentSectionId];
+                        }
+                        for (var i = 0; i < updateArr.length; i++) {
+                            for (var j = 0; j < cacheSection.length; j++) {
+                                if (cacheSection[j][me.setting.header[0].dataCode] == updateArr[i][me.setting.header[0].dataCode]) {
+                                    cacheSection[j] = updateArr[i];
+                                }
+                            }
+                        }
+                        me.showRationItems(me.currentSectionId);
+                    }
+                },
+                error:function(){
+                }
+            })
+        }
     },
     getRationItems: function(sectionID){
         if (sectionID != -1) {
@@ -106,7 +150,8 @@ var rationOprObj = {
                         }
 
                     },
-                    error:function(){
+                    error:function(err){
+                        alert(err);
                     }
                 })
             }
@@ -116,10 +161,12 @@ var rationOprObj = {
         var me = rationOprObj;
         if (me.workBook) {
             if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
-                //
+                var cacheSection = me.currentRations["_SEC_ID_" + sectionID];
+                sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+                sheetCommonObj.showData(me.workBook.getSheet(0), me.setting, cacheSection);
             } else {
                 //清除ration数据及工料机数据
-                sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, 3);
+                sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
             }
         }
     }

+ 1 - 1
web/rationLibEditor/js/rationGLJ.js

@@ -26,6 +26,6 @@ var rationGLJOprObj = {
     },
     buildSheet: function(container) {
         var me = this;
-        me.sheet = sheetCommonObj.buildSheet(container, me.setting);
+        me.sheet = sheetCommonObj.buildSheet(container, me.setting, 30);
     }
 }

+ 23 - 3
web/rationLibEditor/js/sheetCommon.js

@@ -2,7 +2,7 @@
  * Created by Tony on 2017/4/28.
  */
 var sheetCommonObj = {
-    buildSheet: function(container, setting) {
+    buildSheet: function(container, setting, rowCount) {
         var me = this;
         var spreadBook = new GC.Spread.Sheets.Workbook(container, { sheetCount: 1 });
         spreadBook.options.tabStripVisible = false;
@@ -20,7 +20,7 @@ var sheetCommonObj = {
         //setup column header
         me.buildHeader(sheet, setting);
         //setup cells
-        sheet.setRowCount(5);
+        if (rowCount > 0) sheet.setRowCount(rowCount);
         sheet.resumeEvent();
         sheet.resumePaint();
         return spreadBook;
@@ -33,7 +33,27 @@ var sheetCommonObj = {
         }
     },
     cleanSheet: function(sheet, setting, rowCount) {
+        sheet.suspendPaint();
+        sheet.suspendEvent();
         sheet.clear(-1, 0, -1, setting.header.length, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
-        sheet.setRowCount(rowCount);
+        if (rowCount > 0) sheet.setRowCount(rowCount);
+        sheet.resumeEvent();
+        sheet.resumePaint();
+    },
+    showData: function(sheet, setting, data) {
+        var me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        for (var row = 0; row < data.length; row++) {
+            for (var col = 0; col < setting.header.length; col++) {
+                sheet.setValue(row, col, data[row][setting.header[col].dataCode], ch);
+            }
+        }
+        sheet.resumeEvent();
+        sheet.resumePaint();
+        //me.shieldAllCells(sheet);
+    },
+    shieldAllCells: function(sheet) {
+        sheet.options.isProtected = true;
     }
 }