Browse Source

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionOperation

TonyKang 7 years ago
parent
commit
e5cf52d691

+ 1 - 0
modules/all_models/stdBills_bills.js

@@ -18,6 +18,7 @@ const stdBills_bills = new Schema({
             items: [],
             items: [],
             recharge:String,
             recharge:String,
             billsLibId: Number,
             billsLibId: Number,
+            sectionInfo: Schema.Types.Mixed,
             deleted: Boolean
             deleted: Boolean
     },
     },
     {versionKey: false}
     {versionKey: false}

+ 20 - 0
public/web/id_tree.js

@@ -519,6 +519,26 @@ var idTree = {
             }
             }
             return node;
             return node;
         };
         };
+        Tree.prototype.insertByID = function (newID, parentID, nextSiblingID) {
+            var node = null, data = {};
+            var parent = parentID == -1 ? null : this.nodes[this.prefix + parentID];
+            var nextSibling = nextSiblingID == -1 ? null: this.nodes[this.prefix + nextSiblingID];
+            if (newID) {
+                data = {};
+                data[this.setting.id] = newID;
+                data[this.setting.pid] = parent ? parent.getID() : this.setting.rootId;
+                data[this.setting.nid] = nextSibling ? nextSibling.getID() : this.setting.rootId;
+                node = new Node(this, data);
+                if (nextSibling) {
+                    tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
+                } else {
+                    tools.addNodes(this, parent, [node]);
+                }
+                this.nodes[this.prefix + newID] = node;
+                tools.sortTreeItems(this);
+            }
+            return node;
+        };
         Tree.prototype.getInsertData = function (parentID, nextSiblingID) {
         Tree.prototype.getInsertData = function (parentID, nextSiblingID) {
             var data = [];
             var data = [];
             var newID = this.newNodeID();
             var newID = this.newNodeID();

+ 19 - 0
public/web/tree_sheet/tree_sheet_controller.js

@@ -42,6 +42,25 @@ var TREE_SHEET_CONTROLLER = {
                 }
                 }
             }
             }
         };
         };
