rpt_main.js 42 KB

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