rpt_tpl_vis_common.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /**
  2. * Created by Tony on 2018/9/4.
  3. */
  4. const BG_COLORS = ['#BFEFFF', '#C1FFC1', '#F5F5DC', '#B9D3EE', '#C1FFC1', '#EEE0E5', '#B4EEB4', '#CAE1FF', '#EED2EE', '#AEEEEE', '#76EEC6', '#CD8C95'],
  5. unitFactor = 1.0 * 96 / 2.54;
  6. let visualCommonOprObj = {
  7. getActPos: function (textNode, caclStr, typeStr, baseMea) {
  8. let rst = 0;
  9. if (caclStr === JV.CAL_TYPE[0]) {
  10. //percentage
  11. rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100);
  12. } else {
  13. //abstract
  14. rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96);
  15. }
  16. return rst;
  17. },
  18. getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
  19. let me = this;
  20. if (typeof caclObj === 'string') {
  21. return me.getActPos(textNode, caclObj, typeStr, baseMea);
  22. } else {
  23. return me.getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
  24. }
  25. },
  26. pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
  27. let me = this, pos = me.getActPosEx(textNode, caclObj, typeStr, baseMea);
  28. if (posArr.indexOf(pos) < 0) posArr.push(pos);
  29. },
  30. getBandEx: function (bandName, rptTpl) {
  31. let me = this, rst;
  32. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  33. rst = me.getBand(bandName, band);
  34. if (rst !== null) {
  35. break;
  36. }
  37. }
  38. return rst;
  39. },
  40. getBand: function (bandName, parentBand) {
  41. let me = this, rst = null;
  42. if (parentBand[JV.PROP_NAME] === bandName) {
  43. rst = parentBand;
  44. } else {
  45. if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) {
  46. for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  47. rst = me.getBand(bandName, subBand);
  48. if (rst !== null) {
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. return rst;
  55. },
  56. checkInSpan: function (spans, row, col) {
  57. let rst = false;
  58. for (let span of spans) {
  59. if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) {
  60. rst = true;
  61. break;
  62. }
  63. }
  64. return rst;
  65. },
  66. setupHeightWidth: function (dest, text, colWidthArr, rowHeightArr) {
  67. let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
  68. dest[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
  69. if (text.col > 0) {
  70. dest[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
  71. } else {
  72. dest[JV.PROP_AREA][JV.PROP_LEFT] = 0;
  73. }
  74. dest[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
  75. if (text.row > 0) {
  76. dest[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
  77. } else {
  78. dest[JV.PROP_AREA][JV.PROP_TOP] = 0;
  79. }
  80. },
  81. createTxtNode: function (text, parentNode, colWidthArr, rowHeightArr) {
  82. let me = this, rst = dataInfoMapTreeOprObj.getDummyTextNode(parentNode);
  83. me.setupHeightWidth(rst, text, colWidthArr, rowHeightArr);
  84. if (stringUtil.isEmptyString(text[`text`])) {
  85. rst[JV.PROP_NAME] = '';
  86. } else {
  87. rst[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', '');
  88. }
  89. rst[JV.PROP_LABEL] = rst[JV.PROP_NAME];
  90. return rst;
  91. },
  92. collectSheetTxt: function (sheet, texts, reserveRows, colWidthArr, rowHeightArr) {
  93. let me = this, spans= sheet.getSpans();
  94. let private_build_pre_text = function (row, col, rowCount, colCount) {
  95. let cell = sheet.getCell(row, col);
  96. let textValue = sheet.getValue(row, col);
  97. if (textValue && cell.cellType().typeName === '7') {
  98. textValue = `{` + textValue + `}`;
  99. }
  100. texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": textValue});
  101. };
  102. for (let span of spans) {
  103. private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
  104. }
  105. for (let iRow = 0; iRow < sheet.getRowCount() - reserveRows; iRow++) {
  106. rowHeightArr.push(sheet.getRowHeight(iRow));
  107. if (iRow > 0) {
  108. rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1];
  109. }
  110. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  111. if (iRow === 0) {
  112. colWidthArr.push(sheet.getColumnWidth(jCol));
  113. if (jCol > 0) {
  114. colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
  115. }
  116. }
  117. if (!me.checkInSpan(spans, iRow, jCol)) {
  118. private_build_pre_text(iRow, jCol, 1, 1);
  119. }
  120. }
  121. }
  122. texts.sort(function(t1, t2){
  123. if (t1.col === t2.col) {
  124. return t1.row - t2.row;
  125. } else {
  126. return t1.col - t2.col;
  127. }
  128. });
  129. },
  130. addSpan: function (itemNode, sheet, bandW, bandH, xPos, yPos, sheetAreaType) {
  131. let me = this;
  132. let idx1 = xPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW));
  133. let idx2 = xPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW));
  134. let idy1 = yPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH));
  135. let idy2 = yPos.indexOf(me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH));
  136. if (idx2 - idx1 > 1 || idy2 - idy1 > 1) {
  137. sheet.addSpan(idy1, idx1, idy2 - idy1, idx2 - idx1, sheetAreaType);
  138. }
  139. let cell = sheet.getCell(idy1, idx1, sheetAreaType);
  140. if (sheetAreaType === GC.Spread.Sheets.SheetArea.viewport) {
  141. if (itemNode.FieldID) {
  142. me.changeCellType(cell, 'field');
  143. } else {
  144. me.changeCellType(cell, 'text');
  145. }
  146. }
  147. me.setupCell(cell, itemNode);
  148. },
  149. changeBandHeight: function (bandName, newHeight) {
  150. let nodes = bandTreeOprObj.treeObj.getNodes()[0][JV.BAND_PROP_SUB_BANDS];
  151. let private_set_band_height = function(bNode) {
  152. let rst = false;
  153. if (bNode[JV.PROP_NAME] === bandName) {
  154. bNode[JV.BAND_PROP_HEIGHT] = newHeight;
  155. rst = true;
  156. } else if (bNode[JV.BAND_PROP_SUB_BANDS] && bNode[JV.BAND_PROP_SUB_BANDS].length > 0){
  157. for (let subNode of bNode[JV.BAND_PROP_SUB_BANDS]) {
  158. rst = private_set_band_height(subNode);
  159. if (rst) break;
  160. }
  161. }
  162. return rst;
  163. };
  164. for (let bandNode of nodes) {
  165. if (private_set_band_height(bandNode)) break;
  166. }
  167. },
  168. changeCellType: function (cell, newType, newColor) {
  169. let me = this;
  170. switch (newType) {
  171. case `field`:
  172. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  173. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  174. let selectableFields = me.getSelectedFields(rptTpl);
  175. cellType.items(selectableFields);
  176. cell.cellType(cellType);
  177. if (newColor) {
  178. cell.backColor(newColor);
  179. } else {
  180. cell.backColor("LightCyan");
  181. }
  182. break;
  183. case `text`:
  184. default:
  185. cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
  186. cell.value(``);
  187. if (newColor) {
  188. cell.backColor(newColor);
  189. } else {
  190. cell.backColor(undefined);
  191. }
  192. break;
  193. }
  194. },
  195. setupCell: function (cell, itemNode) {
  196. let me = this;
  197. me.private_setCellFont(cell, itemNode);
  198. me.private_setCellControl(cell, itemNode);
  199. me.private_setCellStyle(cell, itemNode);
  200. let value = itemNode[JV.PROP_NAME];
  201. if (itemNode[JV.PROP_NAME].indexOf(`|`) >= 0) {
  202. value = itemNode[JV.PROP_NAME].split('|').join('\n');
  203. }
  204. cell.wordWrap(true);
  205. cell.value(value);
  206. },
  207. private_setCellControl: function (cell, textNode) {
  208. let ctrl = null;
  209. if (typeof textNode[JV.PROP_CONTROL] === 'string') {
  210. let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(textNode[JV.PROP_CONTROL]);
  211. ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
  212. } else {
  213. ctrl = textNode[JV.PROP_CONTROL];
  214. }
  215. if (ctrl) {
  216. switch (ctrl.Horizon) {
  217. case `center`:
  218. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  219. break;
  220. case `right`:
  221. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  222. break;
  223. default:
  224. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  225. break;
  226. }
  227. switch (ctrl.Vertical) {
  228. case `center`:
  229. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  230. break;
  231. case `bottom`:
  232. cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  233. break;
  234. default:
  235. cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  236. break;
  237. }
  238. }
  239. },
  240. private_setCellStyle: function (cell, textNode) {
  241. //默认是normal,暂时不管
  242. },
  243. private_setCellFont: function (cell, textNode) {
  244. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  245. if (font.ID === textNode[JV.PROP_FONT]) {
  246. cell.font(Math.round(font[JV.FONT_PROPS[JV.FONT_PROP_IDX_HEIGHT]] * 3 / 4) + 'pt ' + font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]]);
  247. break;
  248. }
  249. }
  250. },
  251. getSelectedFields: function (rptTpl) {
  252. let rst = [];
  253. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  254. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  255. rst.push(field[JV.PROP_NAME]);
  256. }
  257. }
  258. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  259. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  260. rst.push(field[JV.PROP_NAME]);
  261. }
  262. }
  263. return rst;
  264. },
  265. setupCellDft: function (cell) {
  266. cell.font(`9pt 宋体`);
  267. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  268. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  269. cell.wordWrap(true);
  270. cell.cellType(new GC.Spread.Sheets.CellTypes.Text());
  271. cell.value(``);
  272. },
  273. addBandPos: function (rptTpl, pageW, pageH, xPos, yPos, bandMappingObj) {
  274. let left = 0, right = pageW, top = 0, bottom = pageH;
  275. let orgArea = [left, top, right, bottom];
  276. let colorIdx = 0;
  277. bandMappingObj.items = [];
  278. let private_setup_pos = function (band) {
  279. left = orgArea[JV.IDX_LEFT];
  280. top = orgArea[JV.IDX_TOP];
  281. right = orgArea[JV.IDX_RIGHT];
  282. bottom = orgArea[JV.IDX_BOTTOM];
  283. if (xPos.indexOf(left) < 0) xPos.push(left);
  284. if (xPos.indexOf(right) < 0) xPos.push(right);
  285. if (yPos.indexOf(top) < 0) yPos.push(top);
  286. if (yPos.indexOf(bottom) < 0) yPos.push(bottom);
  287. switch (band[JV.BAND_PROP_ALIGNMENT]) {
  288. case JV.LAYOUT_TOP:
  289. case JV.LAYOUT[JV.LAYOUT_TOP]:
  290. bottom = Math.round(top + unitFactor * band[JV.BAND_PROP_HEIGHT]);
  291. orgArea[JV.IDX_TOP] = bottom;
  292. break;
  293. case JV.LAYOUT_BOTTOM:
  294. case JV.LAYOUT[JV.LAYOUT_BOTTOM]:
  295. top = Math.round(bottom - unitFactor * band[JV.BAND_PROP_HEIGHT]);
  296. orgArea[JV.IDX_BOTTOM] = top;
  297. break;
  298. case JV.LAYOUT_LEFT:
  299. case JV.LAYOUT[JV.LAYOUT_LEFT]:
  300. right = Math.round(left + unitFactor * band[JV.BAND_PROP_WIDTH]);
  301. orgArea[JV.IDX_LEFT] = right;
  302. break;
  303. case JV.LAYOUT_RIGHT:
  304. case JV.LAYOUT[JV.LAYOUT_RIGHT]:
  305. left = Math.round(right - unitFactor * band[JV.BAND_PROP_WIDTH]);
  306. orgArea[JV.IDX_RIGHT] = left;
  307. break;
  308. }
  309. let item = {};
  310. bandMappingObj[band[JV.PROP_NAME]] = item;
  311. item[JV.PROP_AREA] = {};
  312. item[JV.PROP_AREA][JV.PROP_LEFT] = left;
  313. item[JV.PROP_AREA][JV.PROP_RIGHT] = right;
  314. item[JV.PROP_AREA][JV.PROP_TOP] = top;
  315. item[JV.PROP_AREA][JV.PROP_BOTTOM] = bottom;
  316. item[JV.PROP_COLOR] = BG_COLORS[colorIdx];
  317. // item[JV.PROP_COLOR] = 'Blue';
  318. bandMappingObj.items.push(item);
  319. colorIdx++;
  320. if (xPos.indexOf(left) < 0) xPos.push(left);
  321. if (xPos.indexOf(right) < 0) xPos.push(right);
  322. if (yPos.indexOf(top) < 0) yPos.push(top);
  323. if (yPos.indexOf(bottom) < 0) yPos.push(bottom);
  324. if (colorIdx >= BG_COLORS.length) colorIdx = 0;
  325. if (band[JV.BAND_PROP_SUB_BANDS] && band[JV.BAND_PROP_SUB_BANDS].length > 0) {
  326. item[JV.PROP_COLOR] = 'White';
  327. // item[JV.PROP_COLOR] = null;
  328. for (let subBand of band[JV.BAND_PROP_SUB_BANDS]) {
  329. private_setup_pos(subBand);
  330. }
  331. }
  332. };
  333. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  334. private_setup_pos(band);
  335. }
  336. },
  337. pushAbsPos: function (bandMap, itemNode, xPos, yPos) {
  338. let me = this;
  339. if (bandMap) {
  340. let bandW = bandMap[JV.PROP_AREA][JV.PROP_RIGHT] - bandMap[JV.PROP_AREA][JV.PROP_LEFT],
  341. bandH = bandMap[JV.PROP_AREA][JV.PROP_BOTTOM] - bandMap[JV.PROP_AREA][JV.PROP_TOP];
  342. let pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  343. if (xPos.indexOf(pos) < 0) xPos.push(pos);
  344. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  345. if (xPos.indexOf(pos) < 0) xPos.push(pos);
  346. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  347. if (yPos.indexOf(pos) < 0) yPos.push(pos);
  348. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  349. if (yPos.indexOf(pos) < 0) yPos.push(pos);
  350. }
  351. },
  352. addTplTxtFldPos: function (rptTpl, tree, xPos, yPos, bandMappingObj) {
  353. let me = this, nodes = tree.getNodes();
  354. if (rptTpl[JV.NODE_FLOW_INFO]) {
  355. //流水式
  356. let contentBandMap, contentRowH, orgContentTop, lastContentBottom;
  357. for (let node of nodes) {
  358. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  359. //1. 列
  360. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  361. me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  362. bandMap[JV.PROP_COLOR] = 'LightGray';
  363. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  364. //2. 数据
  365. contentBandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  366. contentRowH = Math.round(unitFactor * rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT]);
  367. orgContentTop = contentBandMap[JV.PROP_AREA][JV.PROP_TOP];
  368. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  369. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  370. lastContentBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  371. me.addNormalTxtFldPos(contentBandMap, node, xPos, yPos);
  372. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  373. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  374. contentBandMap[JV.PROP_COLOR] = 'LightCyan';
  375. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  376. //3. 页统计
  377. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  378. for (let itemNode of node.items) {
  379. me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  380. }
  381. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  382. //4. 章统计
  383. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  384. for (let itemNode of node.items) {
  385. me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  386. }
  387. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  388. //5. 分组统计
  389. if (contentBandMap && contentRowH && node.items && node.items.length > 0) {
  390. for (let itemNode of node.items) {
  391. if (itemNode[JV.PROP_NAME] === `分组行`) {
  392. for (let subItemNode of itemNode.items) {
  393. //行
  394. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  395. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  396. lastContentBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  397. for (let txtFldNode of subItemNode.items) {
  398. //分组字段集 与 文本集
  399. me.addNormalTxtFldPos(contentBandMap, txtFldNode, xPos, yPos);
  400. }
  401. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  402. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  403. }
  404. }
  405. }
  406. }
  407. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  408. //6. 离散信息
  409. me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  410. }
  411. }
  412. if (contentBandMap) {
  413. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = orgContentTop;
  414. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = lastContentBottom;
  415. }
  416. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  417. //账单式
  418. for (let node of nodes) {
  419. if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  420. //1. 数据
  421. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  422. me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  423. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  424. //2. 离散信息
  425. me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  426. }
  427. }
  428. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  429. //交叉式
  430. //目前暂缓
  431. }
  432. },
  433. setupTplTxtFld: function (rptTpl, tree, sheet, xPos, yPos, bandMappingObj) {
  434. let me = this, nodes = tree.getNodes();
  435. if (rptTpl[JV.NODE_FLOW_INFO]) {
  436. //流水式
  437. let contentBandMap, contentRowH;
  438. for (let node of nodes) {
  439. if (node[JV.PROP_NAME].indexOf('_列') >= 0) {
  440. //1. 列
  441. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  442. // me.addNormalTxtFldPos(bandMap, node, xPos, yPos);
  443. me.addSpanWholeArea(bandMap, node, sheet, xPos, yPos);
  444. } else if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  445. //2. 数据
  446. contentBandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  447. contentRowH = Math.round(unitFactor * rptTpl[JV.NODE_FLOW_INFO][JV.NODE_FLOW_CONTENT][JV.PROP_CMN_HEIGHT]);
  448. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  449. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  450. // me.addNormalTxtFldPos(contentBandMap, node, xPos, yPos);
  451. me.addSpanWholeArea(contentBandMap, node, sheet, xPos, yPos);
  452. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  453. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  454. } else if (node[JV.PROP_NAME].indexOf('_页统计') >= 0) {
  455. //3. 页统计
  456. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  457. for (let itemNode of node.items) {
  458. // me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  459. me.addSpanWholeArea(bandMap, itemNode, sheet, xPos, yPos);
  460. }
  461. } else if (node[JV.PROP_NAME].indexOf('_段统计') >= 0) {
  462. //4. 章统计
  463. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  464. for (let itemNode of node.items) {
  465. // me.addNormalTxtFldPos(bandMap, itemNode, xPos, yPos);
  466. me.addSpanWholeArea(bandMap, itemNode, sheet, xPos, yPos);
  467. }
  468. } else if (node[JV.PROP_NAME].indexOf('_分组') >= 0) {
  469. //5. 分组统计
  470. if (contentBandMap && contentRowH && node.items && node.items.length > 0) {
  471. for (let itemNode of node.items) {
  472. if (itemNode[JV.PROP_NAME] === `分组行`) {
  473. for (let subItemNode of itemNode.items) {
  474. //行
  475. let bkBottom = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  476. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = contentBandMap[JV.PROP_AREA][JV.PROP_TOP] + contentRowH;
  477. for (let txtFldNode of subItemNode.items) {
  478. //分组字段集 与 文本集
  479. // me.addNormalTxtFldPos(contentBandMap, txtFldNode, xPos, yPos);
  480. me.addSpanWholeArea(contentBandMap, txtFldNode, sheet, xPos, yPos);
  481. }
  482. contentBandMap[JV.PROP_AREA][JV.PROP_TOP] = contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM];
  483. contentBandMap[JV.PROP_AREA][JV.PROP_BOTTOM] = bkBottom;
  484. }
  485. }
  486. }
  487. }
  488. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  489. //6. 离散信息
  490. // me.addDiscreteTxtFldPos(node, xPos, yPos, bandMappingObj);
  491. me.addDiscreteSpan(node, xPos, yPos, bandMappingObj, sheet);
  492. }
  493. }
  494. } else if (rptTpl[JV.NODE_BILL_INFO]) {
  495. //账单式
  496. for (let node of nodes) {
  497. if (node[JV.PROP_NAME].indexOf('数据') >= 0) {
  498. //1. 数据
  499. let bandMap = bandMappingObj[node[JV.PROP_BAND_NAME]];
  500. me.addSpanWholeArea(bandMap, node, sheet, xPos, yPos);
  501. } else if (node[JV.PROP_NAME].indexOf('离散') >= 0) {
  502. //2. 离散信息
  503. me.addDiscreteSpan(node, xPos, yPos, bandMappingObj, sheet);
  504. }
  505. }
  506. } else if (rptTpl[JV.NODE_CROSS_INFO]) {
  507. //交叉式
  508. //目前暂缓
  509. }
  510. },
  511. brushSheet: function (bandMappingObj, sheet, xPos, yPos) {
  512. for (let bandMap of bandMappingObj.items) {
  513. let idxTop = yPos.indexOf(bandMap[JV.PROP_AREA][JV.PROP_TOP]);
  514. let idxBottom = yPos.indexOf(bandMap[JV.PROP_AREA][JV.PROP_BOTTOM]);
  515. if (idxTop >= 0 && idxBottom > idxTop) {
  516. sheet.getRange(idxTop, -1, idxBottom - idxTop, -1).backColor(bandMap[JV.PROP_COLOR]);
  517. let range = sheet.getRange(idxTop, -1, idxBottom - idxTop, -1);
  518. if (bandMap[JV.PROP_COLOR] === 'White') {
  519. range.watermark("[Not Editable]");
  520. } else {
  521. range.watermark(undefined);
  522. }
  523. }
  524. }
  525. },
  526. addDiscreteTxtFldPos: function (discreteItemNode, xPos, yPos, bandMappingObj) {
  527. let me = this;
  528. for (let itemNode of discreteItemNode.items) {
  529. //子项
  530. let bandMap = bandMappingObj[itemNode[JV.PROP_BAND_NAME]];
  531. if (bandMap) {
  532. for (let subItemNode of itemNode.items) {
  533. for (let txtFldDtlNode of subItemNode.items) {
  534. me.pushAbsPos(bandMap, txtFldDtlNode, xPos, yPos);
  535. }
  536. }
  537. }
  538. }
  539. },
  540. addNormalTxtFldPos: function (bandMap, parentNode, xPos, yPos) {
  541. let me = this;
  542. if (bandMap && parentNode.items && parentNode.items.length > 0) {
  543. for (let itemNode of parentNode.items) {
  544. me.pushAbsPos(bandMap, itemNode, xPos, yPos);
  545. }
  546. }
  547. },
  548. addSpanWholeArea: function (bandMap, parentNode, sheet, xPos, yPos) {
  549. let me = this;
  550. if (bandMap && parentNode.items && parentNode.items.length > 0) {
  551. let bandW = bandMap[JV.PROP_AREA][JV.PROP_RIGHT] - bandMap[JV.PROP_AREA][JV.PROP_LEFT],
  552. bandH = bandMap[JV.PROP_AREA][JV.PROP_BOTTOM] - bandMap[JV.PROP_AREA][JV.PROP_TOP];
  553. for (let itemNode of parentNode.items) {
  554. // me.pushAbsPos(bandMap, itemNode, xPos, yPos);
  555. let pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  556. let idxLeft = xPos.indexOf(pos);
  557. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW) + bandMap[JV.PROP_AREA][JV.PROP_LEFT];
  558. let idxRight = xPos.indexOf(pos);
  559. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  560. let idxTop = yPos.indexOf(pos);
  561. pos = me.getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH) + bandMap[JV.PROP_AREA][JV.PROP_TOP];
  562. let idxBottom = yPos.indexOf(pos);
  563. if (idxRight - idxLeft > 1 || idxBottom - idxTop > 1) {
  564. sheet.addSpan(idxTop, idxLeft, idxBottom - idxTop, idxRight - idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  565. }
  566. let cell = sheet.getCell(idxTop, idxLeft, GC.Spread.Sheets.SheetArea.viewport);
  567. if (itemNode.FieldID) {
  568. me.changeCellType(cell, 'field', bandMap[JV.PROP_COLOR]);
  569. } else {
  570. me.changeCellType(cell, 'text', bandMap[JV.PROP_COLOR]);
  571. }
  572. me.setupCell(cell, itemNode);
  573. }
  574. }
  575. },
  576. addDiscreteSpan: function (discreteItemNode, xPos, yPos, bandMappingObj, sheet) {
  577. let me = this;
  578. for (let itemNode of discreteItemNode.items) {
  579. //子项
  580. let bandMap = bandMappingObj[itemNode[JV.PROP_BAND_NAME]];
  581. if (bandMap) {
  582. for (let subItemNode of itemNode.items) {
  583. me.addSpanWholeArea(bandMap, subItemNode, sheet, xPos, yPos);
  584. }
  585. }
  586. }
  587. },
  588. setupBorder: function (cell, border) {
  589. cell.borderLeft(border);
  590. cell.borderRight(border);
  591. cell.borderTop(border);
  592. cell.borderBottom(border);
  593. }
  594. };