Browse Source

定额库补注条件调整debug修改

zhongzewei 7 years ago
parent
commit
bfbef17423

+ 1 - 1
web/maintain/ration_repository/dinge.html

@@ -458,7 +458,7 @@
                 });
 
                 $("#linkFZTJ").click(function(){
-                    rationGLJOprObj.unBindDel();
+                    rationCoeOprObj.bindRationCoeDel();
                     rdSpread.setActiveSheetIndex(2);
                 });
             });

+ 125 - 55
web/maintain/ration_repository/js/ration_coe.js

@@ -1,14 +1,16 @@
 /**
  * Created by CSL on 2017-06-08.
  */
+ //modified by zhong on 2017-09-25
 var rationCoeOprObj = {
     sheet: null,
     libID: null,
     curRation: null,
+    tempDelArr: [],
     cache: {},
     setting: {
         header:[
-            {headerName:"编码",headerWidth:120,dataCode:"ID", dataType: "Number"},
+            {headerName:"编码",headerWidth:120,dataCode:"ID", dataType: "Number", hAlign: 'left'},
             {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
             {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String"}
         ],
@@ -27,7 +29,7 @@ var rationCoeOprObj = {
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
         me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
-        me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
+       // me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
     },
 
     onClipboardPasting: function(sender, args) {
@@ -42,12 +44,49 @@ var rationCoeOprObj = {
         if (me.libID) {
             // 修改第一列(编号)
             if (info.cellRange.col == 0) {
+                me.tempDelArr = [];
                 var coeIDs = [];
-                var temp = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
-                for (let obj of temp) {
-                    coeIDs.push(obj.ID);
-                };
+                var items = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
+                let curCache = typeof me.cache["_Coe_" + me.curRation.ID] !== 'undefined' ? me.cache["_Coe_" + me.curRation.ID] : [];
+                let isRefresh = false;
+                for(let i = 0, len = items.length; i < len; i++){
+                    let row = i + info.cellRange.row;
+                    //update
+                    if(row < curCache.length){
+                        let isExist = false;
+                        for(let j = 0, jLen = curCache.length; j < jLen; j++){
+                            if(items[i].ID === curCache[j].ID && j !== row){
+                                isExist = true;
+                                break;
+                            }
+                        }
+                        if(!isExist){
+                            me.tempDelArr.push({org: curCache[row], newID: items[i].ID});
+                            coeIDs.push(items[i].ID);
+                        }
+                        else{
+                            isRefresh = true;
+                        }
+                    }
+                    else{
+                        coeIDs.push(items[i].ID);
+                    }
+                }
+                //delete in front
+                if(me.tempDelArr.length > 0){
+                   for(let i = 0, len = me.tempDelArr.length; i < len; i++){
+                       for(let j = 0; j < curCache.length; j++){
+                           if(me.tempDelArr[i].org.ID === curCache[j].ID){
+                               curCache.splice(j, 1);
+                               break;
+                           }
+                       }
+                   }
+                }
                 me.addCoeItems(coeIDs);
+                if(isRefresh){
+                    me.showCoeItems(me.curRation.ID);
+                }
             } else {
                 //修改其它列。
             }
@@ -56,52 +95,79 @@ var rationCoeOprObj = {
 
     onEditEnded: function(sender, args){
         var me = rationCoeOprObj;
-        if (args.col == 0) {   // 编号列
-            //delete
-            if (args.editingText == null || args.editingText.trim() == "") {
-                var curCache = me.cache["_Coe_" + me.curRation.ID];
-                if (curCache) {
-                    if (args.row < curCache.length) {
-                        curCache.splice(args.row, 1);
-                        me.updateCurRation();
-                        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-                        me.showCoeItems(me.curRation.ID);
+        if (args.col == 0 && args.editingText && args.editingText.toString().trim().length > 0 && !isNaN(args.editingText)) {   // 编号列
+            let curCahe = typeof me.cache["_Coe_" + me.curRation.ID] !== 'undefined' ? me.cache["_Coe_" + me.curRation.ID] : [];
+            me.tempDelArr = [];
+            //update
+            if(args.row < curCahe.length && args.editingText != curCahe[args.row].ID){
+                let isExist = false;
+                for(let i = 0, len = curCahe.length; i < len; i++){
+                    if(args.editingText == curCahe[i].ID){
+                        isExist = true;
+                        break;
                     }
                 }
-            } else {
-                if (me.libID) {
-                    var ID = args.editingText.trim();
-                    if (!isNaN(ID)) {
-                        me.addCoeItems([ID]);
-                    };
-                };
-            };
-        };
-    },
-
-    onRangeChanged: function(sender, args) {
-        if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
-            if (!confirm(`确定要删除选中的 ${args.rowCount} 条附注条件吗?`)){return; }
-            var me = rationCoeOprObj;
-            if (args.col == 0) {
-                var curCache = me.cache["_Coe_" + me.curRation.ID];
-                if (curCache) {
-                    for (var i = args.rowCount - 1; i >= 0; i--) {
-                        if (args.row + i < curCache.length) {
-                            curCache.splice(args.row + i, 1);
-                        };
-                    };
-                    me.updateCurRation();
-                    sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                if(!isExist){
+                    me.tempDelArr.push({org: curCahe[args.row], newID: args.editingText});
+                    curCahe.splice(args.row, 1);
+                    me.addCoeItems([args.editingText]);
+                }
+                else{
                     me.showCoeItems(me.curRation.ID);
-                };
-            };
-        };
+                }
+            }
+            //insert
+            else{
+                me.addCoeItems([args.editingText]);
+            }
+        }
+        else{
+            me.showCoeItems(me.curRation.ID);
+        }
     },
 
+    bindRationCoeDel: function () {
+        let me = rationCoeOprObj;
+        let workBook = me.sheet.getParent();
+        workBook.commandManager().register('rationCoeDel', function () {
+            let sels = me.sheet.getSelections(), isUpdate = false;
+            let curCahe = me.cache["_Coe_" + me.curRation.ID];
+            for(let i = 0, len = sels.length; i < len; i ++ ){
+                if(sels[i].colCount === me.setting.header.length){
+                    if(sels[i].row < curCahe.length){
+                        isUpdate = true;
+                        curCahe.splice(sels[i].row, sels[i].rowCount);
+                    }
+                }
+            }
+            if(isUpdate){
+                me.updateCurRation();
+                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                me.showCoeItems(me.curRation.ID);
+            }
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('rationCoeDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
+    getRecoveryArr: function (tempDelArr, newArr) {//获得更新的coe不存在,恢复删除的被更新数据
+        let rst = [];
+        for(let i = 0, len = tempDelArr.length; i < len; i++){
+            let isExist = false;
+            for(let j = 0, jLen = newArr.length; j < jLen; j++){
+                if(tempDelArr[i].newID == newArr[j].ID){
+                    isExist = true;
+                    break;
+                }
+            }
+            if(!isExist){
+                rst.push(tempDelArr[i].org);
+            }
+        }
+        return rst;
+    },
     addCoeItems: function(coeIDs) {
         var me = this;
-        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
 
         var curCache = me.cache["_Coe_" + me.curRation.ID];
         var temp = [];
@@ -142,14 +208,10 @@ var rationCoeOprObj = {
                         }else{
                             curCache = rstArr;
                         }
-
-                        curCache.sort(function(a, b) {
-                            var rst = 0;
-                            if (a.ID > b.ID) rst = 1
-                            else if (a.ID < b.ID) rst = -1;
-                            return rst;
-                        });
-
+                        let recoveryArr = me.getRecoveryArr(me.tempDelArr, result.data);
+                        if(recoveryArr.length > 0){
+                            curCache = curCache.concat(recoveryArr);
+                        }
                         me.cache["_Coe_" + me.curRation.ID] = curCache;
                         me.updateCurRation();
                         me.showCoeItems(me.curRation.ID);
@@ -186,7 +248,7 @@ var rationCoeOprObj = {
                 cache:false,
                 timeout:5000,
                 success:function(result){
-                    sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                    sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                     if (result.data) {
                         var tempResult = [];
                         for (let obj of result.data) {
@@ -211,6 +273,12 @@ var rationCoeOprObj = {
         var me = this;
         var curCache = me.cache["_Coe_" + rationID];
         if (curCache) {
+            curCache.sort(function(a, b) {
+                var rst = 0;
+                if (a.ID > b.ID) rst = 1
+                else if (a.ID < b.ID) rst = -1;
+                return rst;
+            });
             sheetCommonObj.showData(me.sheet, me.setting, curCache);
         }
     },
@@ -230,4 +298,6 @@ var rationCoeOprObj = {
             };
         };
     }
-}
+}
+
+

+ 0 - 1
web/maintain/ration_repository/js/ration_glj.js

@@ -342,7 +342,6 @@ var rationGLJOprObj = {
                 //sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
                 if (result) {
                     if(result.data.length > 0){
-                        console.log(`enter1`);
                         //sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
                         sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                         var rstArr = [], dummyR = {gljId: 0, consumeAmt:0}, newAddArr = [];