Browse Source

清单规则添加章节信息sectionInfo: {first: number, second: number, third: number}

zhongzewei 7 years ago
parent
commit
c130454b29

+ 21 - 4
modules/bills_lib/models/bills_lib_interfaces.js

@@ -241,6 +241,7 @@ billsLibDao.prototype.createBills = function(cbillsData, callback){
     let nid = cbillsData.NextSiblingID;
     let billsLibId = cbillsData.billsLibId;
     let updatePreData = cbillsData.updatePreData;
+    let sectionInfo = cbillsData.sectionInfo;
     let lastOperator = cbillsData.lastOperator, lastOperateDate = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
     let newBills = {
         ID: newId,
@@ -253,6 +254,7 @@ billsLibDao.prototype.createBills = function(cbillsData, callback){
         ruleText: '',
         Expression: '',
         recharge:'',
+        sectionInfo: sectionInfo,
         deleted: false
     };
     async.parallel([
@@ -480,7 +482,7 @@ billsLibDao.prototype.upLevel = function(data, callback){
         },
         oprNode: function (data) {
             return function (cb){
-                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID}}, function(err){
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, sectionInfo: data.sectionInfo}}, function(err){
                     if(err){
                         cb(err);
                     }
@@ -504,7 +506,7 @@ billsLibDao.prototype.upLevel = function(data, callback){
         },
         nextSiblingNode: function (data) {
             return function (cb) {
-                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID}}, function (err) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, sectionInfo: data.sectionInfo}}, function (err) {
                     if(err){
                         cb(err);
                     }
@@ -536,7 +538,7 @@ billsLibDao.prototype.upLevel = function(data, callback){
         }
         else if(updateDatas[i].type === 'nextSiblingNode'){
             updateDatas[i].ID.forEach(function (id) {
-                let obj = {ID: id, ParentID: updateDatas[i].ParentID};
+                let obj = {ID: id, ParentID: updateDatas[i].ParentID, sectionInfo: updateDatas[i].sectionInfo};
                 functions.push(parallelFucs.nextSiblingNode(obj));
             });
         }
@@ -596,7 +598,7 @@ billsLibDao.prototype.downLevel = function (data, callback) {
         },
         oprNode: function (data) {
             return function (cb) {
-                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID}}, function (err) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {ParentID: data.ParentID, NextSiblingID: data.NextSiblingID, sectionInfo: data.sectionInfo}}, function (err) {
                     if(err){
                         cb(err);
                     }
@@ -617,6 +619,18 @@ billsLibDao.prototype.downLevel = function (data, callback) {
                     }
                 });
             };
+        },
+        oprChildren: function (data) {
+            return function (cb) {
+                Bills.update({billsLibId: billsLibId, ID: data.ID, deleted: false}, {$set: {sectionInfo: data.sectionInfo}}, function (err) {
+                    if(err){
+                        cb(err);
+                    }
+                    else{
+                        cb(null);
+                    }
+                });
+            };
         }
     }
     for(let i=0; i<updateDatas.length; i++){
@@ -626,6 +640,9 @@ billsLibDao.prototype.downLevel = function (data, callback) {
         else if(updateDatas[i].type === 'oprNode'){
             functions.push(parallelFucs.oprNode(updateDatas[i]));
         }
+        else if(updateDatas[i].type === 'oprChildren'){
+            functions.push(parallelFucs.oprChildren(updateDatas[i]));
+        }
         else {
             functions.push(parallelFucs.preChildren(updateDatas[i]));
         }

+ 1 - 0
modules/bills_lib/models/bills_lib_schemas.js

@@ -50,6 +50,7 @@ let billsSchema = mongoose.Schema({
     items: [],
     recharge:String,
     billsLibId: Number,
+    sectionInfo: {},
     deleted: Boolean
 },
     {versionKey: false}

+ 2 - 2
web/maintain/bills_lib/scripts/bills_lib_ajax.js

@@ -176,11 +176,11 @@ var billsAjax = {
             }
         });
     },
