瀏覽代碼

解决一些Bug和优化节点操作

zhongzewei 8 年之前
父節點
當前提交
a0233ca270

+ 18 - 0
modules/bills_lib/controllers/bills_lib_controllers.js

@@ -82,6 +82,24 @@ module.exports = {
             callback(req, res, err, message, null);
         });
     },
+    downMove: function (req, res) {
+        let data = JSON.parse(req.body.data);
+        billsLibDao.downMove(data, function (err, message) {
+            callback(req, res, err, message, null);
+        })
+    },
+    upLevel: function (req, res) {
+        let data = JSON.parse(req.body.data);
+        billsLibDao.upLevel(data, function(err, message){
+            callback(req, res, err, message, null);
+        })
+    },
+    downLevel: function (req, res) {
+        let data = JSON.parse(req.body.data);
+        billsLibDao.downLevel(data, function (err, message) {
+            callback(req, res, err, message, null)
+        })
+    },
     updatePNId: function (req, res) {
         let data = JSON.parse(req.body.data);
         billsLibDao.updatePNId(data, function(err, message){

+ 253 - 9
modules/bills_lib/models/bills_lib_interfaces.js

@@ -95,11 +95,37 @@ billsLibDao.prototype.createStdBillsLib = function(clibData, callback){
 };
 
 billsLibDao.prototype.deleteStdBillsLib = function(billsLibId, callback){
-    StdBillsLib.update({billsLibId: billsLibId}, {$set: {deleted: true}}, function(err){
+    async.parallel([
+        function(cb){
+            StdBillsLib.update({billsLibId: billsLibId}, {$set: {deleted: true}}, function(err){
+                if(err){
+                    cb(err);
+                }
+                else{
+                    cb(null);
+                }
+            });
+        },
+        function(cb){
+            Bills.update({billsLibId: billsLibId, deleted: false}, {$set: {deleted: true}}, {upsert: false, multi: true}, function(err){
+                cb(null);
+            });
+        },
+        function(cb){
+            JobContent.update({billsLibId: billsLibId, deleted: false}, {$set: {deleted: true}}, {upsert: false, multi: true}, function(err, result){
+                cb(null);
+            });
+        },
+        function(cb){
+            ItemCharacter.update({billsLibId: billsLibId, deleted: false}, {$set: {deleted: true}}, {upsert: false, multi: true}, function(err){
+                cb(null);
+            })
+        }
+    ], function(err){
         if(err){
             callback(1, 'Error');
         }
-        else{
+        else {
             callback(0, '');
         }
     });
@@ -229,17 +255,228 @@ billsLibDao.prototype.upMove = function(data, callback){
     });
 };
 
+billsLibDao.prototype.downMove = function (data, callbck) {
+    let billsLibId = data.billsLibId,
+        updateDatas = data.updateDatas,
+        functions = [];
+    let parallelFucs = {
+        nextSiblingNode: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
+        },
+        oprNode: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else {
+                        cb(null);
+                    }
+                })
+            }
+        },
+        preSiblingNode: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
+        }
+    };
+    for(let i =0; i< updateDatas.length; i++){
+        if(updateDatas[i].type === 'nextSiblingNode'){
+            functions.push(parallelFucs.nextSiblingNode(updateDatas[i]));
+        }
+        else if(updateDatas[i].type === 'oprNode'){
+            functions.push(parallelFucs.oprNode(updateDatas[i]));
+        }
+        else {
+            functions.push(parallelFucs.preSiblingNode(updateDatas[i]));
+        }
+    }
+    async.parallel(functions, function (err) {
+        if(err){
+            callbck(1, 'Error');
+        }
+        else{
+            callbck(0, '');
+        }
+    })
+}
+
+billsLibDao.prototype.upLevel = function(data, callback){
+    let billsLibId = data.billsLibId,
+        updateDatas = data.updateDatas, functions = [];
+    let parallelFucs = {
+        oprNode: function (data) {
+            return function (cb){
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID}}, function(err){
+                    if(err){
+                        console.log(`err1`);
+                        cb(err);
+                    }
+                    else {
+                        cb(null);
+                    }
+                });
+            };
+        },
+        parentNode: function (data) {
+            return function(cb){
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        console.log(`err2`);
+                        cb(err);
+                    }
+                    else {
+                        cb(null);
+                    }
+                })
+            };
+        },
+        nextSiblingNode: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID}}, function (err) {
+                    if(err){
+                        console.log(`err3`);
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
+        },
+        preSiblingNode: function(data){
+            console.log(`billsLIbId: ${billsLibId} ID: ${data.ID} NextS: ${data.NextSiblingID}`);
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        console.log(`err4`);
+                        cb(err);
+                    }
+                    else {
+                        cb(null);
+                    }
+                });
+            };
+        }
+    }
+    for(let i=0; i< updateDatas.length; i++){
+        if(updateDatas[i].type === 'oprNode'){
+            functions.push(parallelFucs.oprNode(updateDatas[i]));
+        }
+        else if(updateDatas[i].type === 'parentNode'){
+            functions.push(parallelFucs.parentNode(updateDatas[i]));
+        }
+        else if(updateDatas[i].type === 'nextSiblingNode'){
+            updateDatas[i].ID.forEach(function (id) {
+                let obj = {ID: id, ParentID: updateDatas[i].ParentID};
+                functions.push(parallelFucs.nextSiblingNode(obj));
+            });
+        }
+        else {
+            functions.push(parallelFucs.preSiblingNode(updateDatas[i]));
+        }
+    }
+    async.parallel(functions, function(err){
+        if(err){
+            console.log(`errfinal`);
+            callback(1, 'Error');
+        }
+        else{
+            callback(0, '');
+        }
+    });
+};
+
+billsLibDao.prototype.downLevel = function (data, callback) {
+    let billsLibId = data.billsLibId,
+        updateDatas = data.updateDatas,
+        functions = [];
+    let parallelFucs = {
+        preSiblingNode: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else {
+                        cb(null);
+                    }
+                });
+            };
+        },
+        oprNode: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
+        },
+        preChildren: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
+        }
+    }
+    for(let i=0; i<updateDatas.length; i++){
+        if(updateDatas[i].type === 'preSiblingNode'){
+            functions.push(parallelFucs.preSiblingNode(updateDatas[i]));
+        }
+        else if(updateDatas[i].type === 'oprNode'){
+            functions.push(parallelFucs.oprNode(updateDatas[i]));
+        }
+        else {
+            functions.push(parallelFucs.preChildren(updateDatas[i]));
+        }
+    }
+    async.parallel(functions, function (err) {
+        if(err){
+            callback(1, 'Error');
+        }
+        else{
+            callback(0, '');
+        }
+    })
+};
+
 billsLibDao.prototype.updatePNId= function(upData, callback){
     let billsLibId = upData.billsLibId;
     let updateDatas = upData.updateData;
     let eachDatas = [];
-    if(updateDatas.length > 0){
         for(let i=0; i< updateDatas.length; i++){
             if(updateDatas[i].ID.length > 1){
                 let ids = updateDatas[i].ID;
                 for(let j=0; j<ids.length; j++){
                     let eachObj = {
-                        id: ids[j].ID,
+                        id: ids[j],
                         data: updateDatas[i]
                     }
                     eachDatas.push(eachObj);
@@ -249,9 +486,13 @@ billsLibDao.prototype.updatePNId= function(upData, callback){
                 eachDatas.push({id: updateDatas[i].ID, data: updateDatas[i]});
             }
         }
+        console.log(eachDatas.length);
         async.each(eachDatas, function(eachObj, cb){
             let id = eachObj.id, data = eachObj.data;
+            console.log(id);
+            console.log(data);
             if(data.ParentID && data.NextSiblingID){
+                console.log(`enter 1 ${id}`);
                 Bills.update({billsLibId: billsLibId, ID: id, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID}}, function(err){
                     if(err){
                         cb(err);
@@ -261,6 +502,7 @@ billsLibDao.prototype.updatePNId= function(upData, callback){
                 });
             }
             else if(data.ParentID && !data.NextSiblingID){
+                console.log(`enter 2 ${id}`);
                 Bills.update({billsLibId: billsLibId, ID: id, deleted: false}, {$set: {ParentID: data.ParentID}}, function(err){
                     if(err){
                         if(err){
@@ -272,6 +514,7 @@ billsLibDao.prototype.updatePNId= function(upData, callback){
                 });
             }
             else if(!data.ParentID && data.NextSiblingID){
+                console.log(`enter 3 ${id}`);
                 Bills.update({billsLibId: billsLibId, ID: id, deleted: false}, {$set: {NextSiblingID: data.NextSiblingID}}, function(err){
                     if(err){
                         cb(err);
@@ -282,13 +525,14 @@ billsLibDao.prototype.updatePNId= function(upData, callback){
             }
         }, function(err){
             if(err){
+                console.log(`err`);
                 callback(1, 'Error');
             }
             else {
+                console.log(`noerr`);
                 callback(0, '');
             }
         });
-    }
 }
 
 billsLibDao.prototype.updateBills = function(ubillsData, callback){
@@ -379,7 +623,7 @@ billsLibDao.prototype.updateBillsArr = function(updateData, callback){
         }
         if(orgId && !newId && type === 'delete'){
             async.each(orgId, function(oid, cb){
-                Bills.update({billsLibId: billsLibId, ID: updateId, deleted: false}, {$pull: {'jobs.id': oid}}, function(err){
+                Bills.update({billsLibId: billsLibId, ID: updateId, deleted: false}, {$pull: {jobs: {id: oid}}}, function(err){
                     if(err){
                         cb(err);
                     }else {
@@ -401,7 +645,7 @@ billsLibDao.prototype.updateBillsArr = function(updateData, callback){
                 });
             });
             async.each(delArr, function(delObj, cb){
-                Bills.update({billsLibId: billsLibId, ID: delObj.updateId, deleted: false}, {$pull: {'jobs.id': delObj.delId}}, function(err){
+                Bills.update({billsLibId: billsLibId, ID: delObj.updateId, deleted: false}, {$pull: {jobs: {id: delObj.delId}}}, function(err){
                     if(err){
                         cb(err);
                     }else {
@@ -431,7 +675,7 @@ billsLibDao.prototype.updateBillsArr = function(updateData, callback){
         }
         if(orgId && !newId && type === 'delete'){
             async.each(orgId, function(oid, cb){
-                Bills.update({billsLibId: billsLibId, ID: updateId, deleted: false}, {$pull: {items: oid}}, function(err){
+                Bills.update({billsLibId: billsLibId, ID: updateId, deleted: false}, {$pull: {items: {id: oid}}}, function(err){
                     if(err){
                         cb(err);
                     }else {
@@ -454,7 +698,7 @@ billsLibDao.prototype.updateBillsArr = function(updateData, callback){
                 });
             });
             async.each(delArr, function(delObj, cb){
-                Bills.update({billsLibId: billsLibId, ID: delObj.updateId, deleted: false}, {$pull: {items: delObj.delId}}, function(err){
+                Bills.update({billsLibId: billsLibId, ID: delObj.updateId, deleted: false}, {$pull: {items: {id: delObj.delId}}}, function(err){
                     if(err){
                         cb(err);
                     }else {

+ 3 - 0
modules/bills_lib/routes/bills_lib_routes.js

@@ -32,6 +32,7 @@ module.exports =function (app) {
     billsRouter.post("/getStdBillsLib", billsController.getStdBillsLib);
     billsRouter.post("/createStdBillsLib", billsController.createStdBillsLib);
     billsRouter.post("/upMove", billsController.upMove);
+    billsRouter.post("/downMove", billsController.downMove);
     billsRouter.post("/deleteStdBillsLib", billsController.deleteStdBillsLib);
     billsRouter.post("/renameStdBillsLib", billsController.renameStdBillsLib);
     billsRouter.post("/getStdBillsLibName", billsController.getStdBillsLibName);
@@ -39,6 +40,8 @@ module.exports =function (app) {
     billsRouter.post("/getBills", billsController.getBills);
     billsRouter.post("/createBills", billsController.createBills);
     billsRouter.post("/updatePNId", billsController.updatePNId);
+    billsRouter.post("/upLevel", billsController.upLevel);
+    billsRouter.post("/downLevel", billsController.downLevel);
     billsRouter.post("/updateBills", billsController.updateBills);
     billsRouter.post("/updateBillsArr", billsController.updateBillsArr);
     billsRouter.post("/pasteBills", billsController.pasteBills);

+ 31 - 33
public/web/id_tree.js

@@ -73,10 +73,8 @@ var idTree = {
                 var next = (pre && iIndex + count - 1 < children.length) ? children[iIndex + count] : null;
                 if (pre) {
                     pre.setNextSibling(next);
-                    //pre.nextSibling = next;
-                }
-                if (next) {
-                    next.preSibling = pre;
+                } else if (next) {
+                    next.preSibling = null;
                 }
                 if (arguments.length === 4) {
                     children.splice(iIndex, count);
@@ -98,10 +96,8 @@ var idTree = {
                 }
                 if (pre) {
                     pre.setNextSibling(nodes[0]);
-                }
-                nodes[0].preSibling = pre;
-                if (next) {
-                    next.preSibling = nodes[nodes.length - 1];
+                } else {
+                    nodes[0].preSibling = null;
                 }
                 nodes[nodes.length - 1].setNextSibling(next);
                 for (i = 0; i < nodes.length; i++) {
@@ -170,6 +166,9 @@ var idTree = {
         };
         Node.prototype.setNextSibling = function (nextSibling) {
             this.nextSibling = nextSibling;
+            if (nextSibling) {
+                nextSibling.preSibling = this;
+            }
             if (this.tree.setting.autoUpdate) {
                 this.data[this.tree.setting.nid] = this.getNextSiblingID();
             }
@@ -212,8 +211,8 @@ var idTree = {
             }
             return iCount;
             /*return (node.children.length === 0) ? 0 : node.children.reduce(function (x, y) {
-                return x.posterityCount() + y.posterityCount();
-            }) + node.children.count;*/
+             return x.posterityCount() + y.posterityCount();
+             }) + node.children.count;*/
         };
 
         Node.prototype.setExpanded = function (expanded) {
@@ -227,8 +226,8 @@ var idTree = {
             setNodesVisible(this.children, expanded);
         };
         /*Node.prototype.vis = function () {
-            return this.parent ? this.parent.vis() && this.parent.expanded() : true;
-        };*/
+         return this.parent ? this.parent.vis() && this.parent.expanded() : true;
+         };*/
         Node.prototype.serialNo = function () {
             return this.tree.items.indexOf(this);
         };
@@ -250,7 +249,7 @@ var idTree = {
             if (nextSibling) {
                 nextSibling.preSibling = preSibling;
             }
-            this.children.splice(this.children.re)
+            this.children.splice(node.siblingIndex, 1);
         };
 
         Node.prototype.canUpLevel = function () {
@@ -336,10 +335,10 @@ var idTree = {
             if (this.canUpMove()) {
                 if (orgPre.preSibling) {
                     orgPre.preSibling.setNextSibling(this);
+                } else {
+                    this.preSibling = null;
                 }
                 orgPre.setNextSibling(this.nextSibling);
-                this.preSibling = orgPre.preSibling;
-                orgPre.preSibling = this;
                 this.setNextSibling(orgPre);
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex - 1, 0, this);
@@ -369,11 +368,11 @@ var idTree = {
             if (this.canDownMove()) {
                 if (this.preSibling) {
                     this.preSibling.setNextSibling(orgNext);
+                } else if (orgNext) {
+                    orgNext.preSibling = null;
                 }
-                orgNext.preSibling = this.preSibling;
                 this.setNextSibling(orgNext.nextSibling);
                 orgNext.setNextSibling(this);
-                this.preSibling = orgNext;
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex + 1, 0, this);
                 tools.sortTreeItems(this.tree);
@@ -433,10 +432,10 @@ var idTree = {
                 }
             }
             /*if (this.maxID >= this.rangeNodeID() || this.rangeNodeID === -1) {
-                return -1;
-            } else {
-                return this.maxNodeID() + 1;
-            }*/
+             return -1;
+             } else {
+             return this.maxNodeID() + 1;
+             }*/
         };
 
         Tree.prototype.clearNodes = function () {
@@ -571,9 +570,8 @@ var idTree = {
                 //delete this.nodes[this.prefix + node.getID()];
                 if (node.preSibling) {
                     node.preSibling.setNextSibling(node.nextSibling);
-                }
-                if (node.nextSibling) {
-                    node.nextSibling.preSibling = node.preSibling;
+                } else if (node.nextSibling) {
+                    node.nextSibling.preSibling = null;
                 }
                 if (node.parent) {
                     node.parent.children.splice(node.siblingIndex(), 1);
@@ -605,15 +603,15 @@ var idTree = {
         };
 
         /*Tree.prototype.editedData = function (field, id, newText) {
-            var node = this.findNode(id), result = {allow: false, nodes: []};
-            if (this.event[this.eventType.editedData]) {
-                return this.event[this.eventType.editedData](field, node.data);
-            } else {
-                node.data[field] = newText;
-                result.allow = true;
-                return result;
-            }
-        };*/
+         var node = this.findNode(id), result = {allow: false, nodes: []};
+         if (this.event[this.eventType.editedData]) {
+         return this.event[this.eventType.editedData](field, node.data);
+         } else {
+         node.data[field] = newText;
+         result.allow = true;
+         return result;
+         }
+         };*/
 
         Tree.prototype.bind = function (eventName, eventFun) {
             this.event[eventName] = eventFun;

+ 9 - 7
web/maintain/bills_lib/html/neirong.html

@@ -261,25 +261,27 @@
                         }
                     }
                 }
-                for(let i=0; i< pasteDatas.length; i++){
+                let uniqPasteDatas = tools.uniqObjArr(pasteDatas);
+                tools.resetRowIdx(uniqPasteDatas, orgRow);
+                for(let i=0; i< uniqPasteDatas.length; i++){
                     let crossedData;
                     let flag = true;
                     sheetJobsDatas.forEach(function(orgData){
-                        if(pasteDatas[i].rowIdx === orgData.rowIdx && pasteDatas[i].colIdx === orgData.colIdx){
+                        if(uniqPasteDatas[i].rowIdx === orgData.rowIdx && uniqPasteDatas[i].colIdx === orgData.colIdx){
                             flag = false;
                             crossedData = {
                                 billsLibId: billsLibId,
-                                rowIdx: pasteDatas[i].rowIdx,
-                                colIdx: pasteDatas[i].colIdx,
-                                field: pasteDatas[i].field,
+                                rowIdx: uniqPasteDatas[i].rowIdx,
+                                colIdx: uniqPasteDatas[i].colIdx,
+                                field: uniqPasteDatas[i].field,
                                 orgId: orgData.id,
-                                data: pasteDatas[i].data,
+                                data: uniqPasteDatas[i].data,
                                 type: 'Update'
                             }
                         }
                     });
                     if(flag){
-                        uncrossedDatas.push(pasteDatas[i]);
+                        uncrossedDatas.push(uniqPasteDatas[i]);
                     }
                     else{
                         crossedDatas.push(crossedData);

+ 17 - 16
web/maintain/bills_lib/html/qingdan.html

@@ -265,34 +265,35 @@
         });
         $('#delete').click(function(){
             dbController.delete(controller, totalJobs, totalItems);
+            //controller.delete();
         });
         $('#upLevel').click(function(){
             dbController.upLevel(controller);
+            //controller.upLevel();
         });
         $('#downLevel').click(function(){
-           dbController.downLevel(controller);
+            dbController.downLevel(controller);
+            //controller.downLevel();
         });
         $('#upMove').click(function(){
             dbController.upMove(controller);
+            //controller.upMove();
         });
         $('#downMove').click(function(){
             dbController.downMove(controller);
+            //controller.downMove();
         });
     }
 
 
     function showBillsSheet(datas, jobsSheet, itemsSheet, setting) {
         let billsSpread = new GC.Spread.Sheets.Workbook($('#spreadBills')[0], {sheetCount: 1});
-        //
-        /*let billsSheet = billsSpread.getActiveSheet();
-        billsSheet.setFormatter(-1, 0, "@", GC.Spread.Sheets.SheetArea.viewport);*/
-        //
         setSheet.initSheet(billsSpread, setting);
-        //setSheet.formatter(billsSpread.getActiveSheet());
         myKey.delKey(billsSpread);
         billsTree.loadDatas(datas);
         let controller = TREE_SHEET_CONTROLLER.createNew(billsTree.tree, billsSpread.getActiveSheet(), setting);
         controller.showTreeData();
+        setSheet.formatter(billsSpread.getActiveSheet());
         //setTagId
         setTagID(controller, setting);
         if (!controller.tree.selected && controller.tree.findNode(controller.sheet.getTag(0, 0, GC.Spread.Sheets.SheetArea.viewport))) {
@@ -410,10 +411,8 @@
         if(controller.tree.selected){
             let arr = controller.tree.selected[classify];
             let recharge = controller.tree.selected.data.recharge;
-            setSheet.setMaxRowCount(sheet, arr);
             let prefix = classify === 'jobs' ? 'job' : 'item';
             if(arr.length > 0){
-                //tools.reshowData(sheet, arr, setting, true);//update--
                 tools.orderReshowData(sheet, arr, setting, prefix,true);
             }
             if(recharge){
@@ -432,7 +431,6 @@
                     let jobs = controller.tree.selected.jobs;
                     setSheet.setMaxRowCount(sheet, jobs);
                     if(jobs.length > 0){
-                     //   tools.reshowData(sheet, jobs, setting, false);
                         tools.orderReshowData(sheet, jobs, setting, 'job', true);
                         orgJobData = sheet.getValue(0, 0);
                     }
@@ -442,7 +440,7 @@
                     let items = controller.tree.selected.items;
                     setSheet.setMaxRowCount(sheet, items);
                     if(items.length > 0){
-                        tools.orderReshowData(sheet, items, setting, 'item', false);
+                        tools.orderReshowData(sheet, items, setting, 'item', true);
                         orgItemData = sheet.getValue(0, 0);
                     }
                     sheetItemsDatas = tools.getsheetDatas(sheet, 'items');
@@ -468,7 +466,6 @@
             for(let i=orgRow, j=0; i<= maxRow; i++, j++){
                 let id = sheet.getTag(i, 0);
                 if(id && j< validDatas.length){
-                    console.log(`id: ${id} row: ${i}`);
                     for(let k=0; k<colLen; k++){
                         setting.cols.forEach(function(col, colIdx){
                             if(colIdx === k){
@@ -484,7 +481,6 @@
                 }
                 else if(i< controller.tree.items.length && j>= validDatas.length) {
                     //reshow orgDatas
-                    console.log(`rowIdx: ${i}`)
                     sheetBillsDatas.forEach(function(rowData){
                         if(rowData.rowIdx === i){
                             sheet.setValue(i, 0, rowData.code + '');
@@ -500,6 +496,7 @@
             }
             billsAjax.pasteBills(datas);
             sheetBillsDatas = tools.getsheetDatas(sheet, 'bills', controller);
+            setSheet.setMaxRowCount(sheet, sheetBillsDatas);
         });
     }
     function bindPasteRel(sheet, controller, totalJobs, setting){
@@ -519,6 +516,7 @@
                     }
                 }
                 let uniqPasteArr = tools.uniqArr(pasteArr);
+                let serialNoUn = tools.getSerialNo(controller.tree.selected.jobs) - 1;
                 for(let i =orgRow, j=0; i<=uniqPasteArr.length+orgRow-1; i++, j++ ){
                     let flag = true;
                     let crossedData;
@@ -534,8 +532,8 @@
                         }
                     });
                     if(flag){
-                        let serialNo = tools.getSerialNo(controller.tree.selected.jobs);
-                        uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNo});
+                        serialNoUn++;
+                        uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNoUn});
                     }
                     else {
                         crossedDatas.push(crossedData);
@@ -573,6 +571,7 @@
                     }
                 }
                 let uniqPasteArr = tools.uniqArr(pasteArr);
+                let serialNoUn = tools.getSerialNo(controller.tree.selected.items) - 1;
                 for(let i =orgRow, j=0; i<=uniqPasteArr.length+orgRow-1; i++, j++ ){
                     let flag = true;
                     let crossedData;
@@ -588,8 +587,10 @@
                         }
                     });
                     if(flag){
-                        let serialNo = tools.getSerialNo(controller.tree.selected.items);
-                        uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNo});
+                        //let serialNo = tools.getSerialNo(controller.tree.selected.items);
+                        serialNoUn ++;
+                        console.log(serialNoUn);
+                        uncrossedDatas.push({data: uniqPasteArr[j], serialNo: serialNoUn});
                     }
                     else {
                         crossedDatas.push(crossedData);

+ 9 - 7
web/maintain/bills_lib/html/tezheng.html

@@ -309,25 +309,27 @@
                         }
                     }
                 }
-                for(let i=0; i< pasteDatas.length; i++){
+                let uniqPasteDatas = tools.uniqObjArr(pasteDatas);
+                tools.resetRowIdx(uniqPasteDatas, orgRow);
+                for(let i=0; i< uniqPasteDatas.length; i++){
                     let crossedData;
                     let flag = true;
                     totalItemsDatas.forEach(function(orgData){
-                        if(pasteDatas[i].rowIdx === orgData.rowIdx && pasteDatas[i].colIdx === orgData.colIdx){
+                        if(uniqPasteDatas[i].rowIdx === orgData.rowIdx && uniqPasteDatas[i].colIdx === orgData.colIdx){
                             flag = false;
                             crossedData = {
                                 billsLibId: billsLibId,
-                                rowIdx: pasteDatas[i].rowIdx,
-                                colIdx: pasteDatas[i].colIdx,
-                                field: pasteDatas[i].field,
+                                rowIdx: uniqPasteDatas[i].rowIdx,
+                                colIdx: uniqPasteDatas[i].colIdx,
+                                field: uniqPasteDatas[i].field,
                                 orgId: orgData.id,
-                                data: pasteDatas[i].data,
+                                data: uniqPasteDatas[i].data,
                                 type: 'Update'
                             }
                         }
                     });
                     if(flag){
-                        uncrossedDatas.push(pasteDatas[i]);
+                        uncrossedDatas.push(uniqPasteDatas[i]);
                     }
                     else{
                         crossedDatas.push(crossedData);

+ 49 - 1
web/maintain/bills_lib/scripts/bills_lib_ajax.js

@@ -184,6 +184,19 @@ var billsAjax = {
             }
         });
     },
+    downMove: function (billsLibId, updateDatas, callback) {
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/downMove',
+            data: {data: JSON.stringify({billsLibId: billsLibId, updateDatas: updateDatas})},
+            dataType: 'json',
+            success: function(result){
+                if(!result.error && callback){
+                    callback();
+                }
+            }
+        })
+    },
     updatePNId: function(billsLibId, updateData, callback){
         $.ajax({
             type: 'post',
@@ -191,15 +204,47 @@ var billsAjax = {
             data: {data: JSON.stringify({billsLibId: billsLibId, updateData: updateData})},
             dataType: 'json',
             success: function(result){
+                console.log(`entersFuc`);
                 if(!result.error && callback){
+                    console.log(`enterSc`);
                     callback();
                 }
                 else {
                     //提示窗口:更新失败
                 }
+            },
+            error: function(){
+                console.log(`error`);
             }
         });
     },
+    upLevel: function(billsLibId, updateDatas, callback){
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/upLevel',
+            data: {data: JSON.stringify({billsLibId: billsLibId, updateDatas: updateDatas})},
+            dataType: 'json',
+            success: function (result) {
+                console.log(`ssc`);
+                if(!result.error && callback){
+                    callback();
+                }
+            }
+        })
+    },
+    downLevel: function (billsLibId, updateDatas, callback) {
+        $.ajax({
+            type: 'post',
+            url: 'stdBillsEditor/downLevel',
+            data: {data: JSON.stringify({billsLibId: billsLibId, updateDatas: updateDatas})},
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error && callback){
+                    callback();
+                }
+            }
+        })
+    },
     deleteBills: function(billsLibId, deleteIds, updateNode, callback){
         $.ajax({
             type: 'post',
@@ -228,13 +273,16 @@ var billsAjax = {
             }
         });
     },
-    updateBillsArr: function(billsLibId, updateId, orgId, newId, type, classify){
+    updateBillsArr: function(billsLibId, updateId, orgId, newId, type, classify, callback){
         $.ajax({
             type: 'post',
             url: 'stdBillsEditor/updateBillsArr',
             data: {data: JSON.stringify({billsLibId: billsLibId, updateId: updateId, orgId: orgId, newId: newId, type: type, classify: classify})},
             dataType: 'json',
             success: function(result){
+                if(!result.error && callback){
+                    callback();
+                }
             }
         });
     },

+ 64 - 33
web/maintain/bills_lib/scripts/db_controller.js

@@ -59,31 +59,36 @@ var dbController = {
                 let updateA = {
                     ID: node.getID(),
                     ParentID: node.parent.getParentID(),
-                    NextSiblingID: node.parent.getNextSiblingID()
+                    NextSiblingID: node.parent.getNextSiblingID(),
+                    type: 'oprNode'
                 };
                 updateData.push(updateA);
                 //parent
                 let updateB = {
                     ID: node.getParentID(),
-                    NextSiblingID: node.getID()
+                    NextSiblingID: node.getID(),
+                    type: 'parentNode'
                 }
                 updateData.push(updateB);
                 if(node.nextSibling){
                     getNextSibling(node);
                     let updateC = {
                         ID: ids,
-                        ParentID: node.getID()
+                        ParentID: node.getID(),
+                        type: 'nextSiblingNode'
                     }
                     updateData.push(updateC);
                 }
                 if(node.preSibling){
                     let updateD = {
                         ID: node.preSibling.getID(),
-                        NextSibingID: -1
+                        NextSiblingID: -1,
+                        type: 'preSiblingNode'
                     }
                     updateData.push(updateD);
                 }
-                billsAjax.updatePNId(billsLibId, updateData, function(){
+                billsAjax.upLevel(billsLibId, updateData, function(){
+                    console.log(`enter upL`);
                     controller.upLevel();
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                 });
@@ -99,23 +104,26 @@ var dbController = {
             if(node.preSibling){
                 var updateA = {
                     ID: node.preSibling.getID(),
-                    NextSiblingID: node.getNextSiblingID()
+                    NextSiblingID: node.getNextSiblingID(),
+                    type: 'preSiblingNode'
                 };
                 var updateB = {
                     ID: node.getID(),
                     ParentID: node.preSibling.getID(),
-                    NextSiblingID: -1
+                    NextSiblingID: -1,
+                    type: 'oprNode'
                 };
                 updateData.push(updateA);
                 updateData.push(updateB);
                 if(node.preSibling.children.length > 0){
                     var updateC  = {
                         ID: node.preSibling.children[node.preSibling.children.length -1].getID(),
-                        NextSiblingID: node.getID()
+                        NextSiblingID: node.getID(),
+                        type: 'preChildren'
                     }
                     updateData.push(updateC);
                 }
-                billsAjax.updatePNId(billsLibId, updateData, function(){
+                billsAjax.downLevel(billsLibId, updateData, function(){
                     controller.downLevel();
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                 });
@@ -176,39 +184,26 @@ var dbController = {
 
     upMove: function(controller){
         var node = controller.tree.selected;
-        console.log(`nodeId ${node.getID()}`);
-        console.log(`preNode ${node.preSibling.getID()}`);
         var updateData = [];
         if(node){
-            //1 2 5 3 4
             if(node.preSibling){
-                let preNode = node.preSibling,
-                    nextNode = node.nextSibling,
-                    prePreNode;
                 let updateA = {
                     ID: node.preSibling.getID(),
                     NextSiblingID: node.getNextSiblingID()
                 };
-                console.log(`update preNode: ID: ${updateA.ID} NextSiblingID: ${updateA.NextSiblingID}`);
                 let updateB = {
                     ID: node.getID(),
                     NextSiblingID: node.preSibling.getID()
                 };
-                console.log(`update oprNode: ID: ${updateB.ID} NextSiblingID: ${updateB.NextSiblingID}`);
                 updateData.push(updateA);
                 updateData.push(updateB);
                 if(node.preSibling.preSibling){
-                    prePreNode = node.preSibling.preSibling;
                     let updateC = {
                         ID: node.preSibling.preSibling.getID(),
                         NextSiblingID: node.getID()
                     }
                     updateData.push(updateC);
-                    console.log(`update prePreNode: ID: ${updateC.ID} NextSiblingID: ${updateC.NextSiblingID}`);
                 }
-                /*billsAjax.updatePNId(billsLibId, updateData, function(){
-                    controller.upMove();
-                });*/
                 billsAjax.upMove(billsLibId, updateData, function(){
                     controller.upMove();
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
@@ -224,22 +219,25 @@ var dbController = {
             if(node.nextSibling){
                 var updateA = {
                     ID: node.getNextSiblingID(),
-                    NextSiblingID: node.getID()
+                    NextSiblingID: node.getID(),
+                    type: 'nextSiblingNode'
                 };
                 var updateB = {
                     ID: node.getID(),
-                    NextSiblingID: node.nextSibling.getNextSiblingID()
+                    NextSiblingID: node.nextSibling.getNextSiblingID(),
+                    type: 'oprNode'
                 };
                 updateData.push(updateA);
                 updateData.push(updateB);
                 if(node.preSibling){
                     var updateC = {
                         ID: node.preSibling.getID(),
-                        NextSiblingID: node.getNextSiblingID()
+                        NextSiblingID: node.getNextSiblingID(),
+                        type: 'preSiblingNode'
                     };
                     updateData.push(updateC);
                 }
-                billsAjax.updatePNId(billsLibId, updateData);
+                billsAjax.downMove(billsLibId, updateData);
                 controller.downMove();
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
             }
@@ -376,7 +374,7 @@ var createObj = {
                     });*/
                     node.data.items.forEach(function(obj){
                         if(me.items[me.prefix + obj.id]){
-                            node.items.push({item: me.items[me.prefix + obj.id]});
+                            node.items.push({item: me.items[me.prefix + obj.id], serialNo: obj.serialNo});
                             me.items[me.prefix + obj.id].count ++;
                         }
                         else {
@@ -598,22 +596,22 @@ var tools = {
 
     },
 
-    deleteELes: function (arr, delIds, callback){
+    deleteELes: function (arr, delIds, classifyStr){
         var ids = [];
         delIds.forEach(function(delId){
             arr.forEach(function(ele){
-                if(ele.data.id === delId){
+                if(ele[classifyStr].data.id === delId){
                     arr.splice(arr.indexOf(ele), 1);
                     ele.count--;
-                    if(ele.count <= 0){
+                    /*if(ele.count <= 0){
                         ids.push(ele.data.id);
-                    }
+                    }*/
                 }
             });
         });
-        if(callback){
+       /* if(callback){
             callback(ids);
-        }
+        }*/
 
     },
 
@@ -773,6 +771,39 @@ var tools = {
         return newArr;
     },
 
+    uniqObjArr: function(arr){
+        let uniqArr = [];
+        for(let i =0; i< arr.length; i++){
+            let uniqLen = uniqArr.length;
+            let flag = false;
+            if(uniqLen > 0){
+                for(let j=0; j< uniqLen; j++){
+                    if(arr[i].field === uniqArr[j].field && arr[i].data === uniqArr[j].data){
+                        flag = true;
+                        //uniqArr.push(arr[i]);
+                    }
+                }
+                if(!flag){
+                    uniqArr.push(arr[i]);
+                }
+            }
+            else {
+                uniqArr.push(arr[i])
+            }
+        }
+        return uniqArr;
+    },
+
+    resetRowIdx: function(arr, beginRow){
+        let rowIdx = beginRow;
+        for(let i=0; i< arr.length; i++){
+            if(arr[i].rowIdx !== rowIdx){
+                rowIdx++;
+                arr[i].rowIdx = rowIdx;
+            }
+        }
+    },
+
     getsheetDatas: function(sheet, classify, controller){
         let rowCount = sheet.getRowCount();
         const colIdx = 1;

+ 19 - 11
web/maintain/bills_lib/scripts/set_sheets.js

@@ -116,20 +116,29 @@ var myKey = {
             spread.commandManager().register('myDelete', function(){
                 spread.suspendEvent();
                 var ids = tools.delIds(sheet);
-                tools.deleteELes(controller.tree.selected[classify], ids, function(result){
+                let classifyStr = classify === 'jobs' ? 'job' : 'item';
+                tools.deleteELes(controller.tree.selected[classify], ids, classifyStr);
                     //deleteFrontData
-                    tools.reshowData(sheet, controller.tree.selected[classify], setting, true);
+                    //tools.reshowData(sheet, controller.tree.selected[classify], setting, true);
                     //deleteDB
-                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), ids, null, 'delete', classify);
-                    if(result.length > 0){
+                    billsAjax.updateBillsArr(billsLibId, controller.tree.selected.getID(), ids, null, 'delete', classify, function(){
+                        tools.orderReshowData(sheet, controller.tree.selected[classify], setting, classifyStr, true);
+                    });
+                    /*if(result.length > 0){
                         if(classify === 'jobs'){
-                            result.forEach(function(id){
-                                if(totalObj.findJob(id)){
+                            /!*result.forEach(function(id){
+                                controller.tree.selected.jobs.forEach(function(obj){
+                                    if(id === obj.job.data.id){
+                                        controller.tree.selected.jobs.splice(obj);
+                                    }
+                                });
+                                /!*if(totalObj.findJob(id)){
                                     totalObj.jobsArr.splice(totalObj.jobsArr.indexOf(totalObj.findJob(id)), 1);
                                     delete  totalObj.jobs[totalObj.prefix + id];
-                                }
-                            });
-                            jobsAjax.deleteJobContent(result);
+                                }*!/
+                            });*!/
+                            //jobsAjax.deleteJobContent(billsLibId, result);
+                            tools.orderReshowData(sheet, controller.tree.selected.jobs, setting, 'job', true);
                         }
                         else {
                             result.forEach(function(id){
@@ -140,8 +149,7 @@ var myKey = {
                             });
                             itemsAjax.deleteItemCharacter(result);
                         }
-                    }
-                });
+                    }*/
                 spread.resumeEvent();
             });
             spread.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);