rpt_main.js 33 KB

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