rpt_main.js 49 KB

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