rpt_tpl_field_location.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /**
  2. * Created by Tony on 2018/8/21.
  3. */
  4. let fieldLocationOprObj = {
  5. columnWorkBook: null,
  6. columnParentNode: null,
  7. contentParentNode: null,
  8. columnFieldCtrls: null,
  9. iniSpreadJs: function (columnParentNode, contentParentNode) {
  10. let me = this;
  11. if (me.columnWorkBook === null) {
  12. me.columnWorkBook = new GC.Spread.Sheets.Workbook($('#rptTplColumnWorkbook')[0], {sheetCount: 1});
  13. // me.columnWorkBook.setHei
  14. me.columnWorkBook.options.tabStripVisible = false;
  15. // me.columnWorkBook.options.scrollbarMaxAlign = true;
  16. me.columnWorkBook.options.allowCopyPasteExcelStyle = false;
  17. // me.columnWorkBook.options.allowExtendPasteRange = isExtendPaste? true : false;
  18. me.columnWorkBook.options.allowUserDragDrop = false;
  19. me.columnWorkBook.options.allowContextMenu = false;
  20. let sheet = me.columnWorkBook.getActiveSheet();
  21. sheet.options.allowCellOverflow = false;
  22. sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
  23. // sheet.showRowOutline(false);
  24. // sheet.setRowCount(10, GC.Spread.Sheets.SheetArea.viewport);
  25. sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onCellEnter);
  26. }
  27. me.columnParentNode = columnParentNode;
  28. me.contentParentNode = contentParentNode;
  29. },
  30. restore: function () {
  31. let me = this;
  32. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  33. me.setupColumn(rptTpl, me.columnParentNode, me.contentParentNode);
  34. },
  35. setupColumn: function (rptTpl, columnParentNode, contentParentNode) {
  36. let me = this, yPos = [], xPos = [];
  37. me.columnFieldCtrls = [];
  38. let bandName = columnParentNode[JV.PROP_BAND_NAME];
  39. let private_getBand = function(parentBand) {
  40. let rst = null;
  41. if (parentBand[JV.PROP_NAME] === bandName) {
  42. rst = parentBand;
  43. } else {
  44. if (parentBand[JV.BAND_PROP_SUB_BANDS] && parentBand[JV.BAND_PROP_SUB_BANDS].length > 0) {
  45. for (let subBand of parentBand[JV.BAND_PROP_SUB_BANDS]) {
  46. rst = private_getBand(subBand);
  47. if (rst !== null) {
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. return rst;
  54. };
  55. let selectedBand;
  56. for (let band of rptTpl[JV.NODE_BAND_COLLECTION]) {
  57. selectedBand = private_getBand(band);
  58. if (selectedBand !== null) {
  59. break;
  60. }
  61. }
  62. if (selectedBand !== null) {
  63. let sheet = me.columnWorkBook.getActiveSheet();
  64. sheet.suspendPaint();
  65. sheet.clearSelection();
  66. let spans =sheet.getSpans();
  67. for(let i = 0; i < spans.length; i++)
  68. {
  69. sheet.removeSpan(spans[i].row, spans[i].col, GC.Spread.Sheets.SheetArea.viewport);
  70. }
  71. // sheet.setRowCount(1);
  72. // sheet.setColumnCount(1);
  73. let bandH = Math.round(parseFloat(selectedBand[JV.BAND_PROP_HEIGHT]) / 2.54 * 96);
  74. let bandW = 700;
  75. let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  76. if (pIdx >= 0) {
  77. bandW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  78. if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
  79. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
  80. bandW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  81. }
  82. }
  83. if (columnParentNode.items && columnParentNode.items.length > 0) {
  84. for (let itemNode of columnParentNode.items) {
  85. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos);
  86. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos);
  87. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos);
  88. me.private_pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos);
  89. }
  90. sheet.setRowCount(yPos.length, GC.Spread.Sheets.SheetArea.viewport);
  91. sheet.setColumnCount(xPos.length - 1, GC.Spread.Sheets.SheetArea.viewport);
  92. for (let idx = 1; idx < xPos.length; idx++) {
  93. me.columnFieldCtrls.push(me.private_create_dft_ctrl());
  94. }
  95. // sheet.clear();
  96. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  97. let selectableFields = me.private_getSelectedFields(rptTpl);
  98. cellType.items(selectableFields);
  99. //设置 最后一行为 行数据选择combobox
  100. let iSelectedRow = sheet.getRowCount() - 1;
  101. sheet.setRowHeight(iSelectedRow, 20);
  102. sheet.getRange(iSelectedRow, -1, 1, -1).backColor("LightCyan");
  103. sheet.getRange(iSelectedRow, -1, 1, -1).locked(true);
  104. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  105. sheet.getCell(iSelectedRow, jCol).cellType(cellType);
  106. }
  107. xPos.sort(function(x1, x2){
  108. return (x1 - x2);
  109. });
  110. yPos.sort(function(y1, y2){
  111. return (y1 - y2);
  112. });
  113. for (let contentItemNode of contentParentNode.items) {
  114. let idxCol = xPos.indexOf(me.private_getActPosEx(contentItemNode, contentItemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
  115. sheet.getCell(iSelectedRow, idxCol).value(contentItemNode[JV.PROP_NAME]);
  116. me.private_merge_ctrl(rptTpl, idxCol, contentItemNode, null);
  117. }
  118. for (let idx = 1; idx < xPos.length; idx++) {
  119. sheet.setColumnWidth(idx - 1, xPos[idx] - xPos[idx - 1]);
  120. }
  121. for (let idx = 1; idx < yPos.length; idx++) {
  122. sheet.setRowHeight(idx - 1, yPos[idx] - yPos[idx - 1]);
  123. sheet.getRange(idx - 1, -1, 1, -1).backColor(undefined);
  124. }
  125. for (let itemNode of columnParentNode.items) {
  126. let idx1 = xPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
  127. let idx2 = xPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos));
  128. let idy1 = yPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos));
  129. let idy2 = yPos.indexOf(me.private_getActPosEx(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos));
  130. if (idx2 - idx1 > 1 || idy2 - idy1 > 1) {
  131. sheet.addSpan(idy1, idx1, idy2 - idy1, idx2 - idx1, GC.Spread.Sheets.SheetArea.viewport);
  132. }
  133. me.private_setupCell(sheet.getCell(idy1, idx1), rptTpl, itemNode);
  134. }
  135. } else {
  136. sheet.setRowCount(2);
  137. sheet.setColumnCount(1);
  138. me.columnFieldCtrls.push(me.private_create_dft_ctrl());
  139. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  140. let selectableFields = me.private_getSelectedFields(rptTpl);
  141. cellType.items(selectableFields);
  142. //设置 最后一行为 行数据选择combobox
  143. let iSelectedRow = sheet.getRowCount() - 1;
  144. sheet.setRowHeight(iSelectedRow, 20);
  145. sheet.getRange(iSelectedRow, -1, 1, -1).backColor("LightCyan");
  146. sheet.getRange(iSelectedRow, -1, 1, -1).locked(true);
  147. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  148. sheet.getCell(iSelectedRow, jCol).cellType(cellType);
  149. }
  150. sheet.setColumnWidth(0, bandW);
  151. sheet.setRowHeight(0, bandH);
  152. }
  153. sheet.resumePaint();
  154. }
  155. },
  156. onCellEnter: function (sender, args) {
  157. let me = fieldLocationOprObj,
  158. sheet = me.columnWorkBook.getActiveSheet();
  159. if (args.row === sheet.getRowCount() - 1) {
  160. me.private_setup_control_options(true);
  161. me.private_update_ctrl_cfg(args.col);
  162. } else {
  163. me.private_setup_control_options(false);
  164. }
  165. },
  166. addRow: function () {
  167. let me = fieldLocationOprObj,
  168. sheet = me.columnWorkBook.getActiveSheet();
  169. sheet.addRows(sheet.getRowCount() - 1, 1);
  170. let rc = sheet.getRowCount();
  171. // let node = me.columnParentNode.items[0]
  172. for (let cc = 0; cc < sheet.getColumnCount(); cc++) {
  173. me.private_setupCellDft(sheet.getCell(rc - 2, cc));
  174. }
  175. // columnParentNode.items
  176. },
  177. deleteRow: function () {
  178. let me = fieldLocationOprObj,
  179. sheet = me.columnWorkBook.getActiveSheet(),
  180. selectedRanges = sheet.getSelections()
  181. ;
  182. let rc = sheet.getRowCount();
  183. if (rc > 2) {
  184. if (selectedRanges.length > 0) {
  185. sheet.deleteRows(selectedRanges[0].row, 1);
  186. }
  187. } else {
  188. alert('不能删除行!');
  189. }
  190. },
  191. addCol: function (rptTpl) {
  192. let me = fieldLocationOprObj,
  193. sheet = me.columnWorkBook.getActiveSheet();
  194. sheet.suspendPaint();
  195. sheet.addColumns(sheet.getColumnCount(), 1);
  196. let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
  197. let selectableFields = me.private_getSelectedFields(rptTpl);
  198. cellType.items(selectableFields);
  199. //设置 最后一行为 行数据选择combobox
  200. // sheet.getRange(sheet.getRowCount() - 1, -1, 1, -1).locked(true);
  201. let colIdx = sheet.getColumnCount() - 1;
  202. sheet.getCell(sheet.getRowCount() - 1, colIdx).cellType(cellType);
  203. for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
  204. me.private_setupCellDft(sheet.getCell(iRow, colIdx));
  205. }
  206. //
  207. me.columnFieldCtrls.push(me.private_create_dft_ctrl());
  208. sheet.resumePaint();
  209. },
  210. deleteCol: function () {
  211. let me = fieldLocationOprObj,
  212. sheet = me.columnWorkBook.getActiveSheet(),
  213. selectedRanges = sheet.getSelections()
  214. ;
  215. let cc = sheet.getColumnCount();
  216. if (cc > 1) {
  217. if (selectedRanges.length > 0) {
  218. sheet.deleteColumns(selectedRanges[0].col, 1);
  219. }
  220. } else {
  221. alert('不能删除列!');
  222. }
  223. },
  224. mergeCells: function () {
  225. let me = fieldLocationOprObj,
  226. sheet = me.columnWorkBook.getActiveSheet();
  227. let selectedRanges = sheet.getSelections();
  228. if (selectedRanges.length > 0) {
  229. if (selectedRanges[0].row + selectedRanges[0].rowCount < sheet.getRowCount()) {
  230. sheet.suspendPaint();
  231. sheet.addSpan(selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
  232. sheet.resumePaint();
  233. } else {
  234. alert("指标列不能被合并!")
  235. }
  236. }
  237. },
  238. dismergeCells: function () {
  239. let me = fieldLocationOprObj,
  240. sheet = me.columnWorkBook.getActiveSheet();
  241. let selectedRanges = sheet.getSelections();
  242. let spans =sheet.getSpans();
  243. if (selectedRanges.length > 0 && spans.length > 0) {
  244. let selectedSpans = [];
  245. for(let i = 0; i < spans.length; i++)
  246. {
  247. for (let j = 0; j < selectedRanges.length; j++) {
  248. if (spans[i].row >= selectedRanges[j].row && spans[i].col >= selectedRanges[j].col &&
  249. spans[i].row <= selectedRanges[j].row + selectedRanges[j].rowCount && spans[i].col <= selectedRanges[j].col + selectedRanges[j].colCount) {
  250. selectedSpans.push(spans[i]);
  251. }
  252. }
  253. }
  254. for (let span of selectedSpans) {
  255. sheet.removeSpan(span.row, span.col, GC.Spread.Sheets.SheetArea.viewport);
  256. }
  257. }
  258. },
  259. fitTheWidth: function (factor) {
  260. let me = this, rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  261. let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
  262. let bandW = 700;
  263. if (pIdx >= 0) {
  264. bandW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  265. if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
  266. rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
  267. bandW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
  268. }
  269. }
  270. bandW *= factor;
  271. let currentWidth = 0;
  272. let sheet = me.columnWorkBook.getActiveSheet();
  273. for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
  274. currentWidth += sheet.getColumnWidth(idx);
  275. }
  276. let actFactor = bandW / currentWidth;
  277. for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
  278. sheet.setColumnWidth(idx, Math.round(sheet.getColumnWidth(idx) * actFactor));
  279. }
  280. },
  281. changeCtrl: function (dom) {
  282. let me = fieldLocationOprObj,
  283. sheet = me.columnWorkBook.getActiveSheet(),
  284. fieldRowIdx = sheet.getRowCount() - 1
  285. ;
  286. //sheet.getSelectio
  287. let selectedRanges = sheet.getSelections();
  288. for(let i = 0; i < selectedRanges.length; i++){
  289. if (selectedRanges[i].row === fieldRowIdx) {
  290. let ctrl = me.columnFieldCtrls[selectedRanges[i].col]
  291. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'F';
  292. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'F';
  293. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'F';
  294. ctrl.isNarrow = false;
  295. ctrl.isAutoHeight = false;
  296. if ($("#eleShrinkEx")[0].checked) {
  297. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'T';
  298. }
  299. if ($("#eleShowZeroEx")[0].checked) {
  300. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'T';
  301. }
  302. if ($("#eleAutoWrapEx")[0].checked) {
  303. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'T';
  304. }
  305. if ($("#eleIsNarrowEx")[0].checked) {
  306. ctrl.isNarrow = true;
  307. }
  308. if ($("#eleIsAutoHeightEx")[0].checked) {
  309. ctrl.isAutoHeight = true;
  310. }
  311. if ($("#hOptionLeft")[0].checked) {
  312. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[0];
  313. } else if ($("#hOptionCenter")[0].checked) {
  314. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[1];
  315. } else {
  316. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[2];
  317. }
  318. if ($("#vOptionUp")[0].checked) {
  319. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[0];
  320. } else if ($("#vOptionCenter")[0].checked) {
  321. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[1];
  322. } else {
  323. ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[2];
  324. }
  325. }
  326. }
  327. },
  328. private_update_ctrl_cfg: function (ctrlIdx) {
  329. let me = fieldLocationOprObj;
  330. if (ctrlIdx >= 0) {
  331. if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]])) {
  332. $("#eleShrinkEx")[0].checked = true;
  333. } else {
  334. $("#eleShrinkEx")[0].checked = false;
  335. }
  336. if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]])) {
  337. $("#eleShowZeroEx")[0].checked = true;
  338. } else {
  339. $("#eleShowZeroEx")[0].checked = false;
  340. }
  341. if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]])) {
  342. $("#eleAutoWrapEx")[0].checked = true;
  343. } else {
  344. $("#eleAutoWrapEx")[0].checked = false;
  345. }
  346. if (me.columnFieldCtrls[ctrlIdx].isNarrow) {
  347. $("#eleIsNarrowEx")[0].checked = true;
  348. } else {
  349. $("#eleIsNarrowEx")[0].checked = false;
  350. }
  351. if (me.columnFieldCtrls[ctrlIdx].isAutoHeight) {
  352. $("#eleIsAutoHeightEx")[0].checked = true;
  353. } else {
  354. $("#eleIsAutoHeightEx")[0].checked = false;
  355. }
  356. switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  357. case JV.OUTPUT_ALIGN.H[0]:
  358. $("#hOptionLeft")[0].checked = `true`;
  359. break;
  360. case JV.OUTPUT_ALIGN.H[1]:
  361. $("#hOptionCenter")[0].checked = `true`;
  362. break;
  363. default:
  364. $("#hOptionRight")[0].checked = `true`;
  365. break;
  366. }
  367. switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
  368. case JV.OUTPUT_ALIGN.V[0]:
  369. $("#vOptionUp")[0].checked = `true`;
  370. break;
  371. case JV.OUTPUT_ALIGN.V[1]:
  372. $("#vOptionCenter")[0].checked = `true`;
  373. break;
  374. default:
  375. $("#vOptionDown")[0].checked = `true`;
  376. break;
  377. }
  378. }
  379. },
  380. private_create_dft_ctrl: function () {
  381. return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
  382. },
  383. private_merge_ctrl: function (rptTpl, srcIdx, fieldNode, directCtrl) {
  384. let me = this, ctrl = null;
  385. if (directCtrl) {
  386. ctrl = directCtrl;
  387. } else {
  388. if (typeof fieldNode[JV.PROP_CONTROL] === 'string') {
  389. let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(fieldNode[JV.PROP_CONTROL]);
  390. if (idx >= 0) {
  391. ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
  392. }
  393. } else {
  394. ctrl = fieldNode[JV.PROP_CONTROL];
  395. }
  396. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  397. if (font.ID === fieldNode[JV.PROP_FONT]) {
  398. if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]].indexOf(`Narrow`) >= 0) {
  399. ctrl.isNarrow = true;
  400. } else {
  401. ctrl.isNarrow = false;
  402. }
  403. break;
  404. }
  405. }
  406. ctrl[JV.PROP_IS_AUTO_HEIGHT] = fieldNode[JV.PROP_IS_AUTO_HEIGHT];
  407. }
  408. if (ctrl) {
  409. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]];
  410. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]];
  411. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]];
  412. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]];
  413. me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]];
  414. me.columnFieldCtrls[srcIdx].isNarrow = ctrl.isNarrow;
  415. me.columnFieldCtrls[srcIdx][JV.PROP_IS_AUTO_HEIGHT] = ctrl[JV.PROP_IS_AUTO_HEIGHT];
  416. }
  417. },
  418. private_setup_control_options: function (enable) {
  419. if (enable) {
  420. $("#fieldControlDiv")[0].style.cursor = "";
  421. $("#hOptionLeft")[0].removeAttribute("disabled");
  422. $("#hOptionCenter")[0].removeAttribute("disabled");
  423. $("#hOptionRight")[0].removeAttribute("disabled");
  424. $("#vOptionUp")[0].removeAttribute("disabled");
  425. $("#vOptionCenter")[0].removeAttribute("disabled");
  426. $("#vOptionDown")[0].removeAttribute("disabled");
  427. $("#eleShrinkEx")[0].removeAttribute("disabled");
  428. $("#eleShowZeroEx")[0].removeAttribute("disabled");
  429. $("#eleAutoWrapEx")[0].removeAttribute("disabled");
  430. $("#eleIsNarrowEx")[0].removeAttribute("disabled");
  431. $("#eleIsAutoHeightEx")[0].removeAttribute("disabled");
  432. } else {
  433. $("#fieldControlDiv")[0].style.cursor = "not-allowed";
  434. $("#hOptionLeft")[0].disabled = "disabled" ;
  435. $("#hOptionCenter")[0].disabled = "disabled" ;
  436. $("#hOptionRight")[0].disabled = "disabled" ;
  437. $("#vOptionUp")[0].disabled = "disabled" ;
  438. $("#vOptionCenter")[0].disabled = "disabled" ;
  439. $("#vOptionDown")[0].disabled = "disabled" ;
  440. $("#eleShrinkEx")[0].disabled = "disabled" ;
  441. $("#eleShowZeroEx")[0].disabled = "disabled" ;
  442. $("#eleAutoWrapEx")[0].disabled = "disabled" ;
  443. $("#eleIsNarrowEx")[0].disabled = "disabled" ;
  444. $("#eleIsAutoHeightEx")[0].disabled = "disabled" ;
  445. }
  446. },
  447. private_getSelectedFields: function (rptTpl) {
  448. let rst = [];
  449. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  450. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  451. rst.push(field[JV.PROP_NAME]);
  452. }
  453. }
  454. if (rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  455. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  456. rst.push(field[JV.PROP_NAME]);
  457. }
  458. }
  459. return rst;
  460. },
  461. private_setupCell: function (cell, rptTpl, textNode) {
  462. let me = this;
  463. me.private_setCellFont(cell, textNode);
  464. me.private_setCellControl(cell, textNode);
  465. me.private_setCellStyle(cell, textNode);
  466. let value = textNode[JV.PROP_NAME];
  467. if (textNode[JV.PROP_NAME].indexOf(`|`) >= 0) {
  468. value = textNode[JV.PROP_NAME].split('|').join('\n');
  469. }
  470. cell.wordWrap(true);
  471. cell.value(value);
  472. },
  473. private_setupCellDft: function (cell) {
  474. cell.font(`9pt 宋体`);
  475. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  476. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  477. cell.wordWrap(true);
  478. cell.value(``);
  479. },
  480. private_setCellControl: function (cell, textNode) {
  481. let ctrl = null;
  482. if (typeof textNode[JV.PROP_CONTROL] === 'string') {
  483. let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(textNode[JV.PROP_CONTROL]);
  484. ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
  485. } else {
  486. ctrl = textNode[JV.PROP_CONTROL];
  487. }
  488. if (ctrl) {
  489. switch (ctrl.Horizon) {
  490. case `center`:
  491. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
  492. break;
  493. case `right`:
  494. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.right);
  495. break;
  496. default:
  497. cell.hAlign(GC.Spread.Sheets.HorizontalAlign.left);
  498. break;
  499. }
  500. switch (ctrl.Vertical) {
  501. case `center`:
  502. cell.vAlign(GC.Spread.Sheets.VerticalAlign.center);
  503. break;
  504. case `bottom`:
  505. cell.vAlign(GC.Spread.Sheets.VerticalAlign.bottom);
  506. break;
  507. default:
  508. cell.vAlign(GC.Spread.Sheets.VerticalAlign.top);
  509. break;
  510. }
  511. }
  512. },
  513. private_setCellStyle: function (cell, textNode) {
  514. //默认是normal,暂时不管
  515. },
  516. private_setCellFont: function (cell, textNode) {
  517. for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
  518. if (font.ID === textNode[JV.PROP_FONT]) {
  519. 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]]);
  520. break;
  521. }
  522. }
  523. },
  524. private_getActPos: function (textNode, caclStr, typeStr, baseMea) {
  525. let rst = 0;
  526. if (caclStr === JV.CAL_TYPE[0]) {
  527. //percentage
  528. rst = Math.round(baseMea * textNode[JV.PROP_AREA][typeStr] / 100);
  529. } else {
  530. //abstract
  531. rst = Math.round(textNode[JV.PROP_AREA][typeStr] / 2.54 * 96);
  532. }
  533. return rst;
  534. },
  535. private_getActPosEx: function (textNode, caclObj, typeStr, baseMea) {
  536. let me = this;
  537. if (typeof caclObj === 'string') {
  538. return me.private_getActPos(textNode, caclObj, typeStr, baseMea);
  539. } else {
  540. return me.private_getActPos(textNode, caclObj[typeStr], typeStr, baseMea);
  541. }
  542. },
  543. private_pushPos: function (textNode, caclObj, typeStr, baseMea, posArr) {
  544. let me = this, pos = me.private_getActPosEx(textNode, caclObj, typeStr, baseMea);
  545. if (posArr.indexOf(pos) < 0) posArr.push(pos);
  546. },
  547. private_create_content_node: function (colWidthArr, cellValue, colIdx, rptTpl) {
  548. let me = this;
  549. let rst = {"Name": cellValue, "Title": '', "FieldID": -1, "font": "Content", "control": "Column", "style" : "Default_Normal", "isAutoHeight" : false,
  550. "area" : {"Left" : 0, "Right" : 100, "Top" : 0, "Bottom" : 100, "H_CalculationType" : "percentage", "V_CalculationType" : "percentage"}
  551. };
  552. //1. 设置FieldID
  553. let hasChkField = false;
  554. if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
  555. for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
  556. if (field[JV.PROP_NAME] === cellValue) {
  557. rst.FieldID = field[JV.PROP_ID];
  558. rst["Title"] = "ID: " + field[JV.PROP_ID];
  559. hasChkField = true;
  560. break;
  561. }
  562. }
  563. }
  564. if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
  565. for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
  566. if (field[JV.PROP_NAME] === cellValue) {
  567. rst.FieldID = field[JV.PROP_ID];
  568. rst["Title"] = "ID: " + field[JV.PROP_ID];
  569. hasChkField = true;
  570. break;
  571. }
  572. }
  573. }
  574. //2. 字体
  575. if (me.columnFieldCtrls[colIdx].isNarrow) {
  576. rst[JV.PROP_FONT] = "Content_Narrow";
  577. }
  578. //3. 自动行高
  579. if (me.columnFieldCtrls[colIdx][JV.PROP_IS_AUTO_HEIGHT]) {
  580. rst[JV.PROP_IS_AUTO_HEIGHT] = true;
  581. }
  582. //4. 左右位置%
  583. let width = colWidthArr[colWidthArr.length - 1];
  584. if (colIdx > 0) {
  585. rst[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[colIdx - 1] / width * 100).toFixed(2);
  586. }
  587. rst[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[colIdx] / width * 100).toFixed(2);
  588. if (me.columnFieldCtrls[colIdx]["Vertical"] === "center") {
  589. switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
  590. case "left":
  591. rst["control"] = "Column_Left";
  592. break;
  593. case "center":
  594. rst["control"] = "Column";
  595. break;
  596. default:
  597. rst["control"] = "Column_Right";
  598. break;
  599. }
  600. } else if (me.columnFieldCtrls[colIdx]["Vertical"] === "bottom") {
  601. switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
  602. case "left":
  603. rst["control"] = "Content_Left";
  604. break;
  605. case "center":
  606. rst["control"] = "Content_Center";
  607. break;
  608. default:
  609. rst["control"] = "Content_Right";
  610. break;
  611. }
  612. }
  613. //return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
  614. return rst;
  615. },
  616. applyBack: function () {
  617. let me = this;
  618. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  619. if (rptTpl && me.columnParentNode && me.contentParentNode && confirm(`请确认提交应用!`)) {
  620. let sheet = me.columnWorkBook.getActiveSheet();
  621. if (sheet.getRowCount() > 1 && sheet.getColumnCount() > 0) {
  622. let spans= sheet.getSpans();
  623. let texts = [], colWidthArr = [], rowHeightArr = [];
  624. let private_build_pre_text = function (row, col, rowCount, colCount) {
  625. texts.push({"row": row, "col": col, "rowCount": rowCount, "colCount": colCount, "text": sheet.getValue(row, col)});
  626. };
  627. let private_chk_in_span = function (row, col) {
  628. let rst = false;
  629. for (let span of spans) {
  630. if (span.row <= row && row < (span.row + span.rowCount) && span.col <= col && col < (span.col + span.colCount)) {
  631. rst = true;
  632. break;
  633. }
  634. }
  635. return rst;
  636. };
  637. for (let span of spans) {
  638. private_build_pre_text(span.row, span.col, span.rowCount, span.colCount);
  639. }
  640. for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
  641. rowHeightArr.push(sheet.getRowHeight(iRow));
  642. if (iRow > 0) {
  643. rowHeightArr[iRow] = rowHeightArr[iRow] + rowHeightArr[iRow - 1];
  644. }
  645. for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
  646. if (iRow === 0) {
  647. colWidthArr.push(sheet.getColumnWidth(jCol));
  648. if (jCol > 0) {
  649. colWidthArr[jCol] = colWidthArr[jCol] + colWidthArr[jCol - 1];
  650. }
  651. }
  652. if (!private_chk_in_span(iRow, jCol)) {
  653. private_build_pre_text(iRow, jCol, 1, 1);
  654. }
  655. }
  656. }
  657. texts.sort(function(t1, t2){
  658. if (t1.col === t2.col) {
  659. return t1.row - t2.row;
  660. } else {
  661. return t1.col - t2.col;
  662. }
  663. });
  664. let nodes = [];
  665. let width = colWidthArr[colWidthArr.length - 1], height = rowHeightArr[rowHeightArr.length - 1];
  666. //表栏重置
  667. //0. 先清除原先所有的column text
  668. dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.columnParentNode);
  669. //1. 需要重新设置columnBand的高度
  670. //2. 重新生成text节点
  671. for (let text of texts) {
  672. let node = dataInfoMapTreeOprObj.getDummyTextNode(me.columnParentNode);
  673. node[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[text.col + text.colCount - 1] / width * 100).toFixed(2);
  674. if (text.col > 0) {
  675. node[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[text.col - 1] / width * 100).toFixed(2);
  676. } else {
  677. node[JV.PROP_AREA][JV.PROP_LEFT] = 0;
  678. }
  679. node[JV.PROP_AREA][JV.PROP_BOTTOM] = (rowHeightArr[text.row + text.rowCount - 1] / height * 100).toFixed(2);
  680. if (text.row > 0) {
  681. node[JV.PROP_AREA][JV.PROP_TOP] = (rowHeightArr[text.row - 1] / height * 100).toFixed(2);
  682. } else {
  683. node[JV.PROP_AREA][JV.PROP_TOP] = 0;
  684. }
  685. if (stringUtil.isEmptyString(text[`text`])) {
  686. node[JV.PROP_NAME] = '';
  687. } else {
  688. node[JV.PROP_NAME] = stringUtil.replaceAll(stringUtil.replaceAll(text[`text`].toString(), '\n', '|'), '\r', '');
  689. }
  690. node[JV.PROP_LABEL] = node[JV.PROP_NAME];
  691. nodes.push(node);
  692. }
  693. dataInfoMapTreeOprObj.treeObj.addNodes(me.columnParentNode, -1, nodes, true);
  694. //内容重置
  695. //0. 先清除原先所有的content node
  696. dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.contentParentNode);
  697. //1. 重新生成节点
  698. let contentNodes = [];
  699. let contenRowIdx = sheet.getRowCount() - 1;
  700. let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
  701. for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
  702. let cellValue = sheet.getValue(contenRowIdx, iCol);
  703. if (!(stringUtil.isEmptyString(cellValue))) {
  704. contentNodes.push(me.private_create_content_node(colWidthArr, cellValue, iCol, rptTpl));
  705. }
  706. }
  707. dataInfoMapTreeOprObj.treeObj.addNodes(me.contentParentNode, -1, contentNodes, true);
  708. displayMessage("应用提交成功!", "green", 2000, "id_column_setup_lbl");
  709. } else {
  710. displayMessage("模板行列数量不足!", "red", 2000, "id_column_setup_lbl");
  711. }
  712. }
  713. }
  714. };