Przeglądaj źródła

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

Chenshilong 8 lat temu
rodzic
commit
208e488015
33 zmienionych plików z 1562 dodań i 747 usunięć
  1. 2 0
      config/db/db_manager.js
  2. 11 11
      modules/pm/models/project.js
  3. 42 0
      modules/rationLibEditor/controller/RItemsController.js
  4. 72 0
      modules/rationLibEditor/controller/RLibMapController.js
  5. 53 0
      modules/rationLibEditor/controller/RtreeController.js
  6. 47 0
      modules/rationLibEditor/controller/gljListController.js
  7. 0 2
      modules/rationLibEditor/RationEditorDB/Schemas.js
  8. 15 21
      modules/rationLibEditor/RationEditorDB/interfaces.js
  9. 80 0
      modules/rationLibEditor/models/gljList.js
  10. 78 0
      modules/rationLibEditor/models/rationItems.js
  11. 92 0
      modules/rationLibEditor/models/rationLibMap.js
  12. 67 0
      modules/rationLibEditor/models/rationTree.js
  13. 25 8
      modules/rationLibEditor/routes/rationLibEditor_route.js
  14. 3 0
      package.json
  15. 16 5
      public/cache/cacheUtil.js
  16. 49 0
      public/counter/counter.js
  17. 1 1
      server.js
  18. 4 2
      test/demo/demo.js
  19. 4 2
      test/unit/cache/testCacheUsage.js
  20. 44 0
      test/unit/counter/testCounter.js
  21. 7 0
      test/unit/reports/testRpt.js
  22. 20 27
      web/main/js/main.js
  23. 66 1
      web/main/js/main_ajax.js
  24. 6 6
      web/pm/html/project-management.html
  25. 38 29
      web/pm/js/pm_main.js
  26. 172 0
      web/rationLibEditor/_zSpread.js
  27. 29 228
      web/rationLibEditor/dinge.html
  28. 7 209
      web/rationLibEditor/gongliao.html
  29. 290 0
      web/rationLibEditor/js/dinge.js
  30. 39 0
      web/rationLibEditor/js/gongliao.js
  31. 171 0
      web/rationLibEditor/js/mainJ.js
  32. 1 188
      web/rationLibEditor/main.html
  33. 11 7
      web/scripts/tree_table.js

+ 2 - 0
config/db/db_manager.js

@@ -2,6 +2,8 @@
  * Created by Tony on 2017/3/9.
  */
 var mg = require('mongoose');
