Forráskód Böngészése

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

TonyKang 8 éve
szülő
commit
4e0470d444

+ 49 - 15
public/web/idTree.js

@@ -7,7 +7,8 @@ var idTree = {
             id: 'id',
             pid: 'pid',
             nid: 'nid',
-            rootId: -1
+            rootId: -1,
+            autoUpdate: false
         };
 
         var _eventType = {
@@ -65,13 +66,14 @@ var idTree = {
                     nodes[i].nextSibling = (i === nodes.length - 1) ? null : nodes[i + 1];
                 }
             },
-            // 在nodes中,从iIndex(包括)开始全部移除
+            // 在nodes中,从iIndex(包括)开始全部移除
             removeNodes: function (tree, parent, iIndex, count) {
                 var children = parent ? parent.children : tree.roots;
                 var pre = (iIndex < 0 || iIndex >= children.length) ? null : children[iIndex].preSibling;
                 var next = (pre && iIndex + count - 1 < children.length) ? children[iIndex + count] : null;
                 if (pre) {
-                    pre.nextSibling = next;
+                    pre.setNextSibling(next);
+                    //pre.nextSibling = next;
                 }
                 if (next) {
                     next.preSibling = pre;
@@ -82,7 +84,7 @@ var idTree = {
                     children.splice(iIndex, children.length - iIndex);
                 }
             },
-            // 在nodes中增加addNodes, 位置从index开始
+            // 在parent.children/tree.roots中增加nodes, 位置从index开始
             addNodes: function (tree, parent, nodes, iIndex) {
                 var children = parent ? parent.children : tree.roots;
                 var pre, next, i;
@@ -95,20 +97,20 @@ var idTree = {
                     next = null;
                 }
                 if (pre) {
-                    pre.nextSibling = nodes[0];
+                    pre.setNextSibling(nodes[0]);
                 }
                 nodes[0].preSibling = pre;
                 if (next) {
                     next.preSibling = nodes[nodes.length - 1];
                 }
-                nodes[nodes.length - 1].nextSibling = next;
+                nodes[nodes.length - 1].setNextSibling(next);
                 for (i = 0; i < nodes.length; i++) {
                     if (arguments.length === 4) {
                         children.splice(iIndex + i, 0, nodes[i]);
                     } else if (arguments.length === 3) {
                         children.push(nodes[i]);
                     }
-                    nodes[i].parent = parent ? parent : null;
+                    nodes[i].setParent(parent ? parent : null);
                 }
             },
             sortTreeItems: function (tree) {
@@ -135,7 +137,7 @@ var idTree = {
         };
 
         var Node = function (tree, data) {
-            // 以下的属性,本单元外均不可直接修改
+            // 以下的属性,本单元外均不可直接修改
             this.tree = tree;
             this.data = data;
             this.children = [];
@@ -160,6 +162,19 @@ var idTree = {
             return this.nextSibling ? this.nextSibling.getID() : -1;
         };
 
+        Node.prototype.setParent = function (parent) {
+            this.parent = parent;
+            if (this.tree.setting.autoUpdate) {
+                this.data[this.tree.setting.pid] = this.getParentID();
+            }
+        };
+        Node.prototype.setNextSibling = function (nextSibling) {
+            this.nextSibling = nextSibling;
+            if (this.tree.setting.autoUpdate) {
+                this.data[this.tree.setting.nid] = this.getNextSiblingID();
+            }
+        }
+
         Node.prototype.firstChild = function () {
             return this.children.length === 0 ? null : this.children[0];
         };
@@ -320,12 +335,12 @@ var idTree = {
             var iIndex = this.siblingIndex(), belongArray = this.parent ? this.parent.children : this.tree.roots, orgPre = this.preSibling;
             if (this.canUpMove()) {
                 if (orgPre.preSibling) {
-                    orgPre.preSibling.nextSibling = this;
+                    orgPre.preSibling.setNextSibling(this);
                 }
-                orgPre.nextSibling = this.nextSibling;
+                orgPre.seNextSibling(this.nextSibling);
                 this.preSibling = orgPre.preSibling;
                 orgPre.preSibling = this;
-                this.nextSibling = orgPre;
+                this.setNextSibling(orgPre);
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex - 1, 0, this);
                 tools.sortTreeItems(this.tree);
@@ -353,11 +368,11 @@ var idTree = {
             var iIndex = this.siblingIndex(), belongArray = this.parent ? this.parent.children : this.tree.roots, orgNext = this.nextSibling;
             if (this.canDownMove()) {
                 if (this.preSibling) {
-                    this.preSibling.nextSibling = orgNext;
+                    this.preSibling.setNextSibling(orgNext);
                 }
                 orgNext.preSibling = this.preSibling;
-                this.nextSibling = orgNext.nextSibling;
-                orgNext.nextSibling = this;
+                this.setNextSibling(orgNext.nextSibling);
+                orgNext.setNextSibling(this);
                 this.preSibling = orgNext;
                 belongArray.splice(iIndex, 1);
                 belongArray.splice(iIndex + 1, 0, this);
@@ -512,6 +527,25 @@ var idTree = {
             }
             return data;
         };
+        Tree.prototype.insertByData = function (data, parentID, nextSiblingID) {
+            var parent = parentID === -1 ? null : this.nodes[this.prefix + parentID];
+            var nextSibling = nextSiblingID === -1 ? null : this.nodes[this.prefix + nextSiblingID];
+            var node = this.nodes[this.prefix + data[this.setting.id]];
+            if (node) {
+                return node;
+            } else {
+                node = new Node(this, data);
+                if (nextSibling) {
+                    tools.addNodes(this, parent, [node], nextSibling.siblingIndex());
+                } else {
+                    tools.addNodes(this, parent, [node]);
+                }
+                this.nodes[this.prefix +  data[this.setting.id]] = node;
+                tools.sortTreeItems(this);
+                this.maxNodeID( data[this.setting.id]);
+                return node;
+            }
+        };
 
         Tree.prototype.delete = function (node) {
             var success = false, that = this;
@@ -525,7 +559,7 @@ var idTree = {
                 deleteIdIndex([node]);
                 //delete this.nodes[this.prefix + node.getID()];
                 if (node.preSibling) {
-                    node.preSibling.nextSibling = node.nextSibling;
+                    node.preSibling.setNextSibling(node.nextSibling);
                 }
                 if (node.nextSibling) {
                     node.nextSibling.preSibling = node.preSibling;

+ 5 - 1
public/web/tree_sheet_helper.js

@@ -94,7 +94,11 @@ var TREE_SHEET_HELPER = {
                     }
                     return data;
                 };
-                cell.value(getFieldText2());
+                if (colSetting.data.getText) {
+                    cell.value(colSetting.data.getText(node));
+                } else {
+                    cell.value(getFieldText2());
+                }
             });
             if (recursive) {
                 TREE_SHEET_HELPER.refreshTreeNodeData(setting, sheet, node.children, recursive);

+ 1 - 1
web/fees/feeRate.html

@@ -48,7 +48,7 @@
                 <span class="btn btn-link btn-sm new-msg">
                   <i class="fa fa-envelope-o" aria-hidden="true"></i>&nbsp;2
                 </span>
-                <button class="btn btn-link btn-sm">注销</button>
+                <button class="btn btn-link btn-sm" id="logout">注销</button>
             </div>
         </nav>
         <nav class="navbar navbar-toggleable-lg justify-content-between navbar-light p-0">

+ 33 - 5
web/fees/feeRate.js

@@ -1,4 +1,4 @@
-/**
+/**
  * Created by CSL on 2017-03-23.
  */
 var region = '重庆';
@@ -15,6 +15,10 @@ $(document).ready(function () {
     $("#projectFeeFile").click(function () {
         loadProjectFeeRates(feeRateFileID);
     });
+
+    $("#logout").click(function () {
+        location.href = '/logout';
+    });
 });
 
 function loadProjectFeeRates(fileID) {
@@ -75,10 +79,6 @@ function loadLibFeeRates(libID) {
 
 function createSpreadView(canEdit) {
     // 创建前先销毁旧树表。
-    //$('#divFee').empty();  // 清空不行,浏览器跟踪显示错误数狂飚:TypeError: G is null
-    //$('#divFee').remove(); // 删除可以,但是太山寨。
-    //$('#content').append($('<div class="grid" id="divFee"></div>'));
-    // 以下找到官方的处理方法,比较面向对象
     if (spreadView) {
         spreadView.destroy();
         spreadView = null;
@@ -173,8 +173,36 @@ function createSpreadView(canEdit) {
         }
     };
 
+    function showObjs(arr){
+        var s = '';
+        for (var i = 0; i < arr.length; i++) {
+            s = s + JSON.stringify(arr[i]) + "\n";
+        }
+        alert(s);
+    }
+
+    function showObjs2(obj) {
+        var str = "";
+        var spr = "";
+        for (var x in obj) {
+            if (obj.hasOwnProperty(x)) {
+                if(str == ''){ spr = '' } else { spr = ', '};
+                str += spr + x + ':' + obj[x];
+            }
+        }
+        return str;
+    }
+
+    function rowClickFun(sender, args) {
+        //var arr = [args.event, args.hitInfo, args.item.dataItem];
+        //showObjs(arr);
+        alert(showObjs2(spreadView.getItem(4).item));
+    }
+
     spreadView = new GC.Spread.Views.DataView($('#divFee')[0],
         dataSource, columns, new GC.Spread.Views.Plugins.GridLayout(options));
+ 
+    spreadView["rowClick"].addHandler(rowClickFun);
     spreadView.invalidate();
     document.querySelector('#divFee').focus();
 }

+ 1 - 0
web/templates/html/bills.html

@@ -100,6 +100,7 @@
 <script type="text/javascript" src="/web/templates/js/bills.js"></script>
 <script type="text/javascript" src="/web/templates/js/tp_bills_setting.js"></script>
 <script type="text/javascript" src="/public/web/common_ajax.js"></script>
+<script>
     autoFlashHeight();
 </script>
 </html>

+ 9 - 17
web/templates/js/bills.js

@@ -26,16 +26,14 @@ $(document).ready(function () {
     }
     var RefreshBillsData = function (datas) {
         datas.forEach(function (data) {
-            bills.forEach(function (billsData) {
-                if (data.data.ID === billsData.ID) {
-                    $.extend(true, billsData, data.data);
-                }
-            })
-        })
-    }
+            var node = tree.findNode(data.data.ID);
+            if (node) {
+                $.extend(true, node.data, data.data);
+            }
+        });
+    };
 
-    var bills;
-    var tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
+    var tree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: true});
     var billsSpread = new GC.Spread.Sheets.Workbook($('#billsSpread')[0], { sheetCount: 1 });
     var controller = TREE_SHEET_CONTROLLER.createNew(tree, billsSpread.getActiveSheet(), TEMPLATE_BILLS_SETTING);
 
@@ -88,7 +86,7 @@ $(document).ready(function () {
     });
 
     CommonAjax.post('/template/bills/getBillsTemplate', {tempType: tempType}, function (data) {
-        bills = data;
+        var bills = data;
         tree.loadDatas(bills);
         controller.showTreeData();
         RefreshBaseActn(tree);
@@ -108,9 +106,8 @@ $(document).ready(function () {
                 updateData = FormatUpdateData(controller.tree.getInsertData());
             }
             if (updateData.updateData.length > 0) {
-                PostData('/template/bills/updateBillsTemplate', updateData, function (data) {
+                CommonAjax.post('/template/bills/updateBillsTemplate', updateData, function (data) {
                     controller.insert();
-                    RefreshBillsData(data);
                     controller.showTreeData();
                 });
             } else {
@@ -124,7 +121,6 @@ $(document).ready(function () {
             updateData = FormatUpdateData(controller.tree.getDeleteData(selected));
             CommonAjax.post('/template/bills/updateBillsTemplate', updateData, function (data) {
                 controller.delete();
-                RefreshBillsData(data);
                 controller.showTreeData();
             });
         }
@@ -135,7 +131,6 @@ $(document).ready(function () {
             updateData = FormatUpdateData(selected.getUpLevelData());
             CommonAjax.post('/template/bills/updateBillsTemplate', updateData, function (data) {
                 controller.upLevel();
-                RefreshBillsData(data);
                 controller.showTreeData();
             });
         }
@@ -146,7 +141,6 @@ $(document).ready(function () {
             updateData = FormatUpdateData(selected.getDownLevelData());
             CommonAjax.post('/template/bills/updateBillsTemplate', updateData, function (data) {
                 controller.downLevel();
-                RefreshBillsData(data);
                 controller.showTreeData();
             });
         }
@@ -157,7 +151,6 @@ $(document).ready(function () {
             updateData = FormatUpdateData(selected.getUpMoveData());
             CommonAjax.post('/template/bills/updateBillsTemplate', updateData, function (data) {
                 controller.upMove();
-                RefreshBillsData(data);
                 controller.showTreeData();
             });
         }
@@ -168,7 +161,6 @@ $(document).ready(function () {
             updateData = FormatUpdateData(selected.getDownMoveData());
             CommonAjax.post('/template/bills/updateBillsTemplate', updateData, function (data) {
                 controller.downMove();
-                RefreshBillsData(data);
                 controller.showTreeData();
             });
         }

+ 24 - 3
web/templates/js/tp_bills_setting.js

@@ -120,7 +120,14 @@ var TEMPLATE_BILLS_SETTING = {
             "field":"ID",
             "vAlign":0,
             "hAlign":1,
-            "font":"14.6667px Calibri"
+            "font":"14.6667px Calibri"/*,
+            "getText": function (node) {
+                if (node) {
+                    return node.getID();
+                } else {
+                    return '';
+                }
+            }*/
         }
     }, {
         "width":50,
@@ -149,7 +156,14 @@ var TEMPLATE_BILLS_SETTING = {
             "field":"ParentID",
             "vAlign":0,
             "hAlign":1,
-            "font":"14.6667px Calibri"
+            "font":"14.6667px Calibri"/*,
+            "getText": function (node) {
+                if (node) {
+                    return node.getParentID();
+                } else {
+                    return '';
+                }
+            }*/
         }
     }, {
         "width":50,
@@ -178,7 +192,14 @@ var TEMPLATE_BILLS_SETTING = {
             "field":"NextSiblingID",
             "vAlign":0,
             "hAlign":1,
-            "font":"14.6667px Calibri"
+            "font":"14.6667px Calibri"/*,
+            "getText": function (node) {
+                if (node) {
+                    return node.getNextSiblingID();
+                } else {
+                    return '';
+                }
+            }*/
         }
     }]
 };