Browse Source

定额库debug

zhongzewei 7 years ago
parent
commit
14386bc4c5

+ 5 - 0
modules/ration_repository/controllers/coe_controller.js

@@ -27,6 +27,11 @@ class CoeListController extends BaseController{
             callback(req, res, err, 'Get coe', data);
         });
     }
+    getCoeItemsByNos(req,res){
+        coeList.getCoeItemsByNos(JSON.parse(req.body.data), function(err,data){
+            callback(req, res, err, 'Get coe', data);
+        });
+    }
 }
 
 export default CoeListController;

+ 12 - 1
modules/ration_repository/models/coe.js

@@ -25,7 +25,18 @@ coeListDAO.prototype.getCoeItemsByIDs = function (data, callback) {
     coeListModel.find({
             "libID": data.libID,
             "ID": {"$in":data.coeIDs}
-        }, ["libID","ID","name","content","-_id"],
+        }, ["libID","ID","serialNo","name","content","-_id"],
+        function (err, doc) {
+            if (err) callback("批量获取系数明细错误!", null)
+            else callback(null, doc);
+        })
+};
+
+coeListDAO.prototype.getCoeItemsByNos = function (data, callback) {
+    coeListModel.find({
+            "libID": data.libID,
+            "serialNo": {"$in":data.coeNos}
+        }, ["libID","ID","serialNo","name","content","-_id"],
         function (err, doc) {
             if (err) callback("批量获取系数明细错误!", null)
             else callback(null, doc);

+ 1 - 0
modules/ration_repository/models/schemas.js

@@ -19,6 +19,7 @@ let coeSchema = new Schema({
 let coeListSchema = new Schema({
     libID: Number,                      // 所属定额定ID
     ID: Number,                         // 系数ID(流水号ID)
+    serialNo: Number,                  //编号
     name: String,                       // 名称
     content: String,                    // 说明
     coes: [coeSchema]

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

@@ -65,6 +65,7 @@ module.exports =  function (app) {
     apiRouter.post("/getCoeList",coeListController.auth, coeListController.init, coeListController.getCoeList);
     apiRouter.post("/saveCoeList",coeListController.auth, coeListController.init, coeListController.saveCoeList);
     apiRouter.post("/getCoeItemsByIDs",coeListController.auth, coeListController.init, coeListController.getCoeItemsByIDs);
+    apiRouter.post("/getCoeItemsByNos",coeListController.auth, coeListController.init, coeListController.getCoeItemsByNos);
 
     apiRouter.post('/getRationItem',searchController.auth, searchController.init, searchController.getRationItem);
     apiRouter.post('/findRation', searchController.auth, searchController.init, searchController.findRation);

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

@@ -526,7 +526,7 @@
                 });
 
                 $("#linkFZDE").click(function(){
-                    rationGLJOprObj.unBindDel();
+                    rationAssistOprObj.bindRationAssDel();
                     rdSpread.setActiveSheetIndex(1);
                 });
 

+ 120 - 25
web/maintain/ration_repository/js/coe.js

@@ -70,10 +70,10 @@ let coeOprObj = {
     workSheet: null,
     currentCoeList: [],
     currentCoe: null,
-    //currentMaxNo: null,
+    currentMaxNo: null,
     setting: {
         header: [
-            {headerName:"编号", headerWidth:60, dataCode:"ID", dataType: "String", hAlign: "center", vAlign: "center", readOnly: true},
+            {headerName:"编号", headerWidth:60, dataCode:"serialNo", dataType: "String", hAlign: "center", vAlign: "center", readOnly: false},
             {headerName:"名称", headerWidth:280, dataCode:"name", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
             {headerName:"内容", headerWidth:250, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", readOnly: false},
         ]
@@ -110,26 +110,64 @@ let coeOprObj = {
     onEditEnded: function (sender, args) {
         let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
         if(args.editingText && args.editingText.toString().trim().length > 0){
+            let inputT = args.editingText.toString().trim();
             //update
             if(args.row < me.currentCoeList.length){
                 let updateObj = me.currentCoeList[args.row];
-                if(updateObj[dataCode] !== args.editingText.toString().trim()){
-                    updateObj[dataCode] = args.editingText;
-                    updateArr.push(updateObj);
-                    me.save([], updateArr, [], true);
+                if(updateObj[dataCode] != inputT){
+                    if(dataCode === 'serialNo'){
+                        if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
+                            me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
+                            updateObj[dataCode] = inputT;
+                            updateArr.push(updateObj);
+                            me.save([], updateArr, [], true);
+                        }
+                        else if(!me.isInt(inputT)){
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
+                            alert('编号只能为整数!');
+                        }
+                        else if(me.hasTisNo(me.currentCoeList, inputT)){
+                            args.sheet.setValue(args.row, args.col, updateObj[dataCode] + '');
+                            alert('该编号已存在!');
+                        }
+                    }
+                    else {
+                        updateObj[dataCode] = inputT;
+                        updateArr.push(updateObj);
+                        me.save([], updateArr, [], true);
+                    }
                 }
             }
             //insert
             else{
                 let newCoe = {};
-                //me.currentMaxNo ++;
                 newCoe.libID = pageObj.libID;
-                //newCoe.serialNo = me.currentMaxNo;
-                newCoe[dataCode] = args.editingText;
-                addArr.push(newCoe);
-                me.save(addArr, [], [], true, function (result) {
-                    me.updateCurrentCoeList(result);
-                });
+                if(dataCode === 'serialNo'){
+                    if(me.isInt(inputT) && !me.hasTisNo(me.currentCoeList, inputT)){
+                        me.currentMaxNo = me.currentMaxNo >= inputT ? me.currentMaxNo : inputT;
+                        newCoe[dataCode] = inputT;
+                        addArr.push(newCoe);
+                        me.save(addArr, [], [], true, function (result) {
+                            me.updateCurrentCoeList(result);
+                        });
+                    }
+                    else if(!me.isInt(inputT)){
+                        args.sheet.setValue(args.row, args.col, '');
+                        alert('编号只能为整数!');
+                    }
+                    else if(me.hasTisNo(me.currentCoeList, inputT)){
+                        args.sheet.setValue(args.row, args.col, '');
+                        alert('该编号已存在!');
+                    }
+                }
+                else{
+                    newCoe.serialNo = ++me.currentMaxNo;
+                    newCoe[dataCode] = inputT;
+                    addArr.push(newCoe);
+                    me.save(addArr, [], [], true, function (result) {
+                        me.updateCurrentCoeList(result);
+                    });
+                }
             }
         }
     },
@@ -142,26 +180,40 @@ let coeOprObj = {
     onClipboardPasted: function (sender, info) {
         let me = coeOprObj, addArr = [], updateArr = [];
         let items = sheetCommonObj.analyzePasteData(me.setting, info);
-        for(let i = 0, len = items.length; i < len; i++){
+        let uniqItems = me.makeUniqItems(items);
+        for(let i = 0, len = uniqItems.length; i < len; i++){
             let row = i + info.cellRange.row;
             //update
             if(row < me.currentCoeList.length){
                 let updateObj = me.currentCoeList[row];
-                for(let attr in items[i]){
-                    updateObj[attr] = items[i][attr];
+                for(let attr in uniqItems[i]){
+                    if(attr === 'serialNo'){
+                        if(me.isInt(uniqItems[i][attr]) && !me.hasTisNo(me.currentCoeList, uniqItems[i][attr])){
+                            me.currentMaxNo = me.currentMaxNo >= uniqItems[i][attr] ? me.currentMaxNo : uniqItems[i][attr];
+                            updateObj[attr] = uniqItems[i][attr];
+                        }
+                    }
+                    else {
+                        updateObj[attr] = uniqItems[i][attr];
+                    }
                 }
                 updateArr.push(updateObj);
             }
             //insert
             else {
-                //items[i].serialNo = ++ me.currentMaxNo;
-                items[i].libID = pageObj.libID;
-                addArr.push(items[i]);
+                if(typeof uniqItems[i].serialNo !== 'undefined' && uniqItems[i] && me.isInt(uniqItems[i].serialNo) && !me.hasTisNo(me.currentCoeList, uniqItems[i].serialNo)){
+                    me.currentMaxNo = me.currentMaxNo >= uniqItems[i].serialNo ? me.currentMaxNo : uniqItems[i].serialNo;
+                }
+                else {
+                    uniqItems[i].serialNo = ++me.currentMaxNo;
+                }
+                uniqItems[i].libID = pageObj.libID;
+                addArr.push(uniqItems[i]);
             }
         }
         if(addArr.length > 0 || updateArr.length > 0){
             me.save(addArr, updateArr, [], true, function (result) {
-                me.updateCurrentCoeList(result)
+                me.updateCurrentCoeList(result);
             });
         }
     },
@@ -197,16 +249,57 @@ let coeOprObj = {
         workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
         workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
     },
+    //粘贴的数据,编号唯一化,去除编号重复的项
+    makeUniqItems: function (items) {
+        let rst = [];
+        for(let i = 0, len = items.length; i < len; i++){
+            if(typeof items[i].serialNo !== 'undefined' && items[i].serialNo){
+                if(rst.length === 0){
+                    rst.push(items[i]);
+                }
+                else{
+                    let isExist = false;
+                    for(let j = 0, jLen = rst.length; j < jLen; j++){
+                        if(items[i].serialNo === rst[j].serialNo){
+                            isExist = true;
+                            break;
+                        }
+                    }
+                    if(!isExist){
+                        rst.push(items[i]);
+                    }
+                }
+            }
+            else {
+                rst.push(items[i]);
+            }
+        }
+        return rst;
+    },
+    isInt: function (num) {
+        return !isNaN(num) && num % 1 === 0;
+    },
+    hasTisNo: function (coeList, newSerialNo) {
+        let rst = false;
+        for(let i = 0, len = coeList.length; i < len; i++){
+            if(coeList[i].serialNo == newSerialNo){
+                rst = true;
+                break;
+            }
+        }
+        return rst;
+    },
     updateCurrentCoeList: function (newCoeList) {
         let me = coeOprObj;
-        me.currentCoeList = me.currentCoeList.concat(newCoeList);
-        me.sortCoeList(me.currentCoeList);
+        if(newCoeList){
+            me.currentCoeList = me.currentCoeList.concat(newCoeList);
+        }
     },
     sortCoeList: function (coeList) {
         coeList.sort(function (a, b) {
             let rst = 0;
-            if(a.ID > b.ID) rst = 1;
-            else if(a.ID < b.ID) rst = -1;
+            if(a.serialNo > b.serialNo) rst = 1;
+            else if(a.serialNo < b.serialNo) rst = -1;
             return rst;
         });
     },
@@ -222,7 +315,7 @@ let coeOprObj = {
                 if(!result.error){
                     me.currentCoeList = result.data;
                     me.sortCoeList(me.currentCoeList);
-                    //me.currentMaxNo =  me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
+                    me.currentMaxNo =  me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
                     pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
                     me.workSheet.clearSelection();
                 }
@@ -256,6 +349,8 @@ let coeOprObj = {
                         callback(result.data);
                     }
                     if(refresh){
+                        me.sortCoeList(me.currentCoeList);
+                        me.currentMaxNo = me.currentCoeList.length > 0 ? me.currentCoeList[me.currentCoeList.length - 1].serialNo : 0;
                         pageObj.showData(me.workSheet, me.setting, me.currentCoeList);
                     }
                 }

+ 23 - 6
web/maintain/ration_repository/js/ration.js

@@ -218,6 +218,7 @@ let rationOprObj = {
             }
             if(updateArr.length > 0 || removeArr.length > 0){
                 me.mixUpdate = 1;
+                me.mixDel = removeArr.length > 0 ? 1 : 0;
                 me.mixUpdateRequest(updateArr, [], removeArr);
             }
 
@@ -480,7 +481,7 @@ let rationOprObj = {
             }
         })
     },
-    mixUpdateRequest: function(updateArr, addArr, removeIds) {
+    mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
         let me = rationOprObj;
         sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, true);
         $.ajax({
@@ -526,8 +527,10 @@ let rationOprObj = {
                     }
                     me.showRationItems(me.currentSectionId);
                     me.mixUpdate = 0;
+                    me.mixDel = 0;
                 }
                 sheetCommonObj.setLockCol(me.workBook.getSheet(0), 0, false);
+                if(callback) callback();
             },
             error:function(){
             }
@@ -598,7 +601,10 @@ let rationOprObj = {
         sheet.resumePaint();
     },
     showRationItems: function(sectionID){
-        let me = rationOprObj;
+        let me = rationOprObj,
+            sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
+            sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
+            sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
         if (me.workBook) {
             if (me.currentRations && me.currentRations["_SEC_ID_" + sectionID] && me.currentRations["_SEC_ID_" + sectionID].length > 0) {
                 let cacheSection = me.currentRations["_SEC_ID_" + sectionID];
@@ -608,16 +614,27 @@ let rationOprObj = {
                 sheetCommonObj.setLockCol(me.workBook.getSheet(0), 4, true);
                 //combo
                 me.setCombo(me.workBook.getActiveSheet(), rationUnits);
-                if(me.mixUpdate === 1){
-                    rationGLJOprObj.getGljItems(cacheSection[cacheSection.length - 1], function () {
-                        me.workBook.focus(true);
-                    });
+                if(me.mixDel === 1){
+                    let row = me.workBook.getSheet(0).getSelections()[0].row;
+                    if (cacheSection && row < cacheSection.length) {
+                        rationGLJOprObj.getGljItems(cacheSection[row]);
+                        rationCoeOprObj.getCoeItems(cacheSection[row]);
+                        rationAssistOprObj.getAssItems(cacheSection[row]);
+                    }
+                    else {
+                        rationGLJOprObj.currentRationItem = null;
+                    }
                 }
 
             } else {
                 //清除ration数据及工料机数据
+                rationGLJOprObj.currentRationItem = null;
                 sheetCommonObj.cleanSheet(me.workBook.getSheet(0), me.setting, -1);
+                sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
+                sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
+                sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
             }
+            me.workBook.focus(true);
         }
     },
     sortByCode: function(arr){

+ 43 - 10
web/maintain/ration_repository/js/ration_assist.js

@@ -9,12 +9,12 @@ var rationAssistOprObj = {
         header:[
             {headerName:"调整名称",headerWidth:200,dataCode:"name", dataType: "String", hAlign: "left"},
             {headerName:"辅助定额号",headerWidth:120,dataCode:"assistCode", dataType: "String", hAlign: "center"},
-            {headerName:"标准值",headerWidth:100,dataCode:"stdValue", dataType: "String", hAlign: "right"},
-            {headerName:"步距",headerWidth:100,dataCode:"stepValue", dataType: "String", hAlign: "right"},
-            {headerName:"精度",headerWidth:80,dataCode:"decimal", dataType: "Number", hAlign: "right"},
+            {headerName:"标准值",headerWidth:100,dataCode:"stdValue", dataType: "Number", hAlign: "right"},
+            {headerName:"步距",headerWidth:100,dataCode:"stepValue", dataType: "Number", hAlign: "right"},
+            {headerName:"精度",headerWidth:80,dataCode:"decimal", formatter: "0", dataType: "Number", hAlign: "right"},
             {headerName:"进位方式",headerWidth:100,dataCode:"carryBit", dataType: "String", hAlign: "center"},
-            {headerName:"最小值",headerWidth:100,dataCode:"minValue", dataType: "String", hAlign: "right"},
-            {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "String", hAlign: "right"}
+            {headerName:"最小值",headerWidth:100,dataCode:"minValue", dataType: "Number", hAlign: "right"},
+            {headerName:"最大值",headerWidth:100,dataCode:"maxValue", dataType: "Number", hAlign: "right"}
         ],
         view:{}
     },
@@ -34,7 +34,7 @@ var rationAssistOprObj = {
         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) {
@@ -56,8 +56,10 @@ var rationAssistOprObj = {
             me.ration.rationAssList = assList;
         };
 
-        rationOprObj.mixUpdateRequest([me.ration], [], []);
-        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+        rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+            me.sheet.getParent().focus(true);
+        });
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
         sheetCommonObj.showData(me.sheet, me.setting, me.ration.rationAssList);
     },
 
@@ -67,6 +69,8 @@ var rationAssistOprObj = {
         var assList = me.ration.rationAssList;
         //var assObj = sheetCommonObj.combineRowData(me.sheet, me.setting, args.row);
         var assObj = sheetsOprObj.combineRationRowData(me.sheet, me.setting, args.row);
+        if(args.col === 2 || args.col === 3 || args.col === 6 || args.col === 7){
+        }
         // 新增
         if ((assList == undefined) || (assList && args.row >= assList.length)) {
             if (assObj.decimal == undefined || assObj.decimal == null){assObj.decimal = '0';};
@@ -76,8 +80,10 @@ var rationAssistOprObj = {
         // 修改
         else{ assList[args.row] = assObj; };
 
-        rationOprObj.mixUpdateRequest([me.ration], [], []);
-        sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+        rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+            me.sheet.getParent().focus(true);
+        });
+        sheetCommonObj.cleanData(me.sheet, me.setting, -1);
         sheetCommonObj.showData(me.sheet, me.setting, assList);
     },
 
@@ -99,6 +105,33 @@ var rationAssistOprObj = {
             sheetCommonObj.showData(me.sheet, me.setting, assList);
         };
     },
+    bindRationAssDel: function () {
+        let me = rationAssistOprObj;
+        let workBook = me.sheet.getParent();
+        workBook.commandManager().register('rationAssDel', function () {
+            let sels = me.sheet.getSelections(), isUpdate = false;
+            if(me.ration){
+                let curCahe = me.ration.rationAssList;
+                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){
+                    rationOprObj.mixUpdateRequest([me.ration], [], [], function () {
+                        workBook.focus(true);
+                    });
+                    sheetCommonObj.cleanData(me.sheet, me.setting, -1);
+                    sheetCommonObj.showData(me.sheet, me.setting, curCahe);
+                }
+            }
+        });
+        workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
+        workBook.commandManager().setShortcutKey('rationAssDel', GC.Spread.Commands.Key.del, false, false, false, false);
+    },
 
     getAssItems: function(ration) {
         var me = this;

+ 52 - 44
web/maintain/ration_repository/js/ration_coe.js

@@ -10,9 +10,9 @@ var rationCoeOprObj = {
     cache: {},
     setting: {
         header:[
-            {headerName:"编码",headerWidth:120,dataCode:"ID", dataType: "Number", hAlign: 'left'},
-            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String"},
-            {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String"}
+            {headerName:"编号",headerWidth:120,dataCode:"serialNo", dataType: "Number", hAlign: 'left'},
+            {headerName:"名称",headerWidth:400,dataCode:"name", dataType: "String", hAlign: 'left'},
+            {headerName:"内容",headerWidth:300,dataCode:"content", dataType: "String", hAlign: 'left'}
         ],
         view:{
             comboBox:[],
@@ -45,45 +45,47 @@ var rationCoeOprObj = {
             // 修改第一列(编号)
             if (info.cellRange.col == 0) {
                 me.tempDelArr = [];
-                var coeIDs = [];
-                var items = sheetCommonObj.analyzePasteData({header:[{dataCode: "ID"}] }, info);
+                var coeNos = [];
+                var items = sheetCommonObj.analyzePasteData({header:[{dataCode: "serialNo"}] }, 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(!isNaN(items[i].serialNo)){
+                        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].serialNo === curCache[j].serialNo && j !== row){
+                                    isExist = true;
+                                    break;
+                                }
+                            }
+                            if(!isExist){
+                                me.tempDelArr.push({org: curCache[row], newNo: items[i].serialNo});
+                                coeNos.push(items[i].serialNo);
+                            }
+                            else{
+                                isRefresh = true;
                             }
-                        }
-                        if(!isExist){
-                            me.tempDelArr.push({org: curCache[row], newID: items[i].ID});
-                            coeIDs.push(items[i].ID);
                         }
                         else{
-                            isRefresh = true;
+                            coeNos.push(items[i].serialNo);
                         }
                     }
-                    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){
+                           if(me.tempDelArr[i].org.serialNo === curCache[j].serialNo){
                                curCache.splice(j, 1);
                                break;
                            }
                        }
                    }
                 }
-                me.addCoeItems(coeIDs);
+                me.addCoeItems(coeNos);
                 if(isRefresh){
                     me.showCoeItems(me.curRation.ID);
                 }
@@ -99,16 +101,16 @@ var rationCoeOprObj = {
             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){
+            if(args.row < curCahe.length && args.editingText != curCahe[args.row].serialNo){
                 let isExist = false;
                 for(let i = 0, len = curCahe.length; i < len; i++){
-                    if(args.editingText == curCahe[i].ID){
+                    if(args.editingText == curCahe[i].serialNo){
                         isExist = true;
                         break;
                     }
                 }
                 if(!isExist){
-                    me.tempDelArr.push({org: curCahe[args.row], newID: args.editingText});
+                    me.tempDelArr.push({org: curCahe[args.row], newNo: args.editingText});
                     curCahe.splice(args.row, 1);
                     me.addCoeItems([args.editingText]);
                 }
@@ -122,6 +124,7 @@ var rationCoeOprObj = {
             }
         }
         else{
+            sheetCommonObj.cleanData(me.sheet, me.setting, -1);
             me.showCoeItems(me.curRation.ID);
         }
     },
@@ -141,7 +144,9 @@ var rationCoeOprObj = {
                 }
             }
             if(isUpdate){
-                me.updateCurRation();
+                me.updateCurRation(function () {
+                    me.sheet.getParent().focus(true);
+                });
                 sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                 me.showCoeItems(me.curRation.ID);
             }
@@ -154,7 +159,7 @@ var rationCoeOprObj = {
         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){
+                if(tempDelArr[i].newNo == newArr[j].serialNo){
                     isExist = true;
                     break;
                 }
@@ -165,27 +170,27 @@ var rationCoeOprObj = {
         }
         return rst;
     },
-    addCoeItems: function(coeIDs) {
+    addCoeItems: function(coeNos) {
         var me = this;
         sheetCommonObj.cleanData(me.sheet, me.setting, -1);
 
         var curCache = me.cache["_Coe_" + me.curRation.ID];
         var temp = [];
         if (curCache) {
-            for (var i = 0; i < coeIDs.length; i++) {
+            for (var i = 0; i < coeNos.length; i++) {
                 var isExist = false;
                 for (let obj of curCache) {
-                    if (obj.ID == coeIDs[i]) {
+                    if (obj.serialNo == coeNos[i]) {
                         isExist = true;
                         break;
                     };
                 };
                 if (!isExist) {
-                    temp.push(coeIDs[i]);
+                    temp.push(coeNos[i]);
                 };
             };
         }else{
-            for (let obj of coeIDs){temp.push(obj)};
+            for (let obj of coeNos){temp.push(obj)};
         };
 
         if(temp.length == 0){
@@ -194,8 +199,8 @@ var rationCoeOprObj = {
         }else{
             $.ajax({
                 type:"POST",
-                url:"api/getCoeItemsByIDs",
-                data: {"data": JSON.stringify({"libID": me.libID, "coeIDs": temp})},
+                url:"api/getCoeItemsByNos",
+                data: {"data": JSON.stringify({"libID": me.libID, "coeNos": temp})},
                 dataType:"json",
                 cache:false,
                 timeout:5000,
@@ -213,7 +218,9 @@ var rationCoeOprObj = {
                             curCache = curCache.concat(recoveryArr);
                         }
                         me.cache["_Coe_" + me.curRation.ID] = curCache;
-                        me.updateCurRation();
+                        me.updateCurRation(function () {
+                            me.sheet.getParent().focus(true);
+                        });
                         me.showCoeItems(me.curRation.ID);
                     };
                     sheetCommonObj.lockCells(me.sheet, me.setting);
@@ -229,12 +236,11 @@ var rationCoeOprObj = {
         var me = this;
         me.curRation = ration;
 
-        if (ration == undefined || ration.rationCoeList == undefined ||
-            ration.rationCoeList.length == 0){return;};
+        /*if (ration == undefined || ration.rationCoeList == undefined ||
+            ration.rationCoeList.length == 0){return;};*/
 
         var coeList = ration.rationCoeList;
         var curCache = me.cache["_Coe_" + ration.ID];
-
         if (curCache && curCache.length > 0) {
             me.showCoeItems(ration.ID);
             sheetCommonObj.lockCells(me.sheet, me.setting);
@@ -260,7 +266,7 @@ var rationCoeOprObj = {
                         me.showCoeItems(ration.ID);
                     }
                     sheetCommonObj.lockCells(me.sheet, me.setting);
-                    callback();
+                    if(callback) callback();
                 },
                 error:function(err){
                     alert(err);
@@ -275,15 +281,15 @@ var rationCoeOprObj = {
         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;
+                if (a.serialNo > b.serialNo) rst = 1
+                else if (a.serialNo < b.serialNo) rst = -1;
                 return rst;
             });
             sheetsOprObj.showData(me.sheet, me.setting, curCache);
         }
     },
 
-    updateCurRation: function() {
+    updateCurRation: function(callback) {
         var me = this, updateArr = [];
         if (me.curRation) {
             var rst = [];
@@ -294,7 +300,9 @@ var rationCoeOprObj = {
                 };
                 me.curRation.rationCoeList = rst;
                 updateArr.push(me.curRation);
-                rationOprObj.mixUpdateRequest(updateArr, [], []);
+                rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                    if(callback) callback();
+                });
             };
         };
     }

+ 25 - 30
web/maintain/ration_repository/js/ration_glj.js

@@ -97,7 +97,6 @@ var rationGLJOprObj = {
         spreadBook.commandManager().register('rationGljDelete', function () {
             let sels = me.sheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
             let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID], isUpdate = false;
-            console.log(cacheSection);
             if(sels.length > 0){
                 for(let sel = 0; sel < sels.length; sel++){
                     if(sels[sel].colCount === me.setting.header.length){
@@ -126,8 +125,10 @@ var rationGLJOprObj = {
                 }
             }
             if(isUpdate){
-                me.updateRationItem();
-                sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                me.updateRationItem(function () {
+                    me.sheet.getParent().focus(true);
+                });
+                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                 me.showGljItems(me.currentRationItem.ID);
             }
            /* if(updateArr.length > 0 || removeArr.length > 0){
@@ -138,25 +139,6 @@ var rationGLJOprObj = {
         spreadBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
         spreadBook.commandManager().setShortcutKey('rationGljDelete', GC.Spread.Commands.Key.del, false, false, false, false);
     },
-    onRangeChanged: function(sender, args) {
-        if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
-            var me = rationGLJOprObj, updateArr = [], removeArr = [];
-            if (args.col == 0) {
-                if (me.cache["_GLJ_" + me.currentRationItem.ID]) {
-                    var cacheArr = me.cache["_GLJ_" + me.currentRationItem.ID];
-                    for (var i = args.rowCount - 1; i >= 0; i--) {
-                        if (args.row + i < cacheArr.length) {
-                            cacheArr.splice(args.row + i, 1);
-                        }
-                    }
-                    me.updateRationItem();
-                    sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
-                    me.showGljItems(me.currentRationItem.ID);
-                }
-            }
-
-        }
-    },
     onClipboardPasting: function(sender, args) {
         var me = rationGLJOprObj;
         if (!(args.cellRange.col === 0 || args.cellRange.col === 5) || !(me.currentRationItem)) {
@@ -192,7 +174,9 @@ var rationGLJOprObj = {
                             let roundCons = me.round(tempConsumes[i].consumeAmt, 3);
                             me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = roundCons;
                         }
-                        me.updateRationItem();
+                        me.updateRationItem(function () {
+                            me.sheet.getParent().focus(true);
+                        });
                         if(info.cellRange.row + info.cellRange.rowCount -1 >= me.cache["_GLJ_" + me.currentRationItem.ID].length -1){
                             me.sheet.suspendPaint();
                             for(let rowIdx = me.cache["_GLJ_" + me.currentRationItem.ID].length; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx++){
@@ -239,7 +223,9 @@ var rationGLJOprObj = {
                             args.sheet.setValue(args.row, args.col, parseNum);
                             let roundNum = me.round(parseNum, 3);
                             editGlj["consumeAmt"] = roundNum;
-                            me.updateRationItem();
+                            me.updateRationItem(function () {
+                                me.sheet.getParent().focus(true);
+                            });
                         }
                     }
                 }
@@ -277,6 +263,9 @@ var rationGLJOprObj = {
                         }
                     }
                 }
+                else {
+                    args.sheet.setValue(args.row, args.col, args.row < cacheArr.length ? cacheArr[args.row].code : '');
+                }
             }
         }
         else {
@@ -311,8 +300,10 @@ var rationGLJOprObj = {
                             }},*/
                             "delete": {name: "删除", icon: 'fa-remove', disabled: delDis, callback: function (key, opt) {
                                 cacheSection.splice(target.row, 1);
-                                me.updateRationItem();
-                                sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                                me.updateRationItem(function () {
+                                    me.sheet.getParent().focus(true);
+                                });
+                                sheetCommonObj.cleanData(me.sheet, me.setting, -1);
                                 me.showGljItems(me.currentRationItem.ID);
                             }}
                         }
@@ -389,7 +380,9 @@ var rationGLJOprObj = {
                         }
                         me.showGljItems(me.currentRationItem.ID);
                         if (newAddArr.length > 0) {
-                            me.updateRationItem();
+                            me.updateRationItem(function () {
+                                me.sheet.getParent().focus(true);
+                            });
                         }
                     }
                     else{
@@ -480,7 +473,7 @@ var rationGLJOprObj = {
         }
         return rst;
     },
-    updateRationItem: function() {
+    updateRationItem: function(callback) {
         var me = this, updateArr = [];
         if (me.currentRationItem) {
             me.currentRationItem.rationGljList = me.buildRationItemGlj();
@@ -491,7 +484,9 @@ var rationGLJOprObj = {
             me.currentRationItem.machinePrice = price.machinePrice;
             me.currentRationItem.basePrice = price.rationBasePrc;
             updateArr.push(me.currentRationItem);
-            rationOprObj.mixUpdateRequest(updateArr, [], []);
+            rationOprObj.mixUpdateRequest(updateArr, [], [], function () {
+                if(callback) callback();
+            });
         }
     },
 
@@ -565,7 +560,7 @@ var rationGLJOprObj = {
                         me.showGljItems(rationID);
                     }
                     sheetCommonObj.lockCells(me.sheet, me.setting);
-                    callback();
+                    if(callback) callback();
                 },
                 error:function(err){
                     alert(err);