+//var Promise = require('bluebird');
+mg.Promise = require('bluebird');
 //mg.connect('mongodb://localhost/Demo');
 module.exports = {
     getConnection : function(server, port, dbName) {

+ 11 - 11
modules/pm/models/project.js

@@ -9,14 +9,14 @@ var dbm = require("../../../config/db/db_manager");
 var db = dbm.getCfgConnection("usersManages");
 var Schema = mongoose.Schema;
 var ProjectSchema = new Schema({
+    "ID": Number,
+    "ParentID": Number,
+    "NextSiblingID": Number,
+    "userID": Number,
     "name": String,
     "projType": String,
     "recentDateTime": Date,
     "createDateTime": Date,
-    "id": Number,
-    "parentId": Number,
-    "nextId": Number,
-    "userId": Number,
     "deleted": Boolean,
     'deleteDateTime': Date,
     'fullFolder': Array
@@ -46,7 +46,7 @@ var Schema = db.mongoose.Schema;
 var ProjectsDAO = function(){};
 
 ProjectsDAO.prototype.getUserProjects = function(userId, callback){
-    Projects.find({userId: userId, deleted: { $in: [false, null]}}, '-_id', function(err, templates){
+    Projects.find({userID: userId, deleted: { $in: [false, null]}}, '-_id', function(err, templates){
         if (err) {
             callback(1, 'Error', null);
         } else {
@@ -56,7 +56,7 @@ ProjectsDAO.prototype.getUserProjects = function(userId, callback){
 };
 
 ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
-    Projects.findOne({userId: userId, id: ProjId}, '-_id', function(err, template){
+    Projects.findOne({userID: userId, ID: ProjId}, '-_id', function(err, template){
         if (err) {
             callback(1, '找不到标段数据', null);
         } else {
@@ -82,9 +82,9 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
         for (var i = 0; i < datas.length && !hasError; i++){
             data = datas[i];
             if (data.updateType === 'update') {
-                Projects.update({userId: userId, id: data.updateData.id}, data.updateData, updateAll)
+                Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll)
             } else if (data.updateType === 'new') {
-                data.updateData['userId'] = userId;
+                data.updateData['userID'] = userId;
                 if (data.updateData.projType === 'Tender') {
                     data.updateData['createDateTime'] = new Date();
                 }
@@ -92,14 +92,14 @@ ProjectsDAO.prototype.updateUserProjects = function(userId, datas, callback){
                 newProject.save(updateAll);
             } else if (data.updateType === 'delete') {
                 data.updateData['deleteDateTime'] = new Date();
-                Projects.update({userId: userId, id: data.updateData.id}, data.updateData, updateAll);
+                Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
             }
         }
     }
 };
 
 ProjectsDAO.prototype.rename = function (userId, projectId, newName, callback){
-    Projects.update({userId: userId, id: projectId}, {name: newName}, function(err){
+    Projects.update({userID: userId, ID: projectId}, {name: newName}, function(err){
        if (err){
            callback(1, '项目不存在.');
        } else {
@@ -110,7 +110,7 @@ ProjectsDAO.prototype.rename = function (userId, projectId, newName, callback){
 
 ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback){
     updateData['recentDateTime'] = new Date();
-    Projects.update({userId: userId, id: projectId}, updateData, function(err){
+    Projects.update({userID: userId, ID: projectId}, updateData, function(err){
         if (err){
             callback(1, '项目不存在.');
         } else {

+ 42 - 0
modules/rationLibEditor/controller/RItemsController.js

@@ -0,0 +1,42 @@
+/**
+ * Created by Syusuke on 2017/3/20.
+ */
+var rationItemsData = require('../models/rationItems');
+var callback = function(req,res,err,data){
+    if(data){
+        res.status(200)
+        res.json({success:true,data:data});
+    }
+    else
+    if(err){
+        res.status(500)
+        res.json({success:false,error:err});
+    }
+    else{
+        res.status(204);
+        res.json({success:true,data:null});
+    }
+}
+module.exports = {
+    insertRation:
+        function(req,res){
+            var libName = req.body.rationLibName;
+            var value = JSON.parse(req.body.value)
+            rationItemsData.insertRation(libName,value,function(err,data){
+                callback(req,res,err,data);
+            })
+        },
+    updateRation:
+        function(req,res){
+            var libName = req.body.rationLibName;
+            var value = JSON.parse(req.body.value)
+           // var code = req.body.code;
+            var data = JSON.parse(req.body.data);
+            rationItemsData.updateRation(libName,value,data,function(err,data){
+                callback(req,res,err,data);
+            })
+        }
+
+}
+
+

+ 72 - 0
modules/rationLibEditor/controller/RLibMapController.js

@@ -0,0 +1,72 @@
+/**
+ * Created by Syusuke on 2017/3/20.
+ */
+var rationLibData = require('../models/rationLibMap');
+var callback = function(req,res,err,data){
+    if(data){
+        res.status(200)
+        res.json({success:true,data:data});
+    }
+    else
+    if(err){
+        res.status(500)
+        res.json({success:false,error:err});
+    }
+    else{
+        res.status(204);
+        res.json({success:true});
+    }
+}
+
+module.exports ={
+    addRationLib:function(req,res){
+        var libName = req.body.rationDisPlayName;
+        rationLibData.addRationLib(libName,function(err,data){
+            if (data) {
+                callback(req, res, err, data);
+            } else {
+                callback(req, res, err, null);
+            }
+        })
+    },
+    getRealLibName:function(req,res){
+        var libName = req.body.rationName;
+        rationLibData.getRealLibName(libName,function(err,data){
+            if (data) {
+                callback(req, res, err, data);
+            } else {
+                callback(req, res, err, null);
+            }
+        })
+    },
+    getDisPlayRationLibs: function(req, res){
+        rationLibData.getDisplayRationLibs(function(err, data){
+            if (data) {
+                callback(req, res, err, data);
+            } else {
+                callback(req, res, err, null);
+            }
+        });
+    },
+    deleteRationLib:function(req,res){
+        var rationName = req.body.rationName;
+        rationLibData.deleteRationLib(rationName,function(err,data){
+            if (data) {
+                callback(req, res, err, data);
+            } else {
+                callback(req, res, err,  null);
+            }
+        })
+    },
+    editRationLibs:function(req,res){
+        var rationName = req.body.rationName;
+        var newName = req.body.newName;
+        rationLibData.editRationLib(rationName,newName,function(err,data){
+            if (data) {
+                callback(req, res, err, data);
+            } else {
+                callback(req, res, err,  null);
+            }
+        })
+    }
+}

+ 53 - 0
modules/rationLibEditor/controller/RtreeController.js

@@ -0,0 +1,53 @@
+/**
+ * Created by Syusuke on 2017/3/21.
+ */
+var rationTreeData = require('../models/rationTree');
+var callback = function(req,res,err,data){
+    if(data){
+        res.status(200)
+        res.json({success:true,data:data});
+    }
+    else
+    if(err){
+        res.status(500)
+        res.json({success:false,error:err});
+    }
+    else{
+        res.status(204);
+        res.json({success:true,data:null});
+    }
+}
+module.exports ={
+    getRationTree:
+        function(req,res){
+             var libName = req.body.rationLibName;
+             rationTreeData.getRationTrees(libName,function(err,data){
+                callback(req,res,err,data)
+             })
+        },
+    tempRationTreeInsert:
+        function(req,res){
+            var DBName = req.body.rationName;
+            var rationTempTree = JSON.parse(req.body.rationTempTree);
+            rationTreeData.tempRationTreeInsert(DBName,rationTempTree,function(err,data){
+                callback(req,res,err,data)
+            })
+        },
+    sectionUpsert:
+        function(req,res){
+            var LibName = req.body.rationLibName;
+            var section = JSON.parse(req.body.rationSection);
+            rationTreeData.sectionUpsert(LibName,section,function(err,data){
+                callback(req,res,err,data)
+            })
+        },
+    deleteSection:
+        function(req,res){
+            var LibName = req.body.rationLibName;
+            var sectionID = req.body.sectionID;
+            rationTreeData.deleteSection(LibName,sectionID,function(err,data){
+                callback(req,res,err,data)
+            })
+        }
+
+}

+ 47 - 0
modules/rationLibEditor/controller/gljListController.js

@@ -0,0 +1,47 @@
+/**
+ * Created by Syusuke on 2017/3/23.
+ */
+var gljListData = require('../models/gljList');
+var callback = function(req,res,err,data){
+    if(data){
+        res.status(200)
+        res.json({success:true,data:data});
+    }
+    else
+    if(err){
+        res.status(500)
+        res.json({success:false,error:err});
+    }
+    else{
+        res.status(204);
+        res.json({success:true,data:null});
+    }
+}
+
+module.exports = {
+    insertGLJList:
+        function(req,res){
+            var libName = req.body.rationLibName;
+            var value = JSON.parse(req.body.value);
+            gljListData.insertGLJList(libName,value,function(err,data){
+                callback(req,res,err,data);
+            })
+        },
+    updateGLJList:
+        function(req,res){
+            var libName = req.body.rationLibName;
+            var value = JSON.parse(req.body.value)
+            var data = JSON.parse(req.body.data);
+            gljListData.updateGLJList(libName,value,data,function(err,data){
+                callback(req,res,err,data);
+            })
+        },
+    removeGLJList:
+        function(req,res){
+            var libName = req.body.rationLibName;
+            var value = JSON.parse(req.body.value)
+            gljListData.removeGLJList(libName,value,function(err,data){
+                callback(req,res,err,data);
+            })
+        }
+}

+ 0 - 2
modules/rationLibEditor/RationEditorDB/Schemas.js

@@ -12,8 +12,6 @@ var connectMap = function(callBack){
 }
 
 
-
-
 var MainContentSchema = mongoose.Schema({
     ContentItems:String,//总说明
     CalcRule:String//计算规则

+ 15 - 21
modules/rationLibEditor/RationEditorDB/interfaces.js

@@ -22,7 +22,7 @@ var inserts = {};
 var searchs = {};
 var updates = {}
 var removes = {}
-inserts.RationLibInsert = function(req,res){
+/*inserts.RationLibInsert = function(req,res){
     var str = req.body.rationDisPlayName;
     Schemas.connectMap(function(db){
         var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
@@ -32,9 +32,9 @@ inserts.RationLibInsert = function(req,res){
            callback(req,res,false," ");
        })
     })
-}
+}*/
 inserts.MainContentInsert = function(){};
-inserts.RationSectionInsert = function(req,res){//find and updata;
+/*inserts.RationSectionInsert = function(req,res){//find and updata;
     var DBName = req.body.rationName;
     var rationSection = JSON.parse(req.body.rationSection);
     Schemas.connectMap(function(db){
@@ -65,7 +65,7 @@ inserts.RationSectionInsert = function(req,res){//find and updata;
             }
         })
     })
-};
+};*/
 inserts.SectionTextInsert = function(req,res){};
 inserts.RationItemsInsert = function(req,res){
     var DBName = req.body.rationName;
@@ -153,7 +153,7 @@ inserts.GLJTypeTreeInsert = function(){};
 inserts.MinorRationInsert = function(){};
 inserts.CoeListInsert = function(){};
 inserts.RationCoeInsert = function(){};
-inserts.TempRationTreeInsert = function(req,res){
+/*inserts.TempRationTreeInsert = function(req,res){
     var DBName = req.body.rationName;
     var rationTempTree = JSON.parse(req.body.rationTempTree);
     Schemas.connectMap(function(db){
@@ -181,8 +181,8 @@ inserts.TempRationTreeInsert = function(req,res){
             }
         })
     })
-}
-searchs.getRationTree = function(req,res){
+}*/
+/*searchs.getRationTree = function(req,res){
     //打开连接相映定额库
     //返回树结构到前段ztree处理
     var DBName = req.body.rationName;
@@ -206,8 +206,8 @@ searchs.getRationTree = function(req,res){
             }
         })
     });
-}
-searchs.getRationLibs = function(req,res){
+}*/
+/*searchs.getRationLibs = function(req,res){
     Schemas.connectMap(function(db){
         var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
         LibMapModel.find({},{"DisplayName":1},function(err,data){
@@ -219,7 +219,7 @@ searchs.getRationLibs = function(req,res){
             }
         })
     })
-}
+}*/
 searchs.getGLJList = function(req,res){
     var DBName = req.body.rationName;
     Schemas.connectMap(function(db){
@@ -358,31 +358,25 @@ searchs.getRationByCode = function(req,res){
         })
     });
 }
-removes.deleteRationLibs = function(req,res){//只删除了映射表内容  级联操作待完成
+/*removes.deleteRationLibs = function(req,res){//只删除了映射表内容  级联操作待完成
     var rationName = req.body.rationName;
     Schemas.connectMap(function(db){
         var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
         LibMapModel.find({"DisplayName":rationName},function(err,data){
             if(data.length) {
                 var realRationName = data[0].DBName;
-                db = mongoose.createConnection("192.168.1.184", realRationName, 60666);
+                db = mongoose.createConnection("192.168.1.184", realRationName,60666);
                 db.dropDatabase(function(err){
                     if(err) callback(req,res,"drop err",false);
                     else{
                         callback(req,res,false,"ok")
-  /*                      var db = mongoose.createConnection("192.168.1.184"," rationLibMap", 60666)
-                        var LibMapModel = db.model("rationlibmaps",Schemas.RationLibMapSchema);
-                        LibMapModel.remove({"DisplayName":rationName},function(err){
-                            if(err) callback(req,res,"删除错误",false);
-                            else callback(req,res,false,"已删除");
-                        })*/
                     }
                 });
             }
         })
     })
 
-}
+}*/
 removes.deleteRationMapItem=function(req,res){
     var rationName = req.body.rationName;
     Schemas.connectMap(function(db){
@@ -474,7 +468,7 @@ removes.deleteRationGLJ = function(req,res){
     })
 
 }
-updates.updateRationLib = function(req,res){
+/*updates.updateRationLib = function(req,res){
     var str = req.body.rationName;
     var newName = req.body.newName;
     Schemas.connectMap(function(db){
@@ -485,7 +479,7 @@ updates.updateRationLib = function(req,res){
             })
     })
 
-}
+}*/
 updates.updateGLJItem = function(req,res){
     var DBName = req.body.rationName;
     var GLJCode = req.body.GLJCode;

+ 80 - 0
modules/rationLibEditor/models/gljList.js

@@ -0,0 +1,80 @@
+/**
+ * Created by Syusuke on 2017/3/23.
+ */
+var mongoose = require("mongoose");
+var dbm = require("../../../config/db/db_manager");
+var async = require("async");
+var Schema = mongoose.Schema;
+
+
+var gljListSchema = mongoose.Schema({
+    GLJCode:String,
+    GLJName:String,
+    specs:String,//规格,钢筋粗细,光圆
+    unit:String,//单位
+    basePrice:Number,
+    type:Number //工料机类型,便于分类
+});
+
+var gljListDAO = function(){};
+
+gljListDAO.prototype.insertGLJList = function(LibName,value,callback){
+    var db = dbm.getCfgConnection(LibName);
+    var gljListModel = db.model("gljlists",gljListSchema);
+    if(value.cellCurrValue == value.cellPrimValue) callback(false,false);
+    gljListModel.find({GLJCode:value.cellCurrValue},function(err,data){
+        if(data.length)
+            callback(false,false);
+        else{
+            if(value.cellPrimValue == null){
+                var glj = {};
+                glj.GLJCode = value.cellCurrValue;
+                glj.GLJName = null;
+                glj.specs = null;
+                glj.unit = null;
+                glj.basePrice = null;
+                glj.type = null;
+                new gljListModel(glj).save(function(err){
+                    if(err)
+                        callback(err,false);
+                    else
+                        callback(err,"ok")
+                })
+            }else
+                gljListModel.update({gljCode:value.cellPrimValue},{$set:{gljCode:value.cellCurrValue}},function(err){
+                    if(err) callback("更新工料机发生错误",false);
+                    else  callback(err,"ok");
+                });
+        }
+    })
+}
+
+gljListDAO.prototype.updateGLJList = function(libName,value,data,callback){
+    var db = dbm.getCfgConnection(libName);
+    var gljListModel = db.model("gljlists",gljListSchema);
+    var glj = {}
+    glj.GLJCode = data[0];
+    glj.GLJName = data[1];
+    glj.specs = data[2];
+    glj.unit = data[3];
+    glj.basePrice = data[4];
+    glj.type = data[5];
+    gljListModel.find({GLJCode:glj.GLJCode},function(err,data){
+        if(err) callback("请确是否有该工料机!",false)
+        else
+            gljListModel.update({GLJCode:glj.GLJCode},glj,function(err){
+                if(err) callback("更新工料机错误",false);
+                else callback(err,"更新成功");
+            })
+    })
+}
+
+gljListDAO.prototype.removeGLJList = function(libName,value,callback){
+    var db = dbm.getCfgConnection(libName);
+    var gljListModel = db.model("gljlists",gljListSchema);
+    gljListModel.remove({GLJCode:value.cellPrimValue},function(err){
+        if(err) callback("删除失败",false)
+        else callback(err,"ok");
+    })
+}
+module.exports = new gljListDAO()

+ 78 - 0
modules/rationLibEditor/models/rationItems.js

@@ -0,0 +1,78 @@
+/**
+ * Created by Syusuke on 2017/3/23.
+ */
+var mongoose = require("mongoose");
+var dbm = require("../../../config/db/db_manager");
+var async = require("async");
+var Schema = mongoose.Schema;
+
+
+var rationItemsSchema = mongoose.Schema({//只记载定额基本元素,并未和工料机挂钩
+    rationCode:String,
+    rationName:String,
+    unit:String,
+    basePrice:Number,
+    sectionId:Number,
+    contentId:Number,
+    caption:String,//显示内容
+    feeType:Number //取费类别,这条定额对应怎样的费率参与计算,在键定额库的时候手动输入
+});
+
+var rationItemsDAO = function(){};
+
+rationItemsDAO.prototype.insertRation = function(LibName,value,callback){
+    var db = dbm.getCfgConnection(LibName);
+    var rationItemsModel = db.model("rationItems",rationItemsSchema);
+    if(value.cellCurrValue == value.cellPrimValue) callback(false,false);
+    rationItemsModel.find({rationCode:value.cellCurrValue},function(err,data){
+        if(data.length)
+            callback(false,false);
+        else{
+            if(value.cellPrimValue == null){
+                var ration = {};
+                ration.rationCode = value.cellCurrValue;
+                ration.rationName = null;
+                ration.unit = null;
+                ration.basePrice = null;
+                ration.sectionId = null;
+                ration.contentId = null;
+                ration.caption = null;
+                ration.feeType = null;
+                new rationItemsModel(ration).save(function(err){
+                    if(err)
+                        callback(err,false);
+                    else
+                        callback(err,"ok")
+
+                })
+            }else
+                rationItemsModel.update({rationCode:value.cellPrimValue},{$set:{rationCode:value.cellCurrValue}},function(err){
+                    if(err) callback("更新定额发生错误",false);
+                    else  callback(err,"ok");
+                });
+        }
+    })
+}
+rationItemsDAO.prototype.updateRation = function(libName,value,data,callback){
+    var db = dbm.getCfgConnection(libName);
+    var rationItemsModel = db.model("rationItems",rationItemsSchema);
+    var ration = {}
+    ration.rationCode = data[0];
+    ration.rationName = data[1];
+    ration.unit = data[2];
+    ration.basePrice = data[3];
+    ration.sectionId = value.sectionSelected;
+    ration.contentId = null;
+    ration.caption = data[4];
+    ration.feeType = data[5];
+    rationItemsModel.find({rationCode:ration.rationCode},function(err,data){
+        if(err) callback("请确是否有该定额!",false)
+        else
+        rationItemsModel.update({rationCode:ration.rationCode},ration,function(err){
+            if(err) callback("更新定额错误",false)
+            else callback(err,"更新成功");
+        })
+    })
+}
+
+module.exports = new rationItemsDAO()

+ 92 - 0
modules/rationLibEditor/models/rationLibMap.js

@@ -0,0 +1,92 @@
+/**
+ * Created by Syusuke on 2017/3/20.
+ */
+var mongoose = require("mongoose");
+var dbm = require("../../../config/db/db_manager");
+var async = require("async");
+var db = dbm.getCfgConnection("rationLibMap");
+//var schema = mongoose.Schema;
+
+var rationLibMapSchema = mongoose.Schema({
+    displayName:String,
+    dbName:String
+})
+
+var rationLibMap = db.model("rationlibmaps", rationLibMapSchema);
+
+var rationLibMapDAO = function(){};
+
+rationLibMapDAO.prototype.getRealLibName = function(rationName,callback){
+    rationLibMap.find({"displayName":rationName}, function(err,data){
+        if (err) {
+            callback('Error', null);
+        } else {
+            callback(0, data);
+        }
+    });
+};
+
+rationLibMapDAO.prototype.addRationLib = function(rationName,callback){
+    rationLibMap.find({"risplayName":rationName},function(err,data){
+        if(data.length == 0)
+            new rationLibMap({"displayName":rationName,"dbName":rationName}).save(function(err) {
+                if (err) callback("Error", null)
+                else
+                    callback(false, "ok");
+            })
+        else
+        callback("定额库重名!",null)
+    })
+}
+
+rationLibMapDAO.prototype.getDisplayRationLibs = function(callback) {
+    rationLibMap.find({}, function(err, data){
+        if (err) {
+            callback( 'Error', null);
+        } else {
+            callback( false, data);
+        }
+    });
+};
+
+rationLibMapDAO.prototype.deleteRationLib = function(rationName,callback){
+    async.waterfall([
+        function(cb){
+            rationLibMap.find({"displayName":rationName},function(err,data){
+                cb(err,data)
+            })
+        },
+        function(data,cb){
+            var db1 = dbm.getCfgConnection(data[0].dbName);
+            db1.dropDatabase(function(err){
+              cb(err,data)
+            })
+        },
+        function(data,cb){
+             RationLibMap.remove({"displayName":rationName},function(err,data){
+                 cb(err,data);
+             })
+        }
+    ],
+        function(err,result){
+        if (err) {
+            callback( 'Error', null);
+        } else {
+            callback( '', "ok");
+        }
+    })
+}
+
+rationLibMapDAO.prototype.editRationLib = function(rationName,newName,callback){
+    rationLibMap.find({"displayName":newName}, function(err, data){
+        if (data.length == 0) {
+            rationLibMap.update({displayName:rationName},{$set:{displayName:newName}},function(err){
+                if(err) callback("err",false);
+                else callback(false,"ok")
+            })
+        } else
+        callback("不可重名!",false);
+    });
+}
+
+module.exports = new rationLibMapDAO();

+ 67 - 0
modules/rationLibEditor/models/rationTree.js

@@ -0,0 +1,67 @@
+/**
+ * Created by Syusuke on 2017/3/20.
+ */
+var mongoose = require("mongoose");
+var dbm = require("../../../config/db/db_manager");
+var async = require("async");
+var Schema = mongoose.Schema;
+
+var rationTreeSchema = mongoose.Schema({//章节树  //生成唯一id改为sectionID  改成string
+    sectionId:Number,
+    parentId:Number,
+    nextSiblingId:Number,
+    name:String
+});
+
+
+var rationTreeDAO = function(){};
+
+rationTreeDAO.prototype.getRationTrees = function(Libname,callback){
+    var db = dbm.getCfgConnection(Libname)
+    var rationTreeModel = db.model("rationtrees",rationTreeSchema)
+    rationTreeModel.find({},function(err,data){
+        if(data.length) callback(false,data);
+        else  if(err) callback("获取定额树错误!",false)
+        else callback(false,false);
+    })
+}
+rationTreeDAO.prototype.tempRationTreeInsert = function(Libname,rationTempTree,callback){
+    var db = dbm.getCfgConnection(Libname)
+    var rationTreeModel = db.model("rationtrees",rationTreeSchema)
+    rationTreeModel.collection.insert(rationTempTree,function(err,data){
+     if(err) callback("插入定额模板错误",false)
+     else callback(false,"ok")
+     })
+}
+
+rationTreeDAO.prototype.sectionUpsert = function(Libname,section,callback){
+    var db = dbm.getCfgConnection(Libname);
+    var rationTreeModel = db.model("rationtrees",rationTreeSchema);
+    rationTreeModel.find({"sectionId": section.sectionId},function(err,data){
+        if(data.length){
+            rationTreeModel.update({'sectionId':section.sectionId},section,function(err,data){
+                if(err){
+                    callback(" ",false);
+                }else
+                    callback(false,"ok");
+            });
+        }else{
+            var N = new rationTreeModel(section).save(function(err){
+                if(err){
+                    callback(" ",false);
+                }else
+                    callback(false,"success!");
+            })
+        }
+    })
+}
+//待  ration模块完成
+rationTreeDAO.prototype.deleteSection= function(Libname,sectionId,callback){
+    var db = dbm.getCfgConnection(Libname);
+    var rationTreeModel = db.model("rationItems",rationTreeSchema);
+    rationTreeModel.find({"sectionId": sectionId},[],function(err,data){
+
+    })
+}
+
+module.exports = new rationTreeDAO()

+ 25 - 8
modules/rationLibEditor/routes/rationLibEditor_route.js

@@ -2,13 +2,17 @@ var express = require("express");
 var apiRouter =express.Router();
 var _rootDir = __dirname;
 
+var RationLibMapController = require("../controller/RLibMapController")
+var RationTreeController = require("../controller/RTreeController");
+var RationItemController = require("../controller/RItemsController")
+var GLJListController = require("../controller/gljListController")
 var path = require('path');
 var htmlPath = path.join(__dirname,'../../../','web/rationLibEditor/');
 apiRouter.get('/', function(req, res) {
         res.redirect('/main');
 });
 
-var RationInterface = require("../RationEditorDB/interfaces");
+var RationInterface = require("../db/interfaces");
 apiRouter.get("/main",function(req,res){
     res.render("rationLibEditor/main.html");
 })
@@ -24,12 +28,8 @@ apiRouter.get('/gongliao', function (req, res) {
 apiRouter.get('/fuzhu', function (req, res) {
     res.render("rationLibEditor/fuzhu.html");
 });
-apiRouter.post("/addRationName",RationInterface.insert.RationLibInsert);
-apiRouter.post("/getRationTree",RationInterface.search.getRationTree);
-apiRouter.post("/saveTempRationTree",RationInterface.insert.TempRationTreeInsert);//Ϊ¿Õ¶¨¶î¿ârationtrees²åÈëÕ½ڵã
-apiRouter.post("/getRationLibs",RationInterface.search.getRationLibs);
-apiRouter.post("/deleteRationLibs",RationInterface.remove.deleteRationLibs);
-apiRouter.post("/addSection",RationInterface.insert.RationSectionInsert);
+
+//apiRouter.post("/addSection",RationInterface.insert.RationSectionInsert);
 apiRouter.post("/removeSection",RationInterface.remove.deleteRationSection);
 apiRouter.post("/saveGLJ",RationInterface.insert.GLJListInsert);
 apiRouter.post("/getGLJ",RationInterface.search.getGLJList);
@@ -40,7 +40,6 @@ apiRouter.post("/getGLJByCode",RationInterface.search.getGLJByCode);
 apiRouter.post("/getRationGLJItems",RationInterface.search.getRationGLJItems);
 apiRouter.post("/saveRationGLJ",RationInterface.insert.RationGLJInsert);
 apiRouter.post("/getGLJItem",RationInterface.search.getGLJ);
-apiRouter.post("/editRationLibs",RationInterface.update.updateRationLib);
 apiRouter.post("/editGLJItem",RationInterface.update.updateGLJItem);
 apiRouter.post("/deleteRation",RationInterface.remove.deleteRation);
 apiRouter.post("/deleteRationMapItem",RationInterface.remove.deleteRationMapItem);
@@ -51,4 +50,22 @@ apiRouter.post("/editRationItem",RationInterface.update.updateRationItem);
 apiRouter.post("/getRationByCode",RationInterface.search.getRationByCode);
 apiRouter.post("/setRationBasePrice",RationInterface.update.setRationBasePrice);
 
+//--------------------------------------------------rationLibMap
+apiRouter.post("/addRationLib",RationLibMapController.addRationLib);
+apiRouter.post("/getRationDisplayNames",RationLibMapController.getDisPlayRationLibs);
+apiRouter.post("/deleteRationLibs",RationLibMapController.deleteRationLib);
+apiRouter.post("/editRationLibs",RationLibMapController.editRationLibs);
+apiRouter.post("/getRealLibName",RationLibMapController.getRealLibName);
+//----------------------------------------------------rationTree
+apiRouter.post("/getRationTree",RationTreeController.getRationTree);
+apiRouter.post("/saveTempRationTree",RationTreeController.tempRationTreeInsert);
+apiRouter.post("/addSection",RationTreeController.sectionUpsert);
+apiRouter.post("/deleteSection",RationTreeController.deleteSection);
+//----------------------------------------------------ration
+apiRouter.post("/insertRation",RationItemController.insertRation);
+apiRouter.post("/updateRation",RationItemController.updateRation);
+//----------------------------------------------------gljList
+apiRouter.post("/insertGLJList",GLJListController.insertGLJList);
+apiRouter.post("/updateGLJList",GLJListController.updateGLJList);
+apiRouter.post("/removeGLJList",GLJListController.removeGLJList);
 module.exports = apiRouter;

+ 3 - 0
package.json

@@ -14,5 +14,8 @@
     "express-session": "^1.15.1",
     "request": "^2.79.0",
     "tape": "^4.6.3"
+  },
+  "dependencies": {
+    "bluebird": "^3.5.0"
   }
 }

+ 16 - 5
public/cache/cacheUtil.js

@@ -4,11 +4,22 @@
 var cache = {};
 
 module.exports = {
-    setCache: function(cacheKey, cacheValue) {
-        cache[cacheKey] = cacheValue;
-        return true;
+    setCache: function(groupKey, cacheKey, cacheValue) {
+        if (groupKey && cacheKey) {
+            if (!(cache[groupKey])) {
+                cache[groupKey] = {};
+            }
+            cache[groupKey][cacheKey] = cacheValue;
+            return true;
+        } else {
+            return false;
+        }
     },
-    getCache: function(cacheKey) {
-        return cache[cacheKey];
+    getCache: function(groupKey, cacheKey) {
+        var rst = null;
+        if (cache[groupKey]) {
+            rst = cache[groupKey][cacheKey];
+        }
+        return rst;
     }
 }

+ 49 - 0
public/counter/counter.js

@@ -0,0 +1,49 @@
+/**
+ * Created by Tony on 2017/3/21.
+ */
+var mongoose = require('mongoose');
+var dbm = require("../../config/db/db_manager");
+var projectdb = dbm.getCfgConnection("scConstruct");
+
+var Schema = mongoose.Schema;
+var counterSchema = new Schema({
+    _id: String,
+    sequence_value: Number
+});
+counterSchema.statics.findAndModify = function (query, sort, doc, options, callback) {
+    return this.collection.findAndModify(query, sort, doc, options, callback);
+};
+var counterModel = projectdb.model("counters", counterSchema);
+
+const PROJECT_COUNTER = 'projects', USER_COUNTER = 'users', BILL_COUNTER = 'bills', RATION_COUNTER = 'rations',
+    REPORT_COUNTER = 'rptTemplates', FEE_COUNTER = 'fees'
+
+var counterDAO = function(){};
+
+counterDAO.prototype.getIDAfterCount = function(moduleName, stepCount, callback) {
+    var sc = stepCount;
+    if (isNaN(stepCount) || (stepCount < 0)) {
+        sc = 1;
+    } else if (!(/^-?\d+$/.test(stepCount))) {
+        sc = Math.round(stepCount + 0.5);
+    }
+    counterModel.findAndModify({_id: moduleName}, [], { $inc: { sequence_value: sc } }, {'new':true}, callback);
+}
+
+counterDAO.prototype.getCurrentID = function(moduleName, callback) {
+    if (callback) {
+        counterModel.findOne({_id: moduleName}).exec()
+        .then(function(result, err) {
+            if (callback) {
+                callback(result, err);
+            }
+        }
+        );
+        return null;
+    } else {
+        var rst = counterModel.findOne({_id: moduleName}).exec() ;
+        return rst;
+    }
+}
+
+module.exports = new counterDAO();

+ 1 - 1
server.js

@@ -71,7 +71,7 @@ app.use("/report", rpt_Router);
 app.use(express.static(_rootDir+"/web"));
 app.use(express.static(_rootDir+"/lib"));
 var rations_Router = require("./modules/rationLibEditor/routes/rationLibEditor_route");
-app.use("/ration",rations_Router);
+app.use("/rationLibEditor",rations_Router);
 //-----------------------------------------------------------------end
 
 var apiRouter = express.Router();

+ 4 - 2
test/demo/demo.js

@@ -5,8 +5,10 @@
 var test = require('tape');
 
 test('basic arithmetic', function (t) {
-    t.plan(2);
-
     t.equal(2 + 3, 5);
     t.equal(7 * 8 + 9, 65);
+    t.equal(/^-?\d+$/.test("10"), true);
+    //t.equal(isNaN(10.1), true);
+    t.equal(Math.round(10.4999), 10);
+    t.end();
 });

+ 4 - 2
test/unit/cache/testCacheUsage.js

@@ -5,7 +5,9 @@ var test = require('tape');
 var cache = require('../../../public/cache/cacheUtil');
 
 test('test cache usage:', function(t) {
-    cache.setCache("unit_TestKey","hello my cache!");
-    t.equal(cache.getCache("unit_TestKey"), "hello my cache!")
+    cache.setCache("unit_Test_Grp","unit_TestKey","hello my cache!");
+    var msg = cache.getCache("unit_Test_Grp","unit_TestKey");
+    console.log(msg);
+    t.equal(msg, "hello my cache!")
     t.end();
 })

+ 44 - 0
test/unit/counter/testCounter.js

@@ -0,0 +1,44 @@
+/**
+ * Created by Tony on 2017/3/21.
+ */
+var test = require('tape');
+var counter = require('../../../public/counter/counter');
+var mongoose = require('mongoose');
+
+test('test counter\'s usage 0:', function(t) {
+    var promise = counter.getCurrentID("rptTemplates",function(result, err) {
+        console.log('callback result 0: ' + result.sequence_value);
+    });
+    if (promise) {
+        promise.then(function(rst){
+            console.log('promise result 0: ' + rst.sequence_value);
+        });
+    }
+    t.pass('just pass');
+    t.end();
+})
+
+test('test counter\'s usage 1:', function(t) {
+    var promise = counter.getCurrentID("rptTemplates", null);
+    if (promise) {
+        promise.then(function(rst){
+            console.log('promise result 1: ' + rst.sequence_value);
+        });
+    }
+    t.pass('just pass');
+    t.end();
+})
+
+test('test counter\'s usage 2:', function(t) {
+    counter.getIDAfterCount("rptTemplates",1, function(err, result){
+        console.log('result 2: ' + result.value.sequence_value);
+        t.equal(result.value.sequence_value, 1);
+        t.end();
+    });
+})
+
+test('finish', function (t) {
+    mongoose.disconnect();
+    t.pass('closing db connection');
+    t.end();
+});

+ 7 - 0
test/unit/reports/testRpt.js

@@ -5,6 +5,7 @@ var test = require('tape');
 var cmn_ctrl = require('../../../modules/reports/models/cfg_control');
 var cmn_font = require('../../../modules/reports/models/cfg_font');
 var cmn_style = require('../../../modules/reports/models/cfg_style');
+var mongoose = require('mongoose');
 
 test('test get report pages function: ', function (t) {
     /*/
@@ -43,4 +44,10 @@ test('test get report pages function: ', function (t) {
         return true;
     });
     //*/
+});
+
+test('finish', function (t) {
+    mongoose.disconnect();
+    t.pass('closing db connection');
+    t.end();
 });

+ 20 - 27
web/main/js/main.js

@@ -2,7 +2,7 @@
  * Created by Mai on 2017/3/10.
  */
 
-var Project, pm = '<a href="/pm">项目管理</a>', angleRight = '<i class="fa fa-angle-right fa-fw"></i>';
+var Project;
 
 var GetQueryString = function (name) {
     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
@@ -10,35 +10,28 @@ var GetQueryString = function (name) {
     if (r != null) return unescape(r[2]); return null;
 };
 
-var LoadFullPath = function (proj) {
-    var fullPath = [], i;
-    fullPath.push(pm);
-    for (i = 0; i < proj.fullFolder.length; i++) {
-        fullPath.push(angleRight, proj.fullFolder[i]);
-    }
-    fullPath.push(angleRight, proj.name)
-    return fullPath;
-};
-
 var LoadData = function () {
-    var fullPath;
+    var loadFullPathHtml = function (proj) {
+        var fullPath = [], i, pm = '<a href="/pm">项目管理</a>', angleRight = '<i class="fa fa-angle-right fa-fw"></i>';
+        fullPath.push(pm);
+        for (i = 0; i < proj.fullFolder.length; i++) {
+            fullPath.push(angleRight, proj.fullFolder[i]);
+        }
+        fullPath.push(angleRight, proj.name)
+        return fullPath.join('');
+    };
+    /*$.post('/getProject', {'data': JSON.stringify({"user_id": userID, "proj_id": GetQueryString('project')})},  function (result) {
+        if (result.error === 0) {
+            Project = result.data;
+            $('#fullpath').html(loadFullPathHtml(Project));
+        } else {
+            alert('error: ' + result.message);
+        };
+    });*/
     GetProject(GetQueryString('project'), function (data) {
         Project = data;
-        fullPath = LoadFullPath(Project);
-        $('#fullpath').html(fullPath.join(''));
+        $('#fullpath').html(loadFullPathHtml(Project));
     });
 };
 
-LoadData();
-
-var setting = {
-    columns: [
-        {
-            data: '',
-            hAlign: '',
-            vAlign: ''
-        },
-    ]
-}
-
-$('#warp-p2')
+LoadData();

+ 66 - 1
web/main/js/main_ajax.js

@@ -2,6 +2,29 @@
  * Created by Mai on 2017/3/10.
  */
 
+var PullData = function (url, data, successCallback, errorCallback) {
+    $.ajax({
+        type:"POST",
+        url: url,
+        data: {'data': JSON.stringify(data)},
+        dataType: 'json',
+        cache: false,
+        timeout: 50000,
+        success: function(result){
+            if (result.error === 0) {
+                successCallback(result.data);
+            } else {
+                alert('error: ' + result.message);
+                errorCallback();
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert('error ' + textStatus + " " + errorThrown);
+            errorCallback();
+        }
+    });
+};
+
 var GetProject = function (proj_id, callback) {
     $.ajax({
         type:"POST",
@@ -21,4 +44,46 @@ var GetProject = function (proj_id, callback) {
             alert('error ' + textStatus + " " + errorThrown);
         }
     });
-}
+};
+
+var GetBills = function (proj_id, callback) {
+    $.ajax({
+        type: "POST",
+        url: '/getBills',
+        data: {'data': JSON.stringify({"user_id": userID, "proj_id": proj_id})},
+        dataType: 'json',
+        cache: false,
+        timeout: 50000,
+        success: function (result) {
+            if (result.error === 0) {
+                callback(result.data);
+            } else {
+                alert('error: ' + result.message);
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert('error ' + textStatus + " " + errorThrown);
+        }
+    });
+};
+
+var GetRations = function (proj_id, callback) {
+    $.ajax({
+        type: "POST",
+        url: '/getRations',
+        data: {'data': JSON.stringify({"user_id": userID, "proj_id": proj_id})},
+        dataType: 'json',
+        cache: false,
+        timeout: 50000,
+        success: function (result) {
+            if (result.error === 0) {
+                callback(result.data);
+            } else {
+                alert('error: ' + result.message);
+            }
+        },
+        error: function(jqXHR, textStatus, errorThrown){
+            alert('error ' + textStatus + " " + errorThrown);
+        }
+    });
+};

+ 6 - 6
web/pm/html/project-management.html

@@ -332,7 +332,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id='addProjOk'>确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id='addProjOk'>确定</a>
                 </div>
             </div>
         </div>
@@ -359,7 +359,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="addFolderOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="addFolderOk">确定</a>
                 </div>
             </div>
         </div>
@@ -383,7 +383,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="renameOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="renameOk">确定</a>
                 </div>
             </div>
         </div>
@@ -405,7 +405,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-danger" id="deleteProjOk">删除</a>
+                    <a href="javacript:void(0);" class="btn btn-danger" id="deleteProjOk">删除</a>
                 </div>
             </div>
         </div>
@@ -425,7 +425,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="movetoOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="movetoOk">确定</a>
                 </div>
             </div>
         </div>
@@ -445,7 +445,7 @@
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
-                    <a href="#" class="btn btn-primary" id="copytoOk">确定</a>
+                    <a href="javacript:void(0);" class="btn btn-primary" id="copytoOk">确定</a>
                 </div>
             </div>
         </div>

+ 38 - 29
web/pm/js/pm_main.js

@@ -4,6 +4,13 @@
 
 var Tree = null, movetoZTree = null, copytoZTree = null;
 var ProjTreeSetting = {
+    tree: {
+        id: 'ID',
+        pid: 'ParentID',
+        nid: 'NextSiblingID',
+        btnColumn: 1,
+        nullId: -1
+    },
     columns: [
         {
             head: '',
@@ -122,7 +129,9 @@ var GetNeedUpdatePreNode = function (parent, next) {
 var GetPreNodeUpdateData = function (pre, nid) {
     var data = {};
     data['updateType'] = 'update';
-    data['updateData'] = {id: pre.id(), nextId: nid};
+    data['updateData'] = {};
+    data.updateData[setting.tree.id] = pre.id();
+    data.updateData[setting.tree.nid] = nid;
     return data;
 }
 // 获取新建项目数据
@@ -131,9 +140,9 @@ var GetAddProjUpdateData = function (parent, next, name) {
     updateData = {};
     updateData['updateType'] = 'new';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = newId;
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = newId;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     updateData['updateData']['name'] = name;
     updateData['updateData']['projType'] = 'Tender';
     datas.push(updateData);
@@ -145,9 +154,9 @@ var GetAddFolderProjUpdateData = function (parent, next, folderName1, folderName
         var data = {};
         data['updateType'] = 'new';
         data['updateData'] = {};
-        data['updateData']['id'] = newId;
-        data['updateData']['parentId'] = parentId;
-        data['updateData']['nextId'] = nextId;
+        data['updateData'][Tree.setting.tree.id] = newId;
+        data['updateData'][Tree.setting.tree.pid] = parentId;
+        data['updateData'][Tree.setting.tree.nid] = nextId;
         data['updateData']['name'] = name;
         data['updateData']['projType'] = projType;
         newId += 1;
@@ -155,8 +164,8 @@ var GetAddFolderProjUpdateData = function (parent, next, folderName1, folderName
         return data;
     }
     folderData1 = addUpdateData(parent.id(), next ? next.id() : -1, folderName1, 'Folder');
-    folderData2 = addUpdateData(folderData1.updateData.id, -1, folderName2, 'Folder');
-    addUpdateData(folderData2.updateData.id, -1, name, 'Tender');
+    folderData2 = addUpdateData(folderData1.updateData[Tree.setting.tree.id], -1, folderName2, 'Folder');
+    addUpdateData(folderData2.updateData[Tree.setting.tree.id], -1, name, 'Tender');
     return datas;
 };
 // 获取新建文件夹数据
@@ -165,9 +174,9 @@ var GetAddForlderUpdateData = function (parent, next, folderName) {
     updateData = {};
     updateData['updateType'] = 'new';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = newId;
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = newId;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     updateData['updateData']['name'] = folderName;
     updateData['updateData']['projType'] = 'Folder';
     datas.push(updateData);
@@ -185,8 +194,8 @@ var GetNextChangeUpdateData = function (datas, node, next) {
         data = {};
         data['updateType'] = 'update';
         data['updateData'] = {};
-        data['updateData']['id'] = node.id();
-        data['updateData']['nextId'] = next ? next.id() : -1;
+        data['updateData'][Tree.setting.tree.id] = node.id();
+        data['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
         datas.push(data);
     }
     return data;
@@ -207,7 +216,7 @@ var GetDeleteUpdateData = function (node) {
             var data = {};
             data['updateType'] = 'delete';
             data['updateData'] = {};
-            data['updateData']['id'] = node.id();
+            data['updateData'][Tree.setting.tree.id] = node.id();
             data['updateData']['deleted'] = true;
             if (node.data.projType === 'Tender') {
                 data['updateData']['FullFolder'] = GetfullFolder(node.parent);
@@ -224,8 +233,8 @@ var GetDeleteUpdateData = function (node) {
         updateData = {};
         updateData['updateType'] = 'update';
         updateData['updateData'] = {};
-        updateData['updateData']['id'] = pre.id();
-        updateData['updateData']['nextId'] = node ? node.nid() : -1;
+        updateData['updateData'][Tree.setting.tree.id] = pre.id();
+        updateData['updateData'][Tree.setting.tree.nid] = node ? node.nid() : -1;
         datas.push(updateData);
     }
     datas.push(deleteNodeData(node));
@@ -242,9 +251,9 @@ var GetMoveUpdateData = function (node, parent, next) {
     updateData = {};
     updateData['updateType'] = 'update';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = node.id();
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = node.id();
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     datas.push(updateData);
     return datas;
 };
@@ -254,9 +263,9 @@ var GetCopyUpdateData = function (node, parent, next){
     updateData = {};
     updateData['updateType'] = 'new';
     updateData['updateData'] = {};
-    updateData['updateData']['id'] = node.tree.maxNodeId() + 1;
-    updateData['updateData']['parentId'] = parent ? parent.id() : -1;
-    updateData['updateData']['nextId'] = next ? next.id() : -1;
+    updateData['updateData'][Tree.setting.tree.id] = node.tree.maxNodeId() + 1;
+    updateData['updateData'][Tree.setting.tree.pid] = parent ? parent.id() : -1;
+    updateData['updateData'][Tree.setting.tree.nid] = next ? next.id() : -1;
     updateData['updateData']['name'] = node.data.name;
     updateData['updateData']['projType'] = node.data.projType;
     datas.push(updateData);
@@ -266,8 +275,8 @@ var GetCopyUpdateData = function (node, parent, next){
         updateData = {};
         updateData['updateType'] = 'update';
         updateData['updateData'] = {};
-        updateData['updateData']['id'] = pre.id();
-        updateData['updateData']['nextId'] = node.tree.maxNodeId() + 1;
+        updateData['updateData'][Tree.setting.tree.id] = pre.id();
+        updateData['updateData'][Tree.setting.tree.nid] = node.tree.maxNodeId() + 1;
         datas.push(updateData);
     }
     return datas;
@@ -288,8 +297,8 @@ var ConvertTreeToZtree = function (Tree, zTreeObj, filterNode) {
             nodes.forEach(function (node) {
                 if (node !== filterNode) {
                     var data = {};
-                    data['id'] = node.data['id'];
-                    data['pId'] = node.pid();// === -1 ? 0 : node.pid();
+                    data['id'] = node.data[Tree.setting.tree.id];
+                    data['pId'] = node.pid();
                     data['name'] = node.data['name'];
                     data['isParent'] = node.data.projType === 'Folder';//(node.data.projType === 'Folder' && node.children.length === 0);
                     data['open'] = node.data.projType === 'Folder';//node.children.length !== 0;
@@ -418,8 +427,8 @@ var AddFolderProj = function () {
             datas.forEach(function (data) {
                 var parent, next;
                 if (data.updateType === 'new') {
-                    parent = data.updateData.parentId === -1 ?  Tree._root : Tree.findNode(data.updateData.parentId);
-                    next = data.updateData.nextId === -1 ? null : Tree.findNode(data.updateData.nextId);
+                    parent = data.updateData[Tree.setting.tree.pid] === -1 ?  Tree._root : Tree.findNode(data.updateData[Tree.setting.tree.pid]);
+                    next = data.updateData[Tree.setting.tree.nid] === -1 ? null : Tree.findNode(data.updateData[Tree.setting.tree.nid]);
                     Tree.addNodeData(data.updateData, parent, next);
                 }
             });

+ 172 - 0
web/rationLibEditor/_zSpread.js

@@ -0,0 +1,172 @@
+/**
+ * Created by Syusuke on 2017/3/17.
+ *
+ */
+(function($){
+    var _spSetting = {
+        spType:"",
+        header:[],
+        view:{
+            comboBox:[],
+            lockedCells:[]
+        },
+        private:{
+            spType:"",
+            colCount:0,
+            sectionSelected:null,
+            cellPrimValue:null,
+            cellCurrValue:null
+        }
+    }
+
+    _tools = {
+        isArray:function(arr){
+            return Object.prototype.toString.apply(arr) === "[object Array]"
+        },
+        clone:function(obj){  //���colon����  �������ֱ����ȸ��ƣ����󲻿���
+            if(obj===null) return null;
+            var o = _tools.isArray(obj)?[]:{};
+            for(var i in obj){
+                o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()): (typeof obj[i] === "object"? _tools.clone(obj[i]): obj[i]);
+            }
+            return o;
+        }
+    }
+
+
+    var _initSpread = function(spID,spSetting){
+        spSetting.private.colCount = spSetting.header.length;
+        spSetting.private.spType = spSetting.spType;
+        var spread = new GC.Spread.Sheets.Workbook(spID[0],{sheetCount:1});
+        var ActiveSheet = spread.getActiveSheet();
+        ActiveSheet.setColumnCount(spSetting.header.length, GC.Spread.Sheets.SheetArea.viewport);
+        ActiveSheet.options.isProtected = true;
+        ActiveSheet.getRange(-1, 0, -1 ,100, GC.Spread.Sheets.SheetArea.viewport).locked(false);
+        spread.options.tabStripVisible = false;
+        spread.options.scrollbarMaxAlign = false;
+        for(var i=0;i<spSetting.header.length;i++){
+            ActiveSheet.setValue(0, i, spSetting.header[i].headerName, GC.Spread.Sheets.SheetArea.colHeader);
+            ActiveSheet.setColumnWidth(i,spSetting.header[i].headerWidth, GC.Spread.Sheets.SheetArea.colHeader);
+        }
+        for(var i=0;i<spSetting.view.comboBox.length;i++){
+                var c = spSetting.view.comboBox[i]
+                var cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
+                cellType.items(c.items);
+                ActiveSheet.getRange(c.row,c.col,c.rowCount,c.colCount, GC.Spread.Sheets.SheetArea.viewport).cellType(cellType);
+            }
+        ActiveSheet.getRange(-1, 1, -1 , 100, GC.Spread.Sheets.SheetArea.viewport).locked(true);
+
+        ActiveSheet.bind(GC.Spread.Sheets.Events.EditStarting,function(sender,args){
+            spSetting.private.cellCurrValue = null;
+            spSetting.private.cellPrimValue = ActiveSheet.getValue(args.row,args.col);
+        })
+
+        ActiveSheet.bind(GC.Spread.Sheets.Events.EditEnding,function(sender,args){
+            spSetting.private.cellCurrValue = args.editingText;
+            if(args.col == 0){
+                var a = spSetting.view.lockedCells;
+                var b = [];
+                ActiveSheet.getRange(args.row, 1, 1 , 100, GC.Spread.Sheets.SheetArea.viewport).locked(args.editingText == null);
+                a.forEach(function(x){
+                    b.push(x.col);
+                })
+                b.forEach(function(x){
+                    ActiveSheet.getCell(args.row,x).locked(true);
+                });
+                if(args.editingText == null){
+                    removeAction(spSetting)
+                   for(var i=0;i<spSetting.private.colCount;i++){
+                       ActiveSheet.setValue(args.row,i,null);
+                   }
+                }else{
+                    insertAction(spSetting,function(status){
+                        if(status == 204)
+                            ActiveSheet.setValue(args.row,0,null)
+                        spSetting.private.cellCurrValue = null;
+                        spSetting.private.cellPrimValue = null;
+                    });
+                }
+            }else
+           // var code = ActiveSheet.getValue(args.row,0);
+            {
+                var data = [];
+                for(var i=0;i<spSetting.header.length;i++){
+                    data.push(ActiveSheet.getValue(args.row,i))
+                }
+                data[args.col] = args.editingText
+                updateAction(spSetting,data);
+            }
+        })
+        return spread;
+    }
+    function insertAction(spSetting,callback){
+        var value =JSON.stringify(spSetting.private);
+        $.ajax({
+            type:"POST",
+            url:"http://localhost:6060/rationLibEditor/insert" + spSetting.private.spType,
+            data:{"rationLibName":params.realLibName,"value":value},
+            dataType:"json",
+            cache:false,
+            timeout:50000,
+            success:function(result,textStatus,status){
+                if(status.status == 204){
+                    alert("编号为"+spSetting.private.cellCurrValue+"已存在,不可重复添加!")
+                    callback(status.status)
+                }
+
+                spSetting.private.cellCurrValue = null;
+                spSetting.private.cellPrimValue = null;
+            },
+            error:function(err){
+                alert(err.statusText);
+                spSetting.private.cellCurrValue = null;
+                spSetting.private.cellPrimValue = null;
+            }
+        })
+    }
+    function updateAction(spSetting,data){
+        var value = JSON.stringify(spSetting.private);
+        var datas = JSON.stringify(data);
+        $.ajax({
+            type:"POST",
+            url:"http://localhost:6060/rationLibEditor/update" + spSetting.private.spType,
+            data:{"rationLibName":params.realLibName,"value":value,"data":datas},
+            dataType:"json",
+            cache:false,
+            timeout:50000,
+            success:function(result,textStatus,status){
+                spSetting.private.cellCurrValue = null;
+                spSetting.private.cellPrimValue = null;
+            },
+            error:function(err){
+                alert(err.responseText.error)
+                spSetting.private.cellCurrValue = null;
+                spSetting.private.cellPrimValue = null;
+            }
+        })
+    }
+    function removeAction(spSetting){
+        var value = JSON.stringify(spSetting.private);
+        $.ajax({
+            type:"POST",
+            url:"http://localhost:6060/rationLibEditor/remove" + spSetting.private.spType,
+            data:{"rationLibName":params.realLibName,"value":value},
+            dataType:"json",
+            cache:false,
+            timeout:50000,
+            success:function(result){
+                spSetting.private.cellCurrValue = null;
+                spSetting.private.cellPrimValue = null;
+            },
+            error:function(){
+            }
+        })
+    }
+    $.fn.Spread = {
+        init:function(spID,zSetting){
+            var spSetting = _tools.clone(_spSetting);
+            $.extend(true,spSetting,zSetting);
+            return  _initSpread(spID,spSetting);
+        }
+    }
+}(jQuery))

+ 29 - 228
web/rationLibEditor/dinge.html

@@ -12,6 +12,7 @@
     <link rel="stylesheet" href="/web/css/font-awesome/font-awesome.min.css">
     <!--zTree-->
   	<link rel="stylesheet" href="/web/css/ztree/zTreeStyle.css" type="text/css">
+    <link rel="stylesheet" href="/web/css/spreadjs/gc.spread.sheets.10.0.1.css" type="text/css">
 
 </head>
 
@@ -67,16 +68,19 @@
                           <!-- Tab panes -->
                           <div class="tab-content">
                               <div class="tab-pane active" id="tde" role="tabpanel">
-                                  <div class="warp-p2">
-                                      <table class="table table-sm table-bordered m-0">
+                                 <div id="rationItemsSheet" class="warp-p2" style='width:100%; height:400px;'>
+
+                            <!--         <table class="table table-sm table-bordered m-0">
 
                                         <thead><tr><th width="30"></th><th width="120">编码</th><th>名称</th><th>单位</th><th>基价</th><th>显示名称(以%s表示参数)</th><th>默认取费专业</th><th width="90">操作</th></tr></thead>
                                         <tbody id ="rationTbody">
 
                                         </tbody>
                                       </table>
-                                      <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">
                                   <div class="warp-p2">
@@ -152,15 +156,17 @@
                             <!-- Tab panes -->
                             <div class="tab-content">
                                 <div class="tab-pane active" id="bglj" role="tabpanel">
-                                    <div class="warp-p2">
-                                        <table class="table table-sm table-bordered m-0" id="rationGLJTbody">
-                                          <thead><tr><th width="30"></th><th width="120">编码</th><th>名称</th><th>单位</th><th>基价单位</th><th>定额消耗</th><th>类型</th><th width="90">操作</th></tr></thead>
-                                          <tbody>
+                                   <div id="rationGLJSheet" class="warp-p2">
+                                       <!--       <table class="table table-sm table-bordered m-0" id="rationGLJTbody">
+                                               <thead><tr><th width="30"></th><th width="120">编码</th><th>名称</th><th>单位</th><th>基价单位</th><th>定额消耗</th><th>类型</th><th width="90">操作</th></tr></thead>
+                                               <tbody>
+
+                                               </tbody>
+                                             </table>
+                                           <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>
 
-                                          </tbody>
-                                        </table>
-                                        <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">
                                     <div class="warp-p2">
@@ -182,7 +188,7 @@
                                           <thead><tr><th width="30"></th><th width="40">编号</th><th width="120">本分项全部适用</th><th>调整顺序</th><th>名称</th><th>内容</th><th width="90">操作</th></tr></thead>
                                           <tbody>
                                             <tr>
-                                              <td>1</td><td>1</td><td><i class="fa fa-check"></td><td>2</td><td>挖湿土时</td><td>人工x1.18</td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#editFztj" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td>
+                                              <td>1</td><td>1</td><td><i class="fa fa-check"></i></td><td>2</td><td>挖湿土时</td><td>人工x1.18</td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#editFztj" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td>
                                             </tr>
                                           </tbody>
                                         </table>
@@ -856,6 +862,7 @@
         </div>
     </div>
     <!-- JS. -->
+    <script src = "/lib/spreadjs/gc.spread.sheets.all.10.0.1.min.js"></script>
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/lib/tether/tether.min.js"></script>
     <script src="/lib/bootstrap/bootstrap.min.js"></script>
@@ -864,8 +871,10 @@
   	<script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
   	<script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
     <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">
-var rationName = getQueryString("rationname");
+/*var rationName = getQueryString("rationname");*/
 var treeObj;
 var zNodes =[
     { id:1, pId:0,nId:2, name:"第一章 土石方工程",isParent:true,children:[]},
@@ -884,7 +893,7 @@ var zNodes =[
 ];
 var setting = {
     view: {
-    //	showIcon: showIconForTree,//已存在*/
+        //	showIcon: showIconForTree,//已存在*/
         addHoverDom: addHoverDom,
         removeHoverDom: removeHoverDom,
         selectedMulti: false
@@ -917,9 +926,8 @@ var setting = {
         onRemove: onRemove,
         onRename: onRename
     }
-};
+}; //ztree  setting
 var log, className = "dark";
-//章节树点击事件
 var properties = {
 }
 //点击树获取定额
@@ -947,35 +955,7 @@ function beforeRemove(treeId, treeNode) {
     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]);
-        }
-    }
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/getRationsBySectionID",
-        data:{"rationName": rationName,"sectionID": treeNode.id},
-        dataType:"json",
-        cache:false,
-        timeout:1000,
-        success:function(result){
-            if(result){
-                caseDeleteTreeNode(result.data)
-            }
 
-        },
-        error:function(){
-        }
-    })
-    removeSection(id)
-    $("#rationTbody").html("");
-    $("#rationGLJTbody").html("");
-}
 //级联删除章节点
 function caseDeleteTreeNode(arryObj){
     for(var i=0;i<arryObj.length;i++){
@@ -1026,11 +1006,6 @@ function beforeRename(treeId, treeNode, newName, isCancel) {
     }
     return true;
 }
-//编辑树节点事件(添加节点到数据库)
-function onRename(e, treeId, treeNode, isCancel) {
-    saveNewSection(treeNode);
-}
-//增加节点Ajax函数
 function showRemoveBtn(treeId, treeNode) {
     return true
 }
@@ -1045,56 +1020,8 @@ function getTime() {
             ms=now.getMilliseconds();
     return (h+":"+m+":"+s+ " " +ms);
 }
-var newCount = 13;
-function addHoverDom(treeId, treeNode) {
-    var sObj = $("#" + treeNode.tId + "_span");
-    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");
-        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,124 +1029,8 @@ function selectAll() {
     var zTree = $.fn.zTree.getZTreeObj("treeDemo");
     zTree.setting.edit.editNameSelectAll =  $("#selectAll").attr("checked");
 }
-//onLoad事件
-$(document).ready(function(){
-   getRationTree();
-});
-//获取章节树ajax函数
-function  getRationTree(){
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/getRationTree",
-        data:{"rationName": rationName},
-        dataType:"json",
-        cache:false,
-        timeout:1000,
-        success:function(result){
-            createRationTree(result.data);//根据返回的全部定额章节对象,构架树。
-        },
-        error:function(){
-            treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
-            saveTempTree();
-        }
-    })
-}
-//新建的定额库保存模板节点
-function saveTempTree(){
-    var rationTempTree = JSON.stringify(zNodes)
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/saveTempRationTree",
-        data:{"rationName":rationName,"rationTempTree":rationTempTree},
-        dataType:"json",
-        cache:false,
-        timeout:1000,
-        success:function(result){
 
-        },
-        error:function(){
 
-        }
-    })
-}
-//根据返回的节点集合构建树节点
-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 getQueryString(key){
-    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
-    var result = window.location.search.substr(1).match(reg);
-    return result?decodeURIComponent(result[2]):null;
-}
-$("#dinge").attr('href', "/ration/rationLib" + "?rationname=" + rationName);
-$("#gongliao").attr('href', "/ration/gongliao" + "?rationname=" + rationName);
 //新增定额事件
 $("#mkadd").click(function(){
     var section = treeObj.getSelectedNodes();
@@ -1257,7 +1068,7 @@ function saveRationItem(obj){
     var rationItem = JSON.stringify(obj)
     $.ajax({
         type:"POST",
-        url:"http://localhost:6060/ration/saveRationItem",
+        url:"http://localhost:6060/rationLibEditor/saveRationItem",
         data:{"rationName":rationName,"rationItem":rationItem},
         dataType:"json",
         cache:false,
@@ -1293,20 +1104,10 @@ function getRationItems(sectionID){
 }
 //显示定额条目
 function showRationItems(data){
-    $("#rationTbody tr").remove();
-    for(var i=0 ;i<data.length;i++){
-        var $tr = $('<tr><td></td><td><a href="#"></a></td><td></td><td></td><td></td><td></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td> </tr>');
-        var td1,td2,td3,td4,td5,td6,a;
-        var code,name,danwei,jijia,xsname,qfzy;
-        td1 = $("td:eq(1)",$tr);td2 = $("td:eq(2)",$tr);td3 = $("td:eq(3)",$tr);td4 = $("td:eq(4)",$tr);td5 = $("td:eq(5)",$tr);td6 = $("td:eq(6)",$tr),
-                a = $("a",td1);
-        code = data[i].RationCode;name = data[i].RationName;danwei=data[i].Unit;jijia = data[i].BasePrice;xsname = data[i].Caption;qfzy=data[i].FeeType;
-        a.text(code);td2.text(name);td3.text(danwei);td4.text(jijia);td5.text(xsname);td6.text(qfzy);
-        $tr.appendTo("#rationTbody");
-    }
-    bindRationClick();
-    bindRationEdit();
-    bindRationDelete();
+    //var RationJSONStr = JSON.stringify(data);
+    var spread = $("#rationItemsSheet").data("workbook");
+    spread.fromJSON(data);
+
 }
 //绑定点击定额号
 function bindRationClick(){

+ 7 - 209
web/rationLibEditor/gongliao.html

@@ -45,8 +45,8 @@
                       <ul id="treeDemo" class="ztree"></ul>
                     </div>
                   </div>
-                  <div class="main-content col-lg-9 p-0">
-                    <table class="table table-sm table-bordered m-0">
+                  <div id="GLJListSheet" class="main-content col-lg-9 p-0">
+          <!--       <table class="table table-sm table-bordered m-0">
                       <thead>
                         <tr>
                           <th></th>
@@ -60,39 +60,11 @@
                         </tr>
                       </thead>
                       <tbody>
-                       <!-- <tr>
-                          <td>1</td>
-                          <td>00010201</td>
-                          <td>土石方综合工日</td>
-                          <td></td>
-                          <td>工日</td>
-                          <td>22.00</td>
-                          <td>人工</td>
-                          <td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td>
-                        </tr>
-                        <tr>
-                          <td>2</td>
-                          <td>03010101</td>
-                          <td>钢材</td>
-                          <td></td>
-                          <td>t</td>
-                          <td>2600.00</td>
-                          <td>材料</td>
-                          <td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td>
-                        </tr>
-                        <tr>
-                          <td>3</td>
-                          <td>36290101</td>
-                          <td>水</td>
-                          <td></td>
-                          <td>m3</td>
-                          <td>2600.00</td>
-                          <td>材料</td>
-                          <td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td>
-                        </tr>-->
+
                       </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>
                 </div>
             </div>
@@ -220,12 +192,13 @@
     <script src="/lib/bootstrap/bootstrap.min.js"></script>
     <script src="/lib/global.js"></script>
     <!-- zTree -->
+    <script src = "/lib/spreadjs/gc.spread.sheets.all.10.0.1.min.js"></script>
   	<script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
   	<script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
+    <script type="text/javascript" src="/web/rationLibEditor/js/gongliao.js"></script>
+    <script type="text/javascript" src="/web/rationLibEditor/_zSpread.js"></script>
     <SCRIPT type="text/javascript">
   		<!--
-var rationName = getQueryString("rationname");//请求参数(定额库名称)
-$("#drirect-dinge").attr('href', "/ration/rationLib" + "?rationname=" + rationName );
 var setting = {
     view: {
         showIcon: false
@@ -245,181 +218,6 @@ var zNodes =[
 function showIconForTree(treeId, treeNode) {
     return !treeNode.isParent;
 };
-//页面onLoad事件,获取工料机并绑定修改删除
-$(document).ready(function(){
-    getGLJ();
-    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
-});
-function getGLJ() {
-    $.ajax({
-        type: "POST",
-        url: "http://localhost:6060/ration/getGLJ",
-        data: {"rationName": rationName},
-        dataType: "json",
-        cache: false,
-        timeout: 1000,
-        success: function (result) {
-          if(result){
-            showGLJ(result.data);
-            deleteGLJ();
-            bindEditGLJ();
-          }
-        },
-        error: function () {}
-    });
-}
-function showGLJ(obj){
-    $("tbody tr").html("");
-    for(var i=0;i<obj.length;i++){
-        addTags(obj[i]);
-    }
-}
-$("#btadd").click(function(){
-    addGLJItems();
-})
-function addTags(obj){
-    var $tr = $('<tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td> </tr>');
-    var td1,td2,td3,td4,td5,td6;
-    var code,name,guige,danwei,jijia,leixin;
-    td1 = $("td:eq(1)",$tr);td2 = $("td:eq(2)",$tr);td3 = $("td:eq(3)",$tr);td4 = $("td:eq(4)",$tr);td5 = $("td:eq(5)",$tr);td6 = $("td:eq(6)",$tr);
-    code = obj.GLJCode;name = obj.GLJName;guige = obj.Specs;danwei=obj.Unit;jijia = obj.BasePrice;leixin = obj.Type;
-    td1.text(code);td2.text(name);td3.text(guige);td4.text(danwei);td5.text(jijia);td6.text(leixin)
-    $tr.appendTo("tbody");
-}
-//绑定删除工料机
-function deleteGLJ(){
-    $("tbody tr").each(function() {
-        var td7, a1,td1,a2;
-        td7 = $("td:eq(7)", $(this));
-        td1 = $("td:eq(1)", $(this));
-        var str = td1.text();
-        a2 = $("a:eq(1)",td7);
-        a2.click(function(){
-            $("#did").val(str);
-        })
-    })
-}
- //绑定编辑工料机
-function bindEditGLJ(){
-    $("tbody tr").each(function() {
-        var td7, td1,a2;
-        td7 = $("td:eq(7)", $(this));
-        td1 = $("td:eq(1)", $(this));
-        var str = td1.text();
-        a2 = $("a:eq(0)",td7);
-        a2.click(function(){
-            $("#did").val(str);
-        })
-    })
-}
-$("#edtglj").click(function(){
-    var GLJCode = $("#did").val();
-    var code,name,guige,danwei,jijia,leixing,glj={};
-    code=$("#Ecode").val();
-    name=$("#Ename").val();
-    guige=$("#Eguige").val();
-    danwei=$("#Edanwei").val();
-    jijia=$("#Ejijia").val();
-    leixing=$("#Eleixing").val();
-    glj.GLJCode = code;
-    glj.GLJName = name;
-    glj.Specs = guige;
-    glj.Unit = danwei;
-    glj.BasePrice = Number(jijia);
-    var type;
-    switch (leixing){
-        case "人工": type = 1;break;
-        case "材料": type = 3;break;
-        case "机械": type = 4;break;
-    }
-    glj.Type =type;
-    var gljItem = JSON.stringify(glj);
-
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/editGLJItem",
-        dataType:"json",
-        data:{"rationName":rationName,"GLJCode": GLJCode,"newGLJ":gljItem},
-        cache:false,
-        timeout:50000,
-        success:function(result){
-
-            getGLJ();
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-            alert("error "+textStatus+" "+errorThrown);
-        }
-    })
-}
-)
-$("#deleteGLJ").click(function(){
-    var GLJCode = $("#did").val();
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/deleteGLJItem",
-        dataType:"json",
-        data:{"rationName":rationName,"GLJCode": GLJCode},
-        cache:false,
-        timeout:50000,
-        success:function(result){
-            $("tbody tr").html("");
-            getGLJ();
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-            alert("error "+textStatus+" "+errorThrown);
-        }
-    })
-})
-function addGLJItems(){
-  //  var $tr = $('<tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td>人工</td> <td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td> </tr>');
-   // var td1,td2,td3,td4,td5,td6;
-    var code,name,guige,danwei,jijia,leixin;
-   // td1 = $("td:eq(1)",$tr);td2 = $("td:eq(2)",$tr);td3 = $("td:eq(3)",$tr);td4 = $("td:eq(4)",$tr);td5 = $("td:eq(5)",$tr);td6 = $("td:eq(6)",$tr);
-    code = $("#gljcode").val();name = $("#gljname").val();guige = $("#gljgg").val();danwei=$("#gljdw").val();jijia = $("#gljjj").val();leixin = $("#gljlx").val();
-  //  td1.text(code);td2.text(name);td3.text(guige);td4.text(danwei);td5.text(jijia);td6.text(leixin)
-  //  $tr.appendTo("tbody");
-        var gljItem = {}
-        gljItem.GLJCode = code;
-        gljItem.GLJName = name;
-        gljItem.Specs = guige;
-        gljItem.Unit = danwei;
-        gljItem.BasePrice =Number(jijia);
-        var type
-        switch (leixin){
-            case "人工": type = 1;break;
-            case "材料": type = 3;break;
-            case "机械": type = 4;break;
-        }
-        gljItem.Type =type;
-        saveGLJ(gljItem);
-}
-function saveGLJ(glj){
-    var gljItem = JSON.stringify(glj)
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/saveGLJ",
-        data:{"rationName":rationName,"gljItem":gljItem},
-            dataType:"json",
-            cache:false,
-            timeout:1000,
-            success:function(result){
-                getGLJ();
-            },
-            error:function(err){
-                var error = JSON.parse(err.responseText)
-                alert(error.error);
-            }
-            })
-
- }
-function getQueryString(key){
-    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
-    var result = window.location.search.substr(1).match(reg);
-    return result?decodeURIComponent(result[2]):null;
-}
-
-
-
   		//-->
   	</SCRIPT>
 </body>

+ 290 - 0
web/rationLibEditor/js/dinge.js

@@ -0,0 +1,290 @@
+/**
+ * Created by Syusuke on 2017/3/17.
+ */
+function getQueryString(key){
+    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
+    var result = window.location.search.substr(1).match(reg);
+    return result?decodeURIComponent(result[2]):null;
+}
+//---------------------------------------------------页面跳转
+var params = {}
+$("#dinge").click(function(){
+    $(this).attr('href', "/rationLibEditor/rationLib" + "?params=" + JSON.stringify(params))
+})
+$("#gongliao").click(function(){
+    $(this).attr('href', "/rationLibEditor/gongliao" + "?params=" + JSON.stringify(params))
+});
+//----------------------------------------------------页面初始化
+$(document).ready(function(){
+    initParam();
+    mkRationItemSpread();
+});
+function initParam(){
+    var rationLibName = getQueryString("rationname");//获取定额库参数
+    if(rationLibName)
+        getRealLib(rationLibName);
+    else{
+        params = JSON.parse(getQueryString("params"));
+        getRationTree();
+    }
+}
+function getRealLib(LibName){
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/getRealLibName",
+        data:{"rationName":LibName},
+        async:false,
+        dataType:"json",
+        cache:false,
+        timeout:1000,
+        success:function(result){
+            params.realLibName = result.data[0].dbName
+            getRationTree();
+        },
+        error:function(){}
+    })
+}
+//---------------------------------------------------初始化章节树界面
+function  getRationTree(){
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/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)
+        }
+    })
+}
+//根据返回的节点集合构建树节点
+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:"http://localhost:6060/rationLibEditor/saveTempRationTree",
+        data:{"rationName":rationLibName,"rationTempTree":rationTempTree},
+        dataType:"json",
+        cache:false,
+        timeout:1000,
+        success:function(result,textStatus,status){},
+        error:function(){}
+    })
+}
+//--------------------------------------------------------树处理事件
+var newCount = 13;
+//新增树节点
+function addHoverDom(treeId, treeNode) {
+    var sObj = $("#" + treeNode.tId + "_span");
+    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");
+        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/rationLibEditor/addSection",
+        data:{"rationLibName":params.realLibName,"rationSection":section},
+        dataType:"json",
+        cache:false,
+        timeout:1000,
+        success:function(result,textStatus,status){
+        },
+        error:function(){
+        }
+    })
+}
+//编辑树节点事件(添加节点到数据库)
+function onRename(e, treeId, treeNode, isCancel) {
+    saveNewSection(treeNode);
+}
+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]);
+        }
+    }
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/deleteSection",
+        data:{"rationLibName":params.realLibName,"sectionID": treeNode.id},
+        dataType:"json",
+        cache:false,
+        timeout:1000,
+        success:function(result,textStatus,status){
+            //if(result){
+            //    caseDeleteTreeNode(result.data)
+            //}
+        },
+        error:function(){
+        }
+    })
+    removeSection(id)
+    $("#rationTbody").html("");
+    $("#rationGLJTbody").html("");
+}
+//--------------------------------------------------------定额spreadjs
+var spSetting_ration = {
+    spType:"Ration",
+    header:[
+        {headerName:"编码",headerWidth:120,data:"rationCode"},
+        {headerName:"名称",headerWidth:400,data:"rationName"},
+        {headerName:"单位",headerWidth:120,data:"unit"},
+        {headerName:"基价",headerWidth:120,data:"basePrice"},
+        {headerName:"显示名称(以%s表示参数)",headerWidth:450,data:"caption"},
+        {headerName:"取费专业",headerWidth:120,data:"feeType"}
+    ],
+    view:{
+        comboBox:[
+            {row:-1,col:2,rowCount:-1,colCount:1}
+        ],
+        lockedCells:[
+            {row:-1,col:3,rowCount:-1, colCount:1}
+        ]
+    }
+};
+var spSetting_rationGLJ = {
+    spType:"RationGLJ",
+    header:[
+        {headerName:"编码",headerWidth:160},
+        {headerName:"名称",headerWidth:400},
+        {headerName:"单位",headerWidth:160},
+        {headerName:"单位基价",headerWidth:160},
+        {headerName:"定额消耗",headerWidth:160},
+        {headerName:"类型",headerWidth:160},
+        {headerName:"操作",headerWidth:130}
+    ],
+    view:{
+        comboBox:[],
+        lockedCells:[
+            {row:-1,col:1,rowCount:-1, colCount:1},
+            {row:-1,col:2,rowCount:-1, colCount:1},
+            {row:-1,col:3,rowCount:-1, colCount:1},
+            {row:-1,col:5,rowCount:-1, colCount:1},
+            {row:-1,col:6,rowCount:-1, colCount:1}
+        ]
+    }
+};
+function mkRationItemSpread(){
+    var rationSpread =  $.fn.Spread.init($("#rationItemsSheet"),spSetting_ration);
+    var rationGLJSpread =  $.fn.Spread.init($("#rationGLJSheet"),spSetting_rationGLJ);
+}

+ 39 - 0
web/rationLibEditor/js/gongliao.js

@@ -0,0 +1,39 @@
+/**
+ * Created by Syusuke on 2017/3/22.
+ */
+//-----------------------------------------------获取参数对象
+var paramStr = getQueryString("params");
+var params = JSON.parse(paramStr);
+function getQueryString(key){
+    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
+    var result = window.location.search.substr(1).match(reg);
+    return result?decodeURIComponent(result[2]):null;
+}
+//-----------------------------------------------页面跳转
+$("#drirect-dinge").click(function(){
+  //  window.location = "/rationLibEditor/rationLib" + "?params=" + JSON.stringify(params);
+   $(this).attr('href', "/rationLibEditor/rationLib" + "?params=" + JSON.stringify(params))
+})
+//-----------------------------------------------页面初始化
+var spSetting_GLJ = {
+    spType:"GLJList",
+    header:[
+        {headerName:"编码",headerWidth:120,data:"GLJCode"},
+        {headerName:"名称",headerWidth:400,data:"GLJName"},
+        {headerName:"规格",headerWidth:120,data:"specs"},
+        {headerName:"单位",headerWidth:120,data:"unit"},
+        {headerName:"基价单价",headerWidth:120,data:"basePrice"},
+        {headerName:"类型",headerWidth:120,data:"type"}
+    ],
+    view:{
+        comboBox:[
+            {row:-1,col:3,rowCount:-1,colCount:1}
+        ],
+        lockedCells:[
+        ]
+    }
+};
+$(document).ready(function(){
+    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
+    var rationSpread =  $.fn.Spread.init($("#GLJListSheet"),spSetting_GLJ);
+});

+ 171 - 0
web/rationLibEditor/js/mainJ.js

@@ -0,0 +1,171 @@
+/**
+ * Created by Syusuke on 2017/3/17.
+ */
+$(function(){
+    getRationLibs();
+})
+
+function addressdirect(){
+    $("tr:gt(0)").each(function() {
+        var td, a;
+        td = $("td:eq(0)", $(this));
+        a = $('a', td);
+        a.attr('href', "/rationLibEditor/rationLib" + "?rationname=" + a.text());
+    })
+}
+function deleteLib(){
+    $("tr:gt(0)").each(function() {
+        var td0, a1,td2,a2;
+        td2 = $("td:eq(2)", $(this));
+        td0 = $("td:eq(0)", $(this));
+        a1 = $('a', td0);
+        var str = a1.text();
+        a2 = $("a:eq(1)",td2);
+        a2.click(function(){
+            $("#did").val(str)
+        })
+        // a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
+    })
+}
+
+function editLib(){
+    $("tr:gt(0)").each(function() {
+        var td0, a1,td2,a2;
+        td2 = $("td:eq(2)", $(this));
+        td0 = $("td:eq(0)", $(this));
+        a1 = $('a', td0);
+        var str = a1.text();
+        a2 = $("a:eq(0)",td2);
+        a2.click(function(){
+            $("#did").val(str)
+        })
+    })
+}
+
+$("#deleteLib").click(function(){
+    var rationLibName = $("#did").val();
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/deleteRationLibs",
+        dataType:"json",
+        data:{"rationName": rationLibName},
+        cache:false,
+        timeout:50000,
+        success:function(result){
+            getRationLibs();
+        },
+        error:function(iqXHR,textStatus,errorThrown){
+
+        }
+    })
+
+
+});
+function getRationLibs(){
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/getRationDisplayNames",
+        dataType:"json",
+        cache:false,
+        timeout:50000,
+        success:function(result){
+            $("tbody tr").html("");
+            for(var i=0;i<result.data.length;i++){
+                addLibTag(result.data[i].displayName);
+            }
+            addressdirect();
+            deleteLib();
+            editLib();
+        },
+        error:function(iqXHR,textStatus,errorThrown){
+            alert("error "+textStatus+" "+errorThrown);
+        }
+    })
+}
+
+function addLibTag(string){
+    var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal"     data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>')
+    var $td0 = $("td:eq(0)",$tr);
+    var $td1 = $("td:eq(1)",$tr);
+    var a = $("a",$td0);
+    var str = string;
+    a.text(str);
+    var date = new Date().format("yyyy-MM-dd");
+    $td1.text(date);
+    $tr.appendTo("tbody");
+}
+
+function addRation(str) {
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/addRationLib",
+        dataType:"json",
+        data:{"rationDisPlayName": str},
+        cache:false,
+        timeout:50000,
+        success:function(result){
+
+        },
+        error:function(iqXHR,textStatus,errorThrown){
+            alert("error "+textStatus+" "+errorThrown);
+        }
+    })
+
+}
+
+$("#rationAdd").click(function(){
+    var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>')
+    var $td0 = $("td:eq(0)",$tr);
+    var $td1 = $("td:eq(1)",$tr);
+    var a = $("a",$td0);
+    var str = $("#addInput").val();
+    a.text(str);
+    var date = new Date().format("yyyy-MM-dd");
+    $td1.text(date);
+    $tr.appendTo("tbody");
+    addRation(str);
+    addressdirect();
+    deleteLib();
+});
+
+$("#edtOK").click(function(){
+    var str = $("#did").val();
+    var newStr = $("#inputRation").val();
+    $.ajax({
+        type:"POST",
+        url:"http://localhost:6060/rationLibEditor/editRationLibs",
+        dataType:"json",
+        data:{"rationName": str,"newName":newStr},
+        cache:false,
+        timeout:50000,
+        success:function(result){
+            getRationLibs();
+        },
+        error:function(jqXHR){
+            var err = JSON.parse(jqXHR.responseText);
+            alert(err.error);
+        }
+    })
+
+});
+Date.prototype.format = function(fmt) {
+    var o = {
+        "M+" : this.getMonth()+1,
+        "d+" : this.getDate(),
+        "h+" : this.getHours(),
+        "m+" : this.getMinutes(),
+        "s+" : this.getSeconds(),
+        "q+" : Math.floor((this.getMonth()+3)/3),
+        "S"  : this.getMilliseconds()
+    };
+    if(/(y+)/.test(fmt)) {
+        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
+    }
+    for(var k in o) {
+        if(new RegExp("("+ k +")").test(fmt)){
+            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
+        }
+    }
+    return fmt;
+}
+autoFlashHeight();

+ 1 - 188
web/rationLibEditor/main.html

@@ -132,197 +132,10 @@
     <!-- zTree -->
   	<script type="text/javascript" src="/lib/ztree/jquery.ztree.core.js"></script>
   	<script type="text/javascript" src="/lib/ztree/jquery.ztree.excheck.js"></script>
-
+    <script type="text/javascript" src="/web/rationLibEditor/js/mainJ.js"></script>
 </body>
 <script type="text/javascript">
-//onLoad  获取所有定额库
-$(function(){
-    getRationLibs();
-})
-//为定额库添加跳转功能
-function addressdirect(){
-    $("tr:gt(0)").each(function() {
-        var td, a;
-        td = $("td:eq(0)", $(this));
-        a = $('a', td);
-        a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
-    })
-}
-//为定额库添加点击删除后对应定额库名称
-function deleteLib(){
-    $("tr:gt(0)").each(function() {
-        var td0, a1,td2,a2;
-        td2 = $("td:eq(2)", $(this));
-        td0 = $("td:eq(0)", $(this));
-        a1 = $('a', td0);
-        var str = a1.text();
-        a2 = $("a:eq(1)",td2);
-        a2.click(function(){
-            $("#did").val(str)
-        })
-       // a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
-    })
-}
-//为定额库添加点击编辑后对应定额库名称
-function editLib(){
-    $("tr:gt(0)").each(function() {
-        var td0, a1,td2,a2;
-        td2 = $("td:eq(2)", $(this));
-        td0 = $("td:eq(0)", $(this));
-        a1 = $('a', td0);
-        var str = a1.text();
-        a2 = $("a:eq(0)",td2);
-        a2.click(function(){
-            $("#did").val(str)
-        })
-        // a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
-    })
-}
-
-//删除按钮点击事件
-$("#deleteLib").click(function(){
-    var rationName = $("#did").val();
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/deleteRationLibs",
-        dataType:"json",
-        data:{"rationName": rationName},
-        cache:false,
-        async:false,
-        timeout:50000,
-        success:function(result){
-        //    getRationLibs();//刷新界面重新获取定额库
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-
-        }
-    })
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/deleteRationMapItem",
-        dataType:"json",
-        data:{"rationName": rationName},
-        async:false,
-        cache:false,
-        timeout:50000,
-        success:function(result){
-            getRationLibs();//刷新界面重新获取定额库
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-
-        }
-    })
-
-
-});
-//获取定额库
-function getRationLibs(){
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/getRationLibs",
-        dataType:"json",
-        cache:false,
-        timeout:50000,
-        success:function(result){
-            $("tbody tr").html("");
-            for(var i=0;i<result.data.length;i++){
-                addLibTag(result.data[i].DisplayName);
-            }
-            addressdirect();//为所有定额库添加跳转功能
-            deleteLib();//为所有定额库添加删除功能
-            editLib();
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-            alert("error "+textStatus+" "+errorThrown);
-        }
-    })
-}
-//显示定额库条目
-function addLibTag(string){
-    var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal"     data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>')
-    var $td0 = $("td:eq(0)",$tr);
-    var $td1 = $("td:eq(1)",$tr);
-    var a = $("a",$td0);
-    var str = string;
-    a.text(str);
-    var date = new Date().format("yyyy-MM-dd");
-    $td1.text(date);
-    $tr.appendTo("tbody");
-}
-//增加定额库ajax函数
-function addRation(str) {
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/addRationName",
-        data:{"rationDisPlayName": str},
-        dataType:"json",
-        cache:false,
-        timeout:50000,
-        success:function(result){
-
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-            alert("error "+textStatus+" "+errorThrown);
-        }
-    })
-
-}
-//增加定额库按钮点击事件
-$("#rationAdd").click(function(){
-    var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>')
-    var $td0 = $("td:eq(0)",$tr);
-    var $td1 = $("td:eq(1)",$tr);
-    var a = $("a",$td0);
-    var str = $("#addInput").val();
-    a.text(str);
-    var date = new Date().format("yyyy-MM-dd");
-    $td1.text(date);
-    $tr.appendTo("tbody");
-    addRation(str);
-    addressdirect();
-    deleteLib();
-});
-//编辑按钮点击事件
-$("#edtOK").click(function(){
-    var str = $("#did").val();
-    var newStr = $("#inputRation").val();
-    $.ajax({
-        type:"POST",
-        url:"http://localhost:6060/ration/editRationLibs",
-        dataType:"json",
-        data:{"rationName": str,"newName":newStr},
-        cache:false,
-        timeout:50000,
-        success:function(result){
-            getRationLibs();//刷新界面重新获取定额库
-        },
-        error:function(iqXHR,textStatus,errorThrown){
-
-        }
-    })
 
-});
-Date.prototype.format = function(fmt) {
-    var o = {
-        "M+" : this.getMonth()+1,                 //月份
-        "d+" : this.getDate(),                    //日
-        "h+" : this.getHours(),                   //小时
-        "m+" : this.getMinutes(),                 //分
-        "s+" : this.getSeconds(),                 //秒
-        "q+" : Math.floor((this.getMonth()+3)/3), //季度
-        "S"  : this.getMilliseconds()             //毫秒
-    };
-    if(/(y+)/.test(fmt)) {
-        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
-    }
-    for(var k in o) {
-        if(new RegExp("("+ k +")").test(fmt)){
-            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
-        }
-    }
-    return fmt;
-}
-autoFlashHeight();
 </script>
 
 </html>

+ 11 - 7
web/scripts/tree_table.js

@@ -6,11 +6,10 @@
 (function($) {
     var _setting = {
  		tree: {
- 			id: 'id',
- 			pid: 'parentId',
- 			nid: 'nextId',
+ 			id: 'ID',
+ 			pid: 'ParentID',
+ 			nid: 'NextSiblingID',
  			btnColumn: 1,
- 			iconCol: 'projType',
 			nullId: -1
  		},
  		columns: [
@@ -28,7 +27,8 @@
  		dataTemp: {
 			id: -1,
 			parentId: -1,
-			nextId: -1
+			nextId: -1,
+			isTemp: true
  		},
         viewEvent: {
             beforeSelect: null,
@@ -253,6 +253,7 @@
  				if (!next && data[setting.tree.nid] !== setting.tree.nullId) {
  					next = createTempNode(data[setting.tree.nid], setting);
  					next.parent = parent;
+					parent.children.push(next);
  				}
  				node.nextSibling = next;
 
@@ -265,7 +266,10 @@
  					} else {
  						parent.children.splice(parent.childIndex(next), 0, node);
  					}
- 				}
+ 				} else if (parent.childIndex(node) !== parent.childIndex(node.next) - 1) {
+					parent.children.splice(parent.childIndex(node), 1);
+					parent.children.splice(parent.childIndex(next), 0, node);
+				};
 			};
 
  			for (i = 0; i < arrData.length; i++){
@@ -338,7 +342,7 @@
  					if (node.row) {
  						if (pre) {
  							_view._moveRowDom(node, pre.deepestRow());
- 						} else if (parent.id() !== setting.tree.nullId) {
+ 						} else if (parent.id() !== this.setting.tree.nullId) {
                             _view._moveRowDom(node, parent.row);
                         } else if (nextSibling) {
  							_view._moveRowDomBefore(node, nextSibling.row);