rpt_main.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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 = 300000;
  10. let fontSuffixMapObj = {"表标题": "title", "列标题": "column", "正文内容": "content", "合计": "summary", "表眉/表脚": "header_footer"};
  11. let rptTplObj = {
  12. hasInitialized: false,
  13. project_tree: null,
  14. pdfFont: {'SmartSimsun': [], 'simhei': [], 'simkai': []},
  15. iniPage: function() {
  16. let me = this;
  17. if (!me.hasInitialized) {
  18. zTreeOprObj.getCustomerCfg();
  19. zTreeOprObj.getAvailablePageSize();
  20. zTreeOprObj.getReportTemplateTree();
  21. me.hasInitialized = true;
  22. let canvas = document.getElementById("rptCanvas");
  23. canvas.onclick = canvasOprObj.canvasOnClick;
  24. canvas.onmousemove = canvasOprObj.canvasOnMouseMove;
  25. if (JpcJsPDFHelper.doc === null) {
  26. JpcJsPDFHelper.initialize('p', 'pt', 'a4');
  27. }
  28. //收集本单位工程所属的建设项目下所有单位工程id用
  29. // GetAllProjectData(function (datas) {
  30. // //
  31. // }
  32. let params = {
  33. rootProjectID: projectObj.project.property.rootProjectID,
  34. user_id: userID
  35. };
  36. CommonAjax.post("pm/api/getAllUnitProjects", params, function(result) {
  37. // console.log(result);
  38. me.project_tree = result;
  39. // console.log(me.getAllPrjIds());
  40. });
  41. }
  42. },
  43. getAllPrjIds: function() {
  44. let me = this;
  45. let rst = [];
  46. if (me.project_tree) {
  47. for (let prj of me.project_tree) {
  48. rst.push(prj.ID);
  49. }
  50. }
  51. return rst;
  52. },
  53. pdfFontSimsunCallBack: function() {
  54. rptTplObj.pdfFont['SmartSimsun'].push('normal');
  55. rptTplObj.pdfFont['SmartSimsun'].push('bold');
  56. },
  57. pdfFontSimkaiCallBack: function() {
  58. rptTplObj.pdfFont['simkai'].push('normal');
  59. rptTplObj.pdfFont['simkai'].push('bold');
  60. },
  61. pdfFontSimheiCallBack: function() {
  62. rptTplObj.pdfFont['simhei'].push('normal');
  63. rptTplObj.pdfFont['simhei'].push('bold');
  64. }
  65. }
  66. let zTreeOprObj = {
  67. treeObj: null,
  68. currentNode: null,
  69. checkedRptTplNodes: null,
  70. currentRptPageRst: null,
  71. reportPageCfg: null,
  72. defReportPageCfg: null,
  73. currentPage: 1,
  74. maxPages: 0,
  75. countChkedRptTpl: function () {
  76. let me = zTreeOprObj;
  77. if (me.treeObj) {
  78. me.checkedRptTplNodes = [];
  79. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  80. for (let node of chkNodes) {
  81. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  82. cnt++;
  83. me.checkedRptTplNodes.push(node);
  84. if (me.currentNode === node) hasCurrentNode = true;
  85. }
  86. }
  87. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  88. //这里根据实际需求再做处理
  89. cnt++;
  90. me.checkedRptTplNodes.push(me.currentNode);
  91. }
  92. $("#export_div").find("span").each(function(cIdx,elementSpan){
  93. elementSpan.innerText = cnt;
  94. });
  95. $("#print_div").find("span").each(function(cIdx,elementSpan){
  96. elementSpan.innerText = cnt;
  97. });
  98. }
  99. },
  100. getReportTemplateTree: function() {
  101. let me = zTreeOprObj, params = {};
  102. params.engineerId = projectObj.project.projectInfo.property.engineering;
  103. let private_chk_hide = function (chkTplItem) {
  104. //考虑未来拓展,统一在此判断报表模板是否显示
  105. let rst = false;
  106. if (chkTplItem.hasOwnProperty('flags') && chkTplItem.flags.hasOwnProperty('taxType') && chkTplItem.flags['taxType'] !== null &&
  107. parseInt(chkTplItem.flags['taxType']) !== parseInt(projectObj.project.projectInfo.property.taxType)) {
  108. rst = true;
  109. }
  110. return rst;
  111. };
  112. // projectObj.project.projectInfo.property.taxType === 1 //1: 一般计税 2: 简易计税
  113. CommonAjax.postEx("report_tpl_api/getRptTplTree", params, 20000, true, function(result){
  114. let private_remove_hide_item = function (items) {
  115. if (items && items.length > 0) {
  116. for (let i = items.length - 1; i >= 0; i--) {
  117. if (!(items[i].released) && items[i].nodeType === 2) {
  118. items.splice(i, 1);
  119. } else if(private_chk_hide(items[i])) {
  120. items.splice(i, 1);
  121. } else {
  122. if (items[i].items && items[i].items.length > 0) {
  123. private_remove_hide_item(items[i].items);
  124. }
  125. }
  126. }
  127. }
  128. }
  129. private_remove_hide_item(result);
  130. for (let topNode of result) {
  131. if (topNode.userId === "-100") {
  132. topNode.name = topNode.name + " - 标准报表";
  133. } else {
  134. topNode.name = topNode.name + " - 定制报表";
  135. }
  136. }
  137. zTreeHelper.createTreeDirectly(result, rpt_tpl_setting, "rptTplTree", me);
  138. me.refreshNodes();
  139. }, null, null);
  140. },
  141. getAvailablePageSize: function() {
  142. let me = zTreeOprObj, params = {};
  143. params.engineerId = projectObj.project.projectInfo.property.engineering;
  144. CommonAjax.postEx("report_tpl_api/getAvailablePageSize", params, 2000, true, function(result){
  145. if (result) {
  146. // console.log(result);
  147. if (result.length > 0) {
  148. $('#btnRptPageSize')[0].innerHTML = result[0];
  149. let divDom = $('#divRptPageSize');
  150. divDom.empty();
  151. for (let pIdx = 1; pIdx < result.length; pIdx++) {
  152. //<a class="dropdown-item" id="hrefRptPageSize_A3" style="cursor:pointer" onclick="zTreeOprObj.changePageSize(this)">A3</a>
  153. let aDomStr = `<a class="dropdown-item" id="hrefRptPageSize_${result[pIdx]}" style="cursor:pointer" onclick="zTreeOprObj.changePageSize(this)">${result[pIdx]}</a>`;
  154. divDom.append(aDomStr);
  155. }
  156. }
  157. } else {
  158. //
  159. }
  160. }, null, null
  161. );
  162. },
  163. getCustomerCfg: function() {
  164. let me = zTreeOprObj, params = {};
  165. params.engineerId = projectObj.project.projectInfo.property.engineering;
  166. CommonAjax.postEx("report_tpl_api/getCustomizeCfg", params, 20000, true, function(result){
  167. if (result) {
  168. me.defReportPageCfg = result[0];
  169. me.reportPageCfg = result[1];
  170. me.iniFontCfgDom(me.reportPageCfg);
  171. me.renderRptCfg(result[1]);
  172. } else {
  173. me.reportPageCfg = null;
  174. me.defReportPageCfg = null;
  175. }
  176. }, null, null
  177. );
  178. },
  179. iniFontCfgDom: function (cfg) {
  180. for (let font of cfg.fonts) {
  181. let domArrs = [];
  182. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  183. domArrs.push("<div class='row mb-1'>");
  184. //1. label
  185. domArrs.push("<div class='col-3'>" + font.CfgDispName + "</div>");
  186. //2. font name
  187. domArrs.push("<div class='col-3'>");
  188. domArrs.push("<select class='form-control input-sm' id='fontName_" + fontPropSuffix + "' onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"Name\", this)'>");
  189. domArrs.push("<option>宋体</option><option>楷体</option><option>黑体</option>");
  190. domArrs.push("</select>");
  191. domArrs.push("</div>");
  192. //3. font height
  193. domArrs.push("<div class='col-3'>");
  194. domArrs.push("<input class='form-control input-sm' id='fontHeight_" + fontPropSuffix + "' type='number' value='30' step='1' min='6' max='66' " +
  195. "onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)' " +
  196. "onkeyup='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)'>");
  197. domArrs.push("</div>");
  198. //4. font bold italic underline
  199. domArrs.push("<div class='col-3'>");
  200. 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>");
  201. 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>");
  202. 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>");
  203. domArrs.push("</div>");
  204. //
  205. domArrs.push("</div>");
  206. $(domArrs.join("")).insertBefore($("#font_cfg_blank_flag"));
  207. }
  208. },
  209. renderRptCfg: function (cfg) {
  210. $("#elementMargin_Left").get(0).value = cfg.margins.Left;
  211. $("#elementMargin_Right").get(0).value = cfg.margins.Right;
  212. $("#elementMargin_Top").get(0).value = cfg.margins.Top;
  213. $("#elementMargin_Bottom").get(0).value = cfg.margins.Bottom;
  214. for (let font of cfg.fonts) {
  215. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  216. document.getElementById("fontName_" + fontPropSuffix).value = font.Name;
  217. document.getElementById("fontHeight_" + fontPropSuffix).value = font.FontHeight;
  218. document.getElementById("font_bold_" + fontPropSuffix).className = (font.FontBold === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  219. document.getElementById("font_italic_" + fontPropSuffix).className = (font.FontItalic === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  220. document.getElementById("font_underline_" + fontPropSuffix).className = (font.FontUnderline === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  221. }
  222. document.getElementById("rpt_vertical_line").checked = cfg.showVerticalLine;
  223. document.getElementById("rpt_narrow").checked = cfg.isNarrow;
  224. // document.getElementById("rpt_narrow").checked = false;
  225. document.getElementById("rpt_fill_zero").checked = cfg.fillZero;
  226. },
  227. extractRptCfg: function (cfg) {
  228. cfg.margins.Left = $("#elementMargin_Left").get(0).value;
  229. cfg.margins.Right = $("#elementMargin_Right").get(0).value;
  230. cfg.margins.Top = $("#elementMargin_Top").get(0).value;
  231. cfg.margins.Bottom = $("#elementMargin_Bottom").get(0).value;
  232. for (let font of cfg.fonts) {
  233. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  234. font.Name = document.getElementById("fontName_" + fontPropSuffix).value;
  235. font.FontHeight = document.getElementById("fontHeight_" + fontPropSuffix).value;
  236. font.FontBold = (document.getElementById("font_bold_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  237. font.FontItalic = (document.getElementById("font_italic_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  238. font.FontUnderline = (document.getElementById("font_underline_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  239. }
  240. cfg.showVerticalLine = document.getElementById("rpt_vertical_line").checked;
  241. cfg.isNarrow = document.getElementById("rpt_narrow").checked;
  242. cfg.fillZero = document.getElementById("rpt_fill_zero").checked;
  243. },
  244. refreshNodes: function() {
  245. let me = this;
  246. let private_setupIsParent = function(node){
  247. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  248. if (node.items && node.items.length) {
  249. for (let i = 0; i < node.items.length; i++) {
  250. private_setupIsParent(node.items[i]);
  251. }
  252. }
  253. };
  254. let topNodes = me.treeObj.getNodes();
  255. for (let i = 0; i < topNodes.length; i++) {
  256. private_setupIsParent(topNodes[i]);
  257. }
  258. me.treeObj.refresh();
  259. },
  260. onCheck: function(event, treeId, treeNode) {
  261. zTreeOprObj.countChkedRptTpl();
  262. },
  263. onClick: async function(event,treeId,treeNode) {
  264. let me = zTreeOprObj;
  265. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  266. let params = {};
  267. let pageSize = rptControlObj.getCurrentPageSize();
  268. params.pageSize = pageSize;
  269. params.rpt_tpl_id = treeNode.refId;
  270. params.prj_id = projectObj.project.projectInfo.ID;
  271. params.custCfg = me.reportPageCfg;
  272. params.flag = null;
  273. if (treeNode.hasOwnProperty('flags')) {
  274. if (treeNode.flags.hasOwnProperty('auditType') && treeNode.flags.auditType === 'audit_compare') {
  275. let pids = [];
  276. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  277. if (comp_pid !== null) {
  278. pids.push(projectObj.project.projectInfo.ID);
  279. pids.push(comp_pid);
  280. params.prj_ids = pids;
  281. } else {
  282. /*
  283. params.prj_ids = [25062, 25082]; // hard code 测试项目:酉阳县东部沿海产业转移承接基地建设项目(一期)一标段 + 审定
  284. /*/
  285. alert('未设置审核对比项目!');
  286. exit;
  287. //*/
  288. }
  289. } else {
  290. params.prj_ids = rptTplObj.getAllPrjIds();
  291. }
  292. params.flag = treeNode.flags;
  293. }
  294. me.currentNode = treeNode;
  295. me.requestReport(params);
  296. me.countChkedRptTpl();
  297. }
  298. },
  299. changePageSize: function(dom) {
  300. let me = zTreeOprObj,
  301. targetDom = document.getElementById("btnRptPageSize");
  302. let tmpStr = targetDom.innerHTML.trim();
  303. targetDom.innerHTML = dom.innerHTML.trim();
  304. dom.innerHTML = tmpStr;
  305. me.changeCfg();
  306. },
  307. changeOrientation: function(dom) {
  308. let me = zTreeOprObj,
  309. targetDom = document.getElementById("btnRptOrientation");
  310. let tmpStr = targetDom.innerHTML.trim();
  311. targetDom.innerHTML = dom.innerHTML.trim();
  312. dom.innerHTML = tmpStr;
  313. me.changeCfg();
  314. },
  315. changeCfg: async function() {
  316. let me = zTreeOprObj;
  317. let params = {};
  318. params.pageSize = rptControlObj.getCurrentPageSize();
  319. params.orientation = rptControlObj.getCurrentOrientation();
  320. params.rpt_tpl_id = me.currentNode.refId;
  321. params.flag = null;
  322. // if (me.currentNode.hasOwnProperty('flags')) {
  323. // params.flag = me.currentNode.flags;
  324. // params.prj_ids = rptTplObj.getAllPrjIds();
  325. // }
  326. if (me.currentNode.hasOwnProperty('flags')) {
  327. if (me.currentNode.flags.hasOwnProperty('auditType') && me.currentNode.flags.auditType === 'audit_compare') {
  328. let pids = [];
  329. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  330. if (comp_pid !== null) {
  331. pids.push(projectObj.project.projectInfo.ID);
  332. pids.push(comp_pid);
  333. params.prj_ids = pids;
  334. } else {
  335. alert('未设置审核对比项目!');
  336. exit;
  337. }
  338. } else {
  339. params.prj_ids = rptTplObj.getAllPrjIds();
  340. }
  341. params.flag = me.currentNode.flags;
  342. }
  343. params.prj_id = projectObj.project.projectInfo.ID;
  344. params.custCfg = me.reportPageCfg;
  345. me.requestReport(params);
  346. },
  347. resetAfter: function (pageRst) {
  348. let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
  349. if (size[0] > size[1]) {
  350. document.getElementById("btnRptOrientation").innerHTML = "横向";
  351. document.getElementById("hrefRptOrientation").innerHTML = "纵向";
  352. } else {
  353. document.getElementById("btnRptOrientation").innerHTML = "纵向";
  354. document.getElementById("hrefRptOrientation").innerHTML = "横向";
  355. }
  356. },
  357. requestReport: function (params) {
  358. let me = zTreeOprObj;
  359. params.compilation = projectObj.project.projectInfo.compilation;
  360. hintBox.waitBox();
  361. CommonAjax.postEx("report_api/getReport", params, 15000, true,
  362. function(result){
  363. hintBox.unWaitBox();
  364. let pageRst = result;
  365. let canvas = document.getElementById("rptCanvas");
  366. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  367. me.resetAfter(pageRst);
  368. me.currentRptPageRst = pageRst;
  369. me.maxPages = pageRst.items.length;
  370. me.currentPage = 1;
  371. me.displayPageValue();
  372. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  373. canvas.width = size[0] + 20;
  374. if (size[1] > size[0]) {
  375. canvas.height = size[1] + 100;
  376. } else {
  377. canvas.height = size[1] + 50;
  378. }
  379. me.showPage(1, canvas);
  380. } else {
  381. //返回了无数据表
  382. JpcCanvasOutput.cleanCanvas(canvas);
  383. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  384. }
  385. }, function(err){
  386. hintBox.unWaitBox();
  387. }, function(ex){
  388. hintBox.unWaitBox();
  389. }
  390. );
  391. },
  392. showPage: function (pageNum, canvas) {
  393. let me = zTreeOprObj;
  394. if (pageNum >= 1 && pageNum <= me.maxPages) {
  395. me.currentPage = pageNum;
  396. JpcCanvasOutput.cleanCanvas(canvas);
  397. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  398. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  399. }
  400. me.displayPageValue();
  401. },
  402. displayPageValue: function() {
  403. let me = zTreeOprObj;
  404. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  405. }
  406. };
  407. let canvasOprObj = {
  408. canvasOnMouseMove: function (event) {
  409. if (zTreeOprObj.currentNode) {
  410. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  411. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  412. if (x < PRE_PAGE_OFFSET) {
  413. canvas.style.cursor = "url(/web/building_saas/img/PreviousPage.cur), auto";
  414. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  415. canvas.style.cursor = "url(/web/building_saas/img/NextPage.cur), auto";
  416. } else {
  417. canvas.style.cursor = "";
  418. }
  419. }
  420. },
  421. canvasOnClick: function(event){
  422. if (zTreeOprObj.currentNode) {
  423. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  424. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  425. if (x < PRE_PAGE_OFFSET) {
  426. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  427. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  428. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  429. }
  430. }
  431. }
  432. };
  433. let rptControlObj = {
  434. currentOutputType: "Excel",
  435. currentDownloadUrl: null,
  436. currentDownloadIdx: 0,
  437. getCurrentPageSize: function() {
  438. // let rst = "A4";
  439. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  440. //btnRptPageSize
  441. return rst;
  442. },
  443. getCurrentOrientation: function() {
  444. // let rst = "横向";
  445. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  446. return rst;
  447. },
  448. getCurrentReportOption: function() {
  449. //
  450. },
  451. changeType: function(newType) {
  452. let me = rptControlObj;
  453. let excelDom = document.getElementById("EXCEL_TYPE");
  454. let pdfDom = document.getElementById("PDF_TYPE");
  455. if (newType === "Excel") {
  456. excelDom.className = "btn btn-block btn-primary";
  457. pdfDom.className = "btn btn-block btn-outline-secondary";
  458. me.currentOutputType = newType;
  459. } else if (newType === "PDF") {
  460. excelDom.className = "btn btn-block btn-outline-secondary";
  461. pdfDom.className = "btn btn-block btn-primary";
  462. me.currentOutputType = newType;
  463. } else {
  464. //me.currentOutputType = newType;
  465. }
  466. },
  467. outputRpt: function() {
  468. let me = rptControlObj;
  469. if (me.currentOutputType === "Excel") {
  470. me.getExcel();
  471. } else if (me.currentOutputType === "PDF") {
  472. me.getPDF();
  473. } else {
  474. //other types if needed.
  475. }
  476. },
  477. getAllInOneBook: async function () {
  478. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  479. let me = rptControlObj;
  480. let orgRptName = projectObj.project.projectInfo.name;
  481. let refRptTplIds = [], compare_ids = [];
  482. let flags = [];
  483. let params = {};
  484. for (let node of zTreeOprObj.checkedRptTplNodes) {
  485. refRptTplIds.push(node.refId);
  486. let flag = null;
  487. if (node.hasOwnProperty('flags')) {
  488. flag = node.flags;
  489. params.prj_ids = rptTplObj.getAllPrjIds();
  490. if (flag.auditType === 'audit_compare') {
  491. let pids = [];
  492. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  493. if (comp_pid !== null) {
  494. pids.push(projectObj.project.projectInfo.ID);
  495. pids.push(comp_pid);
  496. }
  497. compare_ids.push(pids);
  498. } else {
  499. compare_ids.push([]);
  500. }
  501. } else {
  502. compare_ids.push([]);
  503. }
  504. flags.push(flag);
  505. }
  506. params.prj_id = projectObj.project.projectInfo.ID;
  507. params.compare_ids = compare_ids;
  508. params.rpt_ids = refRptTplIds;
  509. params.flags = flags;
  510. params.rptName = orgRptName;
  511. params.pageSize = me.getCurrentPageSize();
  512. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  513. params.custCfg = zTreeOprObj.reportPageCfg;
  514. params.option = "normal";
  515. $.bootstrapLoading.start();
  516. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  517. if (result) {
  518. $.bootstrapLoading.end();
  519. let uuIdUrls = [];
  520. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  521. uuIdUrls.push(uuIdUrl);
  522. downloadReport(uuIdUrls);
  523. } else {
  524. $.bootstrapLoading.end();
  525. }
  526. },
  527. function(failRst){
  528. $.bootstrapLoading.end();
  529. console.log(failRst);
  530. },
  531. function(exceptionRst){
  532. $.bootstrapLoading.end();
  533. console.log(exceptionRst);
  534. }
  535. );
  536. }
  537. },
  538. getAllIndividualExcelBook: async function () {
  539. let me = rptControlObj;
  540. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  541. let rpt_ids = [], flags = [], rpt_names = [], compare_ids = [];
  542. let params = {};
  543. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  544. rpt_ids.push(tplNode.refId);
  545. rpt_names.push(tplNode.name)
  546. let flag = null;
  547. if (tplNode.hasOwnProperty('flags')) {
  548. flag = tplNode.flags;
  549. params.prj_ids = rptTplObj.getAllPrjIds();
  550. if (flag.auditType === 'audit_compare') {
  551. let pids = [];
  552. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  553. if (comp_pid !== null) {
  554. pids.push(projectObj.project.projectInfo.ID);
  555. pids.push(comp_pid);
  556. }
  557. compare_ids.push(pids);
  558. } else {
  559. compare_ids.push([]);
  560. }
  561. } else {
  562. compare_ids.push([]);
  563. }
  564. flags.push(flag);
  565. }
  566. params.prj_id = projectObj.project.projectInfo.ID;
  567. params.compare_ids = compare_ids;
  568. params.rpt_ids = rpt_ids;
  569. params.flags = flags;
  570. params.rpt_names = rpt_names;
  571. params.pageSize = me.getCurrentPageSize();
  572. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  573. params.isOneSheet = true;
  574. params.custCfg = zTreeOprObj.reportPageCfg;
  575. params.option = "normal";
  576. $.bootstrapLoading.start();
  577. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  578. if (result) {
  579. $.bootstrapLoading.end();
  580. let uuIdUrls = [];
  581. for (let uuIdObj of result) {
  582. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  583. uuIdUrls.push(uuIdUrl);
  584. }
  585. downloadReport(uuIdUrls);
  586. } else {
  587. $.bootstrapLoading.end();
  588. }
  589. },
  590. function(failRst){
  591. $.bootstrapLoading.end();
  592. console.log(failRst);
  593. },
  594. function(exceptionRst){
  595. $.bootstrapLoading.end();
  596. console.log(exceptionRst);
  597. }
  598. );
  599. }
  600. },
  601. checkAndGetExcel: function () {
  602. if (zTreeOprObj.treeObj) {
  603. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  604. if (chkNodes.length > 0) {
  605. $("#show_excel_output_cfg").trigger("click");
  606. } else {
  607. rptControlObj.getAllIndividualExcelBook();
  608. }
  609. }
  610. },
  611. getExcel: function () {
  612. let me = rptControlObj;
  613. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  614. me.getAllInOneBook();
  615. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  616. me.getAllIndividualExcelBook();
  617. }
  618. },
  619. getPDF: async function() {
  620. let me = rptControlObj;
  621. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  622. let rpt_ids = [], flags = [], rpt_names = [], compare_ids = [];
  623. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  624. rpt_ids.push(tplNode.refId);
  625. rpt_names.push(tplNode.name);
  626. let flag = null;
  627. if (tplNode.hasOwnProperty('flags')) {
  628. flag = tplNode.flags;
  629. if (flag.auditType === 'audit_compare') {
  630. let pids = [];
  631. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  632. if (comp_pid !== null) {
  633. pids.push(projectObj.project.projectInfo.ID);
  634. pids.push(comp_pid);
  635. }
  636. compare_ids.push(pids);
  637. } else {
  638. compare_ids.push([]);
  639. }
  640. } else {
  641. compare_ids.push([]);
  642. }
  643. flags.push(flag);
  644. }
  645. let params = {};
  646. params.prj_id = projectObj.project.projectInfo.ID;
  647. params.compare_ids = compare_ids;
  648. params.rpt_ids = rpt_ids;
  649. params.flags = flags;
  650. params.rpt_names = rpt_names;
  651. params.pageSize = me.getCurrentPageSize();
  652. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  653. params.custCfg = zTreeOprObj.reportPageCfg;
  654. params.option = "normal";
  655. params.compilation = projectObj.project.projectInfo.compilation;
  656. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  657. if (result) {
  658. let uuIdUrls = [];
  659. for (let uuIdObj of result) {
  660. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  661. uuIdUrls.push(uuIdUrl);
  662. }
  663. downloadReport(uuIdUrls);
  664. } else {
  665. //
  666. }
  667. }, null, null
  668. );
  669. }
  670. },
  671. _hidePdfIniPage: function () {
  672. if ($('#ini_PDF_cover').is(':visible')) {
  673. // $("#ini_PDF_Btn_Cancel").trigger("click");
  674. // 因在Z+可能会有冲突,所以暴力关闭初始化PDF页面!
  675. $('#ini_PDF_cover').remove();
  676. if ($("div.modal-backdrop.fade.show")) {
  677. $('div.modal-backdrop.fade.show').remove();
  678. }
  679. }
  680. },
  681. getPdfFontCallback: function(fontProperty) {
  682. let me = rptControlObj;
  683. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  684. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  685. me._hidePdfIniPage();
  686. setTimeout(function() {
  687. me.getPDFEx();
  688. }, 50); // 50毫秒足够关闭PDF初始化page了
  689. }
  690. },
  691. getPDFPre: function () {
  692. let me = rptControlObj;
  693. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  694. $.bootstrapLoading.start();
  695. me.getPDFEx();
  696. } else {
  697. $("#ini_PDF_Btn").trigger("click");
  698. // dynamicLoadJs('/lib/jspdf/SmartSimsun-normal.js',"normal", me.getPdfFontCallback);
  699. // dynamicLoadJs('/lib/jspdf/SmartSimsun-bold.js',"bold", me.getPdfFontCallback);
  700. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallback);
  701. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallback);
  702. }
  703. },
  704. getPDFEx: async function () {
  705. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  706. let rptIds = [], rpt_names = [], flagsArr = [], compare_ids = [];
  707. let params = {};
  708. params.pageSize = rptControlObj.getCurrentPageSize();
  709. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  710. params.custCfg = zTreeOprObj.reportPageCfg;
  711. params.prj_id = projectObj.project.projectInfo.ID;
  712. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  713. rptIds.push(tplNode.refId);
  714. rpt_names.push(tplNode.name);
  715. let flag = null;
  716. if (tplNode.hasOwnProperty('flags')) {
  717. flag = tplNode.flags;
  718. params.prj_ids = rptTplObj.getAllPrjIds();
  719. if (flag.auditType === 'audit_compare') {
  720. let pids = [];
  721. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  722. if (comp_pid !== null) {
  723. pids.push(projectObj.project.projectInfo.ID);
  724. pids.push(comp_pid);
  725. }
  726. compare_ids.push(pids);
  727. } else {
  728. compare_ids.push([]);
  729. }
  730. } else {
  731. compare_ids.push([]);
  732. }
  733. flagsArr.push(flag);
  734. }
  735. params.rpt_ids = rptIds.join(",");
  736. params.compare_ids = compare_ids;
  737. params.flags = flagsArr;
  738. params.compilation = projectObj.project.projectInfo.compilation;
  739. CommonAjax.postEx("report_api/getMultiReports", params, WAIT_TIME_EXPORT, true,
  740. function(result){
  741. $.bootstrapLoading.end();
  742. rptControlObj._hidePdfIniPage();
  743. let pageSize = rptControlObj.getCurrentPageSize();
  744. downloadPDFReport(result, pageSize, rpt_names);
  745. // for (let idx = 0; idx < result.length; idx++) {
  746. // let pageData = result[idx];
  747. // JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx]);
  748. // }
  749. },
  750. function(failRst){
  751. $.bootstrapLoading.end();
  752. rptControlObj._hidePdfIniPage();
  753. sessionStorage.currentPageData = null;
  754. console.log(failRst);
  755. },
  756. function(exceptionRst){
  757. $.bootstrapLoading.end();
  758. rptControlObj._hidePdfIniPage();
  759. sessionStorage.currentPageData = null;
  760. console.log(exceptionRst);
  761. }
  762. );
  763. } else {
  764. //不可能的branch
  765. }
  766. },
  767. firstPage: function(dom) {
  768. let canvas = document.getElementById("rptCanvas");
  769. zTreeOprObj.showPage(1, canvas);
  770. },
  771. prePage: function(dom) {
  772. let canvas = document.getElementById("rptCanvas");
  773. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  774. },
  775. nextPage: function(dom) {
  776. let canvas = document.getElementById("rptCanvas");
  777. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  778. },
  779. lastPage: function(dom) {
  780. let me = zTreeOprObj;
  781. let canvas = document.getElementById("rptCanvas");
  782. zTreeOprObj.showPage(me.maxPages, canvas);
  783. },
  784. onKeydown: function (event, dom) {
  785. let me = zTreeOprObj, keyPressed = null;
  786. if (window.event) {
  787. keyPressed = window.event.keyCode; // IE/Chrome
  788. } else {
  789. keyPressed = event.which; // Firefox
  790. }
  791. if (keyPressed === 13) {
  792. let pageNum = 1;
  793. try {
  794. pageNum = parseInt(dom.value);
  795. } catch (e) {
  796. pageNum = 1;
  797. }
  798. let canvas = document.getElementById("rptCanvas");
  799. if (pageNum < 1) {
  800. pageNum = 1;
  801. } else if (pageNum > me.maxPages) {
  802. pageNum = me.maxPages;
  803. }
  804. zTreeOprObj.showPage(pageNum, canvas);
  805. return false;
  806. }
  807. },
  808. changeMargin: function(marginPropStr, marginDom) {
  809. zTreeOprObj.reportPageCfg.margins[marginPropStr] = marginDom.value;
  810. },
  811. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  812. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  813. if (font["CfgDispName"] === CfgDispName) {
  814. font[fontProperty] = fontDom.value;
  815. break;
  816. }
  817. }
  818. },
  819. changeCfgOption: function (optStr, dom) {
  820. zTreeOprObj.reportPageCfg[optStr] = dom.checked;
  821. },
  822. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  823. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  824. if (font["CfgDispName"] === CfgDispName) {
  825. if (font[fontProperty] === 'T') {
  826. font[fontProperty] = 'F';
  827. fontDom.className = "btn btn-sm btn-outline-secondary";
  828. } else {
  829. font[fontProperty] = 'T';
  830. fontDom.className = "btn btn-sm btn-outline-secondary active";
  831. }
  832. break;
  833. }
  834. }
  835. },
  836. restoreCustCFG: function () {
  837. let me = this;
  838. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  839. zTreeOprObj.extractRptCfg(zTreeOprObj.reportPageCfg);
  840. me.saveCustCfg();
  841. },
  842. saveCustCfg: function() {
  843. let params = {};
  844. params.custCfg = zTreeOprObj.reportPageCfg;
  845. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  846. // alert("Save successfully!");
  847. $("#update_msg_response")[0].style.color = "green";
  848. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  849. setTimeout(function(){
  850. $("#update_msg_response")[0].innerHTML = "";
  851. }, 1000);
  852. }, function (failRst) {
  853. $("#update_msg_response")[0].style.color = "red";
  854. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  855. setTimeout(function(){
  856. $("#update_msg_response")[0].innerHTML = "";
  857. }, 1000);
  858. }, null
  859. );
  860. },
  861. confirmCfgChange: async function() {
  862. let treeNode = zTreeOprObj.currentNode;
  863. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  864. let params = {};
  865. params.pageSize = rptControlObj.getCurrentPageSize();
  866. params.rpt_tpl_id = treeNode.refId;
  867. params.flag = null;
  868. // if (me.currentNode.hasOwnProperty('flags')) {
  869. // params.flag = me.currentNode.flags;
  870. // params.prj_ids = rptTplObj.getAllPrjIds();
  871. // }
  872. if (treeNode.hasOwnProperty('flags')) {
  873. if (treeNode.flags.hasOwnProperty('auditType') && treeNode.flags.auditType === 'audit_compare') {
  874. let pids = [];
  875. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  876. if (comp_pid !== null) {
  877. pids.push(projectObj.project.projectInfo.ID);
  878. pids.push(comp_pid);
  879. params.prj_ids = pids;
  880. } else {
  881. alert('未设置审核对比项目!');
  882. exit;
  883. }
  884. } else {
  885. params.prj_ids = rptTplObj.getAllPrjIds();
  886. }
  887. params.flag = treeNode.flags;
  888. }
  889. params.prj_id = projectObj.project.projectInfo.ID;
  890. params.custCfg = zTreeOprObj.reportPageCfg;
  891. zTreeOprObj.requestReport(params);
  892. }
  893. }
  894. };
  895. function downloadPDFReport(pageDataArr, pageSize, rpt_names) {
  896. rptControlObj.currentDownloadIdx = 0;
  897. const private_download = function() {
  898. if (rptControlObj.currentDownloadIdx < pageDataArr.length) {
  899. let pageData = pageDataArr[rptControlObj.currentDownloadIdx];
  900. let rptName = rpt_names[rptControlObj.currentDownloadIdx];
  901. rptControlObj.currentDownloadIdx++;
  902. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rptName);
  903. if (rptControlObj.currentDownloadIdx < pageDataArr.length) setTimeout(private_download, 1000);
  904. }
  905. }
  906. private_download();
  907. }
  908. function downloadReport(urls) {
  909. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  910. rptControlObj.currentDownloadUrl = null;
  911. rptControlObj.currentDownloadIdx = 0;
  912. let private_download = function() {
  913. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  914. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  915. rptControlObj.currentDownloadIdx++;
  916. window.location = rptControlObj.currentDownloadUrl;
  917. setTimeout(private_download, 2000);
  918. }
  919. }
  920. private_download();
  921. }
  922. function dynamicLoadJs(url, type, callback) {
  923. let head = document.getElementsByTagName('head')[0];
  924. let script = document.createElement('script');
  925. script.type = 'text/javascript';
  926. script.src = url;
  927. if(callback) {
  928. script.onload = script.onreadystatechange = function (event) {
  929. // console.log('this.readyState: ' + this.readyState);
  930. callback(type);
  931. script.onload = script.onreadystatechange = null;
  932. // if (this.readyState === "loaded" || this.readyState === "complete"){
  933. // }
  934. };
  935. }
  936. head.appendChild(script);
  937. }
  938. function dynamicLoadCss(url) {
  939. let head = document.getElementsByTagName('head')[0];
  940. let link = document.createElement('link');
  941. link.type='text/css';
  942. link.rel = 'stylesheet';
  943. link.href = url;
  944. head.appendChild(link);
  945. }
  946. function _getCommonParams(treeNode) {
  947. let rstParmas = {};
  948. rstParmas.pageSize = rptControlObj.getCurrentPageSize();
  949. rstParmas.rpt_tpl_id = treeNode.refId;
  950. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  951. let refRptTplIds = [];
  952. for (let node of zTreeOprObj.checkedRptTplNodes) {
  953. refRptTplIds.push(node.refId);
  954. let flag = null;
  955. if (node.hasOwnProperty('flags')) {
  956. flag = node.flags;
  957. params.prj_ids = rptTplObj.getAllPrjIds();
  958. }
  959. flags.push(flag);
  960. }
  961. params.rpt_ids = refRptTplIds;
  962. }
  963. params.prj_id = projectObj.project.projectInfo.ID;
  964. rstParmas.prj_id = projectObj.project.projectInfo.ID;
  965. // rstParmas.custCfg = me.reportPageCfg;
  966. return rstParmas;
  967. }