rpt_main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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 < PRE_PAGE_OFFSET) {
  322. canvas.style.cursor = "url(/web/building_saas/img/PreviousPage.cur), auto";
  323. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  324. canvas.style.cursor = "url(/web/building_saas/img/NextPage.cur), auto";
  325. } else {
  326. canvas.style.cursor = "";
  327. }
  328. }
  329. },
  330. canvasOnClick: function(event){
  331. if (zTreeOprObj.currentNode) {
  332. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  333. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  334. if (x < PRE_PAGE_OFFSET) {
  335. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  336. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  337. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  338. }
  339. }
  340. }
  341. };
  342. let rptControlObj = {
  343. currentOutputType: "Excel",
  344. currentDownloadUrl: null,
  345. currentDownloadIdx: 0,
  346. getCurrentPageSize: function() {
  347. // let rst = "A4";
  348. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  349. //btnRptPageSize
  350. return rst;
  351. },
  352. getCurrentOrientation: function() {
  353. // let rst = "横向";
  354. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  355. return rst;
  356. },
  357. getCurrentReportOption: function() {
  358. //
  359. },
  360. changeType: function(newType) {
  361. let me = rptControlObj;
  362. let excelDom = document.getElementById("EXCEL_TYPE");
  363. let pdfDom = document.getElementById("PDF_TYPE");
  364. if (newType === "Excel") {
  365. excelDom.className = "btn btn-block btn-primary";
  366. pdfDom.className = "btn btn-block btn-outline-secondary";
  367. me.currentOutputType = newType;
  368. } else if (newType === "PDF") {
  369. excelDom.className = "btn btn-block btn-outline-secondary";
  370. pdfDom.className = "btn btn-block btn-primary";
  371. me.currentOutputType = newType;
  372. } else {
  373. //me.currentOutputType = newType;
  374. }
  375. },
  376. outputRpt: function() {
  377. let me = rptControlObj;
  378. if (me.currentOutputType === "Excel") {
  379. me.getExcel();
  380. } else if (me.currentOutputType === "PDF") {
  381. me.getPDF();
  382. } else {
  383. //other types if needed.
  384. }
  385. },
  386. getAllInOneBook: function () {
  387. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  388. let me = rptControlObj;
  389. let orgRptName = projectObj.project.projectInfo.name;
  390. let refRptTplIds = [];
  391. for (let node of zTreeOprObj.checkedRptTplNodes) {
  392. refRptTplIds.push(node.refId);
  393. }
  394. let params = {};
  395. params.prj_id = projectObj.project.projectInfo.ID;
  396. params.rpt_ids = refRptTplIds;
  397. params.rptName = orgRptName;
  398. params.pageSize = me.getCurrentPageSize();
  399. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  400. params.custCfg = zTreeOprObj.reportPageCfg;
  401. params.option = "normal";
  402. $.bootstrapLoading.start();
  403. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, 20000, true, function(result){
  404. if (result) {
  405. $.bootstrapLoading.end();
  406. let uuIdUrls = [];
  407. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  408. uuIdUrls.push(uuIdUrl);
  409. downloadReport(uuIdUrls);
  410. } else {
  411. $.bootstrapLoading.end();
  412. }
  413. },
  414. function(failRst){
  415. $.bootstrapLoading.end();
  416. console.log(failRst);
  417. },
  418. function(exceptionRst){
  419. $.bootstrapLoading.end();
  420. console.log(exceptionRst);
  421. }
  422. );
  423. }
  424. },
  425. getAllIndividualExcelBook: function () {
  426. let me = rptControlObj;
  427. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  428. let rpt_ids = [], rpt_names = [];
  429. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  430. rpt_ids.push(tplNode.refId);
  431. rpt_names.push(tplNode.name)
  432. }
  433. let params = {};
  434. params.prj_id = projectObj.project.projectInfo.ID;
  435. params.rpt_ids = rpt_ids;
  436. params.rpt_names = rpt_names;
  437. params.pageSize = me.getCurrentPageSize();
  438. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  439. params.isOneSheet = true;
  440. params.custCfg = zTreeOprObj.reportPageCfg;
  441. params.option = "normal";
  442. $.bootstrapLoading.start();
  443. CommonAjax.postEx("report_api/createExcelFiles", params, 20000, true, function(result){
  444. if (result) {
  445. $.bootstrapLoading.end();
  446. let uuIdUrls = [];
  447. for (let uuIdObj of result) {
  448. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  449. uuIdUrls.push(uuIdUrl);
  450. }
  451. downloadReport(uuIdUrls);
  452. } else {
  453. $.bootstrapLoading.end();
  454. }
  455. },
  456. function(failRst){
  457. $.bootstrapLoading.end();
  458. console.log(failRst);
  459. },
  460. function(exceptionRst){
  461. $.bootstrapLoading.end();
  462. console.log(exceptionRst);
  463. }
  464. );
  465. }
  466. },
  467. checkAndGetExcel: function () {
  468. if (zTreeOprObj.treeObj) {
  469. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  470. if (chkNodes.length > 0) {
  471. $("#show_excel_output_cfg").trigger("click");
  472. } else {
  473. rptControlObj.getAllIndividualExcelBook();
  474. }
  475. }
  476. },
  477. getExcel: function () {
  478. let me = rptControlObj;
  479. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  480. me.getAllInOneBook();
  481. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  482. me.getAllIndividualExcelBook();
  483. }
  484. },
  485. getPDF: function() {
  486. let me = rptControlObj;
  487. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  488. let rpt_ids = [], rpt_names = [];
  489. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  490. rpt_ids.push(tplNode.refId);
  491. rpt_names.push(tplNode.name);
  492. }
  493. let params = {};
  494. params.prj_id = projectObj.project.projectInfo.ID;
  495. params.rpt_ids = rpt_ids;
  496. params.rpt_names = rpt_names;
  497. params.pageSize = me.getCurrentPageSize();
  498. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  499. params.custCfg = zTreeOprObj.reportPageCfg;
  500. params.option = "normal";
  501. CommonAjax.postEx("report_api/createPdfFiles", params, 20000, true, function(result){
  502. if (result) {
  503. let uuIdUrls = [];
  504. for (let uuIdObj of result) {
  505. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  506. uuIdUrls.push(uuIdUrl);
  507. }
  508. downloadReport(uuIdUrls);
  509. } else {
  510. //
  511. }
  512. }, null, null
  513. );
  514. }
  515. },
  516. getPdfFontCallback: function(fontProperty) {
  517. let me = rptControlObj;
  518. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  519. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  520. me.getPDFEx();
  521. }
  522. },
  523. getPDFPre: function () {
  524. let me = rptControlObj;
  525. $.bootstrapLoading.start();
  526. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  527. me.getPDFEx();
  528. } else {
  529. // dynamicLoadJs('/lib/jspdf/SmartSimsun-normal.js',"normal", me.getPdfFontCallback);
  530. // dynamicLoadJs('/lib/jspdf/SmartSimsun-bold.js',"bold", me.getPdfFontCallback);
  531. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallback);
  532. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallback);
  533. }
  534. },
  535. getPDFEx: function () {
  536. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  537. let rptIds = [], rpt_names = [];
  538. let params = {};
  539. params.pageSize = rptControlObj.getCurrentPageSize();
  540. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  541. params.custCfg = zTreeOprObj.reportPageCfg;
  542. params.prj_id = projectObj.project.projectInfo.ID;
  543. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  544. rptIds.push(tplNode.refId);
  545. rpt_names.push(tplNode.name);
  546. }
  547. params.rpt_ids = rptIds.join(",");
  548. CommonAjax.postEx("report_api/getMultiReports", params, 30000, true,
  549. function(result){
  550. $.bootstrapLoading.end();
  551. let pageSize = rptControlObj.getCurrentPageSize();
  552. for (let idx = 0; idx < result.length; idx++) {
  553. let pageData = result[idx];
  554. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx]);
  555. }
  556. },
  557. function(failRst){
  558. $.bootstrapLoading.end();
  559. sessionStorage.currentPageData = null;
  560. console.log(failRst);
  561. },
  562. function(exceptionRst){
  563. $.bootstrapLoading.end();
  564. sessionStorage.currentPageData = null;
  565. console.log(exceptionRst);
  566. }
  567. );
  568. } else {
  569. //不可能的branch
  570. }
  571. },
  572. firstPage: function(dom) {
  573. let canvas = document.getElementById("rptCanvas");
  574. zTreeOprObj.showPage(1, canvas);
  575. },
  576. prePage: function(dom) {
  577. let canvas = document.getElementById("rptCanvas");
  578. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  579. },
  580. nextPage: function(dom) {
  581. let canvas = document.getElementById("rptCanvas");
  582. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  583. },
  584. lastPage: function(dom) {
  585. let me = zTreeOprObj;
  586. let canvas = document.getElementById("rptCanvas");
  587. zTreeOprObj.showPage(me.maxPages, canvas);
  588. },
  589. onKeydown: function (event, dom) {
  590. let me = zTreeOprObj, keyPressed = null;
  591. if (window.event) {
  592. keyPressed = window.event.keyCode; // IE/Chrome
  593. } else {
  594. keyPressed = event.which; // Firefox
  595. }
  596. if (keyPressed === 13) {
  597. let pageNum = 1;
  598. try {
  599. pageNum = parseInt(dom.value);
  600. } catch (e) {
  601. pageNum = 1;
  602. }
  603. let canvas = document.getElementById("rptCanvas");
  604. if (pageNum < 1) {
  605. pageNum = 1;
  606. } else if (pageNum > me.maxPages) {
  607. pageNum = me.maxPages;
  608. }
  609. zTreeOprObj.showPage(pageNum, canvas);
  610. return false;
  611. }
  612. },
  613. changeMargin: function(marginPropStr, marginDom) {
  614. zTreeOprObj.reportPageCfg.margins[marginPropStr] = marginDom.value;
  615. },
  616. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  617. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  618. if (font["CfgDispName"] === CfgDispName) {
  619. font[fontProperty] = fontDom.value;
  620. break;
  621. }
  622. }
  623. },
  624. changeCfgOption: function (optStr, dom) {
  625. zTreeOprObj.reportPageCfg[optStr] = dom.checked;
  626. },
  627. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  628. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  629. if (font["CfgDispName"] === CfgDispName) {
  630. if (font[fontProperty] === 'T') {
  631. font[fontProperty] = 'F';
  632. fontDom.className = "btn btn-sm btn-outline-secondary";
  633. } else {
  634. font[fontProperty] = 'T';
  635. fontDom.className = "btn btn-sm btn-outline-secondary active";
  636. }
  637. break;
  638. }
  639. }
  640. },
  641. restoreCustCFG: function () {
  642. let me = this;
  643. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  644. zTreeOprObj.extractRptCfg(zTreeOprObj.reportPageCfg);
  645. me.saveCustCfg();
  646. },
  647. saveCustCfg: function() {
  648. let params = {};
  649. params.custCfg = zTreeOprObj.reportPageCfg;
  650. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  651. // alert("Save successfully!");
  652. $("#update_msg_response")[0].style.color = "green";
  653. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  654. setTimeout(function(){
  655. $("#update_msg_response")[0].innerHTML = "";
  656. }, 1000);
  657. }, function (failRst) {
  658. $("#update_msg_response")[0].style.color = "red";
  659. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  660. setTimeout(function(){
  661. $("#update_msg_response")[0].innerHTML = "";
  662. }, 1000);
  663. }, null
  664. );
  665. },
  666. confirmCfgChange: function() {
  667. let treeNode = zTreeOprObj.currentNode;
  668. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  669. let params = {};
  670. params.pageSize = rptControlObj.getCurrentPageSize();
  671. params.rpt_tpl_id = treeNode.refId;
  672. params.prj_id = projectObj.project.projectInfo.ID;
  673. params.custCfg = zTreeOprObj.reportPageCfg;
  674. zTreeOprObj.requestReport(params);
  675. }
  676. }
  677. };
  678. function downloadReport(urls) {
  679. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  680. rptControlObj.currentDownloadUrl = null;
  681. rptControlObj.currentDownloadIdx = 0;
  682. let private_download = function() {
  683. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  684. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  685. rptControlObj.currentDownloadIdx++;
  686. window.location = rptControlObj.currentDownloadUrl;
  687. setTimeout(private_download, 2000);
  688. }
  689. }
  690. private_download();
  691. }
  692. function dynamicLoadJs(url, type, callback) {
  693. let head = document.getElementsByTagName('head')[0];
  694. let script = document.createElement('script');
  695. script.type = 'text/javascript';
  696. script.src = url;
  697. if(callback) {
  698. script.onload = script.onreadystatechange = function (event) {
  699. // console.log('this.readyState: ' + this.readyState);
  700. callback(type);
  701. script.onload = script.onreadystatechange = null;
  702. // if (this.readyState === "loaded" || this.readyState === "complete"){
  703. // }
  704. };
  705. }
  706. head.appendChild(script);
  707. }
  708. function dynamicLoadCss(url) {
  709. let head = document.getElementsByTagName('head')[0];
  710. let link = document.createElement('link');
  711. link.type='text/css';
  712. link.rel = 'stylesheet';
  713. link.href = url;
  714. head.appendChild(link);
  715. }