rpt_main.js 34 KB

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