rpt_main.js 30 KB

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