Просмотр исходного кода

完善了定额库编辑器功能,修改了不规范的命名

zhangenping 8 лет назад
Родитель
Сommit
1e8dc7cfc7

modules/rations/RationDB/Schemas.js → modules/rationLibEditor/RationEditorDB/Schemas.js


+ 1 - 1
modules/rations/RationDB/interfaces.js

@@ -46,7 +46,7 @@ inserts.RationSectionInsert = function(req,res){//find and updata;
                 var RationTreeModel = db.model("rationtrees", Schemas.RationTreeSchema);
                 RationTreeModel.find({"SectionID":rationSection.SectionID},function(err,data){
                     if(data.length){
-                        RationTreeModel.update({'SectionID':rationSection.SectionID},{$set:{'Name':rationSection.Name}},function(err,data){
+                        RationTreeModel.update({'SectionID':rationSection.SectionID},rationSection,function(err,data){
                             if(err){
                                 callback(req,res,"some error occured when save RationTempTree!",false);
                             }else

+ 6 - 6
modules/rations/routes/rations_route.js

@@ -3,26 +3,26 @@ var apiRouter =express.Router();
 var _rootDir = __dirname;
 
 var path = require('path');
-var htmlPath = path.join(__dirname,'../../../','web/rations/');
+var htmlPath = path.join(__dirname,'../../../','web/rationLibEditor/');
 apiRouter.get('/', function(req, res) {
         res.redirect('/main');
 });
 
-var RationInterface = require("../RationDB/interfaces");
+var RationInterface = require("../RationEditorDB/interfaces");
 apiRouter.get("/main",function(req,res){
-    res.render("rations/main.html");
+    res.render("rationLibEditor/main.html");
 })
 
 apiRouter.get('/rationLib', function (req, res) {
-    res.render("rations/dinge.html");
+    res.render("rationLibEditor/dinge.html");
 });
 
 apiRouter.get('/gongliao', function (req, res) {
-    res.render("rations/gongliao.html");
+    res.render("rationLibEditor/gongliao.html");
 });
 
 apiRouter.get('/fuzhu', function (req, res) {
-    res.render("rations/fuzhu.html");
+    res.render("rationLibEditor/fuzhu.html");
 });
 apiRouter.post("/addRationName",RationInterface.insert.RationLibInsert);
 apiRouter.post("/getRationTree",RationInterface.search.getRationTree);

+ 1 - 8
server.js

@@ -56,13 +56,6 @@ app.get('/pm', function(req, res){
 var pmRouter = require('./modules/pm/routes/pm_route');
 app.use('/', pmRouter);
 
-/*//zhangenping add 2017.0.13-----------------------------------------begin
-app.use(express.static(_rootDir+"/web"));
-app.use(express.static(_rootDir+"/lib"));
-var rations_Router = require("./modules/rations/routes/rations_route");
-app.use("/ration",rations_Router);
-//-----------------------------------------------------------------end*/
-
 app.get('/main',  function(req, res) {
     if (!req.session.userAccount) {
         res.redirect('/login');
@@ -79,7 +72,7 @@ app.get('/main',  function(req, res) {
 //zhangenping add 2017.0.13-----------------------------------------begin
 app.use(express.static(_rootDir+"/web"));
 app.use(express.static(_rootDir+"/lib"));
-var rations_Router = require("./modules/rations/routes/rations_route");
+var rations_Router = require("./modules/rationLibEditor/routes/rationLibEditor_route");
 app.use("/ration",rations_Router);
 //-----------------------------------------------------------------end
 

+ 154 - 81
web/rations/dinge.html

@@ -75,7 +75,7 @@
 
                                         </tbody>
                                       </table>
-                                      <div class="m-2"><a href="javacript:void(0);" data-toggle="modal" data-target="#add" class="btn btn-primary btn-sm">添加</a></div>
+                                      <div class="m-2"><a href="javacript:void(0);" data-toggle="modal" data-target="#add" id="mkadd" class="btn btn-primary btn-sm">添加</a></div>
                                   </div>
                               </div>
                               <div class="tab-pane" id="tsm" role="tabpanel">
@@ -159,7 +159,7 @@
 
                                           </tbody>
                                         </table>
-                                        <div class="m-2"><a href="javacript:void(0);" data-toggle="modal" data-target="#addBglj"  class="btn btn-primary btn-sm">添加</a></div>
+                                        <div class="m-2"><a href="javacript:void(0);" data-toggle="modal" data-target="#addBglj" id="mkaddglj"  class="btn btn-primary btn-sm">添加</a></div>
                                     </div>
                                 </div>
                                 <div class="tab-pane" id="bfzd" role="tabpanel">
@@ -868,19 +868,19 @@
 var rationName = getQueryString("rationname");
 var treeObj;
 var zNodes =[
-    { id:1, pId:0,nId:2, name:"第一章 土石方工程",isParent:true},
-    { id:2, pId:0,nId:3, name:"第二章 挡墙、护坡工程",isParent:true},
-    { id:3, pId:0,nId:4, name:"第三章 基础工程",isParent:true},
-    { id:4, pId:0,nId:5, name:"第四章 脚手架工程",isParent:true},
-    { id:5, pId:0,nId:6, name:"第五章 砌筑工程",isParent:true},
-    { id:6, pId:0,nId:7, name:"第六章 混凝土及钢筋混凝土工程",isParent:true},
-    { id:7, pId:0,nId:8, name:"第七章 金属工程",isParent:true},
-    { id:8, pId:0,nId:9, name:"第八章 门窗、木结构",isParent:true},
-    { id:9, pId:0,nId:10, name:"第九章 楼地面工程",isParent:true},
-    { id:10, pId:0,nId:11, name:"第十章 层面工程",isParent:true},
-    { id:11, pId:0,nId:12, name:"第十一章 防腐隔热保温工程",isParent:true},
-    { id:12, pId:0,nId:13, name:"第十二章 装饰工程",isParent:true},
-    { id:13, pId:0,nId:-1, name:"第十三章 其他工程",isParent:true},
+    { id:1, pId:0,nId:2, name:"第一章 土石方工程",isParent:true,children:[]},
+    { id:2, pId:0,nId:3, name:"第二章 挡墙、护坡工程",isParent:true,children:[]},
+    { id:3, pId:0,nId:4, name:"第三章 基础工程",isParent:true,children:[]},
+    { id:4, pId:0,nId:5, name:"第四章 脚手架工程",isParent:true,children:[]},
+    { id:5, pId:0,nId:6, name:"第五章 砌筑工程",isParent:true,children:[]},
+    { id:6, pId:0,nId:7, name:"第六章 混凝土及钢筋混凝土工程",isParent:true,children:[]},
+    { id:7, pId:0,nId:8, name:"第七章 金属工程",isParent:true,children:[]},
+    { id:8, pId:0,nId:9, name:"第八章 门窗、木结构",isParent:true,children:[]},
+    { id:9, pId:0,nId:10, name:"第九章 楼地面工程",isParent:true,children:[]},
+    { id:10, pId:0,nId:11, name:"第十章 层面工程",isParent:true,children:[]},
+    { id:11, pId:0,nId:12, name:"第十一章 防腐隔热保温工程",isParent:true,children:[]},
+    { id:12, pId:0,nId:13, name:"第十二章 装饰工程",isParent:true,children:[]},
+    { id:13, pId:0,nId:-1, name:"第十三章 其他工程",isParent:true,children:[]},
 ];
 var setting = {
     view: {
@@ -896,9 +896,13 @@ var setting = {
         showRenameBtn: showRenameBtn
     },
     data: {
-        keep:{
+        keep: {
+            parent:true,
             leaf:true
         },
+        key: {
+            children: "children"
+        },
         simpleData: {
             enable: true
         }
@@ -909,6 +913,7 @@ var setting = {
         beforeEditName: beforeEditName,
         beforeRemove: beforeRemove,
         beforeRename: beforeRename,
+        beforeClick:beforeClick,
         onRemove: onRemove,
         onRename: onRename
     }
@@ -928,28 +933,29 @@ function beforeDrag(treeId, treeNodes) {
 }
 function beforeEditName(treeId, treeNode) {
     className = (className === "dark" ? "":"dark");
-    showLog("[ "+getTime()+" beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
     var zTree = $.fn.zTree.getZTreeObj("treeDemo");
     zTree.selectNode(treeNode);
-    setTimeout(function() {
-        if (confirm("进入节点 -- " + treeNode.name + " 的编辑状态吗?")) {
-            setTimeout(function() {
-                zTree.editName(treeNode);
-            }, 0);
-        }
-    }, 0);
+    zTree.editName(treeNode);
     return false;
 }
+function beforeClick(treeID,treeNode){
+    return (treeNode.level == 2);
+}
 function beforeRemove(treeId, treeNode) {
-    className = (className === "dark" ? "":"dark");
-    showLog("[ "+getTime()+" beforeRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
     var zTree = $.fn.zTree.getZTreeObj("treeDemo");
     zTree.selectNode(treeNode);
-    return confirm("确认删除 节点 -- " + treeNode.name + " 吗?");
+    return true;
 }
 //删除树节点事件
 function onRemove(e, treeId, treeNode) {
     var id = treeNode.id;
+    var pNodes = treeNode.getParentNode().children;
+    for(var i=0;i<pNodes.length;i++){
+        if(pNodes[i].nId==id){
+            pNodes[i].nId = -1;
+            saveNewSection(pNodes[i]);
+        }
+    }
     removeSection(id)
 }
 //删除树节点ajax函数
@@ -962,16 +968,14 @@ function removeSection(id){
         cache:false,
         timeout:1000,
         success:function(result){
-
         },
         error:function(){
-
         }
     })
 }
 function beforeRename(treeId, treeNode, newName, isCancel) {
     className = (className === "dark" ? "":"dark");
-    showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
+  //  showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
     if (newName.length == 0) {
         setTimeout(function() {
             var zTree = $.fn.zTree.getZTreeObj("treeDemo");
@@ -984,53 +988,15 @@ function beforeRename(treeId, treeNode, newName, isCancel) {
 }
 //编辑树节点事件(添加节点到数据库)
 function onRename(e, treeId, treeNode, isCancel) {
-   var nid;
-   if(treeNode.getNextNode()){
-      nid = treeNode.getNextNode().id
-   }else{
-        nid = -1;
-   }
-    var N ={}
-
-    N.SectionID =  new Date().getTime() ;
-
-    N.ParentID = treeNode.pId;
-    N.NextSiblingID = nid;
-    N.Name = treeNode.name;
-    addSection(N);
+    saveNewSection(treeNode);
 }
 //增加节点Ajax函数
-function addSection(n){
-    var section = JSON.stringify(n);
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/addSection",
-        data:{"rationName":rationName,"rationSection":section},
-        dataType:"json",
-        cache:false,
-        timeout:1000,
-        success:function(result){
-            getRationTree();//重新获取刷新树节点
-
-        },
-        error:function(){
-            getRationTree();
-        }
-    })
-}
 function showRemoveBtn(treeId, treeNode) {
     return true
 }
 function showRenameBtn(treeId, treeNode) {
     return true
 }
-function showLog(str) {
-    if (!log) log = $("#log");
-    log.append("<li class='"+className+"'>"+str+"</li>");
-    if(log.children("li").length > 8) {
-        log.get(0).removeChild(log.children("li")[0]);
-    }
-}
 function getTime() {
     var now= new Date(),
             h=now.getHours(),
@@ -1042,17 +1008,53 @@ function getTime() {
 var newCount = 1;
 function addHoverDom(treeId, treeNode) {
     var sObj = $("#" + treeNode.tId + "_span");
-    if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
+    if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0||(treeNode.level==2)) return;
     var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
             + "' title='add node' onfocus='this.blur();'></span>";
     sObj.after(addStr);
     var btn = $("#addBtn_"+treeNode.tId);
     if (btn) btn.bind("click", function(){
         var zTree = $.fn.zTree.getZTreeObj("treeDemo");
-        zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
+        if((treeNode.level==0)){
+            var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:true, name:"请输入章节名称",children:{}});
+
+        }
+        else{
+            var newNode = zTree.addNodes(treeNode, {id:(++newCount), pId:treeNode.id,nId:-1,isParent:false, name:"请输入章节名称"});
+
+        }
+        saveNewSection(newNode[0]);
+        var pnode = newNode[0].getPreNode()
+        if(pnode){
+            pnode.nId = newNode[0].id;
+            saveNewSection(pnode);
+        }
         return false;
     });
 };
+function saveNewSection(n){
+    var sec={};
+    sec.SectionID = n.id;
+    sec.ParentID = n.pId;
+    sec.NextSiblingID = n.nId;
+    sec.Name = n.name;
+    var section = JSON.stringify(sec);
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/ration/addSection",
+        data:{"rationName":rationName,"rationSection":section},
+        dataType:"json",
+        cache:false,
+        timeout:1000,
+        success:function(result){
+         //   getRationTree();//重新获取刷新树节点
+
+        },
+        error:function(){
+          //  getRationTree();
+        }
+    })
+}
 function removeHoverDom(treeId, treeNode) {
     $("#addBtn_"+treeNode.tId).unbind().remove();
 };
@@ -1102,18 +1104,75 @@ function saveTempTree(){
 }
 //根据返回的节点集合构建树节点
 function createRationTree(obj){
-    var treeArr = [];
-    for(var i=0;i<obj.length;i++){
-        var n={};
-        n.id = obj[i].SectionID;
-        n.pId = obj[i].ParentID;
-        n.nId = obj[i].NextSiblingID;
-        n.name = obj[i].Name;
-        n.isParent=true
-        treeArr[i] = n;
-    }
+    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 getQueryString(key){
     var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
     var result = window.location.search.substr(1).match(reg);
@@ -1122,6 +1181,20 @@ function getQueryString(key){
 $("#dinge").attr('href', "/ration/rationLib" + "?rationname=" + rationName);
 $("#gongliao").attr('href', "/ration/gongliao" + "?rationname=" + rationName);
 //新增定额事件
+$("#mkadd").click(function(){
+    var section = treeObj.getSelectedNodes();
+    if(!section.length){
+        alert("请选择需要添加定额的章节!")
+        return;
+    }
+})
+$("#mkaddglj").click(function() {
+    var s = $("#gljparam").val()
+    if (!s) {
+        alert("请选择需要添加工料机的定额!")
+        return;
+    }
+})
 $("#rationAdd").click(function(){
     var section = treeObj.getSelectedNodes();
     var rationItem = {};

web/rations/fuzhu.html → web/rationLibEditor/fuzhu.html


web/rations/gongliao.html → web/rationLibEditor/gongliao.html


web/rations/main.html → web/rationLibEditor/main.html