Преглед изворни кода

重庆2018 A03表 + code sync part I

TonyKang пре 6 година
родитељ
комит
4b62ea2257

+ 66 - 4
modules/reports/rpt_component/jpc_flow_tab.js

@@ -821,6 +821,10 @@ JpcFlowTabSrv.prototype.createNew = function(){
     };
     JpcFlowTabResult.combinePageCells = function (rstPageCells, verticalCombinePos, horizonCombinePos) {
         // let me = this;
+        //备注:纵向合并要考虑以下因素:
+        //     如果有多个column纵向合并,需要总体考虑分割,
+        //     假如:第一列的前3个数据(1、2、3)是相同的,第二列中第2、3、4行数据相同,那么第二列只能合并2、3行的数据,不能合并到第四行
+        //     同理如此类推第三列...n列
         if (verticalCombinePos.length > 0 || horizonCombinePos.length > 1) {
             let cacheObj = {vCache:{}, hCache: {}, hCacheStr: []};
             let removeCellIds = [];
@@ -848,19 +852,56 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 }
             }
             if (verticalCombinePos.length > 0) {
-                for (let vPosArr of verticalCombinePos) {
+                let preColMergePosArr = []; //见上面备注描述,纪录当前列的分割坐标集合情况
+                let private_chk_in_pre_merge = function (preIdx, newCell) {
+                    let rst = true;
+                    if (preIdx >= 0 && preIdx < preColMergePosArr.length) {
+                        for (let mergeArea of preColMergePosArr[preIdx]) {
+                            if (newCell[JV.PROP_AREA][JV.PROP_TOP] >= mergeArea[0] && newCell[JV.PROP_AREA][JV.PROP_TOP] < mergeArea[1]) {
+                                rst = (newCell[JV.PROP_AREA][JV.PROP_BOTTOM] <= mergeArea[1]);
+                                break;
+                            }
+                        }
+                    }
+                    return rst;
+                };
+                for (let vidx = 0; vidx < verticalCombinePos.length; vidx++) {
+                    let vPosArr = verticalCombinePos[vidx];
                     let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
                     //rstPageCells的结果已经是按顺序排列了,这里不用再排序
                     if (cacheObj.vCache[pStr] && cacheObj.vCache[pStr].length > 0) {
                         let preCell = rstPageCells[cacheObj.vCache[pStr][0]];
+                        if (vidx === 0) {
+                            //这里要处理下
+                            let minY = 10000, maxY = 0;
+                            for (let preCIdx = 0; preCIdx < cacheObj.vCache[pStr].length; preCIdx++) {
+                                if (minY > rstPageCells[cacheObj.vCache[pStr][preCIdx]][JV.PROP_AREA][JV.PROP_TOP]) minY = rstPageCells[cacheObj.vCache[pStr][preCIdx]][JV.PROP_AREA][JV.PROP_TOP];
+                                if (maxY < rstPageCells[cacheObj.vCache[pStr][preCIdx]][JV.PROP_AREA][JV.PROP_BOTTOM]) maxY = rstPageCells[cacheObj.vCache[pStr][preCIdx]][JV.PROP_AREA][JV.PROP_BOTTOM];
+                            }
+                            preColMergePosArr.push([[minY, maxY]]);
+                        }
+                        let dtlColMergePosArr = [];
+                        preColMergePosArr.push(dtlColMergePosArr);
                         for (let cIdx = 1; cIdx < cacheObj.vCache[pStr].length; cIdx++) {
                             if (preCell.Value === "") {
+                                dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
                                 preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
                             } else {
                                 if (preCell.Value === rstPageCells[cacheObj.vCache[pStr][cIdx]].Value) {
+                                    let bkBottom = preCell[JV.PROP_AREA][JV.PROP_BOTTOM];
                                     preCell[JV.PROP_AREA][JV.PROP_BOTTOM] = rstPageCells[cacheObj.vCache[pStr][cIdx]][JV.PROP_AREA][JV.PROP_BOTTOM];
-                                    removeCellIds.push(cacheObj.vCache[pStr][cIdx]);
+                                    if (private_chk_in_pre_merge(vidx, preCell)) {
+                                        removeCellIds.push(cacheObj.vCache[pStr][cIdx]);
+                                        if (cIdx === cacheObj.vCache[pStr].length - 1) {
+                                            dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
+                                        }
+                                    } else {
+                                        preCell[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
+                                        dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
+                                        preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
+                                    }
                                 } else {
+                                    dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
                                     preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
                                 }
                             }
@@ -892,8 +933,10 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 }
             }
             if (removeCellIds.length > 0) {
-                //这次真的要排序了
-                removeCellIds.sort(); //默认方式即可
+                //排序,保证一定的顺序,不能用默认的方式(默认方式是针对字符串的简单排序)
+                removeCellIds.sort(function (idx1, idx2) {
+                    return parseInt(idx1) - parseInt(idx2);
+                });
                 for (let idx = removeCellIds.length - 1; idx >= 0; idx--) {
                     rstPageCells.splice(removeCellIds[idx], 1);
                 }
@@ -1099,9 +1142,28 @@ JpcFlowTabSrv.prototype.createNew = function(){
         for (let idIdx = eliminateCells.length - 1; idIdx >= 0; idIdx--) {
             rst.splice(eliminateCells[idIdx], 1);
         }
+        me.checkCombineEvent(JV.RUN_TYPE_BEFORE_COMBINE, verticalCombinePos, horizonCombinePos, rst, $CURRENT_RPT);
         me.combinePageCells(rst, verticalCombinePos, horizonCombinePos);
+        me.checkCombineEvent(JV.RUN_TYPE_AFTER_COMBINE, verticalCombinePos, horizonCombinePos, rst, $CURRENT_RPT);
         return rst;
     };
+    JpcFlowTabResult.checkCombineEvent = function ($RUN_TYPE, $VER_COMB_ARRAY, $HOR_COMB_ARRAY, $CURRENT_CELL_ITEMS, $CURRENT_RPT) {
+        if ($CURRENT_RPT.formulas) {
+            for (let execFmlIdx = 0; execFmlIdx < $CURRENT_RPT.formulas.length; execFmlIdx++) {
+                if ($CURRENT_RPT.formulas[execFmlIdx][JV.PROP_RUN_TYPE] === $RUN_TYPE) {
+                    let expression = $CURRENT_RPT.formulas[execFmlIdx][JV.PROP_EXPRESSION];
+                    if (expression) {
+                        let $ME = $CURRENT_RPT.formulas[execFmlIdx];
+                        try {
+                            eval(expression);
+                        } catch (ex) {
+                            console.log(ex);
+                        }
+                    }
+                }
+            }
+        }
+    };
     JpcFlowTabResult.outputColumn = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, multiColIdx) {
         let me = this, rst = [];
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;

+ 2 - 0
public/web/rpt_value_define.js

@@ -207,6 +207,8 @@ const JV = {
     RUN_TYPE_BEFORE_ANALYZING: "before_analyzing",
     RUN_TYPE_BEFORE_PAGING: "before_paging",
     RUN_TYPE_BEFORE_OUTPUT: "before_output",
+    RUN_TYPE_BEFORE_COMBINE: "before_combine",
+    RUN_TYPE_AFTER_COMBINE: "after_combine",
 
     PAGE_STATUS: ["EveryPage","FirstPage", "LastPage", "SegmentStart", "SegmentEnd", "Group", "CrossRowEnd", "CrossColEnd"],
 

+ 7 - 1
web/maintain/report/js/rpt_tpl_calculation.js

@@ -30,6 +30,8 @@ let calculationTreeOprObj = {
         let et = $("#exprRunType");
         et.append("<option value='" + JV.RUN_TYPE_BEFORE_PAGING + "'>预运行</option>");
         et.append("<option value='" + JV.RUN_TYPE_BEFORE_OUTPUT + "'>实时运行</option>");
+        et.append("<option value='" + JV.RUN_TYPE_BEFORE_COMBINE + "'>合并单元格前事件</option>");
+        et.append("<option value='" + JV.RUN_TYPE_AFTER_COMBINE + "'>合并单元格后事件</option>");
     },
     buildTreeData: function (rptTpl) {
         let me = this, rst = {"Name": "计算式", items: []};
@@ -91,8 +93,12 @@ let calculationTreeOprObj = {
             $("#exprDetail")[0].style.display = "";
             if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_PAGING) {
                 $("#exprRunType")[0].selectedIndex = 0;
-            } else {
+            } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_OUTPUT) {
                 $("#exprRunType")[0].selectedIndex = 1;
+            } else if (treeNode[JV.PROP_RUN_TYPE] === JV.RUN_TYPE_BEFORE_COMBINE) {
+                $("#exprRunType")[0].selectedIndex = 2;
+            } else {
+                $("#exprRunType")[0].selectedIndex = 3;
             }
             $("#exprFormat")[0].value = (treeNode["format"])?treeNode["format"]:"";
             $("#exprContent")[0].value = treeNode[JV.PROP_EXPRESSION];