rpt_main.js 28 KB

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