rpt_main.js 26 KB

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