+        controller.prototype.insertByID = function (ID) {
+            var newNode = null, that = this,  sels = this.sheet.getSelections();
+            if (this.tree) {
+                if (this.tree.selected) {
+                    newNode = this.tree.insertByID(ID, this.tree.selected.getParentID(), this.tree.selected.getNextSiblingID());
+                } else {
+                    newNode = this.tree.insertByID(ID);
+                }
+                if (newNode) {
+                    TREE_SHEET_HELPER.massOperationSheet(this.sheet, function () {
+                        that.sheet.addRows(newNode.serialNo(), 1);
+                        TREE_SHEET_HELPER.refreshTreeNodeData(that.setting, that.sheet, [newNode], false);
+                        that.setTreeSelected(newNode);
+                        that.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
+                        that.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
+                    });
+                }
+            }
+        };
         controller.prototype.delete = function () {
         controller.prototype.delete = function () {
             var that = this, sels = this.sheet.getSelections();
             var that = this, sels = this.sheet.getSelections();
             if (this.tree.selected) {
             if (this.tree.selected) {

+ 211 - 103
web/maintain/bills_lib/scripts/db_controller.js

@@ -8,37 +8,35 @@ var dbController = {
         btn.attr('doing', 'true');
         btn.attr('doing', 'true');
         if(controller.tree.items.length === 0){
         if(controller.tree.items.length === 0){
             controller.tree.maxNodeID(0);
             controller.tree.maxNodeID(0);
-           // let newNodeId = controller.tree.newNodeID();
             let newNodeId = uuid.v1();
             let newNodeId = uuid.v1();
-            console.log(newNodeId);
             let sectionInfo = {first: null, second: null, third: null};
             let sectionInfo = {first: null, second: null, third: null};
             billsAjax.createBills(userAccount, billsLibId, newNodeId, -1 , -1, null, sectionInfo, function(){
             billsAjax.createBills(userAccount, billsLibId, newNodeId, -1 , -1, null, sectionInfo, function(){
-                controller.insert();
+                controller.insertByID(newNodeId);
                 controller.tree.selected.jobs = new Array();
                 controller.tree.selected.jobs = new Array();
                 controller.tree.selected.items = new Array();
                 controller.tree.selected.items = new Array();
                 controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
                 controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                 tools.btnAction(btn);
                 tools.btnAction(btn);
                 btn.attr('doing', 'false');
                 btn.attr('doing', 'false');
+                controller.sheet.getParent().focus(true);
             });
             });
         }
         }
         else {
         else {
             let node = controller.tree.selected;
             let node = controller.tree.selected;
             if(node){
             if(node){
                 var updateId = node.getID(), createpid = node.getParentID(), createnid = node.getNextSiblingID();
                 var updateId = node.getID(), createpid = node.getParentID(), createnid = node.getNextSiblingID();
-                //let newNodeId = controller.tree.newNodeID();
                 let newNodeId = uuid.v1();
                 let newNodeId = uuid.v1();
-                console.log(newNodeId);
                 let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
                 let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
                 let sectionInfo = tools.getSectionInfo(node);
                 let sectionInfo = tools.getSectionInfo(node);
                 billsAjax.createBills(userAccount, billsLibId, newNodeId, createpid, createnid, updatePreData, sectionInfo, function(){
                 billsAjax.createBills(userAccount, billsLibId, newNodeId, createpid, createnid, updatePreData, sectionInfo, function(){
-                    controller.insert();
+                    controller.insertByID(newNodeId);
                     controller.tree.selected.jobs = new Array();
                     controller.tree.selected.jobs = new Array();
                     controller.tree.selected.items = new Array();
                     controller.tree.selected.items = new Array();
                     controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
                     controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
-                     tools.btnAction(btn);
+                    tools.btnAction(btn);
                     btn.attr('doing', 'false');
                     btn.attr('doing', 'false');
+                    controller.sheet.getParent().focus(true);
                 });
                 });
             }
             }
             else {
             else {
@@ -46,17 +44,17 @@ var dbController = {
                 let updateId = updateNode.getID();
                 let updateId = updateNode.getID();
                 //let newNodeId = controller.tree.newNodeID();
                 //let newNodeId = controller.tree.newNodeID();
                 let newNodeId = uuid.v1();
                 let newNodeId = uuid.v1();
-                console.log(newNodeId);
                 let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
                 let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
                 let sectionInfo = tools.getSectionInfo(node);
                 let sectionInfo = tools.getSectionInfo(node);
                 billsAjax.createBills(userAccount, billsLibId, newNodeId, -1, -1, updatePreData, sectionInfo, function(){
                 billsAjax.createBills(userAccount, billsLibId, newNodeId, -1, -1, updatePreData, sectionInfo, function(){
-                    controller.insert();
+                    controller.insertByID(newNodeId);
                     controller.tree.selected.jobs = new Array();
                     controller.tree.selected.jobs = new Array();
                     controller.tree.selected.items = new Array();
                     controller.tree.selected.items = new Array();
                     controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
                     controller.sheet.setTag(controller.tree.selected.serialNo(), 0, newNodeId);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     tools.btnAction(btn);
                     tools.btnAction(btn);
                     btn.attr('doing', 'false');
                     btn.attr('doing', 'false');
+                    controller.sheet.getParent().focus(true);
                 });
                 });
             }
             }
         }
         }
@@ -66,136 +64,221 @@ var dbController = {
         tools.btnClose(btn);
         tools.btnClose(btn);
         btn.attr('doing', 'true');
         btn.attr('doing', 'true');
         var node = controller.tree.selected;
         var node = controller.tree.selected;
-        var ids = [];
+        var nextSiblingIds = [];
         var updateData = [];
         var updateData = [];
-        var getNextSibling = function(node){
+        let selNodes = tools.getSameDepthNodes(controller);
+        let nextSiblings = [];
+        let getNextSibling = function(node){
             if(node.nextSibling){
             if(node.nextSibling){
-                ids.push(node.getNextSiblingID());
+                nextSiblingIds.push(node.getNextSiblingID());
+                nextSiblings.push(node.nextSibling);
                 getNextSibling(node.nextSibling);
                 getNextSibling(node.nextSibling);
             }
             }
-        }
-        //node
-        if(node){
-            if(node.parent){
-                let oprSectionInfo = tools.getSectionInfo(node.parent);
-                let updateA = {
-                    ID: node.getID(),
-                    ParentID: node.parent.getParentID(),
-                    NextSiblingID: node.parent.getNextSiblingID(),
-                    sectionInfo: oprSectionInfo,
-                    type: 'oprNode'
-                };
-                updateData.push(updateA);
-                //parent
-                let updateB = {
-                    ID: node.getParentID(),
-                    NextSiblingID: node.getID(),
+        };
+        if(selNodes.length > 0){
+            let firstParent = selNodes[0].parent;
+            //选中的第一个节点有父节点,则可升级
+            if(firstParent){
+                //更新父节点
+                updateData.push({
+                    ID: firstParent.getID(),
+                    NextSiblingID: selNodes[0].getID(),
                     type: 'parentNode'
                     type: 'parentNode'
+                });
+                //更新前节点
+                if(selNodes[0].preSibling){
+                    updateData.push({
+                        ID: selNodes[0].preSibling.getID(),
+                        NextSiblingID: -1,
+                        type: 'preSiblingNode'
+                    });
                 }
                 }
-                updateData.push(updateB);
-                if(node.nextSibling){
-                    let nextSectionInfo = tools.getSectionInfo(node.parent);
-                    if(!tools.isDef(nextSectionInfo.first)){
-                        nextSectionInfo.first = node.getID();
-                    }
-                    else if(!tools.isDef(nextSectionInfo.second)){
-                        nextSectionInfo.second = node.getID();
+                //更新选中节点的后兄弟节点
+                let lastSelNode = selNodes[selNodes.length - 1];
+                if(lastSelNode.nextSibling){
+                    let nextSectionInfo = tools.getSectionInfo(firstParent);
+                    let nullNextSectionInfo = tools.sectionInfoNull(nextSectionInfo);
+                    if(nullNextSectionInfo){
+                        nextSectionInfo[nullNextSectionInfo] = lastSelNode.getID();
                     }
                     }
-                    else if(!tools.isDef(nextSectionInfo.third)){
-                        nextSectionInfo.third = node.getID();
-                    }
-                    getNextSibling(node);
+                    getNextSibling(lastSelNode);
                     let updateC = {
                     let updateC = {
-                        ID: ids,
+                        ID: nextSiblingIds,
                         ParentID: node.getID(),
                         ParentID: node.getID(),
                         sectionInfo: nextSectionInfo,
                         sectionInfo: nextSectionInfo,
                         type: 'nextSiblingNode'
                         type: 'nextSiblingNode'
+                    };
+                    updateData.push({
+                        ID: nextSiblingIds,
+                        ParentID: lastSelNode.getID(),
+                        sectionInfo: nextSectionInfo,
+                        type: 'nextSiblingNode'
+                    });
+                    //nextSibling children
+                    for(let nextSibling of nextSiblings){
+                        let nextChildSectionInfo = {first: nextSectionInfo.first, second: nextSectionInfo.second, third: nextSectionInfo.third};
+                        let nextCFlag = false;
+                        let nullNextCInfo = tools.sectionInfoNull(nextChildSectionInfo);
+                        if(nullNextCInfo){
+                            nextChildSectionInfo[nullNextCInfo] = nextSibling.getID();
+                            nextCFlag = true;
+                        }
+                        if(nextCFlag){
+                            let nextCIds = [];
+                            for(let nextChild of nextSibling.children){
+                                nextCIds.push(nextChild.getID());
+                                //nextSibling grandChildren
+                                let nextGChildSectionInfo = {first: nextChildSectionInfo.first, second: nextChildSectionInfo.second, third: nextChildSectionInfo.third};
+                                let nextGCFlag = false;
+                                if(!tools.isDef(nextChildSectionInfo.third)){
+                                    nextGChildSectionInfo.third = nextChild.getID();
+                                    nextGCFlag = true;
+                                }
+                                if(nextGCFlag){
+                                    let nextGCIds = [];
+                                    for(let nextGChild of nextChild.children){
+                                        nextGCIds.push(nextGChild.getID());
+                                    }
+                                    updateData.push({ID: nextGCIds, ParentID: nextChild.getID(), sectionInfo: nextGChildSectionInfo, type: 'nextSiblingNode'});
+                                }
+                            }
+                            updateData.push({ID: nextCIds, ParentID: nextSibling.getID(), sectionInfo: nextChildSectionInfo, type: 'nextSiblingNode'});
+                        }
                     }
                     }
-                    updateData.push(updateC);
                 }
                 }
-                if(node.preSibling){
-                    let updateD = {
-                        ID: node.preSibling.getID(),
-                        NextSiblingID: -1,
-                        type: 'preSiblingNode'
+                //更新选中节点
+                for(let i = 0; i < selNodes.length; i++){
+                    let selNode = selNodes[i];
+                    let oprSectionInfo = tools.getSectionInfo(firstParent);
+                    let updateA = {
+                        ID: node.getID(),
+                        ParentID: node.parent.getParentID(),
+                        NextSiblingID: node.parent.getNextSiblingID(),
+                        sectionInfo: oprSectionInfo,
+                        type: 'oprNode'
+                    };
+                    updateData.push({
+                        ID: selNode.getID(),
+                        ParentID: firstParent.getParentID(),
+                        NextSiblingID: firstParent.getNextSiblingID(),
+                        sectionInfo: oprSectionInfo,
+                        type: 'oprNode'
+                    });
+                    //update node children and grandchildren sectionInfo
+                    let nullOprSectionInfo = tools.sectionInfoNull(oprSectionInfo);
+                    if(nullOprSectionInfo){
+                        let oprChildSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
+                        oprChildSectionInfo[nullOprSectionInfo] = selNode.getID();
+                        let oprChildIds = [];
+                        for(let oprChild of selNode.children){
+                            oprChildIds.push(oprChild.getID());
+                            let nullOprCSectionInfo = tools.sectionInfoNull(oprChildSectionInfo);
+                            if(nullOprCSectionInfo){
+                                let oprGCSectionInfo = {first: oprChildSectionInfo.first, second: oprChildSectionInfo.second, third: oprChildSectionInfo.third};
+                                oprGCSectionInfo[nullOprCSectionInfo] = oprChild.getID();
+                                let oprGCIds = [];
+                                for(let oprGChild of oprChild.children){
+                                    oprGCIds.push(oprGChild.getID());
+                                }
+                                if(oprGCIds.length > 0){
+                                    updateData.push({ID: oprGCIds, ParentID: oprChild.getID(), sectionInfo: oprGCSectionInfo, type: 'nextSiblingNode'});
+                                }
+                            }
+                        }
+                        if(oprChildIds.length > 0){
+                            updateData.push({ID: oprChildIds, ParentID: node.getID(), sectionInfo: oprChildSectionInfo, type: 'nextSiblingNode'});
+                        }
                     }
                     }
-                    updateData.push(updateD);
                 }
                 }
                 billsAjax.upLevel(userAccount, billsLibId, updateData, function(){
                 billsAjax.upLevel(userAccount, billsLibId, updateData, function(){
                     tools.btnAction(btn);
                     tools.btnAction(btn);
                     btn.attr('doing', 'false');
                     btn.attr('doing', 'false');
-                    controller.upLevel();
+                    for(let upLevelNode of selNodes){
+                        controller.setTreeSelected(upLevelNode);
+                        controller.upLevel();
+                    }
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
+                    controller.sheet.getParent().focus(true);
                 });
                 });
-                //rechargeController.createRecharge(controller.tree.selected);
             }
             }
         }
         }
     },
     },
-
     downLevel: function(controller, btn){
     downLevel: function(controller, btn){
         tools.btnClose(btn);
         tools.btnClose(btn);
         btn.attr('doing', 'true');
         btn.attr('doing', 'true');
-        var node = controller.tree.selected;
         var updateData = [];
         var updateData = [];
-        if(node){
-            if(node.preSibling){
-                let oprSectionInfo = tools.getSectionInfo(node.preSibling);
-                if(!tools.isDef(oprSectionInfo.first)){
-                    oprSectionInfo.first = node.preSibling.getID();
-                }
-                else if(!tools.isDef(oprSectionInfo.second)){
-                    oprSectionInfo.second = node.preSibling.getID();
-                }
-                else if(!tools.isDef(oprSectionInfo.third)){
-                    oprSectionInfo.third = node.preSibling.getID();
-                }
-                var updateA = {
-                    ID: node.preSibling.getID(),
-                    NextSiblingID: node.getNextSiblingID(),
-                    type: 'preSiblingNode'
-                };
-                var updateB = {
-                    ID: node.getID(),
-                    ParentID: node.preSibling.getID(),
-                    NextSiblingID: -1,
-                    sectionInfo: oprSectionInfo,
-                    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(),
+        let selNodes = tools.getSameDepthNodes(controller);
+        if(selNodes.length > 0){
+            //选中的第一个节点有前节点,则可降级
+            let firstPreSibling = selNodes[0].preSibling;
+            if(firstPreSibling){
+                //更新前节点
+                updateData.push({
+                    ID: firstPreSibling.getID(),
+                    NextSiblingID: selNodes[selNodes.length - 1].getNextSiblingID(),
+                    type: 'preSiblingNode'});
+                //更新前节点最末子节点
+                if(firstPreSibling.children.length > 0){
+                    updateData.push({
+                        ID: firstPreSibling.children[firstPreSibling.children.length - 1].getID(),
+                        NextSiblingID: selNodes[0].getID(),
                         type: 'preChildren'
                         type: 'preChildren'
-                    }
-                    updateData.push(updateC);
-                }
-                //更新子节点sectionInfo
-                let childSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
-                if(!tools.isDef(childSectionInfo.first)){
-                    childSectionInfo.first = node.getID();
-                }
-                else if(!tools.isDef(childSectionInfo.second)){
-                    childSectionInfo.second = node.getID();
-                }
-                else if(!tools.isDef(childSectionInfo.third)){
-                    childSectionInfo.third = node.getID();
+                    })
                 }
                 }
-                for(let i = 0, len = node.children.length; i < len; i++){
+                for(let i = 0; i < selNodes.length; i++){
+                    let selNode = selNodes[i];
+                    //更新选中的节点(第一层)
+                    let oprSectionInfo = tools.getSectionInfo(firstPreSibling);
+                    let nullOprSectionInfo = tools.sectionInfoNull(oprSectionInfo);
+                    if(nullOprSectionInfo){
+                        oprSectionInfo[nullOprSectionInfo] = firstPreSibling.getID();
+                    }
                     updateData.push({
                     updateData.push({
-                        ID: node.children[i].getID(),
-                        sectionInfo: childSectionInfo,
-                        type: 'oprChildren'
-                    })
+                        ID: selNode.getID(),
+                        ParentID: firstPreSibling.getID(),
+                        NextSiblingID: i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(),
+                        sectionInfo: oprSectionInfo,
+                        type: 'oprNode'});
+                    //更新选中节点的子节点(第二层)
+                    let childSectionInfo = {first: oprSectionInfo.first, second: oprSectionInfo.second, third: oprSectionInfo.third};
+                    let updateChildFlag = false;
+                    let nullChildSection = tools.sectionInfoNull(childSectionInfo);
+                    if(nullChildSection){
+                        childSectionInfo[nullChildSection] = selNode.getID();
+                        updateChildFlag = true;
+                    }
+                    if(updateChildFlag){
+                        for(let child of selNode.children){
+                            updateData.push({
+                                ID: child.getID(),
+                                sectionInfo: childSectionInfo,
+                                type: 'oprChildren'
+                            });
+                            //更新选中节点的孙子节点(第三层)
+                            let gChildSectionInfo = {first: childSectionInfo.first, second: childSectionInfo.second, third: childSectionInfo.third};
+                            let updateGChildFlag = false;
+                            if(!tools.isDef(gChildSectionInfo.third)){
+                                gChildSectionInfo.third = child.getID();
+                                updateGChildFlag = true;
+                            }
+                            if(updateGChildFlag){
+                                for(let grandChild of child.children){
+                                    updateData.push({ID: grandChild.getID(), sectionInfo: gChildSectionInfo, type: 'oprChildren'});
+                                }
+                            }
+                        }
+                    }
                 }
                 }
                 billsAjax.downLevel(userAccount, billsLibId, updateData, function(){
                 billsAjax.downLevel(userAccount, billsLibId, updateData, function(){
                     tools.btnAction(btn);
                     tools.btnAction(btn);
                     btn.attr('doing', 'false');
                     btn.attr('doing', 'false');
-                    controller.downLevel();
+                    for(let downNode of selNodes){
+                        controller.setTreeSelected(downNode);
+                        controller.downLevel();
+                    }
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
+                    controller.sheet.getParent().focus(true);
                 });
                 });
-                //rechargeController.createRecharge(controller.tree.selected);
             }
             }
         }
         }
     },
     },
@@ -250,6 +333,7 @@ var dbController = {
                 sheetDatas = tools.getsheetDatas(jobsSheet, 'jobs');
                 sheetDatas = tools.getsheetDatas(jobsSheet, 'jobs');
                 sheetItemsDatas = tools.getsheetDatas(itemsSheet, 'items');
                 sheetItemsDatas = tools.getsheetDatas(itemsSheet, 'items');
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
+                controller.sheet.getParent().focus(true);
                 //to solve refresh after deleted
                 //to solve refresh after deleted
             });
             });
         }
         }
