rpt_main.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. ROLE_REL_LIST = result.signatureRelInfo;
  237. // if (ROLE_REL_LIST)
  238. let canvas = zTreeOprObj.canvas;
  239. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  240. me.resetAfter(pageRst);
  241. me.currentRptPageRst = pageRst;
  242. me.maxPages = pageRst.items.length;
  243. me.currentPage = 1;
  244. me.displayPageValue();
  245. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  246. canvas.width = size[0] + 20;
  247. if (size[1] > size[0]) {
  248. canvas.height = size[1] + 100;
  249. } else {
  250. canvas.height = size[1] + 50;
  251. }
  252. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  253. rptSignatureHelper.buildSelectableAccount();
  254. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  255. me.showPage(1, canvas);
  256. } else {
  257. //返回了无数据表
  258. JpcCanvasOutput.cleanCanvas(canvas);
  259. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  260. }
  261. }, function(err){
  262. // hintBox.unWaitBox();
  263. }, function(ex){
  264. // hintBox.unWaitBox();
  265. }
  266. );
  267. },
  268. scaleReport: function (accScale) {
  269. let me = zTreeOprObj;
  270. let canvas = zTreeOprObj.canvas;
  271. if (accScale !== 0) {
  272. JpcCanvasOutput.scaleFactor += accScale;
  273. if (JpcCanvasOutput.scaleFactor < 0.5) JpcCanvasOutput.scaleFactor = 0.5;
  274. if (JpcCanvasOutput.scaleFactor > 1.5) JpcCanvasOutput.scaleFactor = 1.5;
  275. } else {
  276. JpcCanvasOutput.scaleFactor = 1;
  277. }
  278. document.getElementById("btnNormalScale").innerText = (JpcCanvasOutput.scaleFactor * 100) + '%';
  279. me.showPage(me.currentPage, canvas);
  280. },
  281. requestPrjFolderCommon: function () {
  282. //
  283. },
  284. showPage: function (pageNum, canvas) {
  285. let me = zTreeOprObj;
  286. if (pageNum >= 1 && pageNum <= me.maxPages) {
  287. me.currentPage = pageNum;
  288. JpcCanvasOutput.cleanCanvas(canvas);
  289. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  290. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  291. }
  292. me.displayPageValue();
  293. },
  294. displayPageValue: function() {
  295. let me = zTreeOprObj;
  296. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  297. }
  298. };
  299. let canvasOprObj = {
  300. canvasOnMouseMove: function (event) {
  301. if (zTreeOprObj.currentNode) {
  302. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  303. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  304. if (x < FIRST_PAGE_OFFSET) {
  305. canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
  306. } else if (x < PRE_PAGE_OFFSET) {
  307. canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
  308. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  309. canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
  310. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  311. canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
  312. } else {
  313. canvas.style.cursor = "";
  314. }
  315. }
  316. },
  317. canvasOnClick: function(event){
  318. if (zTreeOprObj.currentNode) {
  319. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  320. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  321. if (x < FIRST_PAGE_OFFSET) {
  322. zTreeOprObj.showPage(1, canvas);
  323. } else if (x < PRE_PAGE_OFFSET) {
  324. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  325. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  326. zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
  327. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  328. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  329. }
  330. }
  331. }
  332. };
  333. let rptControlObj = {
  334. currentOutputType: "Excel",
  335. currentDownloadUrl: null,
  336. currentDownloadIdx: 0,
  337. getCurrentPageSize: function() {
  338. // let rst = "A4";
  339. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  340. //btnRptPageSize
  341. return rst;
  342. },
  343. getCurrentOrientation: function() {
  344. // let rst = "横向";
  345. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  346. return rst;
  347. },
  348. getCurrentReportOption: function() {
  349. //
  350. },
  351. changeType: function(newType) {
  352. let me = rptControlObj;
  353. let excelDom = document.getElementById("EXCEL_TYPE");
  354. let pdfDom = document.getElementById("PDF_TYPE");
  355. if (newType === "Excel") {
  356. excelDom.className = "btn btn-block btn-primary";
  357. pdfDom.className = "btn btn-block btn-outline-secondary";
  358. me.currentOutputType = newType;
  359. } else if (newType === "PDF") {
  360. excelDom.className = "btn btn-block btn-outline-secondary";
  361. pdfDom.className = "btn btn-block btn-primary";
  362. me.currentOutputType = newType;
  363. } else {
  364. //me.currentOutputType = newType;
  365. }
  366. },
  367. outputRpt: function() {
  368. let me = rptControlObj;
  369. if (me.currentOutputType === "Excel") {
  370. me.getExcel();
  371. } else if (me.currentOutputType === "PDF") {
  372. me.getPDF();
  373. } else {
  374. //other types if needed.
  375. }
  376. },
  377. getTplIdsCommon: function (refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names) {
  378. for (let node of zTreeOprObj.checkedRptTplNodes) {
  379. if (node.hasOwnProperty('flags') && node.flags.hasOwnProperty('reportType') && node['flags']['reportType'] !== 'NA') {
  380. if (node['flags']['reportType'] === 'billSummary') {
  381. refBillSumPrjsIds.push(node.refId);
  382. if (bill_rpt_names) bill_rpt_names.push(node.name);
  383. } else if (node['flags']['reportType'] === 'gljSummary') {
  384. refGljSumPrjsIds.push(node.refId);
  385. if (glj_rpt_names) glj_rpt_names.push(node.name);
  386. }
  387. } else {
  388. refRptTplIds.push(node.refId);
  389. if (rpt_names) rpt_names.push(node.name);
  390. }
  391. }
  392. },
  393. creatCommonExportParam: function (refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds) {
  394. let nodes = (zTreeOprObj.prjFolderTreeObj === null)?[]:zTreeOprObj.prjFolderTreeObj.getCheckedNodes(true);
  395. let rst = {};
  396. rst.prj_id = projectObj.project.projectInfo.ID;
  397. rst.rpt_ids = refRptTplIds;
  398. rst.rpt_bill_tpl_ids = refBillSumPrjsIds;
  399. rst.rpt_glj_tpl_ids = refGljSumPrjsIds;
  400. rst.prjIds = [];
  401. zTreeOprObj.selectedPrjIDs = [];
  402. for (let node of nodes) {
  403. rst.prjIds.push(node.ID);
  404. zTreeOprObj.selectedPrjIDs.push(node.ID);
  405. }
  406. // rst.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  407. // rst.rpt_names = rpt_names;
  408. // rst.isOneSheet = true;
  409. rst.pageSize = rptControlObj.getCurrentPageSize();
  410. rst.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  411. rst.custCfg = CUST_CFG;
  412. rst.option = "normal";
  413. return rst;
  414. },
  415. getAllInOneBook: function () {
  416. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  417. let me = rptControlObj;
  418. let orgRptName = projectObj.project.projectInfo.name;
  419. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  420. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  421. if (zTreeOprObj.selectedPrjIDs.length > 0 && (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0)) {
  422. let params = rptControlObj.creatCommonExportParam(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  423. params.rptName = orgRptName;
  424. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  425. if (result) {
  426. let uuIdUrls = [];
  427. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  428. uuIdUrls.push(uuIdUrl);
  429. downloadReport(uuIdUrls);
  430. } else {
  431. //
  432. }
  433. }, null, null
  434. );
  435. } else {
  436. let params = {};
  437. params.prj_id = PROJECT_ID;
  438. params.rpt_ids = refRptTplIds;
  439. params.rptName = orgRptName;
  440. params.pageSize = me.getCurrentPageSize();
  441. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  442. params.custCfg = CUST_CFG;
  443. params.option = "normal";
  444. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  445. if (result) {
  446. let uuIdUrls = [];
  447. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  448. uuIdUrls.push(uuIdUrl);
  449. downloadReport(uuIdUrls);
  450. } else {
  451. //
  452. }
  453. }, null, null
  454. );
  455. }
  456. }
  457. },
  458. getAllIndividualExcelBook: function () {
  459. let me = rptControlObj;
  460. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  461. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  462. let rpt_names = [], bill_rpt_names = [], glj_rpt_names = [];
  463. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names);
  464. if (zTreeOprObj.selectedPrjIDs.length > 0 && (glj_rpt_names.length > 0 || bill_rpt_names.length > 0)) {
  465. let params = rptControlObj.creatCommonExportParam(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  466. params.prj_id = PROJECT_ID;
  467. params.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  468. params.rpt_names = rpt_names;
  469. params.isOneSheet = true;
  470. params.rptName = projectObj.project.projectInfo.name;
  471. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  472. if (result) {
  473. let uuIdUrls = [];
  474. for (let uuIdObj of result) {
  475. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  476. uuIdUrls.push(uuIdUrl);
  477. }
  478. downloadReport(uuIdUrls);
  479. } else {
  480. //
  481. }
  482. }, null, null
  483. );
  484. } else {
  485. if (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0) {
  486. $("#divReqBillSummary")[0].style.display = "none";
  487. $("#divReqGljSummary")[0].style.display = "none";
  488. $("#divReqCommonSummaryExcel")[0].style.display = "none";
  489. $("#divReqCommonSummaryMultiExcel")[0].style.display = "";
  490. $("#divReqCommonSummaryPDF")[0].style.display = "none";
  491. zTreeOprObj.requestPrjFolderCommon(); //先处理需要汇总的报表,走另外一个分支
  492. } else if (refRptTplIds.length > 0) {
  493. let params = {};
  494. params.prj_id = PROJECT_ID;
  495. params.rpt_ids = refRptTplIds;
  496. params.rpt_names = rpt_names;
  497. params.pageSize = me.getCurrentPageSize();
  498. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  499. params.isOneSheet = true;
  500. params.custCfg = CUST_CFG;
  501. params.option = "normal";
  502. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  503. if (result) {
  504. let uuIdUrls = [];
  505. for (let uuIdObj of result) {
  506. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  507. uuIdUrls.push(uuIdUrl);
  508. }
  509. downloadReport(uuIdUrls);
  510. } else {
  511. //
  512. }
  513. }, null, null
  514. );
  515. }
  516. }
  517. }
  518. },
  519. checkAndGetExcel: function () {
  520. if (zTreeOprObj.treeObj) {
  521. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  522. if (chkNodes.length > 0) {
  523. $("#show_excel_output_cfg").trigger("click");
  524. } else {
  525. rptControlObj.getAllIndividualExcelBook();
  526. }
  527. }
  528. },
  529. getExcel: function () {
  530. let me = rptControlObj;
  531. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  532. me.getAllInOneBook();
  533. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  534. me.getAllIndividualExcelBook();
  535. }
  536. },
  537. getPDF: function () {
  538. let me = rptControlObj;
  539. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  540. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  541. let rpt_names = [], bill_rpt_names = [], glj_rpt_names = [];
  542. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names);
  543. if (zTreeOprObj.selectedPrjIDs.length > 0 && (glj_rpt_names.length > 0 || bill_rpt_names.length > 0)) {
  544. let params = rptControlObj.creatCommonExportParam();
  545. params.prj_id = PROJECT_ID;
  546. params.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  547. params.rpt_ids = refRptTplIds;
  548. params.rpt_bill_tpl_ids = refBillSumPrjsIds;
  549. params.rpt_glj_tpl_ids = refGljSumPrjsIds;
  550. params.rpt_names = rpt_names;
  551. params.isOneSheet = true;
  552. params.rptName = projectObj.project.projectInfo.name;
  553. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  554. if (result) {
  555. let uuIdUrls = [];
  556. for (let uuIdObj of result) {
  557. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  558. uuIdUrls.push(uuIdUrl);
  559. }
  560. downloadReport(uuIdUrls);
  561. } else {
  562. //
  563. }
  564. }, null, null
  565. );
  566. } else {
  567. if (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0) {
  568. $("#divReqBillSummary")[0].style.display = "none";
  569. $("#divReqGljSummary")[0].style.display = "none";
  570. $("#divReqCommonSummaryExcel")[0].style.display = "none";
  571. $("#divReqCommonSummaryMultiExcel")[0].style.display = "none";
  572. $("#divReqCommonSummaryPDF")[0].style.display = "";
  573. zTreeOprObj.requestPrjFolderCommon(); //先处理需要汇总的报表,走另外一个分支
  574. } else if (refRptTplIds.length > 0) {
  575. let params = {};
  576. params.prj_id = PROJECT_ID;
  577. params.rpt_ids = refRptTplIds;
  578. params.rpt_names = rpt_names;
  579. params.pageSize = me.getCurrentPageSize();
  580. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  581. params.custCfg = CUST_CFG;
  582. params.option = "normal";
  583. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  584. if (result) {
  585. let uuIdUrls = [];
  586. for (let uuIdObj of result) {
  587. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  588. uuIdUrls.push(uuIdUrl);
  589. }
  590. downloadReport(uuIdUrls);
  591. } else {
  592. //
  593. }
  594. }, null, null
  595. );
  596. }
  597. }
  598. }
  599. },
  600. firstPage: function(dom) {
  601. zTreeOprObj.showPage(1, zTreeOprObj.canvas);
  602. },
  603. prePage: function(dom) {
  604. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, zTreeOprObj.canvas);
  605. },
  606. nextPage: function(dom) {
  607. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, zTreeOprObj.canvas);
  608. },
  609. lastPage: function(dom) {
  610. let me = zTreeOprObj;
  611. zTreeOprObj.showPage(me.maxPages, zTreeOprObj.canvas);
  612. },
  613. onKeydown: function (event, dom) {
  614. let me = zTreeOprObj, keyPressed = null;
  615. if (window.event) {
  616. keyPressed = window.event.keyCode; // IE/Chrome
  617. } else {
  618. keyPressed = event.which; // Firefox
  619. }
  620. if (keyPressed === 13) {
  621. let pageNum = 1;
  622. try {
  623. pageNum = parseInt(dom.value);
  624. } catch (e) {
  625. pageNum = 1;
  626. }
  627. if (pageNum < 1) {
  628. pageNum = 1;
  629. } else if (pageNum > me.maxPages) {
  630. pageNum = me.maxPages;
  631. }
  632. zTreeOprObj.showPage(pageNum, zTreeOprObj.canvas);
  633. return false;
  634. }
  635. },
  636. changeMargin: function(marginPropStr, marginDom) {
  637. CUST_CFG.margins[marginPropStr] = marginDom.value;
  638. },
  639. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  640. for (let font of CUST_CFG.fonts) {
  641. if (font["CfgDispName"] === CfgDispName) {
  642. font[fontProperty] = fontDom.value;
  643. break;
  644. }
  645. }
  646. },
  647. changeCfgOption: function (optStr, dom) {
  648. CUST_CFG[optStr] = dom.checked;
  649. },
  650. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  651. for (let font of CUST_CFG.fonts) {
  652. if (font["CfgDispName"] === CfgDispName) {
  653. if (font[fontProperty] === 'T') {
  654. font[fontProperty] = 'F';
  655. fontDom.className = "btn btn-sm btn-outline-secondary";
  656. } else {
  657. font[fontProperty] = 'T';
  658. fontDom.className = "btn btn-sm btn-outline-secondary active";
  659. }
  660. break;
  661. }
  662. }
  663. },
  664. restoreCustCFG: function () {
  665. let me = this;
  666. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  667. zTreeOprObj.extractRptCfg(CUST_CFG);
  668. me.saveCustCfg();
  669. },
  670. saveCustCfg: function() {
  671. let params = {};
  672. params.custCfg = CUST_CFG;
  673. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  674. // alert("Save successfully!");
  675. $("#update_msg_response")[0].style.color = "green";
  676. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  677. setTimeout(function(){
  678. $("#update_msg_response")[0].innerHTML = "";
  679. }, 1000);
  680. }, function (failRst) {
  681. $("#update_msg_response")[0].style.color = "red";
  682. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  683. setTimeout(function(){
  684. $("#update_msg_response")[0].innerHTML = "";
  685. }, 1000);
  686. }, null
  687. );
  688. },
  689. confirmCfgChange: function() {
  690. zTreeOprObj.changeCfg();
  691. }
  692. };
  693. function downloadReport(urls) {
  694. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  695. rptControlObj.currentDownloadUrl = null;
  696. rptControlObj.currentDownloadIdx = 0;
  697. let private_download = function() {
  698. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  699. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  700. rptControlObj.currentDownloadIdx++;
  701. window.location = rptControlObj.currentDownloadUrl;
  702. setTimeout(private_download, 2000);
  703. }
  704. }
  705. private_download();
  706. }
  707. function getStageId() {
  708. return current_stage_id;
  709. }
  710. function getStageOrder() {
  711. return current_stage_order;
  712. }
  713. function getStageTimes() {
  714. return current_stage_times;
  715. }