Browse Source

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

TonyKang 8 years atrás
parent
commit
73b955dd0c

+ 6 - 6
modules/main/models/bills.js

@@ -8,18 +8,18 @@ var Schema = mongoose.Schema;
 var counter = require("../../../public/counter/counter.js");
 
 var billsSchema = new Schema({
-    id: Number,
-    parentId: Number,
-    nextSiblingId: Number,
-    projectId: Number,
+    ID: Number,
+    ParentID: Number,
+    NextSiblingID: Number,
+    projectID: Number,
     serialNo: Number,
-    chapterId: Number,
+    chapterID: Number,
     code: String,
     fullCode: String,
     name: String,
     unit: String,
     quantity: String, // Decimal
-    programId: Number,
+    programID: Number,
     comments: String,
     // 调价
     xs_Labour: String, // Decimal

+ 1 - 1
modules/main/models/gljs.js

@@ -6,7 +6,7 @@ var db = require("../db/project_db");
 var Schema = mongoose.Schema;
 
 var gljSchema = new Schema({
-    id: Number,
+    ID: Number,
     projectID: Number,
     orgRQuantity: String, //Decimal
     rQuantity: String, //Decimal

+ 1 - 1
modules/main/models/projectGLJ.js

@@ -6,7 +6,7 @@ var db = require("../db/project_db");
 var Schema = mongoose.Schema;
 
 var projectGLJSchema = new Schema({
-    id: Number,
+    ID: Number,
     projectId: Number,
     code: Number,
     name: String,

+ 3 - 3
modules/main/models/rationPrograms.js

@@ -6,11 +6,11 @@ var db = require("../db/project_db");
 var Schema = mongoose.Schema;
 
 var rationProgramSchema = new Schema({
-    id: Number,
-    projectId: Number,
+    ID: Number,
+    projectID: Number,
     name: String,
     programs: [{
-        id: Number,
+        ID: Number,
         serialNo: Number,
         code: String,
         name: String,

+ 3 - 3
modules/main/models/rations.js

@@ -7,9 +7,9 @@ var subSchema = require("./billsSubSchemas");
 var Schema = mongoose.Schema;
 
 var rationsSchema = new Schema({
-    id: Number,
-    projectId: Number,
-    billsItemId: Number,
+    ID: Number,
+    ProjectID: Number,
+    billsItemID: Number,
     serialNo: Number,
     libID: Number,
     code: String,

+ 34 - 4
web/main/html/main.html

@@ -618,10 +618,11 @@
         project = PROJECT.createNew();
         project.Bills.loadDatas(datas);
         project.Rations.loadDatas(drawing_data);
-        project.mainTree.loadDatas(project.Bills.tree, project.Rations.datas);
+        project.loadMainTree();
+        //project.mainTree.loadDatas(project.Bills.tree, project.Rations.datas);
 
-        //controller = TREE_SHEET_CONTROLLER.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
-        controller = TREE_SHEET_CONTROLLER.createNew(project.Bills.tree, billsSpread.getActiveSheet(), BillsGridSetting);
+        controller = TREE_SHEET_CONTROLLER.createNew(project.mainTree, billsSpread.getActiveSheet(), BillsGridSetting);
+        //controller = TREE_SHEET_CONTROLLER.createNew(project.Bills.tree, billsSpread.getActiveSheet(), BillsGridSetting);
         controller.showTreeData();
         controller.bind('refreshBaseActn', function (tree) {
             var showButton = function (show, btn) {
@@ -639,7 +640,36 @@
         });
 
         $('#insert').click(function () {
-            controller.insert();
+            var selected = controller.tree.selected;
+            var newSource = null, newNode = null, sels = billsSpread.getActiveSheet().getSelections();
+
+            if (!selected || selected.sourceType === project.Bills.getSourceType()) {
+                newSource = project.Bills.tree.insert(selected ? selected.source.getParentID() : -1, selected ? selected.source.getNextSiblingID() : -1);
+                newSource.data.Name = 'aaa';
+                newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
+            } else if (selected.sourceType === project.Rations.getSourceType()) {
+
+            } else if (selected.sourceType === project.GLJs.getSourceType()) {
+
+            }
+
+            if (newNode) {
+                newNode.source = newSource;
+                newNode.sourceType = selected ? selected.sourceType : project.Bills.getSourceType();
+                if (newNode.sourceType === project.Bills.getSourceType()) {
+                    newNode.data = newSource.data;
+                } else {
+                    newNode.data = newSource;
+                }
+
+                TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
+                    controller.sheet.addRows(newNode.serialNo(), 1);
+                    TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, [newNode], false);
+                    controller.setTreeSelected(newNode);
+                    controller.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
+                    controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center)
+                });
+            }
         });
         $('#delete').click(function () {
             controller.delete();

+ 14 - 2
web/main/js/models/bills.js

@@ -18,13 +18,25 @@ var Bills = {
         var bills = function (proj) {
             this.project = proj;
             this.datas = null;
-            this.tree = null;
+            this.tree = idTree.createNew(billsTreeSetting);
+
+            var sourceType = 'bills';
+            this.getSourceType = function () {
+                return sourceType;
+            }
         };
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
         bills.prototype.loadDatas = function (datas) {
             this.datas = datas;
-            this.tree = idTree.createNew(billsTreeSetting);
+            // generate Fees Index£¬For View & Calculate
+            /*this.datas.forEach(function (data) {
+                data.FeesIndex = {};
+                data.fees.forEach(function (fee) {
+                    data.FeesIndex[fee.fieldName] = fee;
+                });
+            });*/
+            // datas load to Tree
             this.tree.loadDatas(this.datas);
         };
 

+ 31 - 78
web/main/js/models/cache_tree.js

@@ -3,9 +3,6 @@
  */
 var cacheTree = {
     createNew: function (owner) {
-        var _eventType = {
-            afterSelectedChanged: 'afterSelectedChanged'
-        };
         var tools = {
             findNode: function (nodes, check) {
                 for (var i = 0; i < nodes.length; i++) {
@@ -102,17 +99,6 @@ var cacheTree = {
                     }
                     nodes[i].parent = parent;
                 }
-            },
-            sortTreeItems: function (tree) {
-                var addItems = function (items) {
-                    var i;
-                    for (i = 0; i < items.length; i++) {
-                        tree.items.push(items[i]);
-                        addItems(items[i].children);
-                    }
-                };
-                tree.items.splice(0, tree.items.length);
-                addItems(tree.roots);
             }
         };
 
@@ -129,7 +115,7 @@ var cacheTree = {
             this.expanded = true;
             this.visible = true;
 
-            this.nodeType = null;
+            this.sourceType = null;
             this.source = null;
 
             this.getID = function () {
@@ -212,14 +198,14 @@ var cacheTree = {
         };
 
         Node.prototype.canUpLevel = function () {
-            if (this.nodeType === this.tree.nodeType.bills) {
+            if (this.sourceType === this.tree.owner.Bills.getSourceType()) {
                 return this.parent ? true : false;
             } else {
                 return false;
             }
         };
         Node.prototype.canDownLevel = function () {
-            return this.nodeType === this.tree.nodeType.bills ? !this.isFirst() : false;
+            return this.sourceType === this.tree.owner.Bills.getSourceType() ? !this.isFirst() : false;
         };
         Node.prototype.canUpMove = function () {
             return !this.isFirst();
@@ -268,7 +254,7 @@ var cacheTree = {
                 this.nextSibling = orgPre;
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex - 1, 0, this);
-                tools.sortTreeItems(this.tree);
+                this.tree.sortTreeItems();
                 success = true;
             }
             return success;
@@ -283,22 +269,20 @@ var cacheTree = {
                 this.preSibling = orgNext;
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex + 1, 0, this);
-                tools.sortTreeItems(this.tree);
+                this.tree.sortTreeItems();
                 success = true;
             }
             return success;
         };
 
         var Tree = function (owner) {
+            this.owner = owner;
             this.nodes = {};
             this.roots = [];
             this.items = [];
             this.prefix = 'id_';
             this.selected = null;
 
-            this.nodeType = {bills: 'bills', ration: 'ration', zc: 'zhuCai'};
-            this.masterField = {ration: 'BillsID'};
-
             var _MaxID = 0;
             this.newNodeID = function (id) {
                 if (arguments.length === 0) {
@@ -315,44 +299,29 @@ var cacheTree = {
             }
         };
 
-        Tree.prototype.createNewNode = function () {
-            var node = new Node(this, this.newNodeID());
-            this.nodes[this.prefix + node.getID()] = node;
-            return node;
+        Tree.prototype.addNode = function (parent, nextSibling) {
+            var newNode = new Node(this, this.newNodeID());
+            this.nodes[this.prefix + newNode.getID()] = newNode;
+            if (nextSibling) {
+                tools.addNodes(this, parent, [newNode], nextSibling.siblingIndex());
+            } else {
+                tools.addNodes(this, parent, [newNode]);
+            }
+            return newNode;
         };
-
-        Tree.prototype.loadDatas = function (idTree, rations) {
+        Tree.prototype.sortTreeItems = function () {
             var that = this;
-            var loadRationNode = function (rations, cacheNode) {
-                var newNode;
-                rations.forEach(function (ration) {
-                    if (ration[that.masterField.ration] && ration[that.masterField.ration] === cacheNode.source.getID()) {
-                        newNode = that.createNewNode();
-                        newNode.source = ration;
-                        newNode.nodeType = that.nodeType.ration;
-                        newNode.data = ration;
-                        tools.addNodes(that, cacheNode, [newNode]);
-                    }
-                });
-            };
-            var loadIdTreeNode = function (nodes, parent) {
-                var newNode, i;
+            var addItems = function (nodes) {
+                var i;
                 for (i = 0; i < nodes.length; i++) {
-                    newNode = that.createNewNode();
-                    newNode.source = nodes[i];
-                    newNode.nodeType = that.nodeType.bills;
-                    newNode.data = nodes[i].data;
-                    newNode.parent = parent;
-                    tools.addNodes(that, parent, [newNode]);
-                    if (nodes[i].children.length === 0) {
-                        loadRationNode(rations, newNode);
-                    };
-                    loadIdTreeNode(nodes[i].children, newNode);
+                    that.items.push(nodes[i]);
+                    addItems(nodes[i].children);
                 }
             };
-            loadIdTreeNode(idTree.roots, null);
-            tools.sortTreeItems(this);
+            this.items.splice(0, this.items.length);
+            addItems(this.roots);
         };
+
         Tree.prototype.firstNode = function () {
             return this.roots.length === 0 ? null : this.roots[0];
         };
@@ -371,25 +340,13 @@ var cacheTree = {
         };
 
         Tree.prototype.insert = function (parentID, nextSiblingID) {
-            var newID = this.newNodeID(), node = null, data = {};
-            var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
-            var nextSibling = nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
-            if (newID !== -1) {
-                data = {};
-                data[this.setting.id] = newID;
-                data[this.setting.pid] = parentID;
-                data[this.setting.nid] = nextSiblingID;
-                node = new Node(this, data);
-                if (nextSibling) {
-                    tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
-                } else {
-                    tools.addNodes(this, parent, [node]);
-                }
-                this.nodes[this.prefix + newID] = node;
-                tools.sortTreeItems(this);
-                this.maxNodeID(newID);
-            }
-            return node;
+            var parent = !parentID || parentID === -1 ? null : this.nodes[this.prefix + parentID];
+            var nextSibling = !nextSiblingID || nextSiblingID === -1 ? null: this.nodes[this.prefix + nextSiblingID];
+
+            var newNode = this.addNode(parent, nextSibling);
+            this.sortTreeItems();
+
+            return newNode;
         };
         Tree.prototype.delete = function (node) {
             var success = false;
@@ -406,16 +363,12 @@ var cacheTree = {
                 } else {
                     this.roots.splice(node.siblingIndex(), 1);
                 }
-                tools.sortTreeItems(this);
+                this.sortTreeItems();
                 success = true;
             }
             return success;
         };
 
-        Tree.prototype.editedData = function (field, id, newText) {
-            var node = this.findNode(id);
-        }
-
         return new Tree(owner);
     }
 };

+ 5 - 0
web/main/js/models/gljs.js

@@ -10,6 +10,11 @@ var GLJs = {
         var gljs = function (proj) {
             this.project = proj;
             this.datas = null;
+
+            var sourceType = 'glj';
+            this.getSourceType = function () {
+                return sourceType;
+            }
         };
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨

+ 35 - 0
web/main/js/models/project.js

@@ -13,6 +13,9 @@ var PROJECT = {
             this.Bills = Bills.createNew(this);
             this.Rations = Rations.createNew(this);
             this.GLJ = GLJs.createNew(this);
+
+
+            this.masterField = {ration: 'BillsID'};
         };
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨
@@ -20,6 +23,38 @@ var PROJECT = {
             // To Do
         };
 
+        project.prototype.loadMainTree = function () {
+            var that = this;
+            var loadRationNode = function (rations, cacheNode) {
+                var newNode;
+                rations.forEach(function (ration) {
+                    if (ration[that.masterField.ration] && ration[that.masterField.ration] === cacheNode.source.getID()) {
+                        newNode = that.mainTree.addNode(cacheNode);
+                        newNode.source = ration;
+                        newNode.sourceType = that.Rations.getSourceType();
+                        newNode.data = ration;
+                    }
+                });
+            };
+            var loadIdTreeNode = function (nodes, parent) {
+                var newNode, i;
+                for (i = 0; i < nodes.length; i++) {
+                    newNode = that.mainTree.addNode(parent);
+                    newNode.source = nodes[i];
+                    newNode.sourceType = that.Bills.getSourceType();
+                    newNode.data = nodes[i].data;
+
+                    if (nodes[i].children.length === 0) {
+                        loadRationNode(that.Rations.datas, newNode);
+                    } else {
+                        loadIdTreeNode(nodes[i].children, newNode);
+                    }
+                }
+            };
+            loadIdTreeNode(this.Bills.tree.roots, null);
+            this.mainTree.sortTreeItems();
+        }
+
         return new project();
     }
 };

+ 5 - 0
web/main/js/models/rations.js

@@ -11,6 +11,11 @@ var Rations = {
         var rations = function (proj) {
             this.project = proj;
             this.datas = null;
+
+            var sourceType = 'ration';
+            this.getSourceType = function () {
+                return sourceType;
+            }
         };
 
         // prototypeÓÃÓÚ¶¨Òåpublic·½·¨