@@ -284,6 +368,7 @@ var dbController = {
                     btn.attr('doing', 'false');
                     btn.attr('doing', 'false');
                     controller.upMove();
                     controller.upMove();
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                     sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
+                    controller.sheet.getParent().focus(true);
                 });
                 });
             }
             }
         }
         }
@@ -321,6 +406,7 @@ var dbController = {
                 btn.attr('doing', 'false');
                 btn.attr('doing', 'false');
                 controller.downMove();
                 controller.downMove();
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
                 sheetBillsDatas = tools.getsheetDatas(controller.sheet, 'bills', controller);
+                controller.sheet.getParent().focus(true);
             }
             }
         }
         }
     },
     },
@@ -1438,6 +1524,15 @@ var tools = {
     isDef: function (v) {
     isDef: function (v) {
         return v !== undefined && v !== null;
         return v !== undefined && v !== null;
     },
     },
+    //返回
+    sectionInfoNull: function (sectionInfo) {
+        for(let info in sectionInfo){
+            if(!this.isDef(sectionInfo[info])){
+                return info;
+            }
+        }
+        return false;
+    },
 
 
     getSectionInfo: function (node) {
     getSectionInfo: function (node) {
         let parentIDs = [];
         let parentIDs = [];
@@ -1459,6 +1554,19 @@ var tools = {
                 getParent(node.parent);
                 getParent(node.parent);
             }
             }
         }
         }
