Browse Source

完善复制粘贴等

zhongzewei 8 years ago
parent
commit
9ecad1a591

+ 147 - 3
modules/ration_repository/models/ration_item.js

@@ -213,9 +213,153 @@ function round(v,e){
 }
 
 rationItemDAO.prototype.updateRationBasePrc = function (data, callback) {
-    let adjGljId = data.gljId, adjBasePrice = data.basePrice, adjGljType = data.gljType,
+    let basePrcArr = data.basePrcArr,
+       // adjGljId = data.gljId, adjBasePrice = data.basePrice, adjGljType = data.gljType,
         repId = data.repId, lastOpr = data.lastOpr;
-    async.waterfall([
+    //
+    let updateArr;
+    async.each(basePrcArr, function (basePrcObj, finalCb) {
+        let adjGljId = basePrcObj.gljId, adjBasePrice = basePrcObj.basePrice, adjGljType = basePrcObj.gljType;
+        async.waterfall([
+            function (cb) {
+                rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null, result);
+                    }
+                });
+            },
+            function (result, cb) {
+                async.each(result, function (rationItem, ecb) {
+                    let rationGljList = rationItem.rationGljList,
+                        gljIds = [];
+                    rationGljList.forEach(function (rationGlj) {
+                        gljIds.push(rationGlj.gljId);
+                    });
+                    gljDao.getGljItems(gljIds, function(err, gljItems){
+                        if(err){
+                            ecb(err);
+                        }
+                        else{
+                            let gljArr = [];
+                            for(let i=0; i<gljItems.length; i++){
+                                let gljParentType = -1;
+                                if(gljItems[i].ID === adjGljId){
+                                    gljItems[i].gljType = adjGljType;
+                                }
+                                if(gljItems[i].gljType <= 3){
+                                    gljParentType = gljItems[i].gljType;
+                                }
+                                if(gljItems[i].gljType > 200 && gljItems[i].gljType < 300){
+                                    gljParentType = 2;
+                                }
+                                if(gljItems[i].gljType > 300 && gljItems[i].gljType < 400){
+                                    gljParentType = 3;
+                                }
+                                if(gljItems[i].ID === adjGljId){
+                                    gljArr.push({gljId: gljItems[i].ID, basePrice: adjBasePrice, gljParentType: gljParentType});
+                                }
+                                else {
+                                    gljArr.push({gljId: gljItems[i].ID, basePrice: gljItems[i].basePrice, gljParentType: gljParentType});
+                                }
+                            }
+                            gljArr.forEach(function (gljItem) {
+                                rationGljList.forEach(function (rationGlj) {
+                                    if(gljItem.gljId === rationGlj.gljId){
+                                        gljItem.consumeAmt = rationGlj.consumeAmt;
+                                    }
+                                })
+                            });
+                            //recalculate the price of ration
+                            let labourPrc = [], materialPrc = [], machinePrc = [], singlePrc, updatePrc = {labourPrice: 0, materialPrice: 0, machinePrice: 0, basePrice: 0};
+                            gljArr.forEach(function (gljItem) {
+                                if(gljItem.gljParentType !== -1){
+                                    singlePrc = round(gljItem.basePrice * gljItem.consumeAmt, 3);
+                                    if(gljItem.gljParentType === 1){
+                                        labourPrc.push(singlePrc);
+                                    }
+                                    else if(gljItem.gljParentType ===2){
+                                        materialPrc.push(singlePrc);
+                                    }
+                                    else{
+                                        machinePrc.push(singlePrc);
+                                    }
+                                }
+                            });
+                            if(labourPrc.length > 0){
+                                let sumLaP = 0;
+                                for(let i=0; i<labourPrc.length; i++){
+                                    sumLaP += labourPrc[i];
+                                }
+                                updatePrc.labourPrice = round(sumLaP, 2);
+                            }
+                            if(materialPrc.length > 0){
+                                let sumMtP = 0;
+                                for(let i= 0; i<materialPrc.length; i++){
+                                    sumMtP += materialPrc[i];
+                                }
+                                updatePrc.materialPrice = round(sumMtP, 2);
+                            }
+                            if(machinePrc.length > 0){
+                                let sumMaP = 0;
+                                for(let i =0; i< machinePrc.length; i++){
+                                    sumMaP += machinePrc[i];
+                                }
+                                updatePrc.machinePrice = round(sumMaP, 2);
+                            }
+                            updatePrc.basePrice = updatePrc.labourPrice + updatePrc.materialPrice + updatePrc.machinePrice;
+                            //updateDataBase
+                            rationItemModel.update({ID: rationItem.ID}, {$set: {labourPrice: updatePrc.labourPrice, materialPrice: updatePrc.materialPrice,
+                                    machinePrice: updatePrc.machinePrice, basePrice: updatePrc.basePrice}},
+                                function (err, result) {
+                                    if(err){
+                                        ecb(err);
+                                    }
+                                    else {
+                                        ecb(null);
+                                    }
+                                });
+                        }
+                    });
+                }, function(err){
+                    if(err){
+                        cb(err);
+                    }
+                    else {
+                        cb(null);
+                    }
+                });
+            },
+            function (cb) {
+                rationRepositoryDao.updateOprArr({ID: repId}, lastOpr, moment(Date.now()).format('YYYY-MM-DD HH:mm:ss'), function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                })
+            }
+        ], function (err) {
+            if(err){
+                finalCb(err);
+            }
+            else{
+                finalCb(null);
+            }
+        });
+    }, function (err) {
+        if(err){
+            callback(err, 'Error');
+        }
+        else{
+            callback(null, '');
+        }
+    });
+    //
+    /*async.waterfall([
         function (cb) {
             rationItemModel.find({'rationGljList.gljId': adjGljId}, function (err, result) {
                 if(err){
@@ -344,7 +488,7 @@ rationItemDAO.prototype.updateRationBasePrc = function (data, callback) {
         else{
             callback(null, '');
         }
-    });
+    });*/
 };
 
 rationItemDAO.prototype.getRationGljIds = function (data, callback) {

+ 4 - 2
public/web/sheet/sheet_common.js

@@ -7,6 +7,7 @@ var sheetCommonObj = {
     createSpread: function(container, SheetCount){
         var me = this;
         var spreadBook = new GC.Spread.Sheets.Workbook(container, { sheetCount: SheetCount });
+        spreadBook.options.allowCopyPasteExcelStyle = false;
         spreadBook.options.tabStripVisible = false;
         spreadBook.options.showHorizontalScrollbar = false;
         return spreadBook;
@@ -34,6 +35,7 @@ var sheetCommonObj = {
         spreadBook.options.tabStripVisible = false;
         spreadBook.options.showHorizontalScrollbar = false;
         spreadBook.options.scrollbarMaxAlign = true;
+        spreadBook.options.allowCopyPasteExcelStyle = false;
         var spreadNS = GC.Spread.Sheets;
         var sheet = spreadBook.getSheet(0);
         sheet.suspendPaint();
@@ -124,10 +126,10 @@ var sheetCommonObj = {
         //me.shieldAllCells(sheet);
     },
     analyzePasteData: function(setting, pastedInfo) {
-        var rst = [], propId = 0, preStrIdx = 0, itemObj = {};
+        var rst = [], propId = pastedInfo.cellRange.col, preStrIdx = 0, itemObj = {};
         for (var i = 0; i < pastedInfo.pasteData.text.length; i++) {
             if (pastedInfo.pasteData.text[i] === "\n") {
-                propId = 0;
+                propId = pastedInfo.cellRange.col;
                 preStrIdx = i + 1;
                 rst.push(itemObj);
                 if (i < pastedInfo.pasteData.text.length - 1) {

+ 59 - 36
web/maintain/ration_repository/js/ration.js

@@ -15,6 +15,7 @@ var rationOprObj = {
     currentRations: {},
     currentEditingRation: null,
     currentSectionId: -1,
+    activeCell: null,
     rationsCodes: [],
     setting: {
         header:[
@@ -61,13 +62,13 @@ var rationOprObj = {
             sheetGLJ = rationGLJOprObj.sheet, settingGLJ = rationGLJOprObj.setting,
             sheetCoe = rationCoeOprObj.sheet, settingCoe = rationCoeOprObj.setting,
             sheetAss = rationAssistOprObj.sheet, settingAss = rationAssistOprObj.setting;
+        me.activeCell = {row: args.row, col: args.col};
         sheetCommonObj.cleanSheet(sheetGLJ, settingGLJ, -1);
         sheetCommonObj.shieldAllCells(sheetGLJ);
         sheetCommonObj.cleanSheet(sheetCoe, settingCoe, -1);
         sheetCommonObj.shieldAllCells(sheetCoe);
         sheetCommonObj.cleanSheet(sheetAss, settingAss, -1);
         sheetCommonObj.shieldAllCells(sheetAss);
-
         if(!(args.sheetArea === GC.Spread.Sheets.SheetArea.colHeader || args.sheetArea === GC.Spread.Sheets.SheetArea.corner)){
             var cacheSection = me.getCache();
             if (cacheSection && args.row < cacheSection.length) {
@@ -126,7 +127,6 @@ var rationOprObj = {
         return cacheSection;
     },
     rationDelOpr: function () {
-        console.log(`rebuildDelete`);
         let me = rationOprObj;
         me.workBook.commandManager().register('rationDelete', function () {
             let rationSheet = me.workBook.getActiveSheet();
@@ -140,8 +140,6 @@ var rationOprObj = {
                                 if(sels[sel].row + i < cacheSection.length){
                                     removeArr.push(cacheSection[sels[sel].row + i].ID);
                                     me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
-                                    console.log(`me.rationsCodes`);
-                                    console.log(me.rationsCodes);
                                 }
                             }
                         }
@@ -160,7 +158,7 @@ var rationOprObj = {
                         }
                         else if(sels[sel].col !== 0 && !(sels[sel].col === 3 && sels.col + sels[sel].colCount -1 === 6)){
                             if(cacheSection){
-                                for(let i =0; i < sels[sel].rowCount; i++){
+                                for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
                                     if(sels[sel].row + i < cacheSection.length){
                                         for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
                                             if(lockCols.indexOf(col) === -1){
@@ -168,7 +166,9 @@ var rationOprObj = {
                                             }
                                         }
                                     }
-                                    updateArr.push(cacheSection[sels[sel].row + i]);
+                                    if(cacheSection[sels[sel].row + i] && typeof cacheSection[sels[sel].row + i] !== 'undefined'){
+                                        updateArr.push(cacheSection[sels[sel].row + i]);
+                                    }
                                 }
                             }
                         }
@@ -184,7 +184,6 @@ var rationOprObj = {
         me.workBook.commandManager().setShortcutKey('rationDelete', GC.Spread.Commands.Key.del, false, false, false, false);
     },
     onRangeChanged: function(sender, args) {
-        console.log(`sdad`);
         if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
             var me = rationOprObj, updateArr = [], removeArr = [];
             var cacheSection = me.getCache();
@@ -303,13 +302,13 @@ var rationOprObj = {
             if (!sheetCommonObj.chkIfEmpty(rObj, me.setting)) {
                 //addArr.push(rObj);
                 me.addRationItem = rObj;
-                if(rObj.code){
+                if(rObj.code && rObj.code.trim().length > 0){
                     if(me.rationsCodes.indexOf(rObj.code) === -1){
                         addArr.push(rObj);
                         me.rationsCodes.push(rObj.code);
                         me.addRationItem = null;
                     }
-                    else{
+                    else if(!rObj.code && rObj.code === ''){
                         $('#alertModalBtn').click();
                         me.workBook.getSheet(0).options.isProtected = true;
                         $('#alertModalCls').click(function () {
@@ -326,6 +325,9 @@ var rationOprObj = {
                         });
                     }
                 }
+                else if(rObj.code && rObj.code.trim().length === 0){
+                    me.workBook.getSheet(0).setValue(args.row, args.col, '');
+                }
             }
         }
         if (updateArr.length > 0 || addArr.length > 0) {
@@ -335,50 +337,68 @@ var rationOprObj = {
     },
     onClipboardPasting: function(sender, args) {
         var me = rationOprObj;
-        console.log(`args`);
-        console.log(args);
       /*  if (args.cellRange.colCount != me.setting.header.length) {
             args.cancel = true;
         }*/
     },
     onClipboardPasted: function(e, info) {
-        console.log(`info`);
-        console.log(info);
         var me = rationOprObj;
         var cacheSection = me.getCache();
-        console.log(`cache`);
-        console.log(cacheSection);
         var updateArr = [], addArr = [];
         var items = sheetCommonObj.analyzePasteData(me.setting, info);
-        console.log(`items`);
-        console.log(items);
-        for (var i = 0; i < items.length; i++) {
+        let failPasteArr = [];
+        for (var i = 0, rowIdx =info.cellRange.row; i < items.length; i++, rowIdx++) {
             if (cacheSection) {
-                var hasCacheItem = false;
-                for (var j = 0; j < cacheSection.length; j++) {
-                    if (cacheSection[j][me.setting.header[0].dataCode] == items[i][me.setting.header[0].dataCode]) {
-                        hasCacheItem = true;
-                        items[i]["ID"] = cacheSection[j]["ID"];
-                        break;
+                //var hasCacheItem = false;
+                if(!cacheSection[rowIdx] && info.cellRange.col === 0 ){
+                    if(me.rationsCodes.indexOf(items[i].code) === -1){
+                        addArr.push(items[i]);
+                        me.rationsCodes.push(items[i].code);
+                    }
+                    else{
+                        failPasteArr.push(items[i].code);
+                        me.workBook.getSheet(0).setValue(rowIdx, 0, '');
                     }
                 }
-                if (!hasCacheItem && info.cellRange.col === 0) {
-                    addArr.push(items[i]);
-                } else if(hasCacheItem){
-                    updateArr.push(items[i]);
+                else if(cacheSection[rowIdx]){
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        if(!items[i][me.setting.header[col].dataCode] && typeof cacheSection[rowIdx][me.setting.header[col].dataCode] !== 'undefined'){
+                            items[i][me.setting.header[col].dataCode] = cacheSection[rowIdx][me.setting.header[col].dataCode];
+                        }
+                    }
+                    if(info.cellRange.col === 0){
+                        if(me.rationsCodes.indexOf(items[i].code) === -1){
+                            items[i].ID = cacheSection[rowIdx].ID;
+                            updateArr.push(items[i]);
+                        }
+                        else{
+                            me.workBook.getSheet(0).setValue(rowIdx, 0, cacheSection[rowIdx].code);
+                        }
+                    }
+                    else{
+                        items[i].ID = cacheSection[rowIdx].ID;
+                        updateArr.push(items[i]);
+                    }
                 }
+
             } else {
                 //add
                 if(info.cellRange.col === 0){
-                    addArr.push(items[i])
+                    //是否含有已存在的编号
+                        if(me.rationsCodes.indexOf(items[i].code) === -1){
+                            addArr.push(items[i]);
+                        }
+                        else{
+                            failPasteArr.push(items[i]);
+                        }
                 }
             }
         };
-        console.log(`updateArr`);
-        console.log(updateArr);
-        console.log(addArr);
-        if (updateArr.length > 0 || addArr.length > 0) {
-            //me.mixUpdateRequest(updateArr, addArr, []);
+       /* if(failPasteArr.length > 0 && !(updateArr.length > 0 || addArr.length > 0)){
+            me.showRationItems(me.currentSectionId);
+        }*/
+         if (updateArr.length > 0 || addArr.length > 0) {
+            me.mixUpdateRequest(updateArr, addArr, []);
         }
     },
     getRationsCodes: function (repId) {
@@ -405,8 +425,8 @@ var rationOprObj = {
             cache:false,
             timeout:5000,
             success:function(result){
-                if (result.err) {
-                    alert(err);
+                if (result.error) {
+                    alert(`error`);
                     me.getRationItems(me.currentSectionId);
                 } else {
                     var cacheSection = me.updateCache(addArr, updateArr, removeIds, result);
@@ -417,6 +437,9 @@ var rationOprObj = {
                         return rst;
                     });
                     me.showRationItems(me.currentSectionId);
+                   /* me.workBook.getSheet(0).setActiveCell(me.activeCell.row, me.activeCell.col);
+                    let spreadBook = new GC.Spread.Sheets.Workbook(rationOprObj.sheet, { sheetCount: 1 });
+                    spreadBook.focus(true);*/
                 }
             },
             error:function(){

+ 110 - 4
web/maintain/ration_repository/js/ration_glj.js

@@ -5,6 +5,7 @@ var rationGLJOprObj = {
     sheet: null,
     currentRationItem: null,
     distTypeTree: null,
+    activeCell: null,
     cache: {},
     setting: {
         header:[
@@ -17,7 +18,7 @@ var rationGLJOprObj = {
         ],
         view:{
             comboBox:[],
-            lockColumns:[1,2,3,5,6]
+            lockColumns:[1,2,3,5]
         }
     },
     getDistTypeTree: function (gljDistType) {
@@ -81,12 +82,81 @@ var rationGLJOprObj = {
         me.getGljDistType(function () {
             me.onContextmenuOpr();
             sheetCommonObj.initSheet(me.sheet, me.setting, 30);
+            me.rationGljDelOpr();
             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.onCellEditEnd);
-            me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
+            //me.sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
         });
     },
+    rationGljDelOpr: function () {
+        let me = rationGLJOprObj, spreadBook = me.sheet.getParent();
+        spreadBook.commandManager().register('rationGljDelete', function () {
+            console.log(me.cache["_GLJ_" + me.currentRationItem.ID]);
+            let sels = me.sheet.getSelections(), updateArr = [], removeArr = [], lockCols = me.setting.view.lockColumns;
+            let cacheSection = me.cache["_GLJ_" + me.currentRationItem.ID], isUpdate = false;
+            console.log(`sels`);
+            console.log(sels);
+            if(sels.length > 0){
+                for(let sel = 0; sel < sels.length; sel++){
+                    if(sels[sel].colCount === me.setting.header.length){
+                        if(cacheSection){
+                            for(let i = 0; i < sels[sel].rowCount; i++){
+                                if(sels[sel].row + i < cacheSection.length){
+                                    //removeArr.push(cacheSection[sels[sel].row + i].ID);
+                                    isUpdate = true;
+                                    cacheSection.splice(sels[sel].row + i, 1);
+                                    me.updateRationItem();
+                                    //me.rationsCodes.splice(me.rationsCodes.indexOf(cacheSection[sels[sel].row + i].code), 1);
+                                }
+                            }
+                        }
+                    }
+                    else{
+                        if(sels[sel].col === 0){
+                            $('#alertText').text("编号不能为空,修改失败!");
+                            $('#alertModalBtn').click();
+                            me.sheet.options.isProtected = true;
+                            $('#alertModalCls').click(function () {
+                                me.sheet.options.isProtected = false;
+                            });
+                            $('#alertModalCof').click(function () {
+                                me.sheet.options.isProtected = false;
+                            });
+                        }
+                        else if(sels[sel].col !== 0 && sels[sel].col !== 5 && !(sels[sel].col === 1 && sels.col + sels[sel].colCount -1 === 3)){
+                            console.log(`enter`);
+                            if(cacheSection){
+                                for(let i = sels[sel].row === -1 ? 1 : 0; i < sels[sel].rowCount; i++){
+                                    if(sels[sel].row + i < cacheSection.length){
+                                        for(let col = sels[sel].col; col <= sels[sel].col + sels[sel].colCount - 1; col++){
+                                            if(lockCols.indexOf(col) === -1){
+                                                isUpdate = true;
+                                                cacheSection[sels[sel].row + i][me.setting.header[col].dataCode] = 0;
+                                                me.sheet.setValue(sels[sel].row + i, col, 0.00);
+                                            }
+                                        }
+                                    }
+                                    //updateArr.push(cacheSection[sels[sel].row + i]);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if(isUpdate){
+                me.updateRationItem();
+                sheetCommonObj.cleanSheet(me.sheet, me.setting, -1);
+                me.showGljItems(me.currentRationItem.ID);
+            }
+           /* if(updateArr.length > 0 || removeArr.length > 0){
+                me.mixUpdateRequest(updateArr, [], removeArr);
+            }*/
+
+        });
+        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 = [];
@@ -108,9 +178,9 @@ var rationGLJOprObj = {
     },
     onClipboardPasting: function(sender, args) {
         var me = rationGLJOprObj;
-        if (args.cellRange.colCount != 1 || args.cellRange.col != 0 || !(me.currentRationItem)) {
+        /*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");
@@ -124,6 +194,29 @@ var rationGLJOprObj = {
                 me.addGljItems(codes, repId);
             } else {
                 //修改用量
+                if(me.cache["_GLJ_" + me.currentRationItem.ID] && info.cellRange.row < me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                    let tempConsumes = sheetCommonObj.analyzePasteData(me.setting, info);
+                    let maxCount = info.cellRange.row + info.cellRange.rowCount -1 > me.cache["_GLJ_" + me.currentRationItem.ID].length -1 ?
+                        me.cache["_GLJ_" + me.currentRationItem.ID].length - info.cellRange.row : info.cellRange.rowCount;
+                    for(let i = 0; i < maxCount; i++){
+                        me.cache["_GLJ_" + me.currentRationItem.ID][info.cellRange.row + i].consumeAmt = tempConsumes[i].consumeAmt;
+                    }
+                    me.updateRationItem();
+                    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++){
+                            me.sheet.setValue(rowIdx, info.cellRange.col, '');
+                        }
+                        me.sheet.resumePaint();
+                    }
+                }
+                else if(info.cellRange.row >= me.cache["_GLJ_" + me.currentRationItem.ID].length){
+                    me.sheet.suspendPaint();
+                    for(let rowIdx = info.cellRange.row; rowIdx <= info.cellRange.row + info.cellRange.rowCount -1; rowIdx ++){
+                        me.sheet.setValue(rowIdx, info.cellRange.col, '');
+                    }
+                    me.sheet.resumePaint();
+                }
             }
         }
     },
@@ -366,6 +459,19 @@ var rationGLJOprObj = {
                                 }
                             }
                         }
+                        function compare(){
+                            return function (a, b) {
+                                let rst = 0;
+                                if (a.code > b.code) {
+                                    rst = 1;
+                                }
+                                else if (a.code < b.code) {
+                                    rst = -1;
+                                }
+                                return rst;
+                            }
+                        }
+                        cacheArr.sort(compare());
                         me.cache["_GLJ_" + rationID] = cacheArr;
                         me.showGljItems(rationID);
                     }

+ 235 - 28
web/maintain/ration_repository/js/repository_glj.js

@@ -274,9 +274,11 @@ var pageOprObj = {
     },
     onCellEditEnd: function(sender, args) {
         var me = repositoryGljObj, rObj = sheetCommonObj.combineRowData(me.workBook.getSheet(0), me.setting, args.row, me),
-            updateArr = [], addArr = [];
+            updateArr = [], addArr = [], updateBasePrcArr = [];
         me.editingRowIdx = args.row;
         rObj.basePrice = rObj.basePrice ? rObj.basePrice : 0;
+        console.log(`rObj`);
+        console.log(rObj);
         if (me.currentEditingGlj["ID"]) {
             rObj["ID"] = me.currentEditingGlj["ID"];
             rObj.gljClass = me.currentEditingGlj.gljClass;
@@ -301,13 +303,15 @@ var pageOprObj = {
                 }
                 let gljBasePrcObj = {gljId: me.currentEditingGlj.ID, gljType: gljType, basePrice: rObj.basePrice};
                 if(gljBasePrcObj.gljType !== -1){
-                    me.updateRationBasePrcRq(gljBasePrcObj);
+                    updateBasePrcArr.push(gljBasePrcObj);
+                    me.updateRationBasePrcRq(updateBasePrcArr);
                 }
             }
             //update basePrice of ration when editting gljType of glj
             if(me.currentEditingGlj.gljType !== rObj.gljType){
                let gljTypeObj = {gljId: me.currentEditingGlj.ID, gljType: rObj.gljType, basePrice: rObj.basePrice};
-                me.updateRationBasePrcRq(gljTypeObj);
+                updateBasePrcArr.push(gljTypeObj);
+                me.updateRationBasePrcRq(updateBasePrcArr);
             }
         } else {
             me.addGljObj = rObj;
@@ -325,6 +329,8 @@ var pageOprObj = {
         }
         if(updateArr.length >0 || addArr.length >0){
             me.currentEditingGlj = null;
+            //me.workBook.getSheet(0).setValue(11, 5, "人工");
+            console.log(addArr);
             me.mixUpdateRequest(updateArr, addArr, []);
         }
     },
@@ -447,41 +453,220 @@ var pageOprObj = {
              }
          }
      },
-    onClipboardPasting: function(sender, args) {
-        var me = repositoryGljObj;
-        if (args.cellRange.colCount != me.setting.header.length || me.gljCurTypeId < 0 || me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
-            args.cancel = true;
-        }
-    },
+     validUpdateObj: function (pasteObj, rowIdx) {
+         let rst = {}, backUpObj = {},
+             me = repositoryGljObj,
+             tempObj = me.currentCache[rowIdx],
+             reCalBasePrc = false, isValid = true;
+         //备份原始数据
+         for(let atr in tempObj){
+             backUpObj[atr] = tempObj[atr];
+         }
+         if(typeof pasteObj.code !== 'undefined'){
+             if(pasteObj.code.trim().length !== 0){
+                 let isExist = false;
+                 for(let i = 0; i < me.gljList.length; i++){
+                     if(me.gljList[i].code === pasteObj.code){
+                         isExist = true;
+                         break;
+                     }
+                 }
+                 if(!isExist){
+                     tempObj.code = pasteObj.code;
+                 }
+                 else isValid = false;
+             }
+             else isValid = false;
+         }
+         if(typeof pasteObj.name !== 'undefined'){
+             if(pasteObj.name.trim().length === 0) isValid = false;
+             else tempObj.name = pasteObj.name;
+         }
+         if(typeof pasteObj.specs !== 'undefined'){
+             tempObj.specs = pasteObj.specs;
+         }
+         if(typeof pasteObj.unit !== 'undefined'){
+             tempObj.unit = pasteObj.unit;
+         }
+         if(typeof pasteObj.gljType !== 'undefined'){
+             let isExsit = false;
+             for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
+                 if(pasteObj.gljType === me.distTypeTree.comboDatas[i].text){
+                     isExsit = true;
+                     reCalBasePrc = true;
+                     tempObj.gljType = me.distTypeTree.comboDatas[i].value;
+                     tempObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + tempObj.gljType].data.shortName;
+
+                 }
+             }
+             if(!isExsit) isValid = false;
+         }
+         //
+         pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) :
+                                me.currentCache[rowIdx].basePrice;
+         if(pasteObj.basePrice !== me.currentCache[rowIdx].basePrice){
+             reCalBasePrc = true;
+             tempObj.basePrice = pasteObj.basePrice;
+         }
+         if(isValid){
+             rst.updateGlj = tempObj;
+             if(reCalBasePrc){
+                 //重新计算定额基价对象
+                 rst.updateBasePrc = {gljId: tempObj.ID, gljType: tempObj.gljType, basePrice: tempObj.basePrice};
+             }
+         }
+         else {
+             for(let attr in backUpObj){
+                 tempObj[attr] = backUpObj[attr];
+             }
+         }
+         return rst;
+     },
+     //粘贴的数据是否是可添加的数据,只有含有编号,名称,类型才可添加
+     isValidObj: function(pasteObj) {
+        let me = repositoryGljObj;
+         if(!(pasteObj.code && typeof pasteObj.code !== 'undefined') || !(pasteObj.name && typeof pasteObj.name !== 'undefined') ||
+         !(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined')){
+             return false;
+         }
+         if(pasteObj.gljType && typeof pasteObj.gljType !== 'undefined'){
+             let isExist = false;
+             for(let i = 0; i < me.distTypeTree.comboDatas.length; i++){
+                 if(me.distTypeTree.comboDatas[i].text === pasteObj.gljType){
+                     isExist = true;
+                     pasteObj.gljType = me.distTypeTree.comboDatas[i].value;
+                     pasteObj.shortName = me.distTypeTree.distTypes[me.distTypeTree.prefix + pasteObj.gljType].data.shortName;
+                     break;
+                 }
+             }
+             if(!isExist){
+                 return false;
+             }
+         }
+         if(pasteObj.code && typeof pasteObj.code !== 'undefined'){
+            for(let i = 0; i < me.gljList.length; i++){
+                if(me.gljList[i].code === pasteObj.code){
+                    return false;
+                }
+            }
+         }
+         pasteObj.basePrice = !isNaN(parseFloat(pasteObj.basePrice)) && (pasteObj.basePrice && typeof pasteObj.basePrice !== 'undefined') ? parseFloat(pasteObj.basePrice) : 0;
+         pasteObj.gljClass = me.gljCurTypeId;
+         return true;
+     },
+     onClipboardPasting: function(sender, args) {
+         var me = repositoryGljObj;
+         /*if (args.cellRange.colCount != me.setting.header.length || me.gljCurTypeId < 0 || me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
+          args.cancel = true;
+          }*/
+         if (me.gljCurTypeId < 0 ) {
+             args.cancel = true;
+         }
+     },
     onClipboardPasted: function(e, info) {
         var me = repositoryGljObj;
         var updateArr = [], addArr = [];
         var items = sheetCommonObj.analyzePasteData(me.setting, info);
-        var hasCacheItem = false;
-        for (var i = 0; i < items.length; i++) {
-            for (var j = 0; j < me.gljList.length; j++) {
-                if (me.gljList[j][me.setting.header[0].dataCode] == items[i][me.setting.header[0].dataCode]) {
-                    hasCacheItem = true;
-                    items[i]["ID"] = me.gljList[j]["ID"];
-                    break;
+        let beginRow = info.cellRange.row, endRow = info.cellRange.row + info.cellRange.rowCount - 1,
+            maxRow = me.currentCache.length - 1, updateItems = [], addItems = [], updateBasePrcArr = [] , updateCount, resumeArr = [];
+        if(endRow <= maxRow){
+            //updateItems = items;
+            for(let i = 0; i < items.length; i++){
+                let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
+                if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
+                    updateArr.push(updateObj.updateGlj);
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                        updateBasePrcArr.push(updateObj.updateBasePrc);
+                    }
+                }
+                else{
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        else if(beginRow <= maxRow && endRow > maxRow){
+            updateCount = maxRow - beginRow + 1;
+            for(let i = 0; i < updateCount; i++){
+                let updateObj = me.validUpdateObj(items[i], info.cellRange.row + i);
+                if(updateObj && typeof updateObj.updateGlj !== 'undefined'){
+                    updateArr.push(updateObj.updateGlj);
+                    if(typeof updateObj.updateBasePrc !== 'undefined'){
+                        updateBasePrcArr.push(updateObj.updateBasePrc);
+                    }
+                }
+                else{
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+            if(info.cellRange.colCount === me.setting.header.length){
+                for(let i = updateCount ; i < items.length; i++){
+                    if(me.isValidObj(items[i])){
+                        addItems.push(items[i]);
+                        addArr.push(items[i]);
+                    }
+                    else{
+                        resumeArr.push(info.cellRange.row + i);
+                    }
+                }
+            }
+            else{
+                for(let i = updateCount ; i < items.length; i++){
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        else{
+            if(info.cellRange.colCount === me.setting.header.length){
+                for(let i = 0; i < items.length; i++){
+                    if(me.isValidObj(items[i])){
+                        addArr.push(items[i]);
+                    }
+                    else{
+                        resumeArr.push(info.cellRange.row + i);
+                    }
                 }
             }
-            if (!hasCacheItem) {
-                items[i].gljType = me.gljCurTypeId;
-                addArr.push(items[i]);
-            } else {
-                updateArr.push(items[i]);
+            else{
+                for(let i = 0; i < items.length; i++){
+                    resumeArr.push(info.cellRange.row + i);
+                }
+            }
+        }
+        //repaint
+        if(resumeArr.length > 0){
+            info.sheet.suspendPaint();
+            for(let i = 0; i < resumeArr.length ; i++){
+                if(resumeArr[i] < me.currentCache.length){
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        if(me.setting.header[col].dataCode === 'gljType'){
+                            let gljType = me.currentCache[resumeArr[i]][me.setting.header[col].dataCode];
+                            info.sheet.setValue(resumeArr[i], col, me.distTypeTree.distTypes["gljType" + gljType].data.fullName);
+                        }
+                        else{
+                            info.sheet.setValue(resumeArr[i], col, me.currentCache[resumeArr[i]][me.setting.header[col].dataCode]);
+                        }
+                    }
+                }
+                else{
+                    for(let col = 0; col < me.setting.header.length; col++){
+                        info.sheet.setValue(resumeArr[i], col, '');
+                    }
+                }
             }
+            info.sheet.resumePaint();
         }
         if (updateArr.length > 0 || addArr.length > 0) {
-            me.mixUpdateRequest(updateArr, addArr, []);
+           me.mixUpdateRequest(updateArr, addArr, []);
+        }
+        if(updateBasePrcArr.length > 0){
+           me.updateRationBasePrcRq(updateBasePrcArr);
         }
     },
-    updateRationBasePrcRq: function (gljObj) {
+    updateRationBasePrcRq: function (basePrcArr) {
         $.ajax({
             type: 'post',
             url: 'api/updateRationBasePrc',
-            data:{data: JSON.stringify({repId: pageOprObj.rationLibId, lastOpr: userAccount, gljId: gljObj.gljId, basePrice: gljObj.basePrice, gljType: gljObj.gljType})},
+            data:{data: JSON.stringify({repId: pageOprObj.rationLibId, lastOpr: userAccount, basePrcArr: basePrcArr})},
             dataType: 'json',
             success: function (result) {
                 if(result.error){
@@ -518,10 +703,14 @@ var pageOprObj = {
                     alert(result.message);
                     me.getRationItems(me.currentRepositoryId);
                 } else {
-                    console.log(`enterSc`);
                     me.updateCache(addArr, updateArr, removeIds, result);
                     me.sortGlj();
-                    me.currentCache = me.getCache();
+                    if(me.currentOprParent === 1){
+                        me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
+                    }
+                    else{
+                        me.currentCache = me.getCache();
+                    }
                     me.showGljItems(me.gljList, me.gljCurTypeId);
                 }
             },
@@ -530,6 +719,21 @@ var pageOprObj = {
             }
         })
     },
+     getParentCache: function (nodes) {
+        let me = repositoryGljObj, rst = [];
+        for(let i = 0; i < me.gljList.length; i++){
+            if(nodes.indexOf(me.gljList[i].gljClass) !== -1){
+                rst.push(me.gljList[i]);
+            }
+        }
+         rst.sort(function (a, b) {
+             let rst = 0;
+             if(a.code > b.code) rst = 1;
+             else if(a.code < b.code)rst = -1;
+             return rst;
+         });
+         return rst;
+     },
     getCache: function() {
         var me = this, rst = [];
         for (var i = 0; i < me.gljList.length; i++) {
@@ -591,13 +795,16 @@ var gljTypeTreeOprObj = {
         var me = repositoryGljObj,
             gljTypeId = treeNode.ID;
         me.gljCurTypeId = treeNode.ID;
-        me.currentCache = me.getCache();
+        //me.currentCache = me.getCache();
         me.showGljItems(me.gljList, gljTypeId);
-        console.log(me.gljCurTypeId);
         if (me.parentNodeIds["_pNodeId_" + treeNode.ID]) {
+            me.currentOprParent = 1;
+            me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + treeNode.ID]);
             sheetCommonObj.lockCodeCells(me.workBook.getSheet(0), me.gljList.length);
             //sheetCommonObj.shieldAllCells(me.workBook.getSheet(0), me.setting);
         } else {
+            me.currentOprParent = 0;
+            me.currentCache = me.getCache();
             sheetCommonObj.unShieldAllCells(me.workBook.getSheet(0));
         }
     },