Browse Source

清单sheet复制粘贴

zhongzewei 8 years ago
parent
commit
2225ef5fab

+ 6 - 0
modules/billsLib/billsLibControllers/billsLibControllers.js

@@ -89,6 +89,12 @@ module.exports = {
            callback(req, res, err, message, null);
         });
     },
+    pasteBills: function(req, res){
+        var data = JSON.parse(req.body.data);
+        billsLibDao.pasteBills(data, function(err, message){
+            callback(req, res, err, message, null);
+        });
+    },
     updateRecharge: function(req, res){
       var data = JSON.parse(req.body.data);
         billsLibDao.updateRecharge(data, function(err, message){

+ 12 - 28
modules/billsLib/billsLibModel/billsLibInterfaces.js

@@ -374,6 +374,17 @@ billsLibDao.prototype.updateBillsArr = function(updateData, callback){
             });
         }
     }
+};
+
+billsLibDao.prototype.pasteBills = function(pData, callback){
+    var datas = pData.datas;
+    datas.forEach(function(data){
+        Bills.update({billsLibId: data.billsLibId, ID: data.ID}, {$set: {code: data.code, name: data.name, unit: data.unit, ruleText: data.ruleText}}, function(err){
+            if(err){
+                callback(1, 'Error');
+            }
+        });
+    });
 }
 
 billsLibDao.prototype.updateRecharge = function(uData, callback){
@@ -393,29 +404,13 @@ billsLibDao.prototype.updateRecharge = function(uData, callback){
         callback(0, '');
     }
 };