+    },
+    getSameDepthNodes: function(controller){
+        const items = controller.tree.items;
+        let rst = [];
+        let sel = controller.sheet.getSelections()[0];
+        let selectedDepth = controller.tree.selected.depth();
+        for(let i = 0; i < sel.rowCount; i++){
+            let row = sel.row + i;
+            if(items[row].depth() === selectedDepth){
+                rst.push(items[row]);
+            }
+        }
+        return rst;
     }
     }
 };
 };
 
 

+ 61 - 31
web/maintain/ration_repository/js/section_tree.js

@@ -75,7 +75,7 @@ let sectionTreeObj = {
                 }
                 }
             ],
             ],
             headRows: 1,
             headRows: 1,
-            headRowHeight: [47],
+            headRowHeight: [25],
             emptyRows: 0,
             emptyRows: 0,
             treeCol: 0
             treeCol: 0
         },
         },
@@ -138,14 +138,15 @@ let sectionTreeObj = {
 
 
     onSelectionChanged: function (sender, info) {
     onSelectionChanged: function (sender, info) {
         let me = sectionTreeObj;
         let me = sectionTreeObj;
-        if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
-            let row = info.newSelections[0].row;
-            let section = me.cache[row];
-            me.initSelection(section);
+        let row = info.newSelections[0].row;
+        let section = me.cache[row];
+        me.initSelection(section);
+       /* if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
+
         }
         }
         else {
         else {
             me.refreshBtn(null);
             me.refreshBtn(null);
-        }
+        }*/
     },
     },
 
 
     onEditEnded: function (sender, args) {
     onEditEnded: function (sender, args) {
@@ -355,67 +356,96 @@ let sectionTreeObj = {
             });
             });
         }
         }
     },
     },
