Browse Source

GLJ tuning

TonyKang 8 years ago
parent
commit
6adf120a38

+ 7 - 0
modules/rationRepository/controllers/repositoryGljController.js

@@ -59,6 +59,13 @@ module.exports ={
             callback(req,res,err,'Get Items',data)
         });
     },
+    getGljItemsByCodes: function(req, res) {
+        var gljCodes = JSON.parse(req.body.gljCodes),
+            repId = req.body.repId;
+        gljRepository.getGljItemsByCode(repId, gljCodes, function(err, data){
+            callback(req,res,err,'Get Items',data)
+        });
+    },
     mixUpdateGljItems: function(req, res){
         var repId = req.body.repositoryId,
             updateItems = JSON.parse(req.body.updateItems),

+ 7 - 0
modules/rationRepository/models/gljRepository.js

@@ -78,6 +78,13 @@ gljItemDAO.prototype.getGljItems = function(gljIds, callback){
     })
 };
 
+gljItemDAO.prototype.getGljItemsByCode = function(repositoryId, codes, callback){
+    gljItemModel.find({"repositoryId": repositoryId,"code": {"$in": codes}},function(err,data){
+        if(err) callback(true, "")
+        else callback(false, data);
+    })
+};
+
 gljItemDAO.prototype.mixUpdateGljItems = function(repId, updateItems, addItems, rIds, callback) {
     var me = this;
     if (updateItems.length == 0 && rIds.length == 0) {

+ 1 - 1
modules/rationRepository/models/rationItem.js

@@ -11,7 +11,7 @@ var rationGljItemSchema = mongoose.Schema({
     gljId: Number,
     consumeAmt: Number,
     proportion: Number //配合比,暂时无需使用,默认0
-});
+}, { _id: false });
 var rationItemSchema = mongoose.Schema({
     ID:Number,
     //以下是基于已有access库

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

@@ -31,6 +31,7 @@ apiRouter.post("/getGljTree",repositoryGljController.getGljTree);
 apiRouter.post("/getGljItems",repositoryGljController.getGljItems);
 apiRouter.post("/mixUpdateGljItems",repositoryGljController.mixUpdateGljItems);
 apiRouter.post("/getGljItemsByIds",repositoryGljController.getGljItemsByIds);
+apiRouter.post("/getGljItemsByCodes",repositoryGljController.getGljItemsByCodes);
 
 
 module.exports = apiRouter;

+ 9 - 8
public/storageUtil.js

@@ -2,8 +2,6 @@
  * Created by Tony on 2017/5/15.
  */
 storageUtil = {
-    localStorage: null,
-    sessionStorage: null,
     browserFlag: {isIE: false, isFF: false, isChrome: false, isOpera: false, other: false},
     iniStorage: function() {
         var me = this;
@@ -21,15 +19,18 @@ storageUtil = {
         }
     },
     getSessionCache: function(groupKey, itemKey) {
-        //
+        return sessionStorage[groupKey + "_" + itemKey];
     },
-    setSessionCache: function(groupKey, itemKey) {
-        //
+    setSessionCache: function(groupKey, itemKey, value) {
+        sessionStorage[groupKey + "_" + itemKey] = value;
     },
     getLocalCache: function(groupKey, itemKey) {
-        //
+        return localStorage[groupKey + "_" + itemKey];
     },
-    setLocalCache: function(groupKey, itemKey) {
-        //
+    setLocalCache: function(groupKey, itemKey, value) {
+        localStorage[groupKey + "_" + itemKey] = value;
+    },
+    clearSessionCache: function(groupKey, itemKey) {
+        delete sessionStorage[groupKey + "_" + itemKey];
     }
 }

+ 3 - 2
web/rationLibEditor/dinge.html

@@ -872,6 +872,7 @@
     <script type="text/javascript" src="/web/rationLibEditor/js/rationGLJ.js"></script>
     <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <script type="text/javascript" src="/public/QueryParam.js"></script>
+    <script type="text/javascript" src="/public/storageUtil.js"></script>
     <script type="text/javascript">
         var setting = {
             view: {
@@ -885,8 +886,8 @@
                 editNameSelectAll: true,
                 showRemoveBtn: true,
                 showRenameBtn: true,
-                removeTitle: "remove",
-                renameTitle: "rename"
+                removeTitle: "删除节点",
+                renameTitle: "更改名称"
             },
             data: {
                 keep: {

+ 3 - 0
web/rationLibEditor/js/chapterTree.js

@@ -28,6 +28,9 @@ var zTreeOprObj = {
             timeout:20000,
             success:function(result,textStatus,status){
                 if(status.status == 200) {
+                    if (result.data.length > 0) {
+                        storageUtil.setSessionCache("RationGrp","repositoryID",result.data[0].rationRepId);
+                    }
                     zTreeHelper.createTree(result.data, setting, "rationChapterTree", me);
                 }
             },

+ 109 - 0
web/rationLibEditor/js/rationGLJ.js

@@ -3,6 +3,7 @@
  */
 var rationGLJOprObj = {
     workBook: null,
+    currentRationItem: null,
     cache: {},
     setting: {
         header:[
@@ -22,7 +23,114 @@ var rationGLJOprObj = {
     buildSheet: function(container) {
         var me = this;
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
+        me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
     },
+    onClipboardPasting: function(sender, args) {
+        var me = rationGLJOprObj;
+        if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.currentRationItem)) {
+            args.cancel = true;
+        }
+    },
+    onClipboardPasted: function(e, info) {
+        var me = rationGLJOprObj, repId = storageUtil.getSessionCache("RationGrp","repositoryID");
+        if (repId) {
+            if (info.cellRange.col == 0) {
+                var tmpCodes = sheetCommonObj.analyzePasteData({header:[{dataCode: "code"}] }, info);
+                var codes = [];
+                for (var i = 0; i < tmpCodes.length; i++) {
+                    codes.push(tmpCodes[i].code);
+                }
+                $.ajax({
+                    type:"POST",
+                    url:"api/getGljItemsByCodes",
+                    data:{"gljCodes": JSON.stringify(codes), repId: repId},
+                    dataType:"json",
+                    cache:false,
+                    timeout:5000,
+                    success:function(result){
+                        sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+                        if (result) {
+                            var rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];
+                            for (var i = 0; i < result.data.length; i++) {
+                                dummyR.gljId = result.data[i].ID;
+                                rstArr.push(me.createRationGljDisplayItem(dummyR, result.data[i]));
+                            }
+                            if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
+                                var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+                                for (var i = 0; i < rstArr.length; i++) {
+                                    var hasDup = false;
+                                    for (var j = 0; j < cacheArr.length; j++) {
+                                        if (cacheArr[j].gljId == rstArr[i].gljId) {
+                                            hasDup = true;
+                                            break;
+                                        }
+                                    }
+                                    if (!hasDup) {
+                                        newAddArr.push(rstArr[i]);
+                                    }
+                                }
+                                cacheArr.sort(function(a, b) {
+                                    var rst = 0;
+                                    if (a.code > b.code) rst = 1
+                                    else if (a.code < b.code) rst = -1;
+                                    return rst;
+                                });
+                                me.cache["_GLJ_" + me.currentRationItem.ID] = cacheArr.concat(newAddArr);
+                            }
+                            me.showGljItems(me.currentRationItem.ID);
+                            if (newAddArr.length > 0) {
+                                me.updateRationItem();
+                            }
+                        }
+                        sheetCommonObj.lockCells(me.workBook.getSheet(0), me.setting);
+                    },
+                    error:function(err){
+                        alert(err);
+                    }
+                })
+            } else {
+                //修改用量
+            }
+        }
+    },
+    onCellEditEnd: function(sender, args){
+        var me = rationGLJOprObj;
+        if (args.col != 0) {
+            var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+            if (args.row < cacheArr.length) {
+                var editGlj = cacheArr[args.row];
+                if (editGlj["consumeAmt"] != args.editingText) {
+                    editGlj["consumeAmt"] = args.editingText;
+                    me.updateRationItem();
+                }
+            }
+        } else {
+            //重新更新工料机
+        }
+    },
+
+    updateRationItem: function() {
+        var me = this, updateArr = [];
+        if (me.currentRationItem) {
+            me.currentRationItem.rationGljList = me.buildRationItemGlj();
+            updateArr.push(me.currentRationItem);
+            rationOprObj.mixUpdateRequest(updateArr, [], []);
+        }
+    },
+
+    buildRationItemGlj: function(){
+        var me = this, rst = [];
+        if (me.currentRationItem && me.cache["_GLJ_" + me.currentRationItem.ID]) {
+            var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
+            for (var i = 0; i < cacheArr.length; i++) {
+                rst.push({gljId: cacheArr[i].gljId, consumeAmt: cacheArr[i].consumeAmt, proportion: 0});
+            }
+        }
+        return rst;
+    },
+
     createRationGljDisplayItem: function(rItem, repGlj) {
         var rst = {};
         rst.gljId = rItem.gljId;
@@ -37,6 +145,7 @@ var rationGLJOprObj = {
     },
     getGljItems: function(rationItem) {
         var me = this, rationID = rationItem.ID, rationGljList = rationItem.rationGljList;
+        me.currentRationItem = rationItem;
         if (me.cache["_GLJ_" + rationID]) {
             me.showGljItems(rationID);
             sheetCommonObj.lockCells(me.workBook.getSheet(0), me.setting);