-//todo: test $in
+
 billsLibDao.prototype.deleteBills = function(delData, callback){
     var deleteIds = delData.deleteIds;
     var billsLibId = delData.billsLibId;
     var success = true;
     if(deleteIds){
-        //deleteIds.forEach(function(deleteId){
-        /*Bills.remove({billsLibId: billsLibId, ID: {$in: deleteIds}}, function(err){
-         if(err){
-         callback(1, 'Error');
-         }
-         else {
-         callback(0, '');
-         }
-         });*/
-        //  });
         deleteIds.forEach(function(delId){
-            /*Bills.remove({billsLibId: billsLibId, ID: delId}, function(err){
-                if(err){
-                    success = false;
-                    callback(1, 'Error');
-                }
-            });*/
             Bills.update({billsLibId: billsLibId, ID: delId}, {$set: {deleted: true}}, function(err){
                 if(err){
                     success = false;
@@ -431,17 +426,6 @@ billsLibDao.prototype.deleteBills = function(delData, callback){
 
 //--------------JobContent------------------
 
-/*billsLibDao.prototype.getJobContent = function(gJobData, callback){
- var billsLibId = gJobData.billsLibId;
- JobContent.find({billsLibId: billsLibId}, "-_id", function(err, jobs){
- if(err){
- callback(1, "Error", null);
- }
- else{
- callback(0, "", jobs)
- }
- });
- }*/
 billsLibDao.prototype.getJobContent = function(gJobData, callback){
     var billsLibId = gJobData.billsLibId;
     JobContent.find({billsLibId: billsLibId, deleted: false}, '-_id').sort({code: 1}).exec(function(err, result){

+ 1 - 0
modules/billsLib/billsLibRoutes/billsLibRoutes.js

@@ -17,6 +17,7 @@ billsRouter.post("/createBills", billsController.createBills);
 billsRouter.post("/updatePNId", billsController.updatePNId);
 billsRouter.post("/updateBills", billsController.updateBills);
 billsRouter.post("/updateBillsArr", billsController.updateBillsArr);
+billsRouter.post("/pasteBills", billsController.pasteBills);
 billsRouter.post('/updateRecharge', billsController.updateRecharge);
 billsRouter.post("/deleteBills", billsController.deleteBills);
 billsRouter.post("/getJobContent", billsController.getJobContent);

+ 2 - 1
web/billsLib/html/neirong.html

@@ -199,7 +199,8 @@
             TREE_SHEET_HELPER.loadSheetHeader(setting, spreadAllJobs.getActiveSheet());
             jobsAjax.getJobContent(billsLibId, function(datas){
                 spreadAllJobs.getActiveSheet().suspendPaint();
-                for(var i=0; i<datas.length; i++){
+                var len = datas.length;
+                for(var i=0; i<len; i++){
                     setting.cols.forEach(function(col, colIdx){
                         spreadAllJobs.getActiveSheet().setTag(i, colIdx, datas[i].id, GC.Spread.Sheets.SheetArea.viewport);
                         if(datas[i][col.data.field]){

+ 48 - 4
web/billsLib/html/qingdan.html

@@ -11,8 +11,6 @@
     <link rel="stylesheet" href="web/css/font-awesome/font-awesome.min.css">
     <!--spread-->
     <link rel="stylesheet" href="web/css/spreadjs/gc.spread.sheets.excel2013white.10.0.1.css">
-    <!--zTree-->
-    <link rel="stylesheet" href="web/css/ztree/zTreeStyle.css" type="text/css">
 </head>
 
 <body>
@@ -204,6 +202,13 @@
             </div>
         </div>
     </div>
+    <!--弹出提示窗口-->
+    <div class="modal fade" id="qAlert" style="display: none; margin: 300px auto; width: 300px; height: 200px;">
+        <div id="alertText"></div>
+        <div style="margin: 50px auto">
+            <button id="alertBtn" class="btn btn-warning">确定</button>
+        </div>
+    </div>
     <!-- JS. -->
     <script src="lib/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
     <script src="lib/jquery/jquery.min.js"></script>
@@ -278,6 +283,8 @@
         setSheet.initSheet(billsSpread, setting);
         myKey.delKey(billsSpread);
         billsTree.loadDatas(datas);
+        //粘贴事件
+        bindPasteBills(billsSpread.getActiveSheet(), setting);
         var controller = TREE_SHEET_CONTROLLER.createNew(billsTree.tree, billsSpread.getActiveSheet(), setting);
         controller.showTreeData();
         //setTagId
@@ -301,14 +308,16 @@
     }
 
     function setTagID(controller, setting){
-            for(var i=0; i<controller.tree.items.length; i++){
+        if(controller.tree.items.length > 0){
+            var length = controller.tree.items.length;
+            for(var i=0; i<length; i++){
                 setting.cols.forEach(function(col, colIdx){
                     if(controller.tree.items[i].data.ID){
                         controller.sheet.setTag(i, colIdx, controller.tree.items[i].data.ID);
                     }
                 });
             }
-
+        }
     }
 
     function refreshBtn(controller){
@@ -423,6 +432,41 @@
         });
     }
 
+    function bindPasteBills(sheet, setting){
+        sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, function(sender, args){
+            var datas = [], field;
+            var orgRow = args.cellRange.row, orgCol = args.cellRange.col, rowCount = args.cellRange.rowCount, colCount = args.cellRange.colCount;
+            var maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
+            for(var i=orgRow; i<= maxRow; i++){
+                var id =  sheet.getTag(i, 0, GC.Spread.Sheets.SheetArea.viewport);
+                if(id){
+                    var pasteJson = {billsLibId: billsLibId, ID: id, code: null, name: null, unit: null, ruleText: null};
+                    var colLen = sheet.getColumnCount(GC.Spread.Sheets.SheetArea.viewport);
+                    for(var j=0; j<colLen; j++){
+                        setting.cols.forEach(function(col, colIdx){
+                            if(colIdx === j){
+                                field = col.data.field;
+                            }
+                        });
+                        pasteJson[field] = sheet.getValue(i, j);
+                    }
+                    datas.push(pasteJson);
+                }
+                else {
+                    sheet.clear(i, 0, 1, sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport,GC.Spread.Sheets.StorageType.data);
+                }
+            }
+            billsAjax.pasteBills(datas);
+        });
+    }
+
+    function bindPasteRel(sheet, setting){
+        sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, function(sender, args){
+            var orgRow = args.cellRange.row, orgCol = args.cellRange.col, rowCount = args.cellRange.rowCount, colCount = args.cellRange.colCount;
+            var maxRow = orgRow + rowCount - 1, maxCol = orgCol + colCount -1;
+        });
+    }
+
 
     function buildJobs(jobsSpread, setting){
         setSheet.initSheet(jobsSpread, setting);

+ 2 - 3
web/billsLib/html/tezheng.html

@@ -206,7 +206,8 @@
             TREE_SHEET_HELPER.loadSheetHeader(setting, spread.getActiveSheet());
             itemsAjax.getItemCharacter(billsLibId, function(datas){
                 spread.getActiveSheet().suspendPaint();
-                for(var i=0; i<datas.length; i++){
+                var len = datas.length;
+                for(var i=0; i<len; i++){
                     if(datas[0].id){
                         selectedId = datas[0].id;
                     }
@@ -263,8 +264,6 @@
                     selectedId = itemId;
                     tools.reshowValue(valueSheet, valueArr, eigenValueSetting, true);
                     orgValue = valueSheet.getValue(0, 0);
-                    //
-                    console.log('bindSelectedID: ' + selectedId);
                 }
                 else {
                     tools.clearData(valueSheet);

+ 12 - 15
web/billsLib/scripts/billsLibAjax.js

@@ -159,21 +159,7 @@ var billsAjax = {
             }
         });
     },
-   /* updatePNId: function(billsLibId, updateId, pid, nid, callback){
-        $.ajax({
-            type: 'post',
-            url: 'stdBillsEditor/updatePNId',
-            data: {data: JSON.stringify({billsLibId: billsLibId, updateId: updateId, ParentID: pid, NextSiblingID: nid})},
-            dataType: 'json',
-            success: function(result){
-                if(!result.error){
-                    if(callback){
-                        callback();
-                    }
-                }
-            }
-        });
-    },*/
+
     updatePNId: function(billsLibId, updateData, callback){
         $.ajax({
             type: 'post',
@@ -226,6 +212,17 @@ var billsAjax = {
             }
         });
     },
+    pasteBills: function(datas){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/pasteBills',
+            data: {data: JSON.stringify({datas: datas})},
+            dataType: 'json',
+            success: function(result){
+
+            }
+        });
+    },
     updateRecharge: function(billsLibId, updateIds, data){
         $.ajax({
             type: 'post',

+ 95 - 72
web/billsLib/scripts/dbController.js

@@ -42,8 +42,9 @@ var dbController = {
         var getDeleteIds = function(node){
             if(node){
                 deleteIds.push(node.getID());
-                if(node.children.length > 0){
-                    for(var i=0; i<node.children.length; i++){
+                var length = node.children.length;
+                if(length > 0){
+                    for(var i=0; i<length; i++){
                         getDeleteIds(node.children[i]);
                     }
                 }
@@ -456,7 +457,8 @@ var tools = {
             tools.resort(arr, 'code', false);
         }
         if(arr.length > 0){
-            for(var i=0; i<arr.length; i++){
+            var length = arr.length;
+            for(var i=0; i<length; i++){
                 setting.cols.forEach(function(col, colIdx){
                     sheet.setTag(i, colIdx, arr[i].data.id);
                     if(arr[i].data[col.data.field]){
@@ -476,7 +478,8 @@ var tools = {
             tools.resort(arr, 'code', true);
         }
         if(arr.length > 0){
-            for(var i=0; i<arr.length; i++){
+            var length = arr.length;
+            for(var i=0; i<length; i++){
                 setting.cols.forEach(function(col, colIdx){
                     sheet.setTag(i, colIdx, arr[i].code);
                     if(arr[i][col.data.field]){
@@ -567,7 +570,6 @@ var jobsController = {
                 }
                 //处理重复
                 if(isRepeat){
-                    //todo:redirect focus
                     if(id && newData){
                         sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgJobData);
                     }
@@ -593,7 +595,6 @@ var jobsController = {
                 totalJobs.jobs[totalJobs.prefix + id] = newJob;
                 totalJobs.jobsArr.push(newJob);
                 billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', id);
-                //tools.addAttr(controller.tree.selected.jobs);
                 controller.tree.selected.jobs.push(newJob);
                 tools.reshowData(sheet, controller.tree.selected.jobs, setting, true);
             });
@@ -605,20 +606,14 @@ var jobsController = {
 
     createExist: function(sheet, controller, totalJobs, field, newData, args, setting){
         totalJobs.jobsArr.forEach(function(job){
-            //todo:整合代码
             if(field === 'content'&& newData === job.data.content){
-                //isExist = true;
                 billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data.id);
-                //整合
-               // tools.addAttr(controller.tree.selected.jobs);
                 job.count++;
                 controller.tree.selected.jobs.push(job);
                 tools.reshowData(sheet, controller.tree.selected.jobs, setting, true);
             }
             else if(field == 'code' && newData == job.data.code){
-                //isExist = true;
                 billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'jobs', job.data.id);
-                //tools.addAttr(controller.tree.selected.jobs);
                 job.count++;
                 controller.tree.selected.jobs.push(job);
                 tools.reshowData(sheet, controller.tree.selected.jobs, setting, true);
@@ -634,7 +629,6 @@ var jobsController = {
                     job.count++;
                     controller.tree.selected.jobs.splice(index, 1);
                     controller.tree.selected.jobs.splice(index, 0, job);
-                   // var newJobData = {id: job.data.id, code: newData, content: job.data.content}
                     billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, job.data.id, 'update', 'jobs');
                     tools.reshowData(sheet, controller.tree.selected.jobs, setting, true);
                 }
@@ -643,7 +637,6 @@ var jobsController = {
                     job.count++;
                     controller.tree.selected.jobs.splice(index, 1);
                     controller.tree.selected.jobs.splice(index, 0, job);
-                    //var newJobData = {id: job.data.id, code: job.data.code, content: newData}
                     billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, job.data.id, 'update', 'jobs');
                     tools.reshowData(sheet, controller.tree.selected.jobs, setting, true);
                 }
@@ -660,7 +653,6 @@ var jobsController = {
                     totalJobs.jobs[totalJobs.prefix + newId] = newJob;
                     totalJobs.jobsArr.push(newJob);
                     billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), id, newId, 'update', 'jobs');
-                   // tools.addAttr(controller.tree.selected.jobs);
                     var index = tools.getIndex(controller.tree.selected.jobs, id);
                     controller.tree.selected.jobs.splice(index, 1);
                     controller.tree.selected.jobs.splice(index, 0, newJob);
@@ -668,7 +660,13 @@ var jobsController = {
                 });
             }
             else {
-                sheet.getCell(args.row, args.col).value(orgJobData);
+                //todo: 提示窗口
+                if(typeof newData === 'number'){
+                    sheet.getCell(args.row, args.col).value(orgJobData);
+                }
+                else {
+                  //编号只能是数字
+                }
             }
         }
     },
@@ -731,13 +729,17 @@ var itemsController = {
                 totalItems.items[totalItems.prefix + id] = newItem;
                 totalItems.itemsArr.push(newItem);
                 billsAjax.updateBills(billsLibId, controller.tree.selected.getID(), 'items', id);
-               // tools.addAttr(controller.tree.selected.items);
                 controller.tree.selected.items.push(newItem);
                 tools.reshowData(sheet, controller.tree.selected.items, setting, true);
             });
         }
         else {
-            sheet.getCell(args.row, args.col).value('');
+            if(typeof newData === 'number'){
+                sheet.getCell(args.row, args.col).value('');
+            }
+            else {
+                //编号只能为数字
+            }
         }
     },
 
@@ -806,7 +808,12 @@ var itemsController = {
                 });
             }
             else {
-                sheet.getCell(args.row, args.col).value(orgItemData);
+                if(typeof newData === 'number'){
+                    sheet.getCell(args.row, args.col).value(orgItemData);
+                }
+                else {
+                    //编号只能为数字
+                }
             }
         }
     },
@@ -828,30 +835,17 @@ var valueController = {
             if(selectedId){
                 isRepeat = tools.isRepeat(valueController.getValues(totalItems, selectedId), field, newValue, 'document');
                 if(!tagId && !isRepeat && newValue){//create
-                   // if(field === 'value'){
                         valueController.createValue(sheet, totalItems, selectedId, field, newValue);
-                  //  }
-                    /*else {
-                        sheet.getCell(args.row, args.col).value('');
-                    }*/
                 }
                 else if(tagId && !isRepeat && newValue !== orgValue){//update
-                   // if(field === 'value'){
                         valueController.updateValue(totalItems, tagId, newValue, field);
-                    console.log('updateV');
-                  //  }
-                   /* else {
-                        sheet.getCell(args.row, args.col).value(orgValue);
-                    }*/
                 }
                 if(isRepeat){
                     if(tagId && newValue){
                         sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value(orgValue);
-                        console.log('rePV1');
                     }
                     else {
                         sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).value('');
-                        console.log('rePV2');
                     }
                 }
             }
@@ -866,8 +860,13 @@ var valueController = {
             tools.reSetCell(sheet, sheet.getActiveRowIndex(), 0, newCode, newCode);
         }
         else {
-            newData = {code: newValue, value: ''};
-            tools.reSetCell(sheet, sheet.getActiveRowIndex(), null, null, newValue);
+            if(typeof newValue === 'number'){
+                newData = {code: newValue, value: ''};
+                tools.reSetCell(sheet, sheet.getActiveRowIndex(), null, null, newValue);
+            }
+            else {
+                //编号只能为数字!
+            }
         }
         totalItems.findItem(id).data.itemValue.push(newData);
         itemsAjax.updateValue(id, newData, null, 'create');
@@ -888,22 +887,28 @@ var valueController = {
                 });
                 itemVals.splice(index, 0, updateEle);
             }
+            itemsAjax.updateValue(selectedId, updateData, null, 'update');
         }
         else {
-            if(itemVals){
-                var updateEle;
-                var index;
-                itemVals.forEach(function(val){
-                    if(val.code === tagId){
-                        updateEle = {code: newData, value: val.value};
-                        index = itemVals.indexOf(val);
-                        itemVals.splice(index, 1);
-                    }
-                });
-                itemVals.splice(index, 0, updateEle);
+            if(typeof newData === 'number'){
+                if(itemVals){
+                    var updateEle;
+                    var index;
+                    itemVals.forEach(function(val){
+                        if(val.code === tagId){
+                            updateEle = {code: newData, value: val.value};
+                            index = itemVals.indexOf(val);
+                            itemVals.splice(index, 1);
+                        }
+                    });
+                    itemVals.splice(index, 0, updateEle);
+                }
+                itemsAjax.updateValue(selectedId, updateData, null, 'update');
+            }
+            else {
+                //编号只能为数字!
             }
         }
-        itemsAjax.updateValue(selectedId, updateData, null, 'update');
     },
 
     getValues: function(totalItems, id){
@@ -919,7 +924,6 @@ var valueController = {
         var valArr = totalItems.findItem(id).data.itemValue;
         tools.resort(valArr, 'code', true);
         return valArr.length > 0 ? valArr[valArr.length - 1].code + 1 : 1;
-        //return totalItems.findItem(id).data.itemValue.length;
     },
 
     isRepeat: function(arr, newValue){
@@ -975,25 +979,34 @@ var totalJobsController = {
             });
         }
         else {
-            maxJobsNumber = maxJobsNumber >= newData ? maxJobsNumber : newData;
-            console.log('maxJobs: ' + maxJobsNumber + 'code: ' + newData);
-            jobsAjax.createJobContent(billsLibId, field, '', newData, function(id){
-                var newJobData, newJob;
-                newJobData = {id: id, content: '', code: newData};
-                newJob = createObj.newJob(newJobData);
-                totalJobs.jobsArr.push(newJob);
-                tools.reSetCell(sheet, args.row, 0, null, id);
-            });
+            if(typeof newData === 'number'){
+                maxJobsNumber = maxJobsNumber >= newData ? maxJobsNumber : newData;
+                jobsAjax.createJobContent(billsLibId, field, '', newData, function(id){
+                    var newJobData, newJob;
+                    newJobData = {id: id, content: '', code: newData};
+                    newJob = createObj.newJob(newJobData);
+                    totalJobs.jobsArr.push(newJob);
+                    tools.reSetCell(sheet, args.row, 0, null, id);
+                });
+            }
+            else {
+                //编号只能为数字!
+            }
         }
     },
 
     updateJob: function(totalJobs, id, field, newData){
+        if(field === 'code' && typeof newData !== 'number'){
+            //编号只能为数字
+        }
+        else {
             totalJobs.jobsArr.forEach(function(job){
                 if(job.data[field] === newData){
                     job.data[field] = newData;
                 }
             });
             jobsAjax.updateJobContent(id, field, newData);
+        }
     }
 };
 
@@ -1040,24 +1053,34 @@ var totalItemsController = {
             });
         }
         else {
-            maxItemsNumber = maxItemsNumber >= newData ? maxItemsNumber : newData;
-            itemsAjax.createItemCharacter(billsLibId, field, '', newData, function(id){
-                var newItemData, newItem;
-                newItemData = {id: id, content: '', code: newData};
-                newItem = createObj.newItem(newItemData);
-                totalItems.itemsArr.push(newItem);
-                tools.reSetCell(sheet, args.row, 0, null, id);
-            });
+            if(typeof newData === 'number'){
+                maxItemsNumber = maxItemsNumber >= newData ? maxItemsNumber : newData;
+                itemsAjax.createItemCharacter(billsLibId, field, '', newData, function(id){
+                    var newItemData, newItem;
+                    newItemData = {id: id, content: '', code: newData};
+                    newItem = createObj.newItem(newItemData);
+                    totalItems.itemsArr.push(newItem);
+                    tools.reSetCell(sheet, args.row, 0, null, id);
+                });
+            }
+            else {
+                //编号只能为数字
+            }
         }
     },
 
     updateItem: function(totalItems, id, field, newData){
-        totalItems.itemsArr.forEach(function(item){
-            if(item.data[field] === newData){
-                item.data[field] = newData;
-            }
-        });
-        itemsAjax.updateItemCharacter(id, field, newData);
+        if(field === 'code' && typeof newData !== 'number'){
+            //编号只能为数字
+        }
+        else {
+            totalItems.itemsArr.forEach(function(item){
+                if(item.data[field] === newData){
+                    item.data[field] = newData;
+                }
+            });
+            itemsAjax.updateItemCharacter(id, field, newData);
+        }
     }
 };
 
@@ -1086,7 +1109,6 @@ var rechargeController = {
             var tempId = [];
             tempId.push(node.getID());
             var rootNode = tools.getRoot(node);
-            console.log('rootNodeId: ' + rootNode.getID());
             if(rootNode.data.recharge && rootNode !== node){
                 billsAjax.updateRecharge(billsLibId, tempId, rootNode.data.recharge);
                 node.data.recharge = rootNode.data.recharge;
@@ -1101,7 +1123,8 @@ var rechargeController = {
             $('exampleTextarea').val('');
         }
     }
-}
+};
+
 
 
 

+ 0 - 6
web/billsLib/scripts/setSheets.js

@@ -193,15 +193,9 @@ var myKey = {
             var sheet = spread.getActiveSheet();
             spread.commandManager().register('valDelete', function(){
                 spread.suspendEvent();
-                //test
-                console.log('MYVAL!!');
-                //
                 var ids = tools.delIds(sheet);
-                console.log(ids);
-                console.log('sI: ' + selectedId);
                 //deleteFront
                 var valsArr = valueController.getValues(totalItems, selectedId);
-                console.log('Arr: '+ valsArr);
                 ids.forEach(function(id){
                     valsArr.forEach(function(val){
                         if(val.code === id){