+    getSameDepthNodes: function(){
+        let rst = [];
+        let sel = this.sheet.getSelections()[0];
+        let selectedDepth = this.tree.selected.depth();
+        for(let i = 0; i < sel.rowCount; i++){
+            let row = sel.row + i;
+            if(this.cache[row].depth() === selectedDepth){
+                rst.push(this.cache[row]);
+            }
+        }
+        return rst;
+    },
     upLevel: function (selected) {
     upLevel: function (selected) {
         let me = this;
         let me = this;
         me.upLevelBtn.addClass('disabled');
         me.upLevelBtn.addClass('disabled');
         let postData = [];
         let postData = [];
-        if(!me.isDef(selected)){
-            return;
+        let selNodes = me.getSameDepthNodes();
+        if(selNodes.length <= 0){
+            return ;
         }
         }
-        if(!me.isDef(selected.parent)){
+        let firstParent = selNodes[0].parent;
+        if(!me.isDef(firstParent)){
             return;
             return;
         }
         }
-        if(me.isDef(selected.preSibling)){
-            let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), -1, null, null, null);
-            postData.push(updateObj);
+        //更新父节点
+        postData.push(me.getUpdateObj(me.updateType.update, firstParent.getID(), selNodes[0].getID(), null, null, null));
+        //更新前节点
+        if(me.isDef(selNodes[0].preSibling)){
+            postData.push(me.getUpdateObj(me.updateType.update, selNodes[0].preSibling.getID(), -1, null, null, null));
         }
         }
