rpt_main.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /**
  2. * Created by Tony on 2017/6/26.
  3. */
  4. 'use strict'
  5. const PRE_PAGE_OFFSET = 150;
  6. const NEXT_PAGE_OFFSET = 160;
  7. const FIRST_PAGE_OFFSET = 50;
  8. const LAST_PAGE_OFFSET = 60;
  9. let fontSuffixMapObj = {"表标题": "title", "列标题": "column", "正文内容": "content", "合计": "summary", "表眉/表脚": "header_footer"};
  10. let rptTplObj = {
  11. hasInitialized: false,
  12. iniPage: function() {
  13. let me = this;
  14. if (!me.hasInitialized) {
  15. zTreeOprObj.getCustomerCfg();
  16. zTreeOprObj.getReportTemplateTree();
  17. me.hasInitialized = true;
  18. let canvas = document.getElementById("rptCanvas");
  19. canvas.onclick = canvasOprObj.canvasOnClick;
  20. canvas.onmousemove = canvasOprObj.canvasOnMouseMove;
  21. }
  22. }
  23. }
  24. let zTreeOprObj = {
  25. treeObj: null,
  26. currentNode: null,
  27. checkedRptTplNodes: null,
  28. currentRptPageRst: null,
  29. reportPageCfg: null,
  30. defReportPageCfg: null,
  31. currentPage: 1,
  32. maxPages: 0,
  33. countChkedRptTpl: function () {
  34. let me = zTreeOprObj;
  35. if (me.treeObj) {
  36. me.checkedRptTplNodes = [];
  37. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  38. for (let node of chkNodes) {
  39. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  40. cnt++;
  41. me.checkedRptTplNodes.push(node);
  42. if (me.currentNode === node) hasCurrentNode = true;
  43. }
  44. }
  45. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  46. //这里根据实际需求再做处理
  47. cnt++;
  48. me.checkedRptTplNodes.push(me.currentNode);
  49. }
  50. $("#export_div").find("span").each(function(cIdx,elementSpan){
  51. elementSpan.innerText = cnt;
  52. });
  53. $("#print_div").find("span").each(function(cIdx,elementSpan){
  54. elementSpan.innerText = cnt;
  55. });
  56. }
  57. },
  58. getReportTemplateTree: function() {
  59. let me = zTreeOprObj, params = {};
  60. params.engineerId = projectInfoObj.projectInfo.property.engineering;
  61. CommonAjax.postEx("report_tpl_api/getRptTplTree", params, 20000, true, function(result){
  62. let private_remove_hide_item = function (items) {
  63. if (items && items.length > 0) {
  64. for (let i = items.length - 1; i >= 0; i--) {
  65. if (!(items[i].released) && items[i].nodeType === 2) {
  66. items.splice(i, 1);
  67. } else {
  68. if (items[i].items && items[i].items.length > 0) {
  69. private_remove_hide_item(items[i].items);
  70. }
  71. }
  72. }
  73. }
  74. }
  75. private_remove_hide_item(result);
  76. for (let topNode of result) {
  77. if (topNode.userId === "-100") {
  78. topNode.name = topNode.name + " - 标准报表";
  79. } else {
  80. topNode.name = topNode.name + " - 定制报表";
  81. }
  82. }
  83. zTreeHelper.createTreeDirectly(result, rpt_tpl_setting, "rptTplTree", me);
  84. me.refreshNodes();
  85. }, null, null);
  86. },
  87. getCustomerCfg: function() {
  88. let me = zTreeOprObj, params = {};
  89. params.engineerId = projectInfoObj.projectInfo.property.engineering;
  90. CommonAjax.postEx("report_tpl_api/getCustomizeCfg", params, 20000, true, function(result){
  91. if (result) {
  92. me.defReportPageCfg = result[0];
  93. me.reportPageCfg = result[1];
  94. me.iniFontCfgDom(me.reportPageCfg);
  95. me.renderRptCfg(result[1]);
  96. } else {
  97. me.reportPageCfg = null;
  98. me.defReportPageCfg = null;
  99. }
  100. }, null, null
  101. );
  102. },
  103. iniFontCfgDom: function (cfg) {
  104. for (let font of cfg.fonts) {
  105. let domArrs = [];
  106. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  107. domArrs.push("<div class='row mb-1'>");
  108. //1. label
  109. domArrs.push("<div class='col-3'>" + font.CfgDispName + "</div>");
  110. //2. font name
  111. domArrs.push("<div class='col-3'>");
  112. domArrs.push("<select class='form-control input-sm' id='fontName_" + fontPropSuffix + "' onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"Name\", this)'>");
  113. domArrs.push("<option>宋体</option><option>楷体</option><option>黑体</option>");
  114. domArrs.push("</select>");
  115. domArrs.push("</div>");
  116. //3. font height
  117. domArrs.push("<div class='col-3'>");
  118. domArrs.push("<input class='form-control input-sm' id='fontHeight_" + fontPropSuffix + "' type='number' value='30' step='1' min='6' max='66' " +
  119. "onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)' " +
  120. "onkeyup='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)'>");
  121. domArrs.push("</div>");
  122. //4. font bold italic underline
  123. domArrs.push("<div class='col-3'>");
  124. domArrs.push("<a id='font_bold_" + fontPropSuffix + "' class='btn btn-sm btn-outline-secondary' title='加粗' onclick='rptControlObj.changeFontAdhoc(\"" + font.CfgDispName + "\", \"FontBold\", this)'><i class='fa fa-bold'></i></a>");
  125. domArrs.push("<a id='font_italic_" + fontPropSuffix + "' class='btn btn-sm btn-outline-secondary' title='斜体' onclick='rptControlObj.changeFontAdhoc(\"" + font.CfgDispName + "\", \"FontItalic\", this)'><i class='fa fa-italic'></i></a>");
  126. domArrs.push("<a id='font_underline_" + fontPropSuffix + "' class='btn btn-sm btn-outline-secondary' title='下划线' onclick='rptControlObj.changeFontAdhoc(\"" + font.CfgDispName + "\", \"FontUnderline\", this)'><i class='fa fa-underline'></i></a>");
  127. domArrs.push("</div>");
  128. //
  129. domArrs.push("</div>");
  130. $(domArrs.join("")).insertBefore($("#font_cfg_blank_flag"));
  131. }
  132. },
  133. renderRptCfg: function (cfg) {
  134. $("#elementMargin_Left").get(0).value = cfg.margins.Left;
  135. $("#elementMargin_Right").get(0).value = cfg.margins.Right;
  136. $("#elementMargin_Top").get(0).value = cfg.margins.Top;
  137. $("#elementMargin_Bottom").get(0).value = cfg.margins.Bottom;
  138. for (let font of cfg.fonts) {
  139. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  140. document.getElementById("fontName_" + fontPropSuffix).value = font.Name;
  141. document.getElementById("fontHeight_" + fontPropSuffix).value = font.FontHeight;
  142. document.getElementById("font_bold_" + fontPropSuffix).className = (font.FontBold === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  143. document.getElementById("font_italic_" + fontPropSuffix).className = (font.FontItalic === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  144. document.getElementById("font_underline_" + fontPropSuffix).className = (font.FontUnderline === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  145. }
  146. document.getElementById("rpt_vertical_line").checked = cfg.showVerticalLine;
  147. document.getElementById("rpt_narrow").checked = cfg.isNarrow;
  148. // document.getElementById("rpt_narrow").checked = false;
  149. document.getElementById("rpt_fill_zero").checked = cfg.fillZero;
  150. },
  151. extractRptCfg: function (cfg) {
  152. cfg.margins.Left = $("#elementMargin_Left").get(0).value;
  153. cfg.margins.Right = $("#elementMargin_Right").get(0).value;
  154. cfg.margins.Top = $("#elementMargin_Top").get(0).value;
  155. cfg.margins.Bottom = $("#elementMargin_Bottom").get(0).value;
  156. for (let font of cfg.fonts) {
  157. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  158. font.Name = document.getElementById("fontName_" + fontPropSuffix).value;
  159. font.FontHeight = document.getElementById("fontHeight_" + fontPropSuffix).value;
  160. font.FontBold = (document.getElementById("font_bold_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  161. font.FontItalic = (document.getElementById("font_italic_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  162. font.FontUnderline = (document.getElementById("font_underline_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  163. }
  164. cfg.showVerticalLine = document.getElementById("rpt_vertical_line").checked;
  165. cfg.isNarrow = document.getElementById("rpt_narrow").checked;
  166. cfg.fillZero = document.getElementById("rpt_fill_zero").checked;
  167. },
  168. refreshNodes: function() {
  169. let me = this;
  170. let private_setupIsParent = function(node){
  171. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  172. if (node.items && node.items.length) {
  173. for (let i = 0; i < node.items.length; i++) {
  174. private_setupIsParent(node.items[i]);
  175. }
  176. }
  177. };
  178. let topNodes = me.treeObj.getNodes();
  179. for (let i = 0; i < topNodes.length; i++) {
  180. private_setupIsParent(topNodes[i]);
  181. }
  182. me.treeObj.refresh();
  183. },
  184. onCheck: function(event, treeId, treeNode) {
  185. zTreeOprObj.countChkedRptTpl();
  186. },
  187. onClick: function(event,treeId,treeNode) {
  188. let me = zTreeOprObj;
  189. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  190. let params = {};
  191. let pageSize = rptControlObj.getCurrentPageSize();
  192. params.pageSize = pageSize;
  193. params.rpt_tpl_id = treeNode.refId;
  194. params.prj_id = projectInfoObj.projectInfo.ID;
  195. params.custCfg = me.reportPageCfg;
  196. me.currentNode = treeNode;
  197. me.requestReport(params);
  198. me.countChkedRptTpl();
  199. }
  200. },
  201. changePageSize: function(dom) {
  202. let me = zTreeOprObj,
  203. targetDom = document.getElementById("btnRptPageSize");
  204. let tmpStr = targetDom.innerHTML.trim();
  205. targetDom.innerHTML = dom.innerHTML.trim();
  206. dom.innerHTML = tmpStr;
  207. me.changeCfg();
  208. },
  209. changeOrientation: function(dom) {
  210. let me = zTreeOprObj,
  211. targetDom = document.getElementById("btnRptOrientation");
  212. let tmpStr = targetDom.innerHTML.trim();
  213. targetDom.innerHTML = dom.innerHTML.trim();
  214. dom.innerHTML = tmpStr;
  215. me.changeCfg();
  216. },
  217. changeCfg: function() {
  218. let me = zTreeOprObj;
  219. let params = {};
  220. params.pageSize = rptControlObj.getCurrentPageSize();
  221. params.orientation = rptControlObj.getCurrentOrientation();
  222. params.rpt_tpl_id = me.currentNode.refId;
  223. params.prj_id = projectInfoObj.projectInfo.ID;
  224. params.custCfg = me.reportPageCfg;
  225. me.requestReport(params);
  226. },
  227. resetAfter: function (pageRst) {
  228. let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
  229. if (size[0] > size[1]) {
  230. document.getElementById("btnRptOrientation").innerHTML = "横向";
  231. document.getElementById("hrefRptOrientation").innerHTML = "纵向";
  232. } else {
  233. document.getElementById("btnRptOrientation").innerHTML = "纵向";
  234. document.getElementById("hrefRptOrientation").innerHTML = "横向";
  235. }
  236. },
  237. requestReport: function (params) {
  238. let me = zTreeOprObj;
  239. hintBox.waitBox();
  240. CommonAjax.postEx("report_api/getReport", params, 5000, true,
  241. function(result){
  242. let pageRst = result;
  243. if (pageRst) {
  244. me.resetAfter(pageRst);
  245. let canvas = document.getElementById("rptCanvas");
  246. me.currentRptPageRst = pageRst;
  247. me.maxPages = pageRst.items.length;
  248. me.currentPage = 1;
  249. me.displayPageValue();
  250. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  251. canvas.width = size[0] + 20;
  252. if (size[1] > size[0]) {
  253. canvas.height = size[1] + 100;
  254. } else {
  255. canvas.height = size[1] + 50;
  256. }
  257. me.showPage(1, canvas);
  258. hintBox.unWaitBox();
  259. }
  260. }, function(err){
  261. hintBox.unWaitBox();
  262. }, function(ex){
  263. hintBox.unWaitBox();
  264. }
  265. );
  266. },
  267. showPage: function (pageNum, canvas) {
  268. let me = zTreeOprObj;
  269. if (pageNum >= 1 && pageNum <= me.maxPages) {
  270. me.currentPage = pageNum;
  271. JpcCanvasOutput.cleanCanvas(canvas);
  272. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  273. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  274. }
  275. me.displayPageValue();
  276. },
  277. displayPageValue: function() {
  278. let me = zTreeOprObj;
  279. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  280. }
  281. };
  282. let canvasOprObj = {
  283. canvasOnMouseMove: function (event) {
  284. if (zTreeOprObj.currentNode) {
  285. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  286. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  287. if (x < FIRST_PAGE_OFFSET) {
  288. canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
  289. } else if (x < PRE_PAGE_OFFSET) {
  290. canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
  291. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  292. canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
  293. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  294. canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
  295. } else {
  296. canvas.style.cursor = "";
  297. }
  298. }
  299. },
  300. canvasOnClick: function(event){
  301. if (zTreeOprObj.currentNode) {
  302. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  303. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  304. if (x < FIRST_PAGE_OFFSET) {
  305. zTreeOprObj.showPage(1, canvas);
  306. } else if (x < PRE_PAGE_OFFSET) {
  307. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  308. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  309. zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
  310. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  311. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  312. }
  313. }
  314. }
  315. };
  316. let rptControlObj = {
  317. currentOutputType: "Excel",
  318. currentDownloadUrl: null,
  319. currentDownloadIdx: 0,
  320. getCurrentPageSize: function() {
  321. // let rst = "A4";
  322. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  323. //btnRptPageSize
  324. return rst;
  325. },
  326. getCurrentOrientation: function() {
  327. // let rst = "横向";
  328. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  329. return rst;
  330. },
  331. getCurrentReportOption: function() {
  332. //
  333. },
  334. changeType: function(newType) {
  335. let me = rptControlObj;
  336. let excelDom = document.getElementById("EXCEL_TYPE");
  337. let pdfDom = document.getElementById("PDF_TYPE");
  338. if (newType === "Excel") {
  339. excelDom.className = "btn btn-block btn-primary";
  340. pdfDom.className = "btn btn-block btn-outline-secondary";
  341. me.currentOutputType = newType;
  342. } else if (newType === "PDF") {
  343. excelDom.className = "btn btn-block btn-outline-secondary";
  344. pdfDom.className = "btn btn-block btn-primary";
  345. me.currentOutputType = newType;
  346. } else {
  347. //me.currentOutputType = newType;
  348. }
  349. },
  350. outputRpt: function() {
  351. let me = rptControlObj;
  352. if (me.currentOutputType === "Excel") {
  353. me.getExcel();
  354. } else if (me.currentOutputType === "PDF") {
  355. me.getPDF();
  356. } else {
  357. //other types if needed.
  358. }
  359. },
  360. getAllInOneBook: function () {
  361. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  362. let me = rptControlObj;
  363. let orgRptName = projectInfoObj.projectInfo.name;
  364. let refRptTplIds = [];
  365. for (let node of zTreeOprObj.checkedRptTplNodes) {
  366. refRptTplIds.push(node.refId);
  367. }
  368. let params = {};
  369. params.prj_id = projectInfoObj.projectInfo.ID;
  370. params.rpt_ids = refRptTplIds;
  371. params.rptName = orgRptName;
  372. params.pageSize = me.getCurrentPageSize();
  373. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  374. params.custCfg = zTreeOprObj.reportPageCfg;
  375. params.option = "normal";
  376. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, 20000, true, function(result){
  377. if (result) {
  378. let uuIdUrls = [];
  379. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  380. uuIdUrls.push(uuIdUrl);
  381. downloadReport(uuIdUrls);
  382. } else {
  383. //
  384. }
  385. }, null, null
  386. );
  387. }
  388. },
  389. getAllIndividualExcelBook: function () {
  390. let me = rptControlObj;
  391. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  392. let rpt_ids = [], rpt_names = [];
  393. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  394. rpt_ids.push(tplNode.refId);
  395. rpt_names.push(tplNode.name)
  396. }
  397. let params = {};
  398. params.prj_id = projectInfoObj.projectInfo.ID;
  399. params.rpt_ids = rpt_ids;
  400. params.rpt_names = rpt_names;
  401. params.pageSize = me.getCurrentPageSize();
  402. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  403. params.isOneSheet = true;
  404. params.custCfg = zTreeOprObj.reportPageCfg;
  405. params.option = "normal";
  406. CommonAjax.postEx("report_api/createExcelFiles", params, 20000, true, function(result){
  407. if (result) {
  408. let uuIdUrls = [];
  409. for (let uuIdObj of result) {
  410. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  411. uuIdUrls.push(uuIdUrl);
  412. }
  413. downloadReport(uuIdUrls);
  414. } else {
  415. //
  416. }
  417. }, null, null
  418. );
  419. }
  420. },
  421. checkAndGetExcel: function () {
  422. if (zTreeOprObj.treeObj) {
  423. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  424. if (chkNodes.length > 0) {
  425. $("#show_excel_output_cfg").trigger("click");
  426. } else {
  427. rptControlObj.getAllIndividualExcelBook();
  428. }
  429. }
  430. },
  431. getExcel: function () {
  432. let me = rptControlObj;
  433. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  434. me.getAllInOneBook();
  435. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  436. me.getAllIndividualExcelBook();
  437. }
  438. },
  439. getPDF: function() {
  440. let me = rptControlObj;
  441. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  442. let rpt_ids = [], rpt_names = [];
  443. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  444. rpt_ids.push(tplNode.refId);
  445. rpt_names.push(tplNode.name)
  446. }
  447. let params = {};
  448. params.prj_id = projectInfoObj.projectInfo.ID;
  449. params.rpt_ids = rpt_ids;
  450. params.rpt_names = rpt_names;
  451. params.pageSize = me.getCurrentPageSize();
  452. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  453. params.custCfg = zTreeOprObj.reportPageCfg;
  454. params.option = "normal";
  455. CommonAjax.postEx("report_api/createPdfFiles", params, 20000, true, function(result){
  456. if (result) {
  457. let uuIdUrls = [];
  458. for (let uuIdObj of result) {
  459. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  460. uuIdUrls.push(uuIdUrl);
  461. }
  462. downloadReport(uuIdUrls);
  463. } else {
  464. //
  465. }
  466. }, null, null
  467. );
  468. }
  469. },
  470. firstPage: function(dom) {
  471. let canvas = document.getElementById("rptCanvas");
  472. zTreeOprObj.showPage(1, canvas);
  473. },
  474. prePage: function(dom) {
  475. let canvas = document.getElementById("rptCanvas");
  476. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  477. },
  478. nextPage: function(dom) {
  479. let canvas = document.getElementById("rptCanvas");
  480. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  481. },
  482. lastPage: function(dom) {
  483. let me = zTreeOprObj;
  484. let canvas = document.getElementById("rptCanvas");
  485. zTreeOprObj.showPage(me.maxPages, canvas);
  486. },
  487. onKeydown: function (event, dom) {
  488. let me = zTreeOprObj, keyPressed = null;
  489. if (window.event) {
  490. keyPressed = window.event.keyCode; // IE/Chrome
  491. } else {
  492. keyPressed = event.which; // Firefox
  493. }
  494. if (keyPressed === 13) {
  495. let pageNum = 1;
  496. try {
  497. pageNum = parseInt(dom.value);
  498. } catch (e) {
  499. pageNum = 1;
  500. }
  501. let canvas = document.getElementById("rptCanvas");
  502. if (pageNum < 1) {
  503. pageNum = 1;
  504. } else if (pageNum > me.maxPages) {
  505. pageNum = me.maxPages;
  506. }
  507. zTreeOprObj.showPage(pageNum, canvas);
  508. return false;
  509. }
  510. },
  511. changeMargin: function(marginPropStr, marginDom) {
  512. zTreeOprObj.reportPageCfg.margins[marginPropStr] = marginDom.value;
  513. },
  514. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  515. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  516. if (font["CfgDispName"] === CfgDispName) {
  517. font[fontProperty] = fontDom.value;
  518. break;
  519. }
  520. }
  521. },
  522. changeCfgOption: function (optStr, dom) {
  523. zTreeOprObj.reportPageCfg[optStr] = dom.checked;
  524. },
  525. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  526. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  527. if (font["CfgDispName"] === CfgDispName) {
  528. if (font[fontProperty] === 'T') {
  529. font[fontProperty] = 'F';
  530. fontDom.className = "btn btn-sm btn-outline-secondary";
  531. } else {
  532. font[fontProperty] = 'T';
  533. fontDom.className = "btn btn-sm btn-outline-secondary active";
  534. }
  535. break;
  536. }
  537. }
  538. },
  539. restoreCustCFG: function () {
  540. let me = this;
  541. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  542. zTreeOprObj.extractRptCfg(zTreeOprObj.reportPageCfg);
  543. me.saveCustCfg();
  544. },
  545. saveCustCfg: function() {
  546. let params = {};
  547. params.custCfg = zTreeOprObj.reportPageCfg;
  548. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  549. // alert("Save successfully!");
  550. $("#update_msg_response")[0].style.color = "green";
  551. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  552. setTimeout(function(){
  553. $("#update_msg_response")[0].innerHTML = "";
  554. }, 1000);
  555. }, function (failRst) {
  556. $("#update_msg_response")[0].style.color = "red";
  557. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  558. setTimeout(function(){
  559. $("#update_msg_response")[0].innerHTML = "";
  560. }, 1000);
  561. }, null
  562. );
  563. },
  564. confirmCfgChange: function() {
  565. let treeNode = zTreeOprObj.currentNode;
  566. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  567. let params = {};
  568. params.pageSize = rptControlObj.getCurrentPageSize();
  569. params.rpt_tpl_id = treeNode.refId;
  570. params.prj_id = projectInfoObj.projectInfo.ID;
  571. params.custCfg = zTreeOprObj.reportPageCfg;
  572. zTreeOprObj.requestReport(params);
  573. }
  574. }
  575. };
  576. function downloadReport(urls) {
  577. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  578. rptControlObj.currentDownloadUrl = null;
  579. rptControlObj.currentDownloadIdx = 0;
  580. let private_download = function() {
  581. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  582. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  583. rptControlObj.currentDownloadIdx++;
  584. window.location = rptControlObj.currentDownloadUrl;
  585. setTimeout(private_download, 2000);
  586. }
  587. }
  588. private_download();
  589. }