rpt_main.js 27 KB

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