rpt_main.js 42 KB

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