-    createBills: function(lastOperator, billsLibId, newId, pid, nid, updatePreData, callback){
+    createBills: function(lastOperator, billsLibId, newId, pid, nid, updatePreData, sectionInfo, callback){
         $.ajax({
             type: 'post',
             url: 'stdBillsEditor/createBills',
-            data: {data: JSON.stringify({lastOperator: lastOperator, billsLibId: billsLibId, newId: newId, ParentID: pid, NextSiblingID: nid, updatePreData: updatePreData})},
+            data: {data: JSON.stringify({lastOperator: lastOperator, billsLibId: billsLibId, newId: newId, ParentID: pid, NextSiblingID: nid, updatePreData: updatePreData, sectionInfo: sectionInfo})},
             dataType: 'json',
             success: function(result){
                 if(!result.error){

+ 74 - 4
web/maintain/bills_lib/scripts/db_controller.js

@@ -9,7 +9,8 @@ var dbController = {
         if(controller.tree.items.length === 0){
             controller.tree.maxNodeID(0);
             let newNodeId = controller.tree.newNodeID();
-            billsAjax.createBills(userAccount, billsLibId, newNodeId, -1 , -1, null, function(){
+            let sectionInfo = {first: null, second: null, third: null};
+            billsAjax.createBills(userAccount, billsLibId, newNodeId, -1 , -1, null, sectionInfo, function(){
                 controller.insert();
                 controller.tree.selected.jobs = new Array();
                 controller.tree.selected.items = new Array();
@@ -25,7 +26,8 @@ var dbController = {
                 var updateId = node.getID(), createpid = node.getParentID(), createnid = node.getNextSiblingID();
                 let newNodeId = controller.tree.newNodeID();
                 let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
-                billsAjax.createBills(userAccount, billsLibId, newNodeId, createpid, createnid, updatePreData, function(){
+                let sectionInfo = tools.getSectionInfo(node);
+                billsAjax.createBills(userAccount, billsLibId, newNodeId, createpid, createnid, updatePreData, sectionInfo, function(){
                     controller.insert();
                     controller.tree.selected.jobs = new Array();
                     controller.tree.selected.items = new Array();
@@ -40,7 +42,8 @@ var dbController = {
                 let updateId = updateNode.getID();
                 let newNodeId = controller.tree.newNodeID();
                 let updatePreData = {ID: updateId, NextSiblingID: newNodeId};
-                billsAjax.createBills(userAccount, billsLibId, newNodeId, -1, -1, updatePreData, function(){
+                let sectionInfo = tools.getSectionInfo(node);
+                billsAjax.createBills(userAccount, billsLibId, newNodeId, -1, -1, updatePreData, sectionInfo, function(){
                     controller.insert();
                     controller.tree.selected.jobs = new Array();
                     controller.tree.selected.items = new Array();
@@ -68,10 +71,12 @@ var dbController = {
         //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);
@@ -83,10 +88,21 @@ var dbController = {
                 }
                 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();
+                    }
+                    else if(!tools.isDef(nextSectionInfo.third)){
+                        nextSectionInfo.third = node.getID();
+                    }
                     getNextSibling(node);
                     let updateC = {
                         ID: ids,
                         ParentID: node.getID(),
+                        sectionInfo: nextSectionInfo,
                         type: 'nextSiblingNode'
                     }
                     updateData.push(updateC);
@@ -117,6 +133,16 @@ var dbController = {
         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(),
@@ -126,6 +152,7 @@ var dbController = {
                     ID: node.getID(),
                     ParentID: node.preSibling.getID(),
                     NextSiblingID: -1,
+                    sectionInfo: oprSectionInfo,
                     type: 'oprNode'
                 };
                 updateData.push(updateA);
@@ -138,6 +165,24 @@ var dbController = {
                     }
                     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++){
+                    updateData.push({
+                        ID: node.children[i].getID(),
+                        sectionInfo: childSectionInfo,
+                        type: 'oprChildren'
+                    })
+                }
                 billsAjax.downLevel(userAccount, billsLibId, updateData, function(){
                     tools.btnAction(btn);
                     btn.attr('doing', 'false');
@@ -1382,8 +1427,33 @@ var tools = {
             }
         }
         return conformDatas;
-    }
+    },
+
+    isDef: function (v) {
+        return v !== undefined && v !== null;
+    },
 
+    getSectionInfo: function (node) {
+        let parentIDs = [];
+        let sectionInfo = {first: null, second: null, third: null};
+        getParent(node);
+        if(this.isDef(parentIDs[parentIDs.length - 1])){
+            sectionInfo.first = parentIDs[parentIDs.length - 1];
+        }
+        if(this.isDef(parentIDs[parentIDs.length - 2])){
+            sectionInfo.second = parentIDs[parentIDs.length - 2];
+        }
+        if(this.isDef(parentIDs[parentIDs.length - 3])){
+            sectionInfo.third = parentIDs[parentIDs.length - 3];
+        }
+        return sectionInfo;
+        function getParent(node){
+            if(node.parent){
+                parentIDs.push(node.parent.data.ID);
+                getParent(node.parent);
+            }
+        }
+    }
 };
 
 let pasteController = {

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

@@ -37,7 +37,7 @@
                       <a class="nav-link px-3" id="fuzhu" href="#">附注条件</a>
                   </li>
                   <li class="nav-item">
-                      <a class="nav-link px-3" href="#">安装增加费</a>
+                      <a class="nav-link px-3" href="anzhuang.html">安装增加费</a>
                   </li>
               </ul>
         </nav>