Browse Source

1. 悬浮提示,改变构建方式
2. 增量计算

MaiXinRong 7 years ago
parent
commit
c7428c9baa

+ 52 - 40
public/web/sheet/sheet_data_helper.js

@@ -55,35 +55,44 @@ var SheetDataHelper = {
         spread.getActiveSheet().setRowCount(3);
         return spread;
     },
+    massOperationSheet: function (sheet, Operation) {
+        sheet.suspendPaint();
+        sheet.suspendEvent();
+        Operation();
+        sheet.resumeEvent();
+        sheet.resumePaint();
+    },
     loadSheetHeader: function (setting, sheet) {
-        if (setting.frozenCols) {
-            sheet.frozenColumnCount(setting.frozenCols);
-        }
-        sheet.setColumnCount(setting.cols.length);
-        sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
-        if (setting.headRowHeight) {
-            setting.headRowHeight.forEach(function (rowHeight, index) {
-                sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
-            });
-        }
-        if (setting.cols) {
+        this.massOperationSheet(sheet, function () {
+            if (setting.frozenCols) {
+                sheet.frozenColumnCount(setting.frozenCols);
+            }
             sheet.setColumnCount(setting.cols.length);
-            setting.cols.forEach(function (col, index) {
-                var i, iRow = 0, cell;
-                for (i = 0; i < col.head.spanCols.length; i++) {
-                    if (col.head.spanCols[i] !== 0) {
-                        cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
-                        cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]).wordWrap(true);
-                    }
-                    if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
-                        sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
-                    }
-                    iRow += col.head.spanRows[i];
-                };
-                sheet.setColumnWidth(index, col.width);
-                sheet.setColumnVisible(index, col.visible);
-            });
-        }
+            sheet.setRowCount(setting.headRows, GC.Spread.Sheets.SheetArea.colHeader);
+            if (setting.headRowHeight) {
+                setting.headRowHeight.forEach(function (rowHeight, index) {
+                    sheet.setRowHeight(index, rowHeight, GC.Spread.Sheets.SheetArea.colHeader);
+                });
+            }
+            if (setting.cols) {
+                sheet.setColumnCount(setting.cols.length);
+                setting.cols.forEach(function (col, index) {
+                    var i, iRow = 0, cell;
+                    for (i = 0; i < col.head.spanCols.length; i++) {
+                        if (col.head.spanCols[i] !== 0) {
+                            cell = sheet.getCell(iRow, index, GC.Spread.Sheets.SheetArea.colHeader);
+                            cell.value(col.head.titleNames[i]).font(col.head.font).hAlign(col.head.hAlign[i]).vAlign(col.head.vAlign[i]).wordWrap(true);
+                        }
+                        if (col.head.spanCols[i] > 1 || col.head.spanRows[i] > 1) {
+                            sheet.addSpan(iRow, index, col.head.spanRows[i], col.head.spanCols[i], GC.Spread.Sheets.SheetArea.colHeader);
+                        }
+                        iRow += col.head.spanRows[i];
+                    };
+                    sheet.setColumnWidth(index, col.width);
+                    sheet.setColumnVisible(index, col.visible);
+                });
+            }
+        });
     },
     protectdSheet: function (sheet) {
         var option = {
@@ -127,25 +136,28 @@ var SheetDataHelper = {
             let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
             if (setting.pos && text && text !== '') {
                 if (!this._toolTipElement) {
-                    var div = document.createElement("div");
-                    $(div).css("position", "absolute")
-                        .css("border", "1px #C0C0C0 solid")
-                        .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
-                        .css("font", "9pt Arial")
-                        .css("background", "white")
-                        .css("padding", 5);
-
+                    let div = $('#autoTip')[0];
+                    if (!div) {
+                        div = document.createElement("div");
+                        $(div).css("position", "absolute")
+                            .css("border", "1px #C0C0C0 solid")
+                            .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
+                            .css("font", "9pt Arial")
+                            .css("background", "white")
+                            .css("padding", 5)
+                            .attr("id", 'autoTip');
+                        $(div).hide();
+                        document.body.insertBefore(div, null);
+                    }
                     this._toolTipElement = div;
+                    $(this._toolTipElement).text(text).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
+                    $(this._toolTipElement).show("fast");
                 }
-                $(this._toolTipElement).text(text).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
-                $(this._toolTipElement).hide();
-                document.body.insertBefore(this._toolTipElement, null);
-                $(this._toolTipElement).show("fast");
             }
         };
         TipCellType.prototype.processMouseLeave = function (hininfo) {
             if (this._toolTipElement) {
-                document.body.removeChild(this._toolTipElement);
+                $(this._toolTipElement).hide();
                 this._toolTipElement = null;
             }
         }

+ 34 - 32
public/web/tree_sheet/tree_sheet_helper.js

@@ -156,11 +156,11 @@ var TREE_SHEET_HELPER = {
         });
     },
     showTreeData: function (setting, sheet, tree) {
-        var indent = 20;
-        var halfBoxLength = 5;
-        var halfExpandLength = 3;
+        let indent = 20;
+        let halfBoxLength = 5;
+        let halfExpandLength = 3;
 
-        var TreeNodeCellType = function () {
+        let TreeNodeCellType = function () {
         };
         TreeNodeCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
         TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
@@ -173,7 +173,7 @@ var TREE_SHEET_HELPER = {
                 ctx.clearRect(x, y, w, h);
             }
             // ������(x1, y1)���(��, ��), (x2, y2)�յ�(��, ��), ��ɫ
-            var drawLine = function (canvas, x1, y1, x2, y2, color) {
+            let drawLine = function (canvas, x1, y1, x2, y2, color) {
                 ctx.save();
                 // ����ƫ����
                 ctx.translate(0.5, 0.5);
@@ -184,8 +184,8 @@ var TREE_SHEET_HELPER = {
                 ctx.stroke();
                 ctx.restore();
             };
-            var drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
-                var rect = {}, h1, h2, offset = 1;
+            let drawExpandBox = function (ctx, x, y, w, h, centerX, centerY, expanded) {
+                let rect = {}, h1, h2, offset = 1;
                 rect.top = centerY - halfBoxLength;
                 rect.bottom = centerY + halfBoxLength;
                 rect.left = centerX - halfBoxLength;
@@ -221,16 +221,15 @@ var TREE_SHEET_HELPER = {
                     }
                 }
             }
-            var node = tree.items[options.row];
-            var showTreeLine = true;
+            let node = tree.items[options.row];
+            let showTreeLine = true;
 
             if (!node) { return; }
 
-            var iLevel = node.depth();
-            var centerX = Math.floor(x) + node.depth() * indent + indent / 2;
-            var x1 = centerX + indent / 2;
-            var centerY = Math.floor((y + (y + h)) / 2);
-            var y1;
+            let centerX = Math.floor(x) + node.depth() * indent + indent / 2;
+            let x1 = centerX + indent / 2;
+            let centerY = Math.floor((y + (y + h)) / 2);
+            let y1;
             // Draw Sibling Line
             if (showTreeLine) {
                 // Draw Horizontal Line
@@ -280,17 +279,17 @@ var TREE_SHEET_HELPER = {
             };
         };
         TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
-            var offset = -1;
-            var node = tree.items[hitinfo.row];
+            let offset = -1;
+            let node = tree.items[hitinfo.row];
             tree.selected = node;
             if (!node || node.children.length === 0) { return; }
-            var centerX = hitinfo.cellRect.x + offset + node.depth() * indent + indent / 2;
-            var centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
+            let centerX = hitinfo.cellRect.x + offset + node.depth() * indent + indent / 2;
+            let centerY = (hitinfo.cellRect.y + offset + (hitinfo.cellRect.y + offset + hitinfo.cellRect.height)) / 2;
 
             if (hitinfo.x > centerX - halfBoxLength && hitinfo.x < centerX + halfBoxLength && hitinfo.y > centerY - halfBoxLength && hitinfo.y < centerY + halfBoxLength) {
                 node.setExpanded(!node.expanded);
                 TREE_SHEET_HELPER.massOperationSheet(hitinfo.sheet, function () {
-                    var iCount = node.posterityCount(), i, child;
+                    let iCount = node.posterityCount(), i, child;
                     for (i = 0; i < iCount; i++) {
                         child = tree.items[hitinfo.row + i + 1];
                         hitinfo.sheet.setRowVisible(hitinfo.row + i + 1, child.visible, hitinfo.sheetArea);
@@ -320,25 +319,28 @@ var TREE_SHEET_HELPER = {
             let text = hitinfo.sheet.getText(hitinfo.row, hitinfo.col);
             if (setting.pos && text && text !== '') {
                 if (!this._toolTipElement) {
-                    var div = document.createElement("div");
-                    $(div).css("position", "absolute")
-                        .css("border", "1px #C0C0C0 solid")
-                        .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
-                        .css("font", "9pt Arial")
-                        .css("background", "white")
-                        .css("padding", 5);
-
+                    let div = $('#autoTip')[0];
+                    if (!div) {
+                        div = document.createElement("div");
+                        $(div).css("position", "absolute")
+                            .css("border", "1px #C0C0C0 solid")
+                            .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
+                            .css("font", "9pt Arial")
+                            .css("background", "white")
+                            .css("padding", 5)
+                            .attr("id", 'autoTip');
+                        $(div).hide();
+                        document.body.insertBefore(div, null);
+                    }
                     this._toolTipElement = div;
+                    $(this._toolTipElement).text(text).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
+                    $(this._toolTipElement).show("fast");
                 }
-                $(this._toolTipElement).text(text).css("top", setting.pos.y + hitinfo.y + 15).css("left", setting.pos.x + hitinfo.x + 15);
-                $(this._toolTipElement).hide();
-                document.body.insertBefore(this._toolTipElement, null);
-                $(this._toolTipElement).show("fast");
             }
         };
         TipCellType.prototype.processMouseLeave = function (hitinfo) {
             if (this._toolTipElement) {
-                document.body.removeChild(this._toolTipElement);
+                $(this._toolTipElement).hide();
                 this._toolTipElement = null;
             }
         }

+ 26 - 38
web/building_saas/main/js/calc/bills_calc.js

@@ -235,31 +235,9 @@ let baseCalcField = [
 ];
 
 class BillsCalcHelper {
-    constructor (project, CalcFlag) {
+    constructor (project, calcFlag) {
         this.project = project;
-        this.CalcFlag = CalcFlag;
-        this.calcField = JSON.parse(JSON.stringify(feeType));
-        for (let field of this.calcField) {
-            // unitFeeCalcFlag
-            if (this.calcFlag === rationContent) {
-                field.unitFeeFlag = rationContentUnitFeeFlag;
-            } else if ( this.calcFlag === billsPrice) {
-                field.unitFeeFlag = billsPriceUnitFeeFlag;
-            } else {
-                field.unitFeeFlag = averageQtyUnitFeeFlag;
-            }
-            // totalFeeCalcFlag
-            if (field.type === 'common') {
-                if (this.CalcFlag === rationPriceConverse) {
-                    field.totalFeeFlag = sumTotalFeeFlag;
-                } else {
-                    field.totalFeeFlag = totalFeeFlag;
-                }
-            } else {
-                field.totalFeeFlag = sumTotalFeeFlag;
-            }
-        }
-        this.InitFields(this.calcField);
+        this.InitFields(this.project.calcFields);
     };
 
     getBillsGLjs (node) {
@@ -277,7 +255,7 @@ class BillsCalcHelper {
         let nodeCalc = nodeCalcObj, virData= null;
 
         // 清单单价:套用定额计算程序
-        if (this.CalcFlag === billsPrice) {
+        if (this.project.calcFlag === billsPrice) {
             rationCalcObj.calcGljs = this.getBillsGLjs(node);
             console.log(rationCalcObj.calcGljs);
             rationCalcObj.calcFields = rationCalcFields;
@@ -325,26 +303,36 @@ class BillsCalcHelper {
             node.data.feesIndex[field.type].totalFee = nodeCalcObj.sumTotalFee().toDecimal(this.project.Decimal.common.totalFee);
         }
     };
+    calcNode(node) {
+        if (node.source.children.length > 0) {
+            this.calcParent(node, this.project.calcFields);
+        } else {
+            if (node.children.length > 0) {
+                if (node.firstChild().sourceType === this.project.Ration.getSourceType()) {
+                    this.calcRationLeaf(node, this.project.calcFields);
+                } else {
+                    this.calcVolumePriceLeaf(node, this.project.calcFields);
+                }
+            } else {
+
+            }
+        }
+    }
     calcNodes (nodes) {
         for (let node of nodes) {
             if (node.sourceType !== this.project.Bills.getSourceType()) {
                 return;
             }
-
             if (node.source.children.length > 0) {
                 this.calcNodes(node.children);
-                this.calcParent(node, this.calcField);
-            } else {
-                if (node.children.length > 0) {
-                    if (node.firstChild().sourceType === this.project.Ration.getSourceType()) {
-                        this.calcRationLeaf(node, this.calcField);
-                    } else {
-                        this.calcVolumePriceLeaf(node, this.calcField);
-                    }
-                } else {
-
-                }
             }
+            calcNode(node);
+        }
+    };
+    converseCalc (node) {
+        if (node && node.sourceType === this.project.Bills.getSourceType()) {
+            this.calcNode(node);
+            this.converseCalc(node.parent);
         }
     };
     calcAll () {
@@ -362,5 +350,5 @@ class BillsCalcHelper {
             field.tenderTotalFee = 'feesIndex.' + field.type + '.tenderTotalFee';
             field.tenderTotalFeeSplit = field.tenderTotalFee.split('.');
         }
-    }
+    };
 }

+ 2 - 1
web/building_saas/main/js/controllers/project_controller.js

@@ -104,7 +104,8 @@ ProjectController = {
         }
     },
     calculateAll: function (project, sheetController, CalcType) {
-        let calc = new BillsCalcHelper(project, CalcType);
+        this.project.setCalcFlag(CalcType);
+        let calc = new BillsCalcHelper(project);
         calc.calcAll();
         sheetController.showTreeData();
         project.Bills.updateAll();

+ 26 - 0
web/building_saas/main/js/models/project.js

@@ -287,6 +287,32 @@ var PROJECT = {
             }
         };
 
+        project.prototype.setCalcFlag = function (calcFlag) {
+            this.calcFlag = calcFlag;
+            if (this.calcFields) {
+                for (let field of this.calcFields) {
+                    // unitFeeCalcFlag
+                    if (this.calcFlag === rationContent) {
+                        field.unitFeeFlag = rationContentUnitFeeFlag;
+                    } else if ( this.calcFlag === billsPrice) {
+                        field.unitFeeFlag = billsPriceUnitFeeFlag;
+                    } else {
+                        field.unitFeeFlag = averageQtyUnitFeeFlag;
+                    }
+                    // totalFeeCalcFlag
+                    if (field.type === 'common') {
+                        if (this.calcFlag === rationPriceConverse) {
+                            field.totalFeeFlag = sumTotalFeeFlag;
+                        } else {
+                            field.totalFeeFlag = totalFeeFlag;
+                        }
+                    } else {
+                        field.totalFeeFlag = sumTotalFeeFlag;
+                    }
+                }
+            }
+        }
+
         return new project();
     }
 };

+ 3 - 0
web/building_saas/main/js/views/calc_program_view.js

@@ -227,6 +227,9 @@ let calcProgramObj = {
         me.treeNode = treeNode;
         if (treeNode.sourceType === projectObj.project.Ration.getSourceType()) {
             projectObj.project.calcProgram.calculate(treeNode);
+           if (treeNode.parent) {
+                projectObj.converseCalculateBills(treeNode.parent);
+            }
             me.datas = me.treeNode.data.calcTemplate.calcItems;
             sheetCommonObj.initSheet(me.sheet, me.setting, me.datas.length);
             sheetCommonObj.showData(me.sheet, me.setting, me.datas);

+ 14 - 0
web/building_saas/main/js/views/project_view.js

@@ -91,6 +91,9 @@ var projectObj = {
         this.project = PROJECT.createNew(scUrlUtil.GetQueryString('project'), userID);
         this.project.loadDatas(function (err) {
             if (!err) {
+                that.project.calcFields = JSON.parse(JSON.stringify(feeType));
+                that.project.setCalcFlag(rationContent);
+
                 let str = JSON.stringify(that.project.projSetting.main_tree_col);
                 that.project.projSetting.mainGridSetting = JSON.parse(str);
                 that.project.projSetting.mainGridSetting.frozenCols = 4;
@@ -327,6 +330,17 @@ var projectObj = {
                 }
             }
         });
+    },
+    converseCalculateBills: function (node) {
+        let calc = new BillsCalcHelper(this.project);
+        calc.converseCalc(node, this.project.calcFields);
+        let cur = node, nodes = [];
+        while (cur) {
+            nodes.push(cur);
+            cur = cur.parent;
+        }
+        this.mainController.refreshTreeNode(nodes, false);
+        calc = null;
     }
 };