Explorar el Código

ration tuning

TonyKang hace 8 años
padre
commit
042526f361

+ 7 - 0
modules/rationRepository/controllers/rationChapterTreeController.js

@@ -26,6 +26,13 @@ module.exports ={
                 callback(req,res,err,data)
             })
         },
+    createNewNode: function(req, res){
+        var libName = req.body.rationLibName;
+        var nodeData = JSON.parse(req.body.rawNodeData);
+        rationChapterTreeData.createNewNode(libName, nodeData, function(err,data){
+            callback(req,res,err,data)
+        });
+    },
     tempRationChapterTreeInsert:
         function(req,res){
             var DBName = req.body.rationName;

+ 21 - 4
modules/rationRepository/models/rationChapterTree.js

@@ -13,7 +13,7 @@ var rationChapterTreeSchema = mongoose.Schema({//章节树  //生成唯一id改
     ID:Number,
     ParentID:Number,
     NextSiblingID:Number,
-    dispName: String
+    name: String
 });
 var rationChapterTreeModel = chapterTreeDb.model("rationChapterTrees",rationChapterTreeSchema, "rationChapterTrees")
 var repositoryMap = require('./repositoryMap');
@@ -32,9 +32,26 @@ rationChapterTreeDAO.prototype.getRationChapterTrees = function(repositoryName,c
 }
 
 rationChapterTreeDAO.prototype.createNewNode = function(repositoryName,nodeData,callback){
-    repositoryMap.getRealLibName(repositoryName, function(err, rst){
-        //
-    })
+    var promise = repositoryMap.getRealLibName(repositoryName), libId;
+    if (promise) {
+        promise.then(function(rst){
+            libId = rst[0].ID;
+            return counter.counterDAO.getIDAfterCount(counter.moduleName.rationTree, 1, function(err, result){
+                nodeData.rationRepId = libId;
+                nodeData.ID = result.value.sequence_value;
+                var node = new rationChapterTreeModel(nodeData);
+                node.save(function (err, result) {
+                    if (err) {
+                        callback("章节树ID错误!", false);
+                    } else {
+                        callback(false, result);
+                    }
+                });
+            });
+        });
+    } else {
+        callback("定额库选择错误!", false);
+    }
 },
 
 rationChapterTreeDAO.prototype.tempRationChapterTreeInsert = function(repositoryName,rationTempTree,callback){

+ 12 - 7
modules/rationRepository/models/repositoryMap.js

@@ -32,13 +32,18 @@ function createNewLibModel(rationLibObj){
 rationRepositoryDao = function(){};
 
 rationRepositoryDao.prototype.getRealLibName = function(dispName,callback){
-    rationRepository.find({"dispName": dispName}, function(err,data){
-        if (err) {
-            callback('Error', null);
-        } else {
-            callback(0, data);
-        }
-    });
+    if (callback) {
+        rationRepository.find({"dispName": dispName}, function(err,data){
+            if (err) {
+                callback('Error', null);
+            } else {
+                callback(0, data);
+            }
+        });
+    } else {
+        var rst = rationRepository.find({"dispName": dispName}).exec();
+        return rst;
+    }
 };
 
 rationRepositoryDao.prototype.addRationRepository = function( rationLibObj,callback){

+ 1 - 0
modules/rationRepository/routes/rationRepRoutes.js

@@ -16,6 +16,7 @@ apiRouter.post("/getRealLibName",rationRepositoryController.getRealLibName);
 
 apiRouter.post("/getRationTree",rationChapterTreeController.getRationChapterTree);
 apiRouter.post("/addSection",rationChapterTreeController.sectionUpsert);
+apiRouter.post("/createNewNode",rationChapterTreeController.createNewNode);
 apiRouter.post("/deleteSection",rationChapterTreeController.deleteSection);
 
 module.exports = apiRouter;

+ 19 - 15
web/rationLibEditor/dinge.html

@@ -879,23 +879,24 @@
     <script type="text/javascript" src="/lib/ztree/jquery.ztree.exedit.js"></script>
     <script type="text/javascript" src="/web/rationLibEditor/_zSpread.js"></script>
     <script type="text/javascript" src="/web/rationLibEditor/js/dinge.js"></script>
+    <script type="text/javascript" src="/public/web/treeDataHelper.js"></script>
     <SCRIPT type="text/javascript">
 /*var rationName = getQueryString("rationname");*/
 var treeObj;
 var zNodes =[
-    { id:1, pId:-1,nId:2, name:"第一章 土石方工程",isParent:true,children:[]},
-    { id:2, pId:-1,nId:3, name:"第二章 挡墙、护坡工程",isParent:true,children:[]},
-    { id:3, pId:-1,nId:4, name:"第三章 基础工程",isParent:true,children:[]},
-    { id:4, pId:-1,nId:5, name:"第四章 脚手架工程",isParent:true,children:[]},
-    { id:5, pId:-1,nId:6, name:"第五章 砌筑工程",isParent:true,children:[]},
-    { id:6, pId:-1,nId:7, name:"第六章 混凝土及钢筋混凝土工程",isParent:true,children:[]},
-    { id:7, pId:-1,nId:8, name:"第七章 金属工程",isParent:true,children:[]},
-    { id:8, pId:-1,nId:9, name:"第八章 门窗、木结构",isParent:true,children:[]},
-    { id:9, pId:-1,nId:10, name:"第九章 楼地面工程",isParent:true,children:[]},
-    { id:10, pId:-1,nId:11, name:"第十章 层面工程",isParent:true,children:[]},
-    { id:11, pId:-1,nId:12, name:"第十一章 防腐隔热保温工程",isParent:true,children:[]},
-    { id:12, pId:-1,nId:13, name:"第十二章 装饰工程",isParent:true,children:[]},
-    { id:13, pId:-1,nId:-1, name:"第十三章 其他工程",isParent:true,children:[]},
+    { id:1, pId:-1,nId:2, name:"第一章 土石方工程",isParent:true, items:[]},
+    { id:2, pId:-1,nId:3, name:"第二章 挡墙、护坡工程",isParent:true,items:[]},
+    { id:3, pId:-1,nId:4, name:"第三章 基础工程",isParent:true,items:[]},
+    { id:4, pId:-1,nId:5, name:"第四章 脚手架工程",isParent:true,items:[]},
+    { id:5, pId:-1,nId:6, name:"第五章 砌筑工程",isParent:true,items:[]},
+    { id:6, pId:-1,nId:7, name:"第六章 混凝土及钢筋混凝土工程",isParent:true,items:[]},
+    { id:7, pId:-1,nId:8, name:"第七章 金属工程",isParent:true,items:[]},
+    { id:8, pId:-1,nId:9, name:"第八章 门窗、木结构",isParent:true,items:[]},
+    { id:9, pId:-1,nId:10, name:"第九章 楼地面工程",isParent:true,items:[]},
+    { id:10, pId:-1,nId:11, name:"第十章 层面工程",isParent:true,items:[]},
+    { id:11, pId:-1,nId:12, name:"第十一章 防腐隔热保温工程",isParent:true,items:[]},
+    { id:12, pId:-1,nId:13, name:"第十二章 装饰工程",isParent:true,items:[]},
+    { id:13, pId:-1,nId:-1, name:"第十三章 其他工程",isParent:true,items:[]},
 ];
 var setting = {
     view: {
@@ -916,10 +917,13 @@ var setting = {
             leaf:true
         },
         key: {
-            children: "children"
+            children: "items"
         },
         simpleData: {
-            enable: true
+            enable: true,
+            idKey: "ID",
+            pIdKey: "ParentID",
+            rootPId: -1
         }
     },
     callback:{

+ 64 - 150
web/rationLibEditor/js/dinge.js

@@ -16,162 +16,59 @@ $("#gongliao").click(function(){
 });
 //----------------------------------------------------页面初始化
 $(document).ready(function(){
-    initParam();
+    rationOprObj.initParam();
     mkRationItemSpread();
 });
-function initParam(){
-    var rationLibName = getQueryString("repository");//获取定额库参数
-    if(rationLibName) {
-        params.realLibName = rationLibName;
-        getRationTree();
-    } else{
-        params = JSON.parse(getQueryString("params"));
-        getRationTree();
-    }
-}
-function addRootNode(){
-    //$.ajax({
-    //    type:"POST",
-    //    url:"api/getRationTree",
-    //    data:{"rationLibName": params.realLibName},
-    //    dataType:"json",
-    //    cache:false,
-    //    timeout:20000,
-    //    success:function(result,textStatus,status){
-    //        if(status.status == 200) createRationTree(result.data);//根据返回的全部定额章节对象,构架树。
-    //        else{
-    //            //treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
-    //            //saveTempTree();
-    //        }
-    //    },
-    //    error:function(err){
-    //        alert(err.responseText.error)
-    //    }
-    //})
 
-    var newNodes = [], isSilent = false;
-    newNodes.push({ id: 20, pId:-1, nId:-1, name:"新增节点",isParent:true, children:[]});
-    if (treeObj) {
-        treeObj.addNodes(null, -1, newNodes, isSilent);
-    } else {
-        treeObj = $.fn.zTree.init($("#treeDemo"), setting, newNodes);
+var rationOprObj = {
+    initParam : function() {
+        var me = this, rationLibName = getQueryString("repository");//获取定额库参数
+        if (rationLibName) {
+            params.realLibName = rationLibName;
+            me.getRationTree();
+        } else{
+            params = JSON.parse(getQueryString("params"));
+            me.getRationTree();
+        }
+    },
+    getRationTree: function(){
+        var me = this;
+        $.ajax({
+            type:"POST",
+            url:"api/getRationTree",
+            data:{"rationLibName": params.realLibName},
+            dataType:"json",
+            cache:false,
+            timeout:20000,
+            success:function(result,textStatus,status){
+                if(status.status == 200) {
+                    me.createRationTree(result.data);
+                }
+            },
+            error:function(err){
+                alert(err.responseText.error)
+            }
+        })
+    },
+    createRationTree: function(sourceData){
+        var treeArr = tree_Data_Helper.buildTreeNodeDirectly(sourceData);
+        treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
     }
 }
-//---------------------------------------------------初始化章节树界面
-function  getRationTree(){
-    $.ajax({
-        type:"POST",
-        url:"api/getRationTree",
-        data:{"rationLibName": params.realLibName},
-        dataType:"json",
-        cache:false,
-        timeout:20000,
-        success:function(result,textStatus,status){
-            if(status.status == 200) createRationTree(result.data);//根据返回的全部定额章节对象,构架树。
-            else{
-                //treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
-                //saveTempTree();
+
+function addRootNode(){
+    var rawNode = {ParentID: -1, NextSiblingID: -1, name: "新增节点"};
+    addNewNode(rawNode, function(err, rst){
+        if (!(err)) {
+            var newNodes = [], isSilent = false;
+            newNodes.push({ rationRepId: rst.data.rationRepId, ID: rst.data.ID, ParentID:-1, NextSiblingID:-1, name:"新增节点",isParent:true, items:[]});
+            if (treeObj) {
+                treeObj.addNodes(null, -1, newNodes, isSilent);
+            } else {
+                treeObj = $.fn.zTree.init($("#treeDemo"), setting, newNodes);
             }
-        },
-        error:function(err){
-            alert(err.responseText.error)
         }
-    })
-}
-//根据返回的节点集合构建树节点
-function createRationTree(obj){
-    var treeArr;
-    treeArr = makeNodes(obj);
-    var  maxIDNode = obj.reduce(function(a,b){
-        return (a.id> b.id)?a:b;
     });
-    newCount = maxIDNode.id;
-    treeObj = $.fn.zTree.init($("#treeDemo"), setting, treeArr);
-}
-function makeNodes(obj){
-    var arr=[];
-    arr = obj.filter(function(x){
-        return x.parentId==0
-    })
-    arr.forEach(function(x){
-        x.id = x.sectionId;
-        x.pId = x.parentId;
-        x.nId = x.nextSiblingId;
-        x.name = x.name;
-        x.isParent = true
-        x.lev = 0
-    });
-    arr  =  sortArray(arr);
-    for(var i=0;i<arr.length;i++){
-        var L1 = [];
-        L1 = obj.filter(function(x){
-            return x.parentId ==arr[i].id;
-        });
-        L1.forEach(function(x){
-            x.id = x.sectionId;
-            x.pId = x.parentId;
-            x.nId = x.nextSiblingId;
-            x.name = x.name;
-            x.isParent = true
-            x.lev = 1
-        });
-        L1=sortArray(L1);
-        for(var j=0; j<L1.length;j++){
-            var L2 = [];
-            L2 =obj.filter(function(x){
-                return x.parentId == L1[j].id;
-            })
-            L2.forEach(function(x){
-                x.id = x.sectionId;
-                x.pId = x.parentId;
-                x.nId = x.nextSiblingId;
-                x.name = x.name;
-                x.isParent = false;
-                x.lev = 2
-            })
-            L2=sortArray(L2)
-            L1[j].children = L2;
-        }
-        arr[i].children = L1;
-    }
-    return arr;
-}
-function sortArray(arr){
-    var a = [];
-    for(var i=0;i<arr.length;i++)
-        if (arr[i].nextSiblingId == -1)
-            a.push(arr[i])
-    for(; a.length < arr.length;){
-        for(var j=0;j<arr.length;j++) {
-            if (arr[j].nextSiblingId == a[0].sectionId)
-            {a.unshift(arr[j]); break;}
-        }
-    }
-    return a ;
-}
-//新建的定额库保存模板节点
-function saveTempTree(){
-    var N = []
-    for(i=0;i<zNodes.length;i++){
-        var node ={}
-        node.sectionId = zNodes[i].id;
-        node.parentId = zNodes[i].pId;
-
-        node.nextSiblingId = zNodes[i].nId;
-        node.name =zNodes[i].name;
-        N.push(node);
-    }
-    var rationTempTree = JSON.stringify(N)
-    $.ajax({
-        type:"POST",
-        url:"api/saveTempRationTree",
-        data:{"rationName":rationLibName,"rationTempTree":rationTempTree},
-        dataType:"json",
-        cache:false,
-        timeout:1000,
-        success:function(result,textStatus,status){},
-        error:function(){}
-    })
 }
 //--------------------------------------------------------树处理事件
 var newCount = 13;
@@ -186,7 +83,7 @@ function addHoverDom(treeId, treeNode) {
     if (btn) btn.bind("click", function(){
         var zTree = $.fn.zTree.getZTreeObj("treeDemo");
         if((treeNode.level==0)){
-            var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",children:[]});
+            var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",items:[]});
 
         }
         else{
@@ -202,6 +99,23 @@ function addHoverDom(treeId, treeNode) {
         return false;
     });
 };
+//增加新节点
+function addNewNode(rawNode, callback) {
+    $.ajax({
+        type:"POST",
+        url:"api/createNewNode",
+        data:{"rationLibName":params.realLibName,"rawNodeData": JSON.stringify(rawNode)},
+        dataType:"json",
+        cache:false,
+        timeout:1000,
+        success: function(result,textStatus,status){
+            callback(false, result);
+        },
+        error:function(err){
+            callback(err);
+        }
+    })
+};
 //保存新增的节点
 function saveNewSection(n){
     var sec={};
@@ -229,7 +143,7 @@ function onRename(e, treeId, treeNode, isCancel) {
 }
 function onRemove(e, treeId, treeNode) {
     var id = treeNode.id;
-    var pNodes = treeNode.getParentNode().children;
+    var pNodes = treeNode.getParentNode().items;
     for(var i=0;i<pNodes.length;i++){
         if(pNodes[i].nId==id){
             pNodes[i].nId = -1;