-        let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), selected.parent.getNextSiblingID(), selected.parent.getParentID(), null, null);
-        postData.push(updateObj);
-        let updateParent = me.getUpdateObj(me.updateType.update, selected.getParentID(), selected.getID(), null, null, null);
-        postData.push(updateParent);
+        //更新选中节点的后兄弟节点
+        let lastSelNode = selNodes[selNodes.length - 1];
         let nextIDs = [];
         let nextIDs = [];
-        getNext(selected);
+        getNext(lastSelNode);
         function getNext(node){
         function getNext(node){
             if(me.isDef(node.nextSibling)){
             if(me.isDef(node.nextSibling)){
                 nextIDs.push(node.getNextSiblingID());
                 nextIDs.push(node.getNextSiblingID());
                 getNext(node.nextSibling);
                 getNext(node.nextSibling);
             }
             }
         }
         }
-        for(let i = 0, len = nextIDs.length; i < len; i++){
-            postData.push(me.getUpdateObj(me.updateType.update, nextIDs[i], null, selected.getID(), null, null));
+        for(let nextID of nextIDs){
+            postData.push(me.getUpdateObj(me.updateType.update, nextID, null, lastSelNode.getID(), null, null));
+        }
+        //更新选中节点
+        for(let i = 0; i < selNodes.length; i++){
+            let selNode = selNodes[i];
+            postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), firstParent.getNextSiblingID(), firstParent.getParentID(), null, null));
         }
         }
         if(postData.length > 0){
         if(postData.length > 0){
             //ajax
             //ajax
             me.sectionTreeAjax(postData, function (rstData) {
             me.sectionTreeAjax(postData, function (rstData) {
-                me.controller.upLevel();
+                for(let selNode of selNodes){
+                    me.controller.setTreeSelected(selNode);
+                    me.controller.upLevel();
+                }
                 me.refreshBtn(me.tree.selected);
                 me.refreshBtn(me.tree.selected);
                 me.workBook.focus();
                 me.workBook.focus();
             });
             });
         }
         }
