jpc_flow_tab.js 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. let JV = require('./jpc_value_define');
  2. let JE = require('./jpc_rte');
  3. let JpcFieldHelper = require('./helper/jpc_helper_field');
  4. let JpcBandHelper = require('./helper/jpc_helper_band');
  5. let JpcBand = require('./jpc_band');
  6. let JpcFlowTabHelper = require('./helper/jpc_helper_flow_tab');
  7. let JpcCommonHelper = require('./helper/jpc_helper_common');
  8. let JpcDiscreteHelper = require('./helper/jpc_helper_discrete');
  9. let JpcTextHelper = require('./helper/jpc_helper_text');
  10. let JpcCommonOutputHelper = require('./helper/jpc_helper_common_output');
  11. let JpcAreaHelper = require('./helper/jpc_helper_area');
  12. // let PDFKit = require('pdfkit');
  13. // let fontUtil = require('../util/rpt_font_util');
  14. let fsUtil = require("../../../public/fsUtil");
  15. let strUtil = require("../../../public/stringUtil");
  16. let fontWidthMap = require('./helper/jpc_helper_font_width');
  17. let JpcFlowTabSrv = function(){};
  18. JpcFlowTabSrv.prototype.createNew = function(){
  19. //grpPageInfo :{"segGrpRecStartIdx": 0, "insertedGrpRecAmt": 0, "preAddPageGrpInfo": null}; //纯属解释参数grpPageInfo结构
  20. //valueIdx: [isFollowMode, type(normal, auto-height, group), valueIndex, sub-value-index(自动行高特有), total-value-amount(自动行高特有)] //解释 dispValueIdxLst 数据构造
  21. function private_addPageValue(ValuedIdxLst, sortedSequence, grpSequenceInfo, startRecIdx, maxRecPerPage,page_seg_map, segIdx, pageIdx, grpPageInfo, isFollow, segAutoHeightInfo, prePageLeftAutoHeightRecAmt) {
  22. let vIdx = [], vFirstIdx = [], preAmt = 0, insertedGrpAmt = 0, grp_lines = 0, followMode = (isFollow)?JV.TYPE_FOLLOW_MODE:-1, nextPageAutoHeightRecAmt = 0;
  23. if (grpSequenceInfo && grpPageInfo) {
  24. if (grpPageInfo[JV.PROP_PRE_ADD_GRP_REC_INFO].length > 0) {
  25. for (let grpLineIdx of grpPageInfo[JV.PROP_PRE_ADD_GRP_REC_INFO]) {
  26. //vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_GROUP, grpPageInfo[JV.PROP_SEG_GRP_IDX], grpLineIdx]);
  27. vFirstIdx.push([followMode, JV.DISPLAY_VAL_TYPE_GROUP, grpPageInfo[JV.PROP_SEG_GRP_IDX], grpLineIdx]);
  28. }
  29. grpPageInfo[JV.PROP_SEG_GRP_IDX]++;
  30. }
  31. preAmt = grpPageInfo[JV.PROP_PRE_ADD_GRP_REC_INFO].length;
  32. grpPageInfo[JV.PROP_PRE_ADD_GRP_REC_INFO] = [];
  33. grp_lines = grpPageInfo[JV.PROP_GRP_LINES];
  34. }
  35. let autoHeightAmt = 0;
  36. let private_addAutoHeightPageValue = function (vi) {
  37. let couldBreak = false, startIdx = 0;
  38. let ttlValAmt = 0;
  39. if (segAutoHeightInfo[segIdx].length > startRecIdx + vi) {
  40. ttlValAmt = segAutoHeightInfo[segIdx][startRecIdx + vi];
  41. }
  42. if (prePageLeftAutoHeightRecAmt > 0 && vi === 0) {
  43. startIdx = prePageLeftAutoHeightRecAmt;
  44. }
  45. for (let subValIdx = startIdx; subValIdx < ttlValAmt; subValIdx++) {
  46. vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_AUTO_HEIGHT, sortedSequence[startRecIdx + vi], subValIdx, ttlValAmt]);
  47. autoHeightAmt++;
  48. if (autoHeightAmt >= maxRecPerPage) {
  49. nextPageAutoHeightRecAmt = (subValIdx + 1) % ttlValAmt;
  50. couldBreak = true;
  51. break;
  52. }
  53. }
  54. return couldBreak;
  55. };
  56. let private_inner_add_grp_rec = function(vi) {
  57. let hasFullGrp = true, couldBreak = false;
  58. for (let i = 0; i < grp_lines; i++) {
  59. if (vIdx.length >= maxRecPerPage) {
  60. for (let j = i; j < grp_lines; j++) {
  61. grpPageInfo[JV.PROP_PRE_ADD_GRP_REC_INFO].push(j);
  62. }
  63. //准备要跳出去了
  64. hasFullGrp = false;
  65. break;
  66. } else {
  67. vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_GROUP, grpPageInfo[JV.PROP_SEG_GRP_IDX], i]);
  68. }
  69. }
  70. //3. 进位下一个group信息所在位置
  71. if (hasFullGrp) {
  72. grpPageInfo[JV.PROP_INSERTED_GRP_REC]++;
  73. insertedGrpAmt++;
  74. grpPageInfo[JV.PROP_SEG_GRP_IDX]++;
  75. } else {
  76. couldBreak = true;
  77. }
  78. return couldBreak;
  79. };
  80. let private_normal_add_rec = function(vi) {
  81. let couldBreak = false;
  82. if (segAutoHeightInfo && segAutoHeightInfo.length > 0) {
  83. if (segAutoHeightInfo[segIdx].length > startRecIdx + vi) {
  84. couldBreak = private_addAutoHeightPageValue(vi);
  85. // if (couldBreak) break;
  86. // } else if (vIdx.length > 0 && vIdx.length < maxRecPerPage) {
  87. } else if (vIdx.length < maxRecPerPage) {
  88. vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_NORMAL, JV.BLANK_VALUE_INDEX]);
  89. }
  90. } else {
  91. if (sortedSequence.length > startRecIdx + vi) {
  92. vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_NORMAL, sortedSequence[startRecIdx + vi]]);
  93. } else {
  94. vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_NORMAL, JV.BLANK_VALUE_INDEX]);
  95. }
  96. }
  97. return couldBreak;
  98. };
  99. for (let vi = 0; (vi + insertedGrpAmt * grp_lines) < maxRecPerPage - preAmt; vi++) {
  100. if (grpSequenceInfo && grpPageInfo) {
  101. if ((startRecIdx + vi) === grpSequenceInfo[grpPageInfo[JV.PROP_SEG_GRP_IDX]]) {
  102. //表示这里要插入grouping信息啦!
  103. let couldBreak = false;
  104. //1. 首先push正常的记录(要考虑自动行高调整的分支)
  105. if (segAutoHeightInfo && segAutoHeightInfo.length > 0) {
  106. couldBreak = private_addAutoHeightPageValue(vi);
  107. } else {
  108. vIdx.push([followMode, JV.DISPLAY_VAL_TYPE_NORMAL, sortedSequence[startRecIdx + vi]]);
  109. }
  110. //2. 然后就要push grouping记录了
  111. if (private_inner_add_grp_rec(vi)) break;
  112. if (couldBreak) break;
  113. } else {
  114. //备注: 在有group的情况下,如果grpPageInfo[JV.PROP_SEG_GRP_IDX] 范围大于 grpSequenceInfo.length,则表示已经到最后了,不要再加空白数据了
  115. // !!!但这是在有ex数据的情况下!!!
  116. if (grpPageInfo[JV.PROP_SEG_GRP_IDX] < grpSequenceInfo.length) {
  117. if (private_normal_add_rec(vi)) break;
  118. } else {
  119. //还得判断是否是普通的流水数据情况,这里可以用isFollow来进行判断,暂时不需要特意加新参数(以后如isFollow的意义有变化则需要调整)
  120. if (!isFollow) {
  121. if (private_normal_add_rec(vi)) break;
  122. } else {
  123. break;
  124. }
  125. }
  126. }
  127. } else {
  128. if (private_normal_add_rec(vi)) break;
  129. }
  130. }
  131. if (vFirstIdx.length > 0) {
  132. vIdx = vIdx.concat(vFirstIdx);
  133. //备注: 在一开始就加grp的情况下,这些数据应该放在后面才对
  134. }
  135. page_seg_map.push([pageIdx, segIdx]);
  136. ValuedIdxLst.push(vIdx);
  137. return nextPageAutoHeightRecAmt;
  138. }
  139. let JpcFlowTabResult = {};
  140. JpcFlowTabResult.initialize = function(isEx) {
  141. let me = this;
  142. me.isEx = isEx;
  143. me.paging_option = JV.PAGING_OPTION_NORMAL;
  144. me.segments = [];
  145. me.dispValueIdxLst = [];
  146. me.page_seg_map = [];
  147. me.disp_fields_idx = [];
  148. me.disp_fields_ex_idx = [];
  149. me.seg_sum_fields_idx = [];
  150. me.seg_sum_tab_fields = [];
  151. me.page_sum_fields_idx = [];
  152. me.page_sum_tab_fields = [];
  153. me.auto_height_fields_idx = [];//那些被标记为判断自动行高的指标集合
  154. me.auto_height_info = [];
  155. me.group_check_fields = [];
  156. me.group_sum_fields = [];
  157. me.group_sum_values = null;
  158. me.group_node_info = null; //记录在哪个seg及到哪条记录后有group sum信息
  159. me.group_lines_amt = 0; //每group一次占用多少行,计算page信息会用到
  160. me.pageStatusLst = [];
  161. me.groupSumValLst = [];
  162. me.segSumValLst = [];
  163. me.pageSumValLst = [];
  164. me.multiCols = 1;
  165. me.pagesAmt = 0;
  166. };
  167. JpcFlowTabResult.sorting = function(rptTpl, dataObj, dataSeq, $CURRENT_RPT) {
  168. let me = this;
  169. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  170. if (rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_SEG_SUM]) JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_SEG_SUM][JV.PROP_SUM_FIELDS], me.seg_sum_tab_fields, me.seg_sum_fields_idx, me.isEx);
  171. if (rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_PAGE_SUM]) JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_PAGE_SUM][JV.PROP_SUM_FIELDS], me.page_sum_tab_fields, me.page_sum_fields_idx, me.isEx);
  172. if (rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP]) {
  173. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_FIELDS], me.group_check_fields, null, me.isEx);
  174. if (rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES]) {
  175. for (let grpLine of rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES]) {
  176. if (grpLine[JV.PROP_GROUP_SUM_KEYS] && grpLine[JV.PROP_GROUP_SUM_KEYS].length > 0) {
  177. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, grpLine[JV.PROP_GROUP_SUM_KEYS], me.group_sum_fields, null, me.isEx);
  178. }
  179. }
  180. }
  181. for (let grp_sum_f of me.group_sum_fields) {
  182. grp_sum_f[JV.PROP_SUM_KEY] = `grp_sum_key_` + grp_sum_f[JV.PROP_FIELD_ID];
  183. }
  184. }
  185. JpcFieldHelper.findAutoHeightFieldIdx(rptTpl, rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], me.auto_height_fields_idx, me.isEx);
  186. for (let si = 0; si < dataSeq.length; si++) {
  187. me.segments.push(dataSeq[si].slice(0));
  188. }
  189. //pre-sum the data(for seg sum display)
  190. //考虑到实际会有离散指标的汇总,这些离散指标数据是通过计算式后得来的,这种情况下,不适宜在sorting阶段进行汇总统计,现挪到preSetupPages阶段处理
  191. };
  192. JpcFlowTabResult.sumSeg = function (dataObj, $CURRENT_RPT) {
  193. let me = this;
  194. let data_details = me.isEx?dataObj[JV.DATA_DETAIL_DATA_EX]:dataObj[JV.DATA_DETAIL_DATA],
  195. data_fields = [];
  196. for (let i = 0; i < me.seg_sum_fields_idx.length; i++) {
  197. if (typeof(me.seg_sum_fields_idx[i]) === "object") {
  198. let exField = JE.F(me.seg_sum_fields_idx[i][JV.PROP_ID], $CURRENT_RPT);
  199. if (exField) {
  200. data_fields.push(exField[JV.PROP_AD_HOC_DATA]);
  201. } else {
  202. data_fields.push(null);
  203. }
  204. } else {
  205. let data_field = data_details[me.seg_sum_fields_idx[i]];
  206. data_fields.push(data_field);
  207. }
  208. }
  209. for (let i = 0; i < me.segments.length; i++) { //seg level
  210. if (me.segments[i].length > 0) {
  211. let rowGrandTotal = [];
  212. for (let di = 0; di < data_fields.length; di++) {
  213. rowGrandTotal.push(0.0);
  214. let precisionAmt = 4;
  215. let sum_field = JE.F(me.seg_sum_tab_fields[di][JV.PROP_FIELD_ID], $CURRENT_RPT);
  216. if (sum_field[JV.PROP_PRECISION] && sum_field[JV.PROP_PRECISION].type === `fixed`) {
  217. precisionAmt = sum_field[JV.PROP_FIXED_PRECISION_AMT];
  218. } else {
  219. let flowF = me.seg_sum_tab_fields[di];
  220. if (flowF && !strUtil.isEmptyString(flowF[JV.PROP_FORMAT])) {
  221. let idx = flowF[JV.PROP_FORMAT].indexOf('.');
  222. if (idx >= 0) {
  223. precisionAmt = flowF[JV.PROP_FORMAT].length - idx - 1;
  224. }
  225. }
  226. }
  227. for (let j = 0; j < me.segments[i].length; j++) {
  228. //3. start to sum
  229. // rowGrandTotal[di] = rowGrandTotal[di] + 1.0 * JpcFieldHelper.getValue(data_fields[di], me.segments[i][j]);
  230. let sv = JpcFieldHelper.getValue(data_fields[di], me.segments[i][j]);
  231. if (sv) {
  232. rowGrandTotal[di] = rowGrandTotal[di] + parseFloat(parseFloat(sv).toFixed(precisionAmt));
  233. }
  234. }
  235. }
  236. me.segSumValLst.push(rowGrandTotal);
  237. }
  238. }
  239. };
  240. JpcFlowTabResult.sumUpGrp = function (rptTpl, $CURRENT_RPT, dataObj, segIdx, preGrpIdx, nexGrpIdx) {
  241. let me = this, segDataIdx = me.segments[segIdx];
  242. for (let j = 0; j < me.group_sum_fields.length; j++) {
  243. let sum_field = JE.F(me.group_sum_fields[j][JV.PROP_FIELD_ID], $CURRENT_RPT);
  244. if (sum_field) {
  245. let data_field = null;
  246. if (sum_field[JV.PROP_AD_HOC_DATA]) {
  247. data_field = sum_field[JV.PROP_AD_HOC_DATA]
  248. } else {
  249. data_field = dataObj[sum_field.DataNodeName][sum_field.DataSeq];
  250. }
  251. let sumV = 0, precisionAmt = 4;
  252. for (let si = preGrpIdx; si <= nexGrpIdx; si++) {
  253. if (sum_field[JV.PROP_PRECISION] && sum_field[JV.PROP_PRECISION].type === `fixed`) {
  254. precisionAmt = sum_field[JV.PROP_FIXED_PRECISION_AMT];
  255. } else {
  256. let flowF = me.group_sum_fields[j]; //调整后,me.group_sum_fields[j]就是group lines下数组SumKey_S的元素值,无需再找
  257. if (flowF && !strUtil.isEmptyString(flowF[JV.PROP_FORMAT])) {
  258. let idx = flowF[JV.PROP_FORMAT].indexOf('.');
  259. if (idx >= 0) {
  260. precisionAmt = flowF[JV.PROP_FORMAT].length - idx - 1;
  261. }
  262. }
  263. }
  264. //sumV += parseFloat(JpcFieldHelper.getValue(data_field, segDataIdx[si]));
  265. sumV += parseFloat(parseFloat(JpcFieldHelper.getValue(data_field, segDataIdx[si])).toFixed(precisionAmt));
  266. }
  267. // me.group_sum_values[segIdx][j].push(sumV);
  268. me.group_sum_values[segIdx][me.group_sum_fields[j][JV.PROP_SUM_KEY]].push(sumV);
  269. }
  270. }
  271. me.group_node_info[segIdx].push(nexGrpIdx);
  272. };
  273. JpcFlowTabResult.setupGroupingData = function (rptTpl, dataObj, $CURRENT_RPT) {
  274. let me = this;
  275. if (me.group_check_fields.length > 0 && me.group_sum_fields.length > 0) {
  276. me.group_sum_values = [];
  277. me.group_node_info = [];
  278. let CURRENT_FLOW_INFO = (me.isEx)?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  279. me.group_lines_amt = rptTpl[CURRENT_FLOW_INFO][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES].length;
  280. //
  281. let preGrpIdx = 0, nexGrpIdx = 0;
  282. for (let segIdx = 0; segIdx < me.segments.length; segIdx++) {
  283. let segDataIdx = me.segments[segIdx];
  284. // me.group_sum_values.push([]);
  285. me.group_sum_values.push({});
  286. me.group_node_info.push([]);
  287. for (let j = 0; j < me.group_sum_fields.length; j++) {
  288. // me.group_sum_values[segIdx].push([]);
  289. me.group_sum_values[segIdx][me.group_sum_fields[j][JV.PROP_SUM_KEY]] = [];
  290. // me.group_node_info[segIdx].push([]);
  291. }
  292. for (let di = 0; di < segDataIdx.length; di++) {
  293. let hasDiff = false;
  294. if (di >= 1) {
  295. for (let i = 0; i < me.group_check_fields.length; i++) {
  296. let grp_field = JE.F(me.group_check_fields[i][JV.PROP_FIELD_ID], $CURRENT_RPT);
  297. if (grp_field) {
  298. let data_field = null;
  299. if (grp_field[JV.PROP_AD_HOC_DATA]) {
  300. data_field = grp_field[JV.PROP_AD_HOC_DATA]
  301. } else {
  302. data_field = dataObj[grp_field.DataNodeName][grp_field.DataSeq];
  303. }
  304. let v1 = JpcFieldHelper.getValue(data_field, segDataIdx[di]), v2 = JpcFieldHelper.getValue(data_field, segDataIdx[di - 1]);
  305. if (v1 !== v2) {
  306. hasDiff = true;
  307. break;
  308. }
  309. }
  310. }
  311. }
  312. if (hasDiff) {
  313. //then sum up the fields
  314. me.sumUpGrp(rptTpl, $CURRENT_RPT, dataObj, segIdx, preGrpIdx, nexGrpIdx);
  315. nexGrpIdx = di;
  316. preGrpIdx = di;
  317. if (di === segDataIdx.length - 1) {
  318. me.sumUpGrp(rptTpl, $CURRENT_RPT, dataObj, segIdx, preGrpIdx, nexGrpIdx);
  319. }
  320. } else if (di === segDataIdx.length - 1) {
  321. me.sumUpGrp(rptTpl, $CURRENT_RPT, dataObj, segIdx, preGrpIdx, di);
  322. } else {
  323. nexGrpIdx = di;
  324. }
  325. }
  326. }
  327. }
  328. };
  329. JpcFlowTabResult.setupAutoHeightData = function(bands, segIdx, rptTpl, dataObj, $CURRENT_RPT, defProperties, outputType) {
  330. let me = this;
  331. if (me.auto_height_fields_idx.length > 0) {
  332. let CURRENT_FLOW_INFO = (me.isEx)?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  333. let band = bands[rptTpl[CURRENT_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_BAND_NAME]];
  334. let data_details = me.isEx?dataObj[JV.DATA_DETAIL_DATA_EX]:dataObj[JV.DATA_DETAIL_DATA];
  335. let tab_fields = rptTpl[CURRENT_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS];
  336. let adHocAutoHeightStyleStr = [];
  337. let reg1 = new RegExp('\n\r','g'), reg2 = new RegExp('\r\n','g'),
  338. reg3 = new RegExp('\n','g'), reg4 = new RegExp('\r','g');
  339. // let doc = new PDFKit({autoFirstPage: false});
  340. let fonts = defProperties.fonts;
  341. let fontCache = {};
  342. let private_get_font = function (fontKey) {
  343. let rst = null;
  344. if (fontCache[fontKey]) {
  345. rst = fontCache[fontKey];
  346. } else {
  347. for (let i = 0; i < fonts.length; i++) {
  348. if (fonts[i][JV.PROP_ID] === fontKey) {
  349. fontCache[fontKey] = fonts[i];
  350. rst = fonts[i];
  351. break;
  352. }
  353. }
  354. }
  355. return rst;
  356. };
  357. let private_get_max_lines_of_the_record = function(theRecIdx) {
  358. let rst = 1;
  359. let maxAmt = 1;
  360. for (let loop = 0; loop < me.auto_height_fields_idx.length; loop++) {
  361. /*
  362. let data_field = null;
  363. let tab_field = me.auto_height_fields_idx[loop][1];
  364. if (me.auto_height_fields_idx[loop][0] !== JV.BLANK_FIELD_INDEX) {
  365. data_field = data_details[me.auto_height_fields_idx[loop][0]];
  366. }
  367. /*/
  368. let tab_field = me.auto_height_fields_idx[loop][1];
  369. let data_field = null,
  370. map_data_field = JE.F(tab_field[JV.PROP_FIELD_ID], $CURRENT_RPT);
  371. if (me.auto_height_fields_idx[loop][0] !== JV.BLANK_FIELD_INDEX && (typeof me.auto_height_fields_idx[loop][0] !== 'object')) {
  372. data_field = data_details[me.auto_height_fields_idx[loop][0]];
  373. } else {
  374. if (map_data_field) {
  375. data_field = map_data_field[JV.PROP_AD_HOC_DATA];
  376. }
  377. }
  378. //*/
  379. if (data_field) {
  380. let value = JpcFieldHelper.getValue(data_field, theRecIdx);
  381. let area = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, 1, 1, 0, 1, 0, 1, 0, false, false);
  382. if (value !== null && value !== undefined) {
  383. if (typeof value === "string") {
  384. value = value.replace('\t', '');
  385. value = value.replace(reg1, '|').replace(reg2, '|').replace(reg3, '|').replace(reg4, '|');
  386. } else {
  387. // console.log(`has other value: ${value}`);
  388. value = '' + value;
  389. }
  390. } else {
  391. value = '';
  392. }
  393. JpcFieldHelper.setValue(data_field, theRecIdx, value);
  394. let values = value.split('|');
  395. // if (values.length > rst) rst = values.length; // 考虑到紧凑输出,不能那么快设置rst
  396. let font = private_get_font(tab_field[JV.PROP_FONT]);
  397. let chkFontName = '宋体';
  398. let chkFontHeight = 12;
  399. if (font) {
  400. chkFontName = font[JV.FONT_PROPS[0]];
  401. chkFontHeight = parseFloat(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]]);
  402. }
  403. let hasSplitStr = false, splitStrArr = [];
  404. let accAmt = 0;
  405. // let chnW = doc.widthOfString('一'), otherW = doc.widthOfString('_');
  406. let chnW = fontWidthMap.getFontWidth(chkFontName, chkFontHeight, '宽'), otherW = fontWidthMap.getFontWidth(chkFontName, chkFontHeight, '窄');
  407. for (let i = 0; i < values.length; i++) {
  408. let amt = JpcCommonHelper.getStringLinesInArea(area, values[i], chnW, otherW);
  409. accAmt += amt;
  410. if (amt > 1) {
  411. hasSplitStr = true;
  412. splitStrArr.push(i);
  413. }
  414. }
  415. if (accAmt > 3) {
  416. // 新优化,计算实际能显示完的真正行数
  417. const rowHeight = JpcFlowTabHelper.getRowHeight(bands, rptTpl, me.isEx);
  418. let tmpFV = ((chkFontHeight + JV.CLOSE_OUTPUT_ROW_BUFFER) * accAmt) / rowHeight;
  419. let tmpAmt = Math.floor(tmpFV);
  420. if (Math.ceil(tmpFV) > tmpAmt) {
  421. tmpAmt++;
  422. }
  423. if (maxAmt < tmpAmt) maxAmt = tmpAmt;
  424. } else {
  425. if (maxAmt < accAmt) maxAmt = accAmt;
  426. }
  427. // if (hasSplitStr && outputType !== JV.OUTPUT_TYPE_EXCEL) {
  428. if (hasSplitStr) {
  429. let newValArr = [];
  430. for (let i = 0; i < values.length; i++) {
  431. if (splitStrArr.indexOf(i) < 0) {
  432. newValArr.push(values[i]);
  433. } else {
  434. newValArr = newValArr.concat(JpcCommonHelper.splitString(area, values[i], chnW, otherW));
  435. }
  436. }
  437. JpcFieldHelper.setValue(data_field, theRecIdx, newValArr.join('|'));
  438. splitStrArr = [];
  439. newValArr = [];
  440. }
  441. //备注: 如果outputType是excel类型,那么就只保留原始的分行符,无需介入分行,由excel本身去处理分行,只需要保留足够的空间即可。
  442. // 根据最新需求,暂时不考虑excel类型输出,换回原来逻辑
  443. }
  444. }
  445. if (rst < maxAmt) rst = maxAmt; // 最后才设置最大结果
  446. return rst;
  447. };
  448. for (let tabField of tab_fields) {
  449. if (adHocAutoHeightStyleStr.indexOf(tabField[JV.PROP_STYLE]) < 0) {
  450. adHocAutoHeightStyleStr.push(tabField[JV.PROP_STYLE]);
  451. }
  452. }
  453. if (adHocAutoHeightStyleStr.length > 0) {
  454. if (!(rptTpl[JV.NODE_STYLE_COLLECTION])) {
  455. rptTpl[JV.NODE_STYLE_COLLECTION] = [];
  456. }
  457. for (let styleStr of adHocAutoHeightStyleStr) {
  458. let adHocStyle1 = {"ID": styleStr + "_AutoHeightMerge_Top"};
  459. let adHocStyle2 = {"ID": styleStr + "_AutoHeightMerge_Middle"};
  460. let adHocStyle3 = {"ID": styleStr + "_AutoHeightMerge_Bottom"};
  461. rptTpl[JV.NODE_STYLE_COLLECTION].push(adHocStyle1);
  462. rptTpl[JV.NODE_STYLE_COLLECTION].push(adHocStyle2);
  463. rptTpl[JV.NODE_STYLE_COLLECTION].push(adHocStyle3);
  464. }
  465. }
  466. //这里先记录下来每一Segment里的每一条record占用行的数量(普通是1行高度,超过1就表示需要调整行数了)
  467. let infoArr = [];
  468. me.auto_height_info.push(infoArr);
  469. let segArr = me.segments[segIdx];
  470. for (let i = 0; i < segArr.length; i++) {
  471. infoArr.push(private_get_max_lines_of_the_record(segArr[i]));
  472. }
  473. }
  474. };
  475. JpcFlowTabResult.preSetupPages = function (rptTpl, dataObj, defProperties, option, $CURRENT_RPT, followTabEx, outputType) {
  476. //换一种思路来整理流水式数据
  477. let me = this, rst = 1, counterRowRec = 0, counterRowRecEx = 0, maxRowRec = 1, pageIdx = 0, currentRecAmt = 0;
  478. me.paging_option = option||JV.PAGING_OPTION_NORMAL;
  479. let CURRENT_FLOW_INFO = (me.isEx)?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  480. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[CURRENT_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], null, me.disp_fields_idx, me.isEx);
  481. if (followTabEx) {
  482. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], null, me.disp_fields_ex_idx, true);
  483. }
  484. //根据实际情况,统计前要先根据format整理好小数位数,否则会出现显示的数据的累计与最后统计的结果不一致
  485. me.setupGroupingData(rptTpl, dataObj, $CURRENT_RPT);
  486. if (followTabEx) {
  487. followTabEx.setupGroupingData(rptTpl, dataObj, $CURRENT_RPT);
  488. }
  489. me.sumSeg(dataObj, $CURRENT_RPT); //考虑到实际会有离散指标的汇总,这些离散指标数据是通过计算式后得来的,这种情况下,不适宜在sorting阶段进行汇总统计,现统一挪到这里处理
  490. if (me.paging_option === JV.PAGING_OPTION_INFINITY) {
  491. rst = me.segments.length;
  492. let pageStatus = [true, true, false, true, true, true, false, false];
  493. for (let segIdx = 0; segIdx < me.segments.length; segIdx++) {
  494. if (segIdx === me.segments.length - 1) {
  495. pageStatus[JV.STATUS_REPORT_END] = true;
  496. }
  497. if (segIdx > 0) {
  498. pageStatus[JV.STATUS_REPORT_START] = false;
  499. }
  500. me.pageStatusLst.push(pageStatus.slice(0));
  501. pageIdx++;
  502. let grpSeqInfo = (me.group_node_info)?me.group_node_info[segIdx]:null;
  503. private_addPageValue(me.dispValueIdxLst, me.segments[segIdx], grpSeqInfo, 0, me.segments[segIdx].length, me.page_seg_map, segIdx, pageIdx, null, false, me.auto_height_info, 0);
  504. }
  505. //目前不支持flowTabEx
  506. } else {
  507. let bands = JpcBand.createNew(rptTpl, defProperties);
  508. let pageStatus = [true, true, false, true, false, false, false, false];
  509. if (me.isEx) {
  510. pageStatus[JV.STATUS_REPORT_START] = false;
  511. }
  512. if (rptTpl[CURRENT_FLOW_INFO][JV.PROP_MULTI_COLUMN]) {
  513. me.multiCols = 1 * rptTpl[CURRENT_FLOW_INFO][JV.PROP_MULTI_COLUMN];
  514. }
  515. let grpPageInfo = {};
  516. let prePageLeftAutoHeightRecAmt = 0; //考虑自动行高的跨页情况
  517. function private_resetBandArea() {
  518. JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, !me.isEx, me.isEx);
  519. maxRowRec = JpcFlowTabHelper.getMaxRowsPerPage(bands, rptTpl, me.isEx);
  520. }
  521. let handledRowAmt = 0; //handledRowAmt纪录的是真正处理过的显示行数,包含了空白行,主要是为分页用(自动行高)
  522. let segRestRecAmt = 0; //一般情况下为0,只有在特殊情况下才需要,如09-x表中,正常流水一页显示不了的时候,就有大问题了
  523. function private_addPage(segIdx, grpSeqInfo, isFollow, isMix, mixSplitPoint) {
  524. private_resetBandArea();
  525. me.pageStatusLst.push(pageStatus.slice(0));
  526. currentRecAmt += maxRowRec; //在自动行高的场景下,currentRecAmt在后面还需要调整
  527. handledRowAmt += maxRowRec;
  528. let redundantRecAmt = 0;
  529. pageIdx++;
  530. function private_chk_handle_rec_amt(dv, isEx) {
  531. if ((dv[1] === JV.DISPLAY_VAL_TYPE_NORMAL) || (dv[1] === JV.DISPLAY_VAL_TYPE_AUTO_HEIGHT && dv[3] === dv[4] - 1)) {
  532. if (isEx) {counterRowRecEx++} else counterRowRec++;
  533. } else if (dv[1] === JV.DISPLAY_VAL_TYPE_AUTO_HEIGHT) {
  534. redundantRecAmt++;
  535. }
  536. }
  537. let restRecAmt = 0;
  538. if (isMix) {
  539. //先处理上半部分
  540. prePageLeftAutoHeightRecAmt = private_addPageValue(me.dispValueIdxLst, me.segments[segIdx], grpSeqInfo, counterRowRec, mixSplitPoint,me.page_seg_map, segIdx, pageIdx, grpPageInfo, false, me.auto_height_info, prePageLeftAutoHeightRecAmt);
  541. for (let dv of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
  542. private_chk_handle_rec_amt(dv, false);
  543. }
  544. //再处理下半部分
  545. restRecAmt = maxRowRec - me.dispValueIdxLst[me.dispValueIdxLst.length - 1].length; //备注:在一些极端条件下,mixSplitPoint这个分割点不合适处理下半部分数据,以实际生成的value-index数量为准
  546. // private_addPageValue(me.dispValueIdxLst, followTabEx.segments[segIdx], null, counterRowRecEx, maxRowRec - mixSplitPoint, me.page_seg_map, segIdx, pageIdx, null, true, null, 0);
  547. private_addPageValue(me.dispValueIdxLst, followTabEx.segments[segIdx], null, counterRowRecEx, restRecAmt, me.page_seg_map, segIdx, pageIdx, null, true, null, 0);
  548. for (let dv of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
  549. private_chk_handle_rec_amt(dv, true);
  550. }
  551. //合并到一页中
  552. me.page_seg_map.splice(me.page_seg_map.length - 1, 1);
  553. let vl = me.dispValueIdxLst[me.dispValueIdxLst.length - 2];
  554. for (let item of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
  555. vl.push(item);
  556. }
  557. me.dispValueIdxLst.splice(me.dispValueIdxLst.length - 1, 1);
  558. } else if (isFollow) {
  559. prePageLeftAutoHeightRecAmt = private_addPageValue(me.dispValueIdxLst, followTabEx.segments[segIdx], null, counterRowRecEx, maxRowRec, me.page_seg_map, segIdx, pageIdx, null, true, null, 0);
  560. for (let dv of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
  561. private_chk_handle_rec_amt(dv, true);
  562. }
  563. } else {
  564. prePageLeftAutoHeightRecAmt = private_addPageValue(me.dispValueIdxLst, me.segments[segIdx], grpSeqInfo, counterRowRec, maxRowRec,me.page_seg_map, segIdx, pageIdx, grpPageInfo, false, me.auto_height_info, prePageLeftAutoHeightRecAmt);
  565. for (let dv of me.dispValueIdxLst[me.dispValueIdxLst.length - 1]) {
  566. private_chk_handle_rec_amt(dv, false);
  567. }
  568. }
  569. currentRecAmt -= redundantRecAmt; //在自动行高调整场景下,需要减去冗余的数量
  570. if (restRecAmt < 0) {
  571. currentRecAmt -= restRecAmt;
  572. segRestRecAmt = restRecAmt;
  573. }
  574. }
  575. for (let segIdx = 0; segIdx < me.segments.length; segIdx++) {
  576. let grpSeqInfo = (me.group_node_info)?me.group_node_info[segIdx]:null;
  577. let grpRecAmt = (grpSeqInfo)?(grpSeqInfo.length*me.group_lines_amt):0;
  578. let grpRecAmtEx = 0;
  579. let accAutoHeightAmt = 0; //累计的自动行高数量
  580. handledRowAmt = 0; //初始化每一段的已处理纪录行数
  581. segRestRecAmt = 0;
  582. if (followTabEx && followTabEx.group_node_info) {
  583. grpRecAmtEx = followTabEx.group_node_info.length * followTabEx.group_lines_amt;
  584. }
  585. grpPageInfo[JV.PROP_SEG_GRP_IDX] = 0;
  586. grpPageInfo[JV.PROP_INSERTED_GRP_REC] = 0;
  587. grpPageInfo[JV.PROP_PRE_ADD_GRP_REC_INFO] = [];
  588. grpPageInfo[JV.PROP_GRP_LINES] = me.group_lines_amt;
  589. pageStatus[JV.STATUS_SEGMENT_START] = true;
  590. private_resetBandArea();
  591. me.setupAutoHeightData(bands, segIdx, rptTpl, dataObj, $CURRENT_RPT, defProperties, outputType);
  592. let threshold = 0;
  593. currentRecAmt = 0;
  594. counterRowRec = 0;
  595. counterRowRecEx = 0;
  596. let ttlSegRecAmtNormal = me.segments[segIdx].length + grpRecAmt; //正常的segment下的数据长度累计(含grouping data)
  597. let ttlSegRecAmt = (followTabEx)?(me.segments[segIdx].length + grpRecAmt + followTabEx.segments[segIdx].length + grpRecAmtEx):(me.segments[segIdx].length + grpRecAmt); //所有的segment下的数据长度累计(包括ex部分)
  598. let adHocAutoHeightAmt = 0;
  599. let normalContentAmt = 0;
  600. let exBuffer = 0;
  601. let adHocAutoHeightGrpStartIdx = 0;
  602. if (me.auto_height_fields_idx.length > 0) {
  603. for (let loop = 0; loop < me.auto_height_info[segIdx].length; loop++) {
  604. adHocAutoHeightAmt += (me.auto_height_info[segIdx][loop] - 1);
  605. normalContentAmt++;
  606. if (me.group_node_info && me.group_node_info[segIdx]) {
  607. if (me.group_node_info[segIdx][adHocAutoHeightGrpStartIdx] === loop) {
  608. adHocAutoHeightGrpStartIdx++;
  609. }
  610. }
  611. }
  612. ttlSegRecAmtNormal += adHocAutoHeightAmt;
  613. ttlSegRecAmt += adHocAutoHeightAmt;
  614. if (adHocAutoHeightAmt > 0) exBuffer = grpRecAmt;
  615. }
  616. //自动行高调整在多流水合并方式时,只支持前部分(后期需要再加)
  617. while (true) {
  618. if (currentRecAmt > 0) pageStatus[JV.STATUS_SEGMENT_START] = false;
  619. if (pageIdx > 0) pageStatus[JV.STATUS_REPORT_START] = false;
  620. private_resetBandArea(); // 这里得预先算maxRowRec(实际数据情况,会有章首页框,在章数据多的情况下,章第二页开始就得补上章首页框不显示遗留下来的row)
  621. //开始判断各种scenarios
  622. adHocAutoHeightAmt = 0;
  623. if (me.auto_height_fields_idx.length > 0) {
  624. adHocAutoHeightAmt -= prePageLeftAutoHeightRecAmt;
  625. //for (let loop = currentRecAmt; loop < me.auto_height_info[segIdx].length; loop++) {
  626. for (let loop = currentRecAmt; loop < currentRecAmt + maxRowRec; loop++) {
  627. if (me.auto_height_info[segIdx].length > loop) {
  628. adHocAutoHeightAmt += (me.auto_height_info[segIdx][loop] - 1);
  629. } else {
  630. break;
  631. }
  632. }
  633. }
  634. if ((ttlSegRecAmtNormal < ttlSegRecAmt) || (followTabEx !== null)) {
  635. //有流水拓展,并且是follow mode
  636. if (currentRecAmt + accAutoHeightAmt + exBuffer + maxRowRec > ttlSegRecAmtNormal) {
  637. // if (currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt + maxRowRec > ttlSegRecAmtNormal) {
  638. // if (currentRecAmt + adHocAutoHeightAmt >= ttlSegRecAmtNormal) {
  639. if (currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt >= ttlSegRecAmtNormal) {
  640. //纯 followTabEx 数据
  641. // if (currentRecAmt + adHocAutoHeightAmt + maxRowRec >= ttlSegRecAmt) {
  642. if (currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt + maxRowRec >= ttlSegRecAmt) {
  643. pageStatus[JV.STATUS_SEGMENT_END] = true;
  644. private_resetBandArea();
  645. let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt, maxRowRec, me.isEx);
  646. if (hasAdHocRow) {
  647. //add page info(pre segment end)
  648. pageStatus[JV.STATUS_SEGMENT_END] = false;
  649. private_addPage(segIdx, null, true, false, -1);
  650. }
  651. //add page info
  652. pageStatus[JV.STATUS_SEGMENT_END] = true;
  653. private_addPage(segIdx, null, true, false, -1);
  654. } else {
  655. private_addPage(segIdx, null, true, false, -1);
  656. }
  657. } else {
  658. //混合数据
  659. // if (currentRecAmt + adHocAutoHeightAmt + maxRowRec >= ttlSegRecAmt) {
  660. if (currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt + maxRowRec >= ttlSegRecAmt) {
  661. pageStatus[JV.STATUS_SEGMENT_END] = true;
  662. private_resetBandArea();
  663. let hasAdHocRow = !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt, maxRowRec, me.isEx);
  664. if (hasAdHocRow) {
  665. //add page info(pre segment end)
  666. pageStatus[JV.STATUS_SEGMENT_END] = false;
  667. private_addPage(segIdx, grpSeqInfo, false, true, ttlSegRecAmtNormal);
  668. }
  669. //add page info
  670. pageStatus[JV.STATUS_SEGMENT_END] = true;
  671. // if (currentRecAmt + adHocAutoHeightAmt >= ttlSegRecAmtNormal) {
  672. if (currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt >= ttlSegRecAmtNormal) {
  673. //纯 followTabEx 数据啦
  674. private_addPage(segIdx, null, true, false, -1);
  675. } else {
  676. // private_addPage(segIdx, grpSeqInfo, false, true, ttlSegRecAmtNormal);
  677. //在这里要考虑如果有多页正常的流水数据情况,那么就得考虑这页有多少条普通流水记录,不应该一刀切地用ttlSegRecAmtNormal
  678. let splitPoint = ttlSegRecAmtNormal - handledRowAmt ;
  679. private_addPage(segIdx, grpSeqInfo, false, true, splitPoint);
  680. }
  681. } else {
  682. //在这里要考虑如果有多页正常的流水数据情况,那么就得考虑这页有多少条普通流水记录,不应该一刀切地用ttlSegRecAmtNormal
  683. let splitPoint = ttlSegRecAmtNormal - handledRowAmt ;
  684. // if (splitPoint > (exBuffer + maxRowRec)) {
  685. // splitPoint = splitPoint % (exBuffer + maxRowRec);
  686. // }
  687. private_addPage(segIdx, grpSeqInfo, false, true, splitPoint);
  688. }
  689. }
  690. } else {
  691. //纯followTab数据
  692. private_addPage(segIdx, grpSeqInfo, false, false, -1);
  693. }
  694. } else {
  695. //普通流水数据情况
  696. if (handledRowAmt + maxRowRec >= ttlSegRecAmt) {
  697. //备注: 理论上自动行高是没有上限的,有可能正常一页的数据可以拓展到3页及以上,在此极端情况下,必须做一些限制判断,否则会出现缺页情况。
  698. // 2018-08-04 其实之前的判断逻辑完全是自找麻烦,而且还不够正确。其实只需要判断已经处理了多少行纪录(所有的都算,包括空白行),
  699. // 与总的seg纪录数想比较,就很容易得到结果,而且能处理极端边界的情况。
  700. pageStatus[JV.STATUS_SEGMENT_END] = true;
  701. // pageStatus[JV.STATUS_REPORT_END] = true;
  702. pageStatus[JV.STATUS_REPORT_END] = (segIdx === me.segments.length - 1);
  703. private_resetBandArea();
  704. let hasAdHocRow = ((adHocAutoHeightAmt > maxRowRec) || !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, handledRowAmt, maxRowRec, me.isEx));
  705. // !JpcFlowTabHelper.chkSegEnd(bands, rptTpl, ttlSegRecAmt, currentRecAmt + adHocAutoHeightAmt, maxRowRec, me.isEx));
  706. if (hasAdHocRow) {
  707. //add page info(pre segment end)
  708. pageStatus[JV.STATUS_SEGMENT_END] = false;
  709. pageStatus[JV.STATUS_REPORT_END] = false;
  710. private_addPage(segIdx, grpSeqInfo, false, false, -1);
  711. pageStatus[JV.STATUS_REPORT_START] = false;
  712. pageStatus[JV.STATUS_SEGMENT_START] = false;
  713. }
  714. //add page info
  715. pageStatus[JV.STATUS_SEGMENT_END] = true;
  716. pageStatus[JV.STATUS_REPORT_END] = (segIdx === me.segments.length - 1);
  717. private_addPage(segIdx, grpSeqInfo, false, false, -1);
  718. pageStatus[JV.STATUS_SEGMENT_END] = false; // 加完章统计页后,记得把章尾页设置为false
  719. } else {
  720. private_addPage(segIdx, grpSeqInfo, false, false, -1);
  721. }
  722. }
  723. //检测是否可退出
  724. // if ((currentRecAmt + accAutoHeightAmt + adHocAutoHeightAmt >= ttlSegRecAmt) && (pageIdx % me.multiCols === 0)) {
  725. if (handledRowAmt >= (ttlSegRecAmt + segRestRecAmt) && (pageIdx % me.multiCols === 0)) {
  726. //备注:这里必须得考虑多栏的情况,否则会造成pageStatus出界的问题
  727. break;
  728. }
  729. accAutoHeightAmt += adHocAutoHeightAmt;
  730. //控制阈值,超过阈值则强制退出,防止死循环
  731. threshold++;
  732. if (threshold > 1000) {
  733. console.log("Hey! There may be a dead loop here!!!");
  734. break;
  735. }
  736. }
  737. }
  738. // console.log(me.auto_height_info);
  739. // console.log(me.dispValueIdxLst);
  740. rst = Math.ceil(pageIdx / me.multiCols);
  741. }
  742. me.pagesAmt = rst;
  743. return rst;
  744. };
  745. JpcFlowTabResult.outputAsPreviewPage = function (rptTpl, bands, controls, $CURRENT_RPT) {
  746. let me = this, rst = [], vIdx = [];
  747. //只预览第一页的数据
  748. let pageStatus = [true, true, true, true, true, true, true, true];
  749. me.pageStatusLst.push(pageStatus);
  750. JpcFieldHelper.findAndPutDataFieldIdx(rptTpl, rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_FLOW_FIELDS], null, me.disp_fields_idx, false);
  751. JpcBandHelper.setBandArea(bands, rptTpl, pageStatus, true, false);
  752. let maxRowRec = JpcFlowTabHelper.getMaxRowsPerPage(bands, rptTpl, false);
  753. for (let i = 0; i < maxRowRec; i++) {
  754. vIdx.push([-1, JV.DISPLAY_VAL_TYPE_NORMAL, JV.BLANK_VALUE_INDEX]);
  755. }
  756. let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  757. // 2.2 Column tab
  758. rst = rst.concat(me.outputColumn(rptTpl, null, 1, 0, bands, unitFactor, 0));
  759. // 2.1 Content-Tab
  760. rst = rst.concat(me.outputPreviewContent(rptTpl, bands, unitFactor, controls, pageStatus, maxRowRec));
  761. // 2.3 Sum Seg
  762. rst = rst.concat(me.outputPreviewSegSum(rptTpl, bands, unitFactor, controls, pageStatus));
  763. // 2.4 Sum Page
  764. rst = rst.concat(me.outputPreviewPageSum(rptTpl, bands, unitFactor, controls, pageStatus));
  765. // 2.5 Group
  766. // 2.6 Discrete
  767. rst = rst.concat(JpcDiscreteHelper.outputPreviewDiscreteInfo(rptTpl[JV.NODE_FLOW_INFO][JV.NODE_DISCRETE_INFO], bands, unitFactor, pageStatus));
  768. return rst;
  769. };
  770. JpcFlowTabResult.outputAsSimpleJSONPage = function (rptTpl, dataObj, page, bands, controls, adHocMergePos, $CURRENT_RPT, customizeCfg) {
  771. let me = this, rst = [], tabRstLst = [];
  772. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  773. let unitFactor = JpcCommonHelper.getUnitFactor(rptTpl);
  774. if (me.paging_option === JV.PAGING_OPTION_INFINITY) {
  775. let segIdx = page - 1;
  776. //1 calculate the band position
  777. JpcBandHelper.setBandArea(bands, rptTpl, me.pageStatusLst[page - 1], !me.isEx, me.isEx);
  778. //2. then reset the band height
  779. let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT];
  780. let flowContentBand = bands[tab[JV.PROP_BAND_NAME]];
  781. let actH = JpcFlowTabHelper.getActualContentAreaHeight(bands, rptTpl, me.segments, page, me.isEx);
  782. let offsetY = actH - (flowContentBand.Bottom - flowContentBand.Top);
  783. JpcBandHelper.resetBandPos(rptTpl[JV.NODE_BAND_COLLECTION], bands, flowContentBand, 0, offsetY);
  784. // 2.1 Content-Tab
  785. tabRstLst.push(me.outputContent(rptTpl, dataObj, page, bands, unitFactor, controls, 0, $CURRENT_RPT, customizeCfg));
  786. // 2.2 Column tab
  787. tabRstLst.push(me.outputColumn(rptTpl, dataObj, page, segIdx, bands, unitFactor, 0));
  788. // 2.3 Sum Seg
  789. tabRstLst.push(me.outputSegSum(rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
  790. // 2.4 Sum Page
  791. tabRstLst.push(me.outputPageSum(rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
  792. // 2.5 Group
  793. // 2.6 Discrete
  794. tabRstLst.push(JpcDiscreteHelper.outputDiscreteInfo(rptTpl[FLOW_NODE_STR][JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[page - 1], segIdx, 1, 0, $CURRENT_RPT, customizeCfg));
  795. //3. reset merge band position
  796. if (bands[JV.BAND_PROP_MERGE_BAND] && adHocMergePos) {
  797. let mergedBand = bands[JV.BAND_PROP_MERGE_BAND];
  798. let arr = [];
  799. arr.push(parseInt(mergedBand[JV.PROP_LEFT].toFixed(0)));
  800. adHocMergePos[JV.PROP_LEFT] = arr;
  801. arr = [];
  802. arr.push(parseInt(mergedBand[JV.PROP_RIGHT].toFixed(0)));
  803. adHocMergePos[JV.PROP_RIGHT] = arr;
  804. arr = [];
  805. arr.push(parseInt(mergedBand[JV.PROP_TOP].toFixed(0)));
  806. adHocMergePos[JV.PROP_TOP] = arr;
  807. arr = [];
  808. arr.push(parseInt((mergedBand[JV.PROP_BOTTOM]).toFixed(0)));
  809. adHocMergePos[JV.PROP_BOTTOM] = arr;
  810. }
  811. } else {
  812. let segIdx = JpcCommonHelper.getSegIdxByPageIdx(page, me.page_seg_map);
  813. //1 calculate the band position
  814. JpcBandHelper.setBandArea(bands, rptTpl, me.pageStatusLst[page - 1], !me.isEx, me.isEx);
  815. //2. start to output detail-part
  816. for (let pi = 0; pi < me.multiCols; pi++) {
  817. let actualPage = (page - 1) * me.multiCols + pi + 1;
  818. // 2.1 Content-Tab
  819. tabRstLst.push(me.outputContent(rptTpl, dataObj, actualPage, bands, unitFactor, controls, pi, $CURRENT_RPT, customizeCfg));
  820. // 2.2 Column tab
  821. tabRstLst.push(me.outputColumn(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, pi));
  822. // 2.3 Sum Seg
  823. tabRstLst.push(me.outputSegSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
  824. // 2.4 Sum Page
  825. tabRstLst.push(me.outputPageSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
  826. // 2.5 Group
  827. // 2.6 Discrete
  828. if (pi === 0) {
  829. tabRstLst.push(JpcDiscreteHelper.outputDiscreteInfo(rptTpl[FLOW_NODE_STR][JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[actualPage - 1], segIdx, 1, pi, $CURRENT_RPT, customizeCfg));
  830. }
  831. }
  832. }
  833. for (let i = 0; i < tabRstLst.length; i++) {
  834. rst = rst.concat(tabRstLst[i]);
  835. tabRstLst[i] = null;
  836. }
  837. return rst;
  838. };
  839. JpcFlowTabResult.combinePageCells = function (rstPageCells, verticalCombinePos, horizonCombinePos) {
  840. // let me = this;
  841. //备注:纵向合并要考虑以下因素:
  842. // 如果有多个column纵向合并,需要总体考虑分割,
  843. // 假如:第一列的前3个数据(1、2、3)是相同的,第二列中第2、3、4行数据相同,那么第二列只能合并2、3行的数据,不能合并到第四行
  844. // 同理如此类推第三列...n列
  845. if (verticalCombinePos.length > 0 || horizonCombinePos.length > 1) {
  846. let cacheObj = {vCache:{}, hCache: {}, hCacheStr: []};
  847. let removeCellIds = [];
  848. for (let vPosArr of verticalCombinePos) {
  849. let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
  850. cacheObj.vCache[pStr] = [];
  851. }
  852. //horizonCombinePos不需要预记
  853. for (let idx = 0; idx < rstPageCells.length; idx++) {
  854. let cell = rstPageCells[idx];
  855. for (let vPosArr of verticalCombinePos) {
  856. if (cell[JV.PROP_AREA][JV.PROP_LEFT] === vPosArr[0] && cell[JV.PROP_AREA][JV.PROP_RIGHT] === vPosArr[1]) {
  857. cacheObj.vCache["_" + vPosArr[0] + "_" + vPosArr[1]].push(idx);
  858. }
  859. }
  860. for (let hPosArr of horizonCombinePos) {
  861. if (cell[JV.PROP_AREA][JV.PROP_LEFT] === hPosArr[0] && cell[JV.PROP_AREA][JV.PROP_RIGHT] === hPosArr[1]) {
  862. let hpStr = "_" + cell[JV.PROP_AREA][JV.PROP_TOP] + "_" + cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  863. if (cacheObj.hCacheStr.indexOf(hpStr) < 0) {
  864. cacheObj.hCache[hpStr] = [];
  865. cacheObj.hCacheStr.push(hpStr);
  866. }
  867. cacheObj.hCache[hpStr].push(idx);
  868. }
  869. }
  870. }
  871. if (verticalCombinePos.length > 0) {
  872. let preColMergePosArr = []; //见上面备注描述,纪录当前列的分割坐标集合情况
  873. let private_chk_in_pre_merge = function (preIdx, newCell) {
  874. let rst = true;
  875. if (preIdx >= 0 && preIdx < preColMergePosArr.length) {
  876. for (let mergeArea of preColMergePosArr[preIdx]) {
  877. if (newCell[JV.PROP_AREA][JV.PROP_TOP] >= mergeArea[0] && newCell[JV.PROP_AREA][JV.PROP_TOP] < mergeArea[1]) {
  878. rst = (newCell[JV.PROP_AREA][JV.PROP_BOTTOM] <= mergeArea[1]);
  879. break;
  880. }
  881. }
  882. }
  883. return rst;
  884. };
  885. for (let vidx = 0; vidx < verticalCombinePos.length; vidx++) {
  886. let vPosArr = verticalCombinePos[vidx];
  887. let pStr = "_" + vPosArr[0] + "_" + vPosArr[1];
  888. //rstPageCells的结果已经是按顺序排列了,这里不用再排序
  889. if (cacheObj.vCache[pStr] && cacheObj.vCache[pStr].length > 0) {
  890. let preCell = rstPageCells[cacheObj.vCache[pStr][0]];
  891. if (vidx === 0) {
  892. //这里要处理下
  893. let minY = 10000, maxY = 0;
  894. for (let preCIdx = 0; preCIdx < cacheObj.vCache[pStr].length; preCIdx++) {
  895. 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];
  896. 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];
  897. }
  898. preColMergePosArr.push([[minY, maxY]]);
  899. }
  900. let dtlColMergePosArr = [];
  901. preColMergePosArr.push(dtlColMergePosArr);
  902. for (let cIdx = 1; cIdx < cacheObj.vCache[pStr].length; cIdx++) {
  903. if (preCell.Value === "") {
  904. dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
  905. preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
  906. } else {
  907. if (preCell.Value === rstPageCells[cacheObj.vCache[pStr][cIdx]].Value) {
  908. let bkBottom = preCell[JV.PROP_AREA][JV.PROP_BOTTOM];
  909. preCell[JV.PROP_AREA][JV.PROP_BOTTOM] = rstPageCells[cacheObj.vCache[pStr][cIdx]][JV.PROP_AREA][JV.PROP_BOTTOM];
  910. if (private_chk_in_pre_merge(vidx, preCell)) {
  911. removeCellIds.push(cacheObj.vCache[pStr][cIdx]);
  912. if (cIdx === cacheObj.vCache[pStr].length - 1) {
  913. dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
  914. }
  915. } else {
  916. preCell[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  917. dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
  918. preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
  919. }
  920. } else {
  921. dtlColMergePosArr.push([preCell[JV.PROP_AREA][JV.PROP_TOP], preCell[JV.PROP_AREA][JV.PROP_BOTTOM]]);
  922. preCell = rstPageCells[cacheObj.vCache[pStr][cIdx]];
  923. }
  924. }
  925. }
  926. }
  927. }
  928. }
  929. if (horizonCombinePos.length > 1) {
  930. if (cacheObj.hCacheStr.length > 0) {
  931. for (let hStr of cacheObj.hCacheStr) {
  932. let preCell = rstPageCells[cacheObj.hCache[hStr][0]];
  933. for (let cIdx = 1; cIdx < cacheObj.hCache[hStr].length; cIdx++) {
  934. if (preCell.Value === "") {
  935. preCell = rstPageCells[cacheObj.hCache[hStr][cIdx]];
  936. } else {
  937. if (preCell.Value === rstPageCells[cacheObj.hCache[hStr][cIdx]].Value) {
  938. if (preCell[JV.PROP_AREA][JV.PROP_RIGHT] < rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_RIGHT]) {
  939. preCell[JV.PROP_AREA][JV.PROP_RIGHT] = rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_RIGHT];
  940. } else {
  941. preCell[JV.PROP_AREA][JV.PROP_LEFT] = rstPageCells[cacheObj.hCache[hStr][cIdx]][JV.PROP_AREA][JV.PROP_LEFT];
  942. }
  943. removeCellIds.push(cacheObj.hCache[hStr][cIdx]);
  944. } else {
  945. preCell = rstPageCells[cacheObj.hCache[hStr][cIdx]];
  946. }
  947. }
  948. }
  949. }
  950. }
  951. }
  952. if (removeCellIds.length > 0) {
  953. //排序,保证一定的顺序,不能用默认的方式(默认方式是针对字符串的简单排序)
  954. removeCellIds.sort(function (idx1, idx2) {
  955. return parseInt(idx1) - parseInt(idx2);
  956. });
  957. for (let idx = removeCellIds.length - 1; idx >= 0; idx--) {
  958. rstPageCells.splice(removeCellIds[idx], 1);
  959. }
  960. }
  961. }
  962. };
  963. JpcFlowTabResult.outputPreviewContent = function(rptTpl, bands, unitFactor, controls, pageStatus, maxRec) {
  964. let me = this, rst = [];
  965. let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT];
  966. let band = bands[tab[JV.PROP_BAND_NAME]];
  967. if (band) {
  968. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  969. let tab_fields = tab[JV.PROP_FLOW_FIELDS];
  970. for (let rowIdx = 0; rowIdx < maxRec; rowIdx++) {
  971. for (let i = 0; i < tab_fields.length; i++) {
  972. let tab_field = tab_fields[i];
  973. if (!(tab_field[JV.PROP_HIDDEN])) {
  974. rst.push(me.outputTabField(band, tab_field, null, -1, -1, maxRec, rowIdx, 1, 0, unitFactor, false, controls, 0));
  975. }
  976. }
  977. }
  978. }
  979. }
  980. return rst;
  981. };
  982. JpcFlowTabResult.outputContent = function(rptTpl, dataObj, page, bands, unitFactor, controls, multiColIdx, $CURRENT_RPT, customizeCfg) {
  983. let me = this, rst = [], prepareObj = {};
  984. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  985. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT];
  986. let tabEx = (rptTpl[JV.NODE_FLOW_INFO_EX])?rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]:null;
  987. let verticalCombinePos = [], horizonCombinePos = []; //合并特性用
  988. let band = bands[tab[JV.PROP_BAND_NAME]];
  989. if (band) {
  990. let pageStatus = me.pageStatusLst[page - 1];
  991. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  992. let tab_fields = tab[JV.PROP_FLOW_FIELDS];
  993. let tab_fields_ex = tabEx?tabEx[JV.PROP_FLOW_FIELDS]:null;
  994. let data_details = me.isEx?dataObj[JV.DATA_DETAIL_DATA_EX]:dataObj[JV.DATA_DETAIL_DATA];
  995. let data_details_ex = $CURRENT_RPT.isFollowMode?dataObj[JV.DATA_DETAIL_DATA_EX]:null;
  996. let contentValuesIdx = me.dispValueIdxLst[page - 1];
  997. let page_sum_data_fields = [];
  998. for (let i = 0; i < me.page_sum_fields_idx.length; i++) {
  999. if (typeof(me.page_sum_fields_idx[i]) === "object") {
  1000. let exField = JE.F(me.page_sum_fields_idx[i][JV.PROP_ID], $CURRENT_RPT);
  1001. if (exField) {
  1002. page_sum_data_fields.push(exField[JV.PROP_AD_HOC_DATA]);
  1003. } else {
  1004. page_sum_data_fields.push(null);
  1005. }
  1006. } else {
  1007. let data_field = data_details[me.page_sum_fields_idx[i]];
  1008. page_sum_data_fields.push(data_field);
  1009. }
  1010. }
  1011. let rowGrandTotal = [];
  1012. for (let di = 0; di < page_sum_data_fields.length; di++) {
  1013. rowGrandTotal.push(0.0);
  1014. }
  1015. //normal content
  1016. let flexiblePrecisionRefObj = null, flexibleRefField = null, precision_ref_data = null;
  1017. for (let rowIdx = 0; rowIdx < contentValuesIdx.length; rowIdx++) {
  1018. for (let fieldIdx = 0; fieldIdx < tab_fields.length; fieldIdx++) {
  1019. let tab_field = tab_fields[fieldIdx];
  1020. let data_field = null,
  1021. map_data_field = JE.F(tab_field[JV.PROP_FIELD_ID], $CURRENT_RPT);
  1022. if (me.disp_fields_idx[fieldIdx] !== JV.BLANK_FIELD_INDEX && (typeof me.disp_fields_idx[fieldIdx] !== 'object')) {
  1023. data_field = data_details[me.disp_fields_idx[fieldIdx]];
  1024. } else {
  1025. if (map_data_field) {
  1026. data_field = map_data_field[JV.PROP_AD_HOC_DATA];
  1027. }
  1028. }
  1029. if (map_data_field && map_data_field[JV.PROP_PRECISION] && map_data_field.flexiblePrecisionRefObj) {
  1030. if (flexiblePrecisionRefObj === null) {
  1031. flexiblePrecisionRefObj = {};
  1032. flexibleRefField = JE.F(map_data_field[JV.PROP_PRECISION][JV.PROP_FLEXIBLE_REF_FILED_ID], $CURRENT_RPT);
  1033. precision_ref_data = dataObj[map_data_field.DataNodeName][flexibleRefField.DataSeq];
  1034. for (let decimalObj of map_data_field.flexiblePrecisionRefObj) {
  1035. flexiblePrecisionRefObj["refUnit_" + decimalObj.unit] = decimalObj.decimal;
  1036. }
  1037. }
  1038. JpcFieldHelper.resetFlexibleFormat(tab_field, precision_ref_data, flexiblePrecisionRefObj, contentValuesIdx[rowIdx][2], customizeCfg);
  1039. } else {
  1040. if (rowIdx === 0) JpcFieldHelper.resetFormat(tab_field, map_data_field, customizeCfg);
  1041. }
  1042. if (!(tab_field[JV.PROP_HIDDEN])) {
  1043. if (contentValuesIdx[rowIdx][0] !== JV.TYPE_FOLLOW_MODE && contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_NORMAL) {
  1044. rst.push(me.outputTabField(band, tab_field, data_field, contentValuesIdx[rowIdx][2], -1, contentValuesIdx.length, rowIdx, 1, 0, unitFactor, false, controls, multiColIdx));
  1045. } else if (contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_AUTO_HEIGHT) {
  1046. if (contentValuesIdx[rowIdx][4] === 1) {
  1047. //等效于普通输出
  1048. rst.push(me.outputTabField(band, tab_field, data_field, contentValuesIdx[rowIdx][2], -1, contentValuesIdx.length, rowIdx, 1, 0, unitFactor, false, controls, multiColIdx));
  1049. } else {
  1050. //这里需要做些style调整(中间的那些横杠线去掉)
  1051. let cellItem = me.outputAutoHeightTabField(band, tab_field, data_field, contentValuesIdx[rowIdx], contentValuesIdx.length, rowIdx, 1, 0, unitFactor, true, controls, multiColIdx);
  1052. rst.push(cellItem);
  1053. if (contentValuesIdx[rowIdx][3] === 0 || rowIdx === 0) {
  1054. cellItem[JV.PROP_STYLE] = cellItem[JV.PROP_STYLE] + '_AutoHeightMerge_Top';
  1055. } else if (contentValuesIdx[rowIdx][3] === contentValuesIdx[rowIdx][4] - 1) {
  1056. cellItem[JV.PROP_STYLE] = cellItem[JV.PROP_STYLE] + '_AutoHeightMerge_Bottom';
  1057. } else {
  1058. cellItem[JV.PROP_STYLE] = cellItem[JV.PROP_STYLE] + '_AutoHeightMerge_Middle';
  1059. }
  1060. prepareAutoHeightCells(prepareObj, cellItem, rst.length - 1, rst);
  1061. }
  1062. }
  1063. }
  1064. if (rowIdx === 0 && tab_field[JV.PROP_COMBINE_TYPE] !== undefined && tab_field[JV.PROP_COMBINE_TYPE] !== null) {
  1065. let rstCellItem = rst[rst.length - 1];
  1066. let cbfPos = [];
  1067. cbfPos.push(rstCellItem[JV.PROP_AREA][JV.PROP_LEFT]);
  1068. cbfPos.push(rstCellItem[JV.PROP_AREA][JV.PROP_RIGHT]);
  1069. if (tab_field[JV.PROP_COMBINE_TYPE] === 'vertical') {
  1070. verticalCombinePos.push(cbfPos);
  1071. } else if (tab_field[JV.PROP_COMBINE_TYPE] === 'horizon') {
  1072. horizonCombinePos.push(cbfPos);
  1073. }
  1074. }
  1075. }
  1076. if (contentValuesIdx[rowIdx][0] === JV.TYPE_FOLLOW_MODE) {
  1077. for (let idx_ex = 0; idx_ex < tab_fields_ex.length; idx_ex++) {
  1078. let tab_fieldex = tab_fields_ex[idx_ex];
  1079. let data_fieldex = null, map_data_fieldex = JE.F(tab_fieldex[JV.PROP_FIELD_ID], $CURRENT_RPT);
  1080. if (me.disp_fields_ex_idx[idx_ex] !== JV.BLANK_FIELD_INDEX && (typeof me.disp_fields_ex_idx[idx_ex] !== 'object')) {
  1081. data_fieldex = data_details_ex[me.disp_fields_ex_idx[idx_ex]];
  1082. } else {
  1083. if (map_data_fieldex) {
  1084. data_fieldex = map_data_fieldex[JV.PROP_AD_HOC_DATA];
  1085. }
  1086. }
  1087. if (map_data_fieldex && map_data_fieldex[JV.PROP_PRECISION] && map_data_fieldex.flexiblePrecisionRefObj) {
  1088. if (flexiblePrecisionRefObj === null) {
  1089. flexiblePrecisionRefObj = {};
  1090. flexibleRefField = JE.F(map_data_fieldex[JV.PROP_PRECISION][JV.PROP_FLEXIBLE_REF_FILED_ID], $CURRENT_RPT);
  1091. for (let decimalObj of map_data_fieldex.flexiblePrecisionRefObj) {
  1092. flexiblePrecisionRefObj["refUnit_" + decimalObj.unit] = decimalObj.decimal;
  1093. }
  1094. }
  1095. JpcFieldHelper.resetFlexibleFormat(tab_fieldex, flexibleRefField, flexiblePrecisionRefObj, contentValuesIdx[rowIdx][2], customizeCfg);
  1096. } else {
  1097. if (rowIdx === 0) JpcFieldHelper.resetFormat(tab_fieldex, map_data_fieldex, customizeCfg);
  1098. }
  1099. if (!(tab_fieldex[JV.PROP_HIDDEN])) {
  1100. if (contentValuesIdx[rowIdx][0] === JV.TYPE_FOLLOW_MODE && contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_NORMAL) {
  1101. rst.push(me.outputTabField(band, tab_fieldex, data_fieldex, contentValuesIdx[rowIdx][2], -1, contentValuesIdx.length, rowIdx, 1, 0, unitFactor, false, controls, multiColIdx));
  1102. }
  1103. }
  1104. }
  1105. }
  1106. //page sum content
  1107. for (let di = 0; di < page_sum_data_fields.length; di++) {
  1108. if (contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_NORMAL ||
  1109. contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_AUTO_HEIGHT && contentValuesIdx[rowIdx][3] === 0) {
  1110. let precisionAmt = 4;
  1111. let sum_field = JE.F(me.page_sum_tab_fields[di][JV.PROP_FIELD_ID], $CURRENT_RPT);
  1112. if (sum_field[JV.PROP_PRECISION] && sum_field[JV.PROP_PRECISION].type === `fixed`) {
  1113. precisionAmt = sum_field[JV.PROP_FIXED_PRECISION_AMT];
  1114. } else {
  1115. let flowF = me.page_sum_tab_fields[di];
  1116. if (flowF && !strUtil.isEmptyString(flowF[JV.PROP_FORMAT])) {
  1117. let idx = flowF[JV.PROP_FORMAT].indexOf('.');
  1118. if (idx >= 0) {
  1119. precisionAmt = flowF[JV.PROP_FORMAT].length - idx - 1;
  1120. }
  1121. }
  1122. }
  1123. // rowGrandTotal[di] = rowGrandTotal[di] + 1.0 * JpcFieldHelper.getValue(page_sum_data_fields[di], contentValuesIdx[rowIdx][2]);
  1124. if (contentValuesIdx[rowIdx][2] >= 0) {
  1125. let psv = JpcFieldHelper.getValue(page_sum_data_fields[di], contentValuesIdx[rowIdx][2]);
  1126. if (psv) {
  1127. rowGrandTotal[di] = rowGrandTotal[di] + parseFloat(parseFloat(psv).toFixed(precisionAmt));
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }
  1133. me.pageSumValLst.push(rowGrandTotal);
  1134. //grouping content
  1135. let grpCntIdx = 0;
  1136. for (let rowIdx = 0; rowIdx < contentValuesIdx.length; rowIdx++) {
  1137. if (contentValuesIdx[rowIdx][1] === JV.DISPLAY_VAL_TYPE_GROUP) {
  1138. for (let grpIdx = 0; grpIdx < rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES].length; grpIdx++) {
  1139. if (contentValuesIdx[rowIdx][3] === grpIdx) {
  1140. let grp_line = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_GROUP][JV.PROP_GROUP_LINES][grpIdx];
  1141. if (page === 1) {
  1142. if (grp_line[JV.PROP_GROUP_SUM_KEYS] && grp_line[JV.PROP_GROUP_SUM_KEYS].length > 0) {
  1143. for (let grp_sum_field of grp_line[JV.PROP_GROUP_SUM_KEYS]) {
  1144. if (grp_sum_field[JV.PROP_FIELD_ID]) {
  1145. let map_field = JE.F(grp_sum_field[JV.PROP_FIELD_ID], $CURRENT_RPT);
  1146. JpcFieldHelper.resetFormat(grp_sum_field, map_field, customizeCfg);
  1147. }
  1148. }
  1149. }
  1150. }
  1151. let lineRst = me.outputTabGrpLine(band, grp_line, page, contentValuesIdx[rowIdx], contentValuesIdx.length, rowIdx, 1, 0, unitFactor, true, controls, multiColIdx, grpCntIdx, $CURRENT_RPT);
  1152. rst = rst.concat(lineRst);
  1153. }
  1154. }
  1155. grpCntIdx++;
  1156. }
  1157. }
  1158. }
  1159. }
  1160. let eliminateCells = combineAutoHeightCells(prepareObj, page, controls);
  1161. for (let idIdx = eliminateCells.length - 1; idIdx >= 0; idIdx--) {
  1162. rst.splice(eliminateCells[idIdx], 1);
  1163. }
  1164. me.checkCombineEvent(JV.RUN_TYPE_BEFORE_COMBINE, verticalCombinePos, horizonCombinePos, rst, $CURRENT_RPT);
  1165. me.combinePageCells(rst, verticalCombinePos, horizonCombinePos);
  1166. me.checkCombineEvent(JV.RUN_TYPE_AFTER_COMBINE, verticalCombinePos, horizonCombinePos, rst, $CURRENT_RPT);
  1167. return rst;
  1168. };
  1169. JpcFlowTabResult.checkCombineEvent = function ($RUN_TYPE, $VER_COMB_ARRAY, $HOR_COMB_ARRAY, $CURRENT_CELL_ITEMS, $CURRENT_RPT) {
  1170. if ($CURRENT_RPT.formulas) {
  1171. for (let execFmlIdx = 0; execFmlIdx < $CURRENT_RPT.formulas.length; execFmlIdx++) {
  1172. if ($CURRENT_RPT.formulas[execFmlIdx][JV.PROP_RUN_TYPE] === $RUN_TYPE) {
  1173. let expression = $CURRENT_RPT.formulas[execFmlIdx][JV.PROP_EXPRESSION];
  1174. if (expression) {
  1175. let $ME = $CURRENT_RPT.formulas[execFmlIdx];
  1176. try {
  1177. eval(expression);
  1178. } catch (ex) {
  1179. console.log(ex);
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. };
  1186. JpcFlowTabResult.outputColumn = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, multiColIdx) {
  1187. let me = this, rst = [];
  1188. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  1189. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_COLUMN];
  1190. let band = bands[tab[JV.PROP_BAND_NAME]];
  1191. if (band) {
  1192. let pageStatus = me.pageStatusLst[page - 1];
  1193. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  1194. rst = rst.concat(me.commonTabRestOutput(dataObj, page, segIdx, bands, band, unitFactor, tab, multiColIdx));
  1195. }
  1196. }
  1197. return rst;
  1198. };
  1199. JpcFlowTabResult.outputPreviewSegSum = function (rptTpl, bands, unitFactor, controls, pageStatus) {
  1200. let rst = [];
  1201. let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_SEG_SUM];
  1202. let band = bands[tab[JV.PROP_BAND_NAME]];
  1203. if (band) {
  1204. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  1205. rst = rst.concat(JpcDiscreteHelper.outputPreviewSumInfoOutput(band, unitFactor, tab));
  1206. }
  1207. }
  1208. return rst;
  1209. };
  1210. JpcFlowTabResult.outputPreviewPageSum = function (rptTpl, bands, unitFactor, controls, pageStatus) {
  1211. let rst = [];
  1212. let tab = rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_PAGE_SUM];
  1213. let band = bands[tab[JV.PROP_BAND_NAME]];
  1214. if (band) {
  1215. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  1216. rst = rst.concat(JpcDiscreteHelper.outputPreviewSumInfoOutput(band, unitFactor, tab));
  1217. }
  1218. }
  1219. return rst;
  1220. };
  1221. JpcFlowTabResult.outputSegSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg) {
  1222. let me = this, rst = [];
  1223. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  1224. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_SEG_SUM];
  1225. let refTab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT];
  1226. let refTabEx = (rptTpl[JV.NODE_FLOW_INFO_EX])?rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]:null;
  1227. let band = bands[tab[JV.PROP_BAND_NAME]];
  1228. if (band) {
  1229. let pageStatus = me.pageStatusLst[page - 1];
  1230. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  1231. let ref_tab_fields = refTab[JV.PROP_FLOW_FIELDS];
  1232. let ref_tab_fields_ex = refTabEx?refTabEx[JV.PROP_FLOW_FIELDS]:null;
  1233. let tab_fields = me.seg_sum_tab_fields;
  1234. for (let i = 0; i < tab_fields.length; i++) {
  1235. if (!JpcFieldHelper.resetSumFormat(ref_tab_fields, tab_fields[i])) {
  1236. if (!JpcFieldHelper.resetSumFormat(ref_tab_fields_ex, tab_fields[i])) {
  1237. let map_data_field = JE.F(tab_fields[i][JV.PROP_FIELD_ID], $CURRENT_RPT);
  1238. JpcFieldHelper.resetFormat(tab_fields[i], map_data_field, customizeCfg)
  1239. //如果都找不到,就得靠自己的Format属性了
  1240. }
  1241. }
  1242. let sumVal = 0;
  1243. if (me.segSumValLst[segIdx] && me.segSumValLst[segIdx].length > i) {
  1244. sumVal = me.segSumValLst[segIdx][i];
  1245. }
  1246. //备注:考虑到有时候会出现没有数据可合计的scenario,得有容错处理
  1247. let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_fields[i], sumVal, controls);
  1248. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_fields[i][JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0, false, false);
  1249. rst.push(cellItem);
  1250. }
  1251. rst = rst.concat(me.commonTabRestOutput(dataObj, page, segIdx, bands, band, unitFactor, tab, 0));
  1252. }
  1253. }
  1254. return rst;
  1255. };
  1256. JpcFlowTabResult.outputPageSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg) {
  1257. let me = this, rst = [];
  1258. let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
  1259. let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_PAGE_SUM];
  1260. let refTab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_CONTENT];
  1261. let refTabEx = (rptTpl[JV.NODE_FLOW_INFO_EX])?rptTpl[JV.NODE_FLOW_INFO_EX][JV.NODE_FLOW_CONTENT]:null;
  1262. let band = bands[tab[JV.PROP_BAND_NAME]];
  1263. if (band) {
  1264. let pageStatus = me.pageStatusLst[page - 1];
  1265. if (pageStatus[band[JV.BAND_PROP_DISPLAY_TYPE]]) {
  1266. let ref_tab_fields = refTab[JV.PROP_FLOW_FIELDS];
  1267. let ref_tab_fields_ex = refTabEx?refTabEx[JV.PROP_FLOW_FIELDS]:null;
  1268. let tab_fields = me.page_sum_tab_fields;
  1269. for (let i = 0; i < tab_fields.length; i++) {
  1270. if (!JpcFieldHelper.resetSumFormat(ref_tab_fields, tab_fields[i])) {
  1271. if (!JpcFieldHelper.resetSumFormat(ref_tab_fields_ex, tab_fields[i])) {
  1272. let map_data_field = JE.F(tab_fields[i][JV.PROP_FIELD_ID], $CURRENT_RPT);
  1273. JpcFieldHelper.resetFormat(tab_fields[i], map_data_field, customizeCfg)
  1274. //如果都找不到,就得靠自己的Format属性了
  1275. }
  1276. }
  1277. let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_fields[i], me.pageSumValLst[page - 1][i], controls);
  1278. cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_fields[i][JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0, false, false);
  1279. rst.push(cellItem);
  1280. }
  1281. rst = rst.concat(me.commonTabRestOutput(dataObj, page, segIdx, bands, band, unitFactor, tab, 0));
  1282. }
  1283. }
  1284. return rst;
  1285. };
  1286. JpcFlowTabResult.outputTabField = function (band, tab_field, data_field, valueIdx, serialIdx, rows, rowIdx, cols, colIdx, unitFactor, isRow, controls, multiColIdx) {
  1287. let me = this,
  1288. rst = JpcCommonOutputHelper.createCommonOutput(tab_field, JpcFieldHelper.getValue(data_field, valueIdx), controls);
  1289. rst[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx, isRow, false);
  1290. return rst;
  1291. };
  1292. JpcFlowTabResult.outputAutoHeightTabField = function (band, tab_field, data_field, contentValInfo, rows, rowIdx, cols, colIdx, unitFactor, isRow, controls, multiColIdx) {
  1293. let me = this;
  1294. let showText = JpcFieldHelper.getValue(data_field, contentValInfo[2]);
  1295. if (tab_field[JV.PROP_IS_AUTO_HEIGHT]) {
  1296. let textArr = [];
  1297. if (showText) {
  1298. textArr = textArr.concat(showText.split('|'));
  1299. }
  1300. /*
  1301. if (contentValInfo[3] < textArr.length && contentValInfo[3] >= 0) {
  1302. showText = textArr[contentValInfo[3]];
  1303. } else {
  1304. showText = '';
  1305. }
  1306. /*/
  1307. // 因新逻辑要优化自动行高,不再是一个折行占用1row,而是:
  1308. // a. 根据实际情况,设置了一个实际的行数值(比如共有10行,根据行高情况,可能只设置了6行的高度,在setupAutoHeightData方法里处理)
  1309. // b. 这里最大的难题在于跨页分配(预估会有来回调整,目前采用按比例分配原则)
  1310. // c. 还有个问题就是多个自动行高指标的问题
  1311. const ACT_ROWS = contentValInfo[4]; //经实际计算,能容纳所有数据的实际行数
  1312. const CURRENT_ROW = contentValInfo[3]; //从0开始
  1313. const QUOTA_Rate = textArr.length / ACT_ROWS; //每行显示的加权系数(超过2的话,表示给的行高太多了,需要另外一些特殊处理,后期有需要再加)
  1314. if (textArr.length <= 3 || ACT_ROWS > textArr.length) {
  1315. //表示这个一定是附属的autoheight指标,或者数据就只有3行(假如数据3行精简成2行,但刚好处于分页状态,那么无论是前一页或后一页,显示上都很纠结(多出来的一行放哪好?),所以新逻辑的起点要3行以上,少了就不折腾了,老老实实地一个萝卜一个坑)
  1316. if (CURRENT_ROW < textArr.length && CURRENT_ROW >= 0) {
  1317. showText = textArr[CURRENT_ROW];
  1318. } else {
  1319. showText = '';
  1320. }
  1321. } else {
  1322. //这里不管是不是附属autoheight指标,有足够的条件单独处理
  1323. // console.log(`ACT_ROWS: ${ACT_ROWS}`);
  1324. // console.log(`QUOTA_Rate: ${QUOTA_Rate}`);
  1325. if (QUOTA_Rate >= 2) {
  1326. //压缩超过一半空间的话,说明给的行高度太高了,需要另外一些特殊处理,后期有需要再加
  1327. console.log('压缩率异常!!!!!');
  1328. } else {
  1329. //正常的压缩比例
  1330. let startIdx = 0, endIdx = 0;
  1331. if (CURRENT_ROW > 0) {
  1332. endIdx = Math.round((CURRENT_ROW + 1) * QUOTA_Rate) - 1;
  1333. let preEndIdx = 0;
  1334. if (CURRENT_ROW > 1) {
  1335. //重定位 preEndIdx
  1336. preEndIdx = Math.round(CURRENT_ROW * QUOTA_Rate) - 1;
  1337. }
  1338. startIdx = preEndIdx + 1;
  1339. }
  1340. //按比例分配
  1341. showText = textArr[startIdx];
  1342. for (let idx = startIdx + 1; idx <= endIdx; idx++) {
  1343. showText += `|${textArr[idx]}`;
  1344. }
  1345. }
  1346. }
  1347. //*/
  1348. let rst = JpcCommonOutputHelper.createCommonOutput(tab_field, showText, controls);
  1349. rst[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx, true, false);
  1350. rst[JV.PROP_IS_AUTO_HEIGHT] = true;
  1351. return rst;
  1352. } else {
  1353. if (contentValInfo[3] > 0) showText = '';
  1354. let rst = JpcCommonOutputHelper.createCommonOutput(tab_field, showText, controls);
  1355. rst[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_field[JV.PROP_AREA], band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx, true, false);
  1356. rst[JV.PROP_IS_AUTO_HEIGHT] = false;
  1357. return rst;
  1358. }
  1359. };
  1360. JpcFlowTabResult.outputTabGrpLine = function (band, grp_line, page, grpValueIdx, rows, rowIdx, cols, colIdx, unitFactor, isRow, controls, multiColIdx, grpCntIdx, $CURRENT_RPT) {
  1361. let me = this, rst = [];
  1362. if (grp_line[JV.PROP_GROUP_SUM_KEYS]) {
  1363. let segIdx = JpcCommonHelper.getSegIdxByPageIdx(page, me.page_seg_map);
  1364. let curSegGrpSum = me.group_sum_values[segIdx];
  1365. for (let sumFieldNode of grp_line[JV.PROP_GROUP_SUM_KEYS]) {
  1366. // let value = curSegGrpSum[sumFieldNode[JV.PROP_SUM_KEY]][grpValueIdx[2]];
  1367. let value = curSegGrpSum[`grp_sum_key_` + sumFieldNode[JV.PROP_FIELD_ID]][grpValueIdx[2]];
  1368. let sumFldRst = JpcTextHelper.outputDirectValue(sumFieldNode, value, band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx);
  1369. rst.push(sumFldRst);
  1370. }
  1371. }
  1372. if (grp_line[JV.PROP_TEXTS]) {
  1373. for (let txt of grp_line[JV.PROP_TEXTS]) {
  1374. me.checkGrpTxtOutEvent(JV.RUN_TYPE_BEFORE_GROUP_TEXT_OUT, txt, grpCntIdx, $CURRENT_RPT);
  1375. rst.push(JpcTextHelper.outputText(txt, band, unitFactor, rows, rowIdx, cols, colIdx, me.multiCols, multiColIdx));
  1376. // me.combinePageCells(rst, verticalCombinePos, horizonCombinePos);
  1377. // 可能会有一个After,但意义不大,用不着
  1378. }
  1379. }
  1380. if (grp_line[JV.PROP_DISCRETE_FIELDS]) {
  1381. //暂时不支持
  1382. }
  1383. if (grp_line[JV.PROP_PARAMS]) {
  1384. //暂时不支持
  1385. }
  1386. // console.log(rst);
  1387. return rst;
  1388. };
  1389. JpcFlowTabResult.checkGrpTxtOutEvent = function ($RUN_TYPE, $TEXT, $TIMES, $CURRENT_RPT) {
  1390. if ($CURRENT_RPT.formulas) {
  1391. for (let execFmlIdx = 0; execFmlIdx < $CURRENT_RPT.formulas.length; execFmlIdx++) {
  1392. if ($CURRENT_RPT.formulas[execFmlIdx][JV.PROP_RUN_TYPE] === $RUN_TYPE) {
  1393. let expression = $CURRENT_RPT.formulas[execFmlIdx][JV.PROP_EXPRESSION];
  1394. if (expression) {
  1395. let $ME = $CURRENT_RPT.formulas[execFmlIdx];
  1396. try {
  1397. eval(expression);
  1398. } catch (ex) {
  1399. console.log(ex);
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. };
  1406. JpcFlowTabResult.commonTabRestOutput = function(dataObj, page, segIdx, bands, band, unitFactor, tab, multiColIdx){
  1407. let me = this, rst = [];
  1408. if (tab[JV.PROP_TEXT]) {
  1409. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXT], band, unitFactor, 1, 0, 1, 0, me.multiCols, multiColIdx));
  1410. }
  1411. if (tab[JV.PROP_TEXTS]) {
  1412. for (let j = 0; j < tab[JV.PROP_TEXTS].length; j++) {
  1413. rst.push(JpcTextHelper.outputText(tab[JV.PROP_TEXTS][j], band, unitFactor, 1, 0, 1, 0, me.multiCols, multiColIdx));
  1414. }
  1415. }
  1416. if (tab[JV.NODE_DISCRETE_INFO]) {
  1417. rst = rst.concat(JpcDiscreteHelper.outputDiscreteInfo(tab[JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[page - 1], segIdx, 1, 0, null));
  1418. }
  1419. return rst;
  1420. };
  1421. return JpcFlowTabResult;
  1422. };
  1423. function push_cell(pageCellObj, cell, cellIdx) {
  1424. let key = cell[JV.PROP_AREA][JV.PROP_LEFT] + '_' + cell[JV.PROP_AREA][JV.PROP_RIGHT];
  1425. if (!pageCellObj[key]) {
  1426. pageCellObj[key] = [];
  1427. }
  1428. let cellArr = pageCellObj[key];
  1429. cellArr.push({"cellIdx": cellIdx, "cell": cell});
  1430. }
  1431. function prepareAutoHeightCells(prepareObj, cellItem, cellIdx, cellsArr) {
  1432. if (prepareObj) {
  1433. if (prepareObj.cellsArr === undefined) {
  1434. prepareObj.cellsArr = cellsArr;
  1435. prepareObj.pageCellObj = {};
  1436. }
  1437. push_cell(prepareObj.pageCellObj, cellItem, cellIdx);
  1438. }
  1439. }
  1440. function setupControl(mergeCell, controls) {
  1441. let orgCtrl = null;
  1442. if ( typeof mergeCell[JV.PROP_CONTROL] === "string") {
  1443. orgCtrl = controls[mergeCell[JV.PROP_CONTROL]];
  1444. mergeCell[JV.PROP_CONTROL] = {
  1445. "Shrink": "T",
  1446. "ShrinkFirst": orgCtrl.ShrinkFirst,
  1447. "CloseOutput": orgCtrl.CloseOutput,
  1448. "ShowZero": orgCtrl.ShowZero,
  1449. "Horizon": orgCtrl.Horizon,
  1450. "Vertical": orgCtrl.Vertical,
  1451. "Wrap": (mergeCell[JV.PROP_IS_AUTO_HEIGHT])?'T':'F',
  1452. "VerticalForExcel": "center"
  1453. };
  1454. } else {
  1455. mergeCell[JV.PROP_CONTROL].Shrink = "T";
  1456. mergeCell[JV.PROP_CONTROL].Vertical = "top";
  1457. mergeCell[JV.PROP_CONTROL].Wrap = (mergeCell[JV.PROP_IS_AUTO_HEIGHT])?'T':'F',
  1458. mergeCell[JV.PROP_CONTROL].VerticalForExcel = "center";
  1459. orgCtrl = mergeCell[JV.PROP_CONTROL];
  1460. }
  1461. if (mergeCell[JV.PROP_IS_AUTO_HEIGHT]) {
  1462. mergeCell[JV.PROP_CONTROL]["VerticalForExcel"] = 'justify';
  1463. // mergeCell[JV.PROP_CONTROL]["Vertical"] = 'center';
  1464. } else {
  1465. mergeCell[JV.PROP_CONTROL]["VerticalForExcel"] = 'center';
  1466. // mergeCell[JV.PROP_CONTROL]["Vertical"] = 'top';
  1467. }
  1468. return orgCtrl;
  1469. }
  1470. function combineAutoHeightCells(prepareObj, page, controls) {
  1471. let rst = [];
  1472. if (prepareObj.cellsArr) {
  1473. //merge cells' value and area
  1474. //备注: 系统逻辑已经把Cell的顺序放好,无需再做排序。
  1475. for (let mergeKey in prepareObj.pageCellObj) {
  1476. let sameColCells = prepareObj.pageCellObj[mergeKey]; //左右位置相同的Cell先放在一起,统一处理
  1477. if (sameColCells.length > 1) {
  1478. let firstMergeCell = sameColCells[0].cell;
  1479. firstMergeCell[JV.PROP_STYLE] = firstMergeCell[JV.PROP_STYLE].slice(0, firstMergeCell[JV.PROP_STYLE].indexOf("_AutoHeightMerge")); //首先还原original style
  1480. let orgCtrl = setupControl(firstMergeCell, controls);
  1481. let validValueAmt = 0, fullValidValueAmt = 0;
  1482. for (let i = 1; i < sameColCells.length; i++) {
  1483. let mergeCell = sameColCells[i].cell;
  1484. if (mergeCell[JV.PROP_STYLE].indexOf("_AutoHeightMerge_Top") < 0) {
  1485. fullValidValueAmt++;
  1486. //merge into the firstMergeCell! position & value
  1487. firstMergeCell[JV.PROP_AREA][JV.PROP_BOTTOM] = mergeCell[JV.PROP_AREA][JV.PROP_BOTTOM];
  1488. if (mergeCell[JV.PROP_VALUE]) {
  1489. firstMergeCell[JV.PROP_VALUE] = firstMergeCell[JV.PROP_VALUE] + "|" + mergeCell[JV.PROP_VALUE];
  1490. validValueAmt++;
  1491. }
  1492. rst.push(sameColCells[i].cellIdx); //记下Cell的位置,在函数外消除
  1493. //如果到了最后一条数据,得判断firstMergeCell是否满格(即数据是满的,有可能有些格数据也有折行但不是自动行高判断指标)
  1494. //不满格的cell的Vertical强制设置为 'center'
  1495. if (i === sameColCells.length - 1 && validValueAmt !== fullValidValueAmt && (fullValidValueAmt / validValueAmt > 2.5) ) {
  1496. firstMergeCell[JV.PROP_CONTROL].VerticalForExcel = 'center';
  1497. }
  1498. } else {
  1499. //碰到新开始的自动行高行,判断原先的firstMergeCell是否满格(即数据是满的,有可能有些格数据也有折行但不是自动行高判断指标)
  1500. //不满格的cell的Vertical强制设置为 'center'
  1501. if (validValueAmt !== fullValidValueAmt && (fullValidValueAmt / validValueAmt > 2.5)) {
  1502. firstMergeCell[JV.PROP_CONTROL].VerticalForExcel = 'center';
  1503. }
  1504. firstMergeCell = sameColCells[i].cell;
  1505. firstMergeCell[JV.PROP_STYLE] = firstMergeCell[JV.PROP_STYLE].slice(0, firstMergeCell[JV.PROP_STYLE].indexOf("_AutoHeightMerge"));
  1506. orgCtrl = setupControl(firstMergeCell, controls);
  1507. validValueAmt = 0;
  1508. fullValidValueAmt = 0;
  1509. }
  1510. }
  1511. }
  1512. }
  1513. rst.sort(function (i1, i2) {
  1514. return (i1 > i2)?1:-1;
  1515. });
  1516. }
  1517. return rst;
  1518. }
  1519. module.exports = new JpcFlowTabSrv();