rpt_main.js 33 KB

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