-
     },
     },
     downLevel: function (selected) {
     downLevel: function (selected) {
         let me = this;
         let me = this;
         me.downLevelBtn.addClass('disabled');
         me.downLevelBtn.addClass('disabled');
         let postData = [];
         let postData = [];
-        if(!me.isDef(selected)){
+        let selNodes = me.getSameDepthNodes();
+        if(selNodes.length <= 0 ){
             return;
             return;
         }
         }
-        if(!me.isDef(selected.preSibling)){
+        let firstPreSibling = selNodes[0].preSibling;
+        if(!me.isDef(firstPreSibling)){
             return;
             return;
         }
         }
-        let updatePre = me.getUpdateObj(me.updateType.update, selected.preSibling.getID(), selected.getNextSiblingID(), null, null, null);
-        postData.push(updatePre);
-        if(selected.preSibling.children.length > 0){
-            let updateObj = me.getUpdateObj(me.updateType.update, selected.preSibling.children[selected.preSibling.children.length - 1].getID(), selected.getID(), null, null, null);
-            postData.push(updateObj);
+        //更新前节点
+        postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.getID(), selNodes[selNodes.length - 1].getNextSiblingID(), null, null, null));
+        //更新前节点最末子节点
+        if(firstPreSibling.children.length > 0){
+            postData.push(me.getUpdateObj(me.updateType.update, firstPreSibling.children[firstPreSibling.children.length - 1].getID(), selNodes[0].getID(), null, null, null));
+        }
+        //更新选中节点
+        for(let i = 0; i < selNodes.length; i++){
+            let selNode = selNodes[i];
+            postData.push(me.getUpdateObj(me.updateType.update, selNode.getID(), i === selNodes.length - 1 ? -1 : selNode.getNextSiblingID(), firstPreSibling.getID(), null, null));
         }
         }
-        let updateObj = me.getUpdateObj(me.updateType.update, selected.getID(), -1, selected.preSibling.getID(), null, null);
-        postData.push(updateObj);
         if(postData.length > 0){
         if(postData.length > 0){
             //ajax
             //ajax
             me.sectionTreeAjax(postData, function (rstData) {
             me.sectionTreeAjax(postData, function (rstData) {
-                me.controller.downLevel();
+                for(let selNode of selNodes){
+                    me.controller.setTreeSelected(selNode);
+                    me.controller.downLevel();
+                }
                 me.refreshBtn(me.tree.selected);
                 me.refreshBtn(me.tree.selected);
                 me.workBook.focus();
                 me.workBook.focus();
             });
             });