rpt_main.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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_fill_zero").checked = cfg.fillZero;
  149. },
  150. extractRptCfg: function (cfg) {
  151. cfg.margins.Left = $("#elementMargin_Left").get(0).value;
  152. cfg.margins.Right = $("#elementMargin_Right").get(0).value;
  153. cfg.margins.Top = $("#elementMargin_Top").get(0).value;
  154. cfg.margins.Bottom = $("#elementMargin_Bottom").get(0).value;
  155. for (let font of cfg.fonts) {
  156. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  157. font.Name = document.getElementById("fontName_" + fontPropSuffix).value;
  158. font.FontHeight = document.getElementById("fontHeight_" + fontPropSuffix).value;
  159. font.FontBold = (document.getElementById("font_bold_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  160. font.FontItalic = (document.getElementById("font_italic_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  161. font.FontUnderline = (document.getElementById("font_underline_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  162. }
  163. cfg.showVerticalLine = document.getElementById("rpt_vertical_line").checked;
  164. cfg.isNarrow = document.getElementById("rpt_narrow").checked;
  165. cfg.fillZero = document.getElementById("rpt_fill_zero").checked;
  166. },
  167. refreshNodes: function() {
  168. let me = this;
  169. let private_setupIsParent = function(node){
  170. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  171. if (node.items && node.items.length) {
  172. for (let i = 0; i < node.items.length; i++) {
  173. private_setupIsParent(node.items[i]);
  174. }
  175. }
  176. };
  177. let topNodes = me.treeObj.getNodes();
  178. for (let i = 0; i < topNodes.length; i++) {
  179. private_setupIsParent(topNodes[i]);
  180. }
  181. me.treeObj.refresh();
  182. },
  183. onCheck: function(event, treeId, treeNode) {
  184. zTreeOprObj.countChkedRptTpl();
  185. },
  186. onClick: function(event,treeId,treeNode) {
  187. let me = zTreeOprObj;
  188. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  189. let params = {};
  190. let pageSize = rptControlObj.getCurrentPageSize();
  191. params.pageSize = pageSize;
  192. params.rpt_tpl_id = treeNode.refId;
  193. params.prj_id = projectInfoObj.projectInfo.ID;
  194. params.custCfg = me.reportPageCfg;
  195. me.currentNode = treeNode;
  196. me.requestReport(params);
  197. me.countChkedRptTpl();
  198. }
  199. },
  200. changePageSize: function(dom) {
  201. let me = zTreeOprObj,
  202. targetDom = document.getElementById("btnRptPageSize");
  203. let tmpStr = targetDom.innerHTML.trim();
  204. targetDom.innerHTML = dom.innerHTML.trim();
  205. dom.innerHTML = tmpStr;
  206. me.changeCfg();
  207. },
  208. changeOrientation: function(dom) {
  209. let me = zTreeOprObj,
  210. targetDom = document.getElementById("btnRptOrientation");
  211. let tmpStr = targetDom.innerHTML.trim();
  212. targetDom.innerHTML = dom.innerHTML.trim();
  213. dom.innerHTML = tmpStr;
  214. me.changeCfg();
  215. },
  216. changeCfg: function() {
  217. let me = zTreeOprObj;
  218. let params = {};
  219. params.pageSize = rptControlObj.getCurrentPageSize();
  220. params.orientation = rptControlObj.getCurrentOrientation();
  221. params.rpt_tpl_id = me.currentNode.refId;
  222. params.prj_id = projectInfoObj.projectInfo.ID;
  223. params.custCfg = me.reportPageCfg;
  224. me.requestReport(params);
  225. },
  226. resetAfter: function (pageRst) {
  227. let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
  228. if (size[0] > size[1]) {
  229. document.getElementById("btnRptOrientation").innerHTML = "横向";
  230. document.getElementById("hrefRptOrientation").innerHTML = "纵向";
  231. } else {
  232. document.getElementById("btnRptOrientation").innerHTML = "纵向";
  233. document.getElementById("hrefRptOrientation").innerHTML = "横向";
  234. }
  235. },
  236. requestReport: function (params) {
  237. let me = zTreeOprObj;
  238. // $("rptCanvas").css("cursor")
  239. let canvas = document.getElementById("rptCanvas");
  240. canvas.style.cursor = "wait";
  241. canvas.parentNode.style.cursor = "wait";
  242. CommonAjax.postEx("report_api/getReport", params, 5000, true,
  243. function(result){
  244. let pageRst = result;
  245. if (pageRst) {
  246. me.resetAfter(pageRst);
  247. let canvas = document.getElementById("rptCanvas");
  248. me.currentRptPageRst = pageRst;
  249. me.maxPages = pageRst.items.length;
  250. me.currentPage = 1;
  251. me.displayPageValue();
  252. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  253. canvas.width = size[0] + 20;
  254. if (size[1] > size[0]) {
  255. canvas.height = size[1] + 100;
  256. } else {
  257. canvas.height = size[1] + 50;
  258. }
  259. me.showPage(1, canvas);
  260. canvas.parentNode.style.cursor = "default";
  261. }
  262. }, function(err){
  263. canvas.parentNode.style.cursor = "default";
  264. }, function(ex){
  265. canvas.parentNode.style.cursor = "default";
  266. }
  267. );
  268. },
  269. showPage: function (pageNum, canvas) {
  270. let me = zTreeOprObj;
  271. if (pageNum >= 1 && pageNum <= me.maxPages) {
  272. me.currentPage = pageNum;
  273. JpcCanvasOutput.cleanCanvas(canvas);
  274. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  275. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  276. }
  277. me.displayPageValue();
  278. },
  279. displayPageValue: function() {
  280. let me = zTreeOprObj;
  281. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  282. }
  283. };
  284. let canvasOprObj = {
  285. canvasOnMouseMove: function (event) {
  286. if (zTreeOprObj.currentNode) {
  287. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  288. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  289. if (x < FIRST_PAGE_OFFSET) {
  290. canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
  291. } else if (x < PRE_PAGE_OFFSET) {
  292. canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
  293. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  294. canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
  295. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  296. canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
  297. } else {
  298. canvas.style.cursor = "";
  299. }
  300. }
  301. },
  302. canvasOnClick: function(event){
  303. if (zTreeOprObj.currentNode) {
  304. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  305. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  306. if (x < FIRST_PAGE_OFFSET) {
  307. zTreeOprObj.showPage(1, canvas);
  308. } else if (x < PRE_PAGE_OFFSET) {
  309. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  310. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  311. zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
  312. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  313. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  314. }
  315. }
  316. }
  317. };
  318. let rptControlObj = {
  319. currentOutputType: "Excel",
  320. currentDownloadUrl: null,
  321. currentDownloadIdx: 0,
  322. getCurrentPageSize: function() {
  323. // let rst = "A4";
  324. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  325. //btnRptPageSize
  326. return rst;
  327. },
  328. getCurrentOrientation: function() {
  329. // let rst = "横向";
  330. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  331. return rst;
  332. },
  333. getCurrentReportOption: function() {
  334. //
  335. },
  336. changeType: function(newType) {
  337. let me = rptControlObj;
  338. let excelDom = document.getElementById("EXCEL_TYPE");
  339. let pdfDom = document.getElementById("PDF_TYPE");
  340. if (newType === "Excel") {
  341. excelDom.className = "btn btn-block btn-primary";
  342. pdfDom.className = "btn btn-block btn-outline-secondary";
  343. me.currentOutputType = newType;
  344. } else if (newType === "PDF") {
  345. excelDom.className = "btn btn-block btn-outline-secondary";
  346. pdfDom.className = "btn btn-block btn-primary";
  347. me.currentOutputType = newType;
  348. } else {
  349. //me.currentOutputType = newType;
  350. }
  351. },
  352. outputRpt: function() {
  353. let me = rptControlObj;
  354. if (me.currentOutputType === "Excel") {
  355. me.getExcel();
  356. } else if (me.currentOutputType === "PDF") {
  357. me.getPDF();
  358. } else {
  359. //other types if needed.
  360. }
  361. },
  362. getAllInOneBook: function () {
  363. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  364. let me = rptControlObj;
  365. let orgRptName = projectInfoObj.projectInfo.name;
  366. let refRptTplIds = [];
  367. for (let node of zTreeOprObj.checkedRptTplNodes) {
  368. refRptTplIds.push(node.refId);
  369. }
  370. let params = {};
  371. params.prj_id = projectInfoObj.projectInfo.ID;
  372. params.rpt_ids = refRptTplIds;
  373. params.rptName = orgRptName;
  374. params.pageSize = me.getCurrentPageSize();
  375. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  376. params.custCfg = zTreeOprObj.reportPageCfg;
  377. params.option = "normal";
  378. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, 20000, true, function(result){
  379. if (result) {
  380. let uuIdUrls = [];
  381. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + result.reportName + "/xlsx";
  382. uuIdUrls.push(uuIdUrl);
  383. downloadReport(uuIdUrls);
  384. } else {
  385. //
  386. }
  387. }, null, null
  388. );
  389. }
  390. },
  391. getAllIndividualExcelBook: function () {
  392. let me = rptControlObj;
  393. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  394. let rpt_ids = [], rpt_names = [];
  395. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  396. rpt_ids.push(tplNode.refId);
  397. rpt_names.push(tplNode.name)
  398. }
  399. let params = {};
  400. params.prj_id = projectInfoObj.projectInfo.ID;
  401. params.rpt_ids = rpt_ids;
  402. params.rpt_names = rpt_names;
  403. params.pageSize = me.getCurrentPageSize();
  404. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  405. params.isOneSheet = true;
  406. params.custCfg = zTreeOprObj.reportPageCfg;
  407. params.option = "normal";
  408. CommonAjax.postEx("report_api/createExcelFiles", params, 20000, true, function(result){
  409. if (result) {
  410. let uuIdUrls = [];
  411. for (let uuIdObj of result) {
  412. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + uuIdObj.reportName + "/xlsx";
  413. uuIdUrls.push(uuIdUrl);
  414. }
  415. downloadReport(uuIdUrls);
  416. } else {
  417. //
  418. }
  419. }, null, null
  420. );
  421. }
  422. },
  423. checkAndGetExcel: function () {
  424. if (zTreeOprObj.treeObj) {
  425. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  426. if (chkNodes.length > 0) {
  427. $("#show_excel_output_cfg").trigger("click");
  428. } else {
  429. rptControlObj.getAllIndividualExcelBook();
  430. }
  431. }
  432. },
  433. getExcel: function () {
  434. let me = rptControlObj;
  435. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  436. me.getAllInOneBook();
  437. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  438. me.getAllIndividualExcelBook();
  439. }
  440. },
  441. getPDF: function() {
  442. // let me = rptControlObj;
  443. // if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  444. // let urls = [];
  445. // let orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  446. // for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  447. // let orgRptName = tplNode.name;
  448. // let url = "/report_api/getPDF/" + projectInfoObj.projectInfo.ID + "/" + tplNode.refId + "/" +
  449. // me.getCurrentPageSize() + "/" + orientation + "/" + orgRptName
  450. // // + "/" + encodeURI(JSON.stringify(zTreeOprObj.reportPageCfg));
  451. // urls.push(url);
  452. // }
  453. // downloadReport(urls);
  454. // }
  455. let me = rptControlObj;
  456. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  457. let rpt_ids = [], rpt_names = [];
  458. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  459. rpt_ids.push(tplNode.refId);
  460. rpt_names.push(tplNode.name)
  461. }
  462. let params = {};
  463. params.prj_id = projectInfoObj.projectInfo.ID;
  464. params.rpt_ids = rpt_ids;
  465. params.rpt_names = rpt_names;
  466. params.pageSize = me.getCurrentPageSize();
  467. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  468. params.custCfg = zTreeOprObj.reportPageCfg;
  469. params.option = "normal";
  470. CommonAjax.postEx("report_api/createPdfFiles", params, 20000, true, function(result){
  471. if (result) {
  472. let uuIdUrls = [];
  473. for (let uuIdObj of result) {
  474. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + uuIdObj.reportName + "/pdf";
  475. uuIdUrls.push(uuIdUrl);
  476. }
  477. downloadReport(uuIdUrls);
  478. } else {
  479. //
  480. }
  481. }, null, null
  482. );
  483. }
  484. },
  485. firstPage: function(dom) {
  486. let canvas = document.getElementById("rptCanvas");
  487. zTreeOprObj.showPage(1, canvas);
  488. },
  489. prePage: function(dom) {
  490. let canvas = document.getElementById("rptCanvas");
  491. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  492. },
  493. nextPage: function(dom) {
  494. let canvas = document.getElementById("rptCanvas");
  495. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  496. },
  497. lastPage: function(dom) {
  498. let me = zTreeOprObj;
  499. let canvas = document.getElementById("rptCanvas");
  500. zTreeOprObj.showPage(me.maxPages, canvas);
  501. },
  502. onKeydown: function (event, dom) {
  503. let me = zTreeOprObj, keyPressed = null;
  504. if (window.event) {
  505. keyPressed = window.event.keyCode; // IE/Chrome
  506. } else {
  507. keyPressed = event.which; // Firefox
  508. }
  509. if (keyPressed === 13) {
  510. let pageNum = 1;
  511. try {
  512. pageNum = parseInt(dom.value);
  513. } catch (e) {
  514. pageNum = 1;
  515. }
  516. let canvas = document.getElementById("rptCanvas");
  517. if (pageNum < 1) {
  518. pageNum = 1;
  519. } else if (pageNum > me.maxPages) {
  520. pageNum = me.maxPages;
  521. }
  522. zTreeOprObj.showPage(pageNum, canvas);
  523. return false;
  524. }
  525. },
  526. changeMargin: function(marginPropStr, marginDom) {
  527. zTreeOprObj.reportPageCfg.margins[marginPropStr] = marginDom.value;
  528. },
  529. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  530. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  531. if (font["CfgDispName"] === CfgDispName) {
  532. font[fontProperty] = fontDom.value;
  533. break;
  534. }
  535. }
  536. },
  537. changeCfgOption: function (optStr, dom) {
  538. zTreeOprObj.reportPageCfg[optStr] = dom.checked;
  539. },
  540. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  541. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  542. if (font["CfgDispName"] === CfgDispName) {
  543. if (font[fontProperty] === 'T') {
  544. font[fontProperty] = 'F';
  545. fontDom.className = "btn btn-sm btn-outline-secondary";
  546. } else {
  547. font[fontProperty] = 'T';
  548. fontDom.className = "btn btn-sm btn-outline-secondary active";
  549. }
  550. break;
  551. }
  552. }
  553. },
  554. restoreCustCFG: function () {
  555. let me = this;
  556. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  557. zTreeOprObj.extractRptCfg(zTreeOprObj.reportPageCfg);
  558. me.saveCustCfg();
  559. },
  560. saveCustCfg: function() {
  561. let params = {};
  562. params.custCfg = zTreeOprObj.reportPageCfg;
  563. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  564. // alert("Save successfully!");
  565. $("#update_msg_response")[0].style.color = "green";
  566. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  567. setTimeout(function(){
  568. $("#update_msg_response")[0].innerHTML = "";
  569. }, 1000);
  570. }, function (failRst) {
  571. $("#update_msg_response")[0].style.color = "red";
  572. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  573. setTimeout(function(){
  574. $("#update_msg_response")[0].innerHTML = "";
  575. }, 1000);
  576. }, null
  577. );
  578. },
  579. confirmCfgChange: function() {
  580. let treeNode = zTreeOprObj.currentNode;
  581. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  582. let params = {};
  583. params.pageSize = rptControlObj.getCurrentPageSize();
  584. params.rpt_tpl_id = treeNode.refId;
  585. params.prj_id = projectInfoObj.projectInfo.ID;
  586. params.custCfg = zTreeOprObj.reportPageCfg;
  587. zTreeOprObj.requestReport(params);
  588. }
  589. }
  590. };
  591. function downloadReport(urls) {
  592. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  593. rptControlObj.currentDownloadUrl = null;
  594. rptControlObj.currentDownloadIdx = 0;
  595. let private_download = function() {
  596. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  597. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  598. rptControlObj.currentDownloadIdx++;
  599. window.location = rptControlObj.currentDownloadUrl;
  600. setTimeout(private_download, 2000);
  601. }
  602. }
  603. private_download();
  604. }