rpt_main.js 32 KB

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