rpt_main.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  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. params.construct_id = projectObj.project.property.rootProjectID;
  353. hintBox.waitBox();
  354. CommonAjax.postEx("report_api/getReport", params, 15000, true,
  355. function(result){
  356. hintBox.unWaitBox();
  357. let pageRst = result;
  358. let canvas = document.getElementById("rptCanvas");
  359. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  360. me.resetAfter(pageRst);
  361. me.currentRptPageRst = pageRst;
  362. me.maxPages = pageRst.items.length;
  363. me.currentPage = 1;
  364. me.displayPageValue();
  365. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  366. canvas.width = size[0] + 20;
  367. if (size[1] > size[0]) {
  368. canvas.height = size[1] + 100;
  369. } else {
  370. canvas.height = size[1] + 50;
  371. }
  372. me.showPage(1, canvas);
  373. } else {
  374. //返回了无数据表
  375. JpcCanvasOutput.cleanCanvas(canvas);
  376. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  377. }
  378. }, function(err){
  379. hintBox.unWaitBox();
  380. }, function(ex){
  381. hintBox.unWaitBox();
  382. }
  383. );
  384. },
  385. showPage: function (pageNum, canvas) {
  386. let me = zTreeOprObj;
  387. if (pageNum >= 1 && pageNum <= me.maxPages) {
  388. me.currentPage = pageNum;
  389. JpcCanvasOutput.cleanCanvas(canvas);
  390. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  391. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  392. }
  393. me.displayPageValue();
  394. },
  395. displayPageValue: function() {
  396. let me = zTreeOprObj;
  397. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  398. }
  399. };
  400. let canvasOprObj = {
  401. canvasOnMouseMove: function (event) {
  402. if (zTreeOprObj.currentNode) {
  403. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  404. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  405. if (x < PRE_PAGE_OFFSET) {
  406. canvas.style.cursor = "url(/web/building_saas/img/PreviousPage.cur), auto";
  407. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  408. canvas.style.cursor = "url(/web/building_saas/img/NextPage.cur), auto";
  409. } else {
  410. canvas.style.cursor = "";
  411. }
  412. }
  413. },
  414. canvasOnClick: function(event){
  415. if (zTreeOprObj.currentNode) {
  416. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  417. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  418. if (x < PRE_PAGE_OFFSET) {
  419. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  420. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  421. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  422. }
  423. }
  424. }
  425. };
  426. let rptControlObj = {
  427. currentOutputType: "Excel",
  428. currentDownloadUrl: null,
  429. currentDownloadIdx: 0,
  430. getCurrentPageSize: function() {
  431. // let rst = "A4";
  432. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  433. //btnRptPageSize
  434. return rst;
  435. },
  436. getCurrentOrientation: function() {
  437. // let rst = "横向";
  438. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  439. return rst;
  440. },
  441. getCurrentReportOption: function() {
  442. //
  443. },
  444. changeType: function(newType) {
  445. let me = rptControlObj;
  446. let excelDom = document.getElementById("EXCEL_TYPE");
  447. let pdfDom = document.getElementById("PDF_TYPE");
  448. if (newType === "Excel") {
  449. excelDom.className = "btn btn-block btn-primary";
  450. pdfDom.className = "btn btn-block btn-outline-secondary";
  451. me.currentOutputType = newType;
  452. } else if (newType === "PDF") {
  453. excelDom.className = "btn btn-block btn-outline-secondary";
  454. pdfDom.className = "btn btn-block btn-primary";
  455. me.currentOutputType = newType;
  456. } else {
  457. //me.currentOutputType = newType;
  458. }
  459. },
  460. outputRpt: function() {
  461. let me = rptControlObj;
  462. if (me.currentOutputType === "Excel") {
  463. me.getExcel();
  464. } else if (me.currentOutputType === "PDF") {
  465. me.getPDF();
  466. } else {
  467. //other types if needed.
  468. }
  469. },
  470. getAllInOneBook: async function () {
  471. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  472. let me = rptControlObj;
  473. let orgRptName = projectObj.project.projectInfo.name;
  474. let refRptTplIds = [], compare_ids = [];
  475. let flags = [];
  476. let params = {};
  477. for (let node of zTreeOprObj.checkedRptTplNodes) {
  478. refRptTplIds.push(node.refId);
  479. let flag = null;
  480. if (node.hasOwnProperty('flags')) {
  481. flag = node.flags;
  482. params.prj_ids = rptTplObj.getAllPrjIds();
  483. if (flag.auditType === 'audit_compare') {
  484. let pids = [];
  485. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  486. if (comp_pid !== null) {
  487. pids.push(projectObj.project.projectInfo.ID);
  488. pids.push(comp_pid);
  489. }
  490. compare_ids.push(pids);
  491. } else {
  492. compare_ids.push([]);
  493. }
  494. } else {
  495. compare_ids.push([]);
  496. }
  497. flags.push(flag);
  498. }
  499. params.prj_id = projectObj.project.projectInfo.ID;
  500. params.construct_id = projectObj.project.property.rootProjectID;
  501. params.compare_ids = compare_ids;
  502. params.rpt_ids = refRptTplIds;
  503. params.flags = flags;
  504. params.rptName = orgRptName;
  505. params.pageSize = me.getCurrentPageSize();
  506. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  507. params.custCfg = zTreeOprObj.reportPageCfg;
  508. params.option = "normal";
  509. $.bootstrapLoading.start();
  510. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  511. if (result) {
  512. $.bootstrapLoading.end();
  513. let uuIdUrls = [];
  514. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  515. uuIdUrls.push(uuIdUrl);
  516. downloadReport(uuIdUrls);
  517. } else {
  518. $.bootstrapLoading.end();
  519. }
  520. },
  521. function(failRst){
  522. $.bootstrapLoading.end();
  523. console.log(failRst);
  524. },
  525. function(exceptionRst){
  526. $.bootstrapLoading.end();
  527. console.log(exceptionRst);
  528. }
  529. );
  530. }
  531. },
  532. getAllIndividualExcelBook: async function () {
  533. let me = rptControlObj;
  534. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  535. let rpt_ids = [], flags = [], rpt_names = [], compare_ids = [];
  536. let params = {};
  537. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  538. rpt_ids.push(tplNode.refId);
  539. rpt_names.push(tplNode.name)
  540. let flag = null;
  541. if (tplNode.hasOwnProperty('flags')) {
  542. flag = tplNode.flags;
  543. params.prj_ids = rptTplObj.getAllPrjIds();
  544. if (flag.auditType === 'audit_compare') {
  545. let pids = [];
  546. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  547. if (comp_pid !== null) {
  548. pids.push(projectObj.project.projectInfo.ID);
  549. pids.push(comp_pid);
  550. }
  551. compare_ids.push(pids);
  552. } else {
  553. compare_ids.push([]);
  554. }
  555. } else {
  556. compare_ids.push([]);
  557. }
  558. flags.push(flag);
  559. }
  560. params.prj_id = projectObj.project.projectInfo.ID;
  561. params.construct_id = projectObj.project.property.rootProjectID;
  562. params.compare_ids = compare_ids;
  563. params.rpt_ids = rpt_ids;
  564. params.flags = flags;
  565. params.rpt_names = rpt_names;
  566. params.pageSize = me.getCurrentPageSize();
  567. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  568. params.isOneSheet = true;
  569. params.custCfg = zTreeOprObj.reportPageCfg;
  570. params.option = "normal";
  571. $.bootstrapLoading.start();
  572. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  573. if (result) {
  574. $.bootstrapLoading.end();
  575. let uuIdUrls = [];
  576. for (let uuIdObj of result) {
  577. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  578. uuIdUrls.push(uuIdUrl);
  579. }
  580. downloadReport(uuIdUrls);
  581. } else {
  582. $.bootstrapLoading.end();
  583. }
  584. },
  585. function(failRst){
  586. $.bootstrapLoading.end();
  587. console.log(failRst);
  588. },
  589. function(exceptionRst){
  590. $.bootstrapLoading.end();
  591. console.log(exceptionRst);
  592. }
  593. );
  594. }
  595. },
  596. checkAndGetExcel: function () {
  597. if (zTreeOprObj.treeObj) {
  598. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  599. if (chkNodes.length > 0) {
  600. $("#show_excel_output_cfg").trigger("click");
  601. } else {
  602. rptControlObj.getAllIndividualExcelBook();
  603. }
  604. }
  605. },
  606. getExcel: function () {
  607. let me = rptControlObj;
  608. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  609. me.getAllInOneBook();
  610. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  611. me.getAllIndividualExcelBook();
  612. }
  613. },
  614. getPDF: async function() {
  615. let me = rptControlObj;
  616. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  617. let rpt_ids = [], flags = [], rpt_names = [], compare_ids = [];
  618. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  619. rpt_ids.push(tplNode.refId);
  620. rpt_names.push(tplNode.name);
  621. let flag = null;
  622. if (tplNode.hasOwnProperty('flags')) {
  623. flag = tplNode.flags;
  624. if (flag.auditType === 'audit_compare') {
  625. let pids = [];
  626. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  627. if (comp_pid !== null) {
  628. pids.push(projectObj.project.projectInfo.ID);
  629. pids.push(comp_pid);
  630. }
  631. compare_ids.push(pids);
  632. } else {
  633. compare_ids.push([]);
  634. }
  635. } else {
  636. compare_ids.push([]);
  637. }
  638. flags.push(flag);
  639. }
  640. let params = {};
  641. params.prj_id = projectObj.project.projectInfo.ID;
  642. params.construct_id = projectObj.project.property.rootProjectID;
  643. params.compare_ids = compare_ids;
  644. params.rpt_ids = rpt_ids;
  645. params.flags = flags;
  646. params.rpt_names = rpt_names;
  647. params.pageSize = me.getCurrentPageSize();
  648. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  649. params.custCfg = zTreeOprObj.reportPageCfg;
  650. params.option = "normal";
  651. params.compilation = projectObj.project.projectInfo.compilation;
  652. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  653. if (result) {
  654. let uuIdUrls = [];
  655. for (let uuIdObj of result) {
  656. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  657. uuIdUrls.push(uuIdUrl);
  658. }
  659. downloadReport(uuIdUrls);
  660. } else {
  661. //
  662. }
  663. }, null, null
  664. );
  665. }
  666. },
  667. getPdfFontCallback: function(fontProperty) {
  668. let me = rptControlObj;
  669. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  670. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  671. me.getPDFEx();
  672. }
  673. },
  674. getPDFPre: function () {
  675. let me = rptControlObj;
  676. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  677. $.bootstrapLoading.start();
  678. me.getPDFEx();
  679. } else {
  680. $("#ini_PDF_Btn").trigger("click");
  681. // dynamicLoadJs('/lib/jspdf/SmartSimsun-normal.js',"normal", me.getPdfFontCallback);
  682. // dynamicLoadJs('/lib/jspdf/SmartSimsun-bold.js',"bold", me.getPdfFontCallback);
  683. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', me.getPdfFontCallback);
  684. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', me.getPdfFontCallback);
  685. }
  686. },
  687. getPDFEx: async function () {
  688. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  689. let rptIds = [], rpt_names = [], flagsArr = [], compare_ids = [];
  690. let params = {};
  691. params.pageSize = rptControlObj.getCurrentPageSize();
  692. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  693. params.custCfg = zTreeOprObj.reportPageCfg;
  694. params.prj_id = projectObj.project.projectInfo.ID;
  695. params.construct_id = projectObj.project.property.rootProjectID;
  696. for (let tplNode of zTreeOprObj.checkedRptTplNodes) {
  697. rptIds.push(tplNode.refId);
  698. rpt_names.push(tplNode.name);
  699. let flag = null;
  700. if (tplNode.hasOwnProperty('flags')) {
  701. flag = tplNode.flags;
  702. params.prj_ids = rptTplObj.getAllPrjIds();
  703. if (flag.auditType === 'audit_compare') {
  704. let pids = [];
  705. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  706. if (comp_pid !== null) {
  707. pids.push(projectObj.project.projectInfo.ID);
  708. pids.push(comp_pid);
  709. }
  710. compare_ids.push(pids);
  711. } else {
  712. compare_ids.push([]);
  713. }
  714. } else {
  715. compare_ids.push([]);
  716. }
  717. flagsArr.push(flag);
  718. }
  719. params.rpt_ids = rptIds.join(",");
  720. params.compare_ids = compare_ids;
  721. params.flags = flagsArr;
  722. params.compilation = projectObj.project.projectInfo.compilation;
  723. CommonAjax.postEx("report_api/getMultiReports", params, WAIT_TIME_EXPORT, true,
  724. function(result){
  725. $.bootstrapLoading.end();
  726. if ($('#ini_PDF_cover').is(':visible')) {
  727. $("#ini_PDF_Btn_Cancel").trigger("click");
  728. // $("#ini_PDF_cover").remove();
  729. }
  730. let pageSize = rptControlObj.getCurrentPageSize();
  731. downloadPDFReport(result, pageSize, rpt_names);
  732. // for (let idx = 0; idx < result.length; idx++) {
  733. // let pageData = result[idx];
  734. // JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx]);
  735. // }
  736. },
  737. function(failRst){
  738. $.bootstrapLoading.end();
  739. if ($('#ini_PDF_cover').is(':visible')) {
  740. $("#ini_PDF_Btn_Cancel").trigger("click");
  741. // $("#ini_PDF_cover").remove();
  742. }
  743. sessionStorage.currentPageData = null;
  744. console.log(failRst);
  745. },
  746. function(exceptionRst){
  747. $.bootstrapLoading.end();
  748. if ($('#ini_PDF_cover').is(':visible')) {
  749. $("#ini_PDF_Btn_Cancel").trigger("click");
  750. // $("#ini_PDF_cover").remove();
  751. }
  752. sessionStorage.currentPageData = null;
  753. console.log(exceptionRst);
  754. }
  755. );
  756. } else {
  757. //不可能的branch
  758. }
  759. },
  760. firstPage: function(dom) {
  761. let canvas = document.getElementById("rptCanvas");
  762. zTreeOprObj.showPage(1, canvas);
  763. },
  764. prePage: function(dom) {
  765. let canvas = document.getElementById("rptCanvas");
  766. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  767. },
  768. nextPage: function(dom) {
  769. let canvas = document.getElementById("rptCanvas");
  770. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  771. },
  772. lastPage: function(dom) {
  773. let me = zTreeOprObj;
  774. let canvas = document.getElementById("rptCanvas");
  775. zTreeOprObj.showPage(me.maxPages, canvas);
  776. },
  777. onKeydown: function (event, dom) {
  778. let me = zTreeOprObj, keyPressed = null;
  779. if (window.event) {
  780. keyPressed = window.event.keyCode; // IE/Chrome
  781. } else {
  782. keyPressed = event.which; // Firefox
  783. }
  784. if (keyPressed === 13) {
  785. let pageNum = 1;
  786. try {
  787. pageNum = parseInt(dom.value);
  788. } catch (e) {
  789. pageNum = 1;
  790. }
  791. let canvas = document.getElementById("rptCanvas");
  792. if (pageNum < 1) {
  793. pageNum = 1;
  794. } else if (pageNum > me.maxPages) {
  795. pageNum = me.maxPages;
  796. }
  797. zTreeOprObj.showPage(pageNum, canvas);
  798. return false;
  799. }
  800. },
  801. changeMargin: function(marginPropStr, marginDom) {
  802. zTreeOprObj.reportPageCfg.margins[marginPropStr] = marginDom.value;
  803. },
  804. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  805. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  806. if (font["CfgDispName"] === CfgDispName) {
  807. font[fontProperty] = fontDom.value;
  808. break;
  809. }
  810. }
  811. },
  812. changeCfgOption: function (optStr, dom) {
  813. zTreeOprObj.reportPageCfg[optStr] = dom.checked;
  814. },
  815. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  816. for (let font of zTreeOprObj.reportPageCfg.fonts) {
  817. if (font["CfgDispName"] === CfgDispName) {
  818. if (font[fontProperty] === 'T') {
  819. font[fontProperty] = 'F';
  820. fontDom.className = "btn btn-sm btn-outline-secondary";
  821. } else {
  822. font[fontProperty] = 'T';
  823. fontDom.className = "btn btn-sm btn-outline-secondary active";
  824. }
  825. break;
  826. }
  827. }
  828. },
  829. restoreCustCFG: function () {
  830. let me = this;
  831. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  832. zTreeOprObj.extractRptCfg(zTreeOprObj.reportPageCfg);
  833. me.saveCustCfg();
  834. },
  835. saveCustCfg: function() {
  836. let params = {};
  837. params.custCfg = zTreeOprObj.reportPageCfg;
  838. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  839. // alert("Save successfully!");
  840. $("#update_msg_response")[0].style.color = "green";
  841. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  842. setTimeout(function(){
  843. $("#update_msg_response")[0].innerHTML = "";
  844. }, 1000);
  845. }, function (failRst) {
  846. $("#update_msg_response")[0].style.color = "red";
  847. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  848. setTimeout(function(){
  849. $("#update_msg_response")[0].innerHTML = "";
  850. }, 1000);
  851. }, null
  852. );
  853. },
  854. confirmCfgChange: async function() {
  855. let treeNode = zTreeOprObj.currentNode;
  856. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  857. let params = {};
  858. params.pageSize = rptControlObj.getCurrentPageSize();
  859. params.rpt_tpl_id = treeNode.refId;
  860. params.flag = null;
  861. // if (me.currentNode.hasOwnProperty('flags')) {
  862. // params.flag = me.currentNode.flags;
  863. // params.prj_ids = rptTplObj.getAllPrjIds();
  864. // }
  865. if (treeNode.hasOwnProperty('flags')) {
  866. if (treeNode.flags.hasOwnProperty('auditType') && treeNode.flags.auditType === 'audit_compare') {
  867. let pids = [];
  868. let comp_pid = await compareObject.getCompareID(); //返回单个对应的project ID
  869. if (comp_pid !== null) {
  870. pids.push(projectObj.project.projectInfo.ID);
  871. pids.push(comp_pid);
  872. params.prj_ids = pids;
  873. } else {
  874. alert('未设置审核对比项目!');
  875. exit;
  876. }
  877. } else {
  878. params.prj_ids = rptTplObj.getAllPrjIds();
  879. }
  880. params.flag = treeNode.flags;
  881. }
  882. params.prj_id = projectObj.project.projectInfo.ID;
  883. params.custCfg = zTreeOprObj.reportPageCfg;
  884. zTreeOprObj.requestReport(params);
  885. }
  886. }
  887. };
  888. function downloadPDFReport(pageDataArr, pageSize, rpt_names) {
  889. rptControlObj.currentDownloadIdx = 0;
  890. const private_download = function() {
  891. if (rptControlObj.currentDownloadIdx < pageDataArr.length) {
  892. let pageData = pageDataArr[rptControlObj.currentDownloadIdx];
  893. let rptName = rpt_names[rptControlObj.currentDownloadIdx];
  894. rptControlObj.currentDownloadIdx++;
  895. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rptName);
  896. if (rptControlObj.currentDownloadIdx < pageDataArr.length) setTimeout(private_download, 1000);
  897. }
  898. }
  899. private_download();
  900. }
  901. function downloadReport(urls) {
  902. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  903. rptControlObj.currentDownloadUrl = null;
  904. rptControlObj.currentDownloadIdx = 0;
  905. let private_download = function() {
  906. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  907. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  908. rptControlObj.currentDownloadIdx++;
  909. window.location = rptControlObj.currentDownloadUrl;
  910. setTimeout(private_download, 2000);
  911. }
  912. }
  913. private_download();
  914. }
  915. function dynamicLoadJs(url, type, callback) {
  916. let head = document.getElementsByTagName('head')[0];
  917. let script = document.createElement('script');
  918. script.type = 'text/javascript';
  919. script.src = url;
  920. if(callback) {
  921. script.onload = script.onreadystatechange = function (event) {
  922. // console.log('this.readyState: ' + this.readyState);
  923. callback(type);
  924. script.onload = script.onreadystatechange = null;
  925. // if (this.readyState === "loaded" || this.readyState === "complete"){
  926. // }
  927. };
  928. }
  929. head.appendChild(script);
  930. }
  931. function dynamicLoadCss(url) {
  932. let head = document.getElementsByTagName('head')[0];
  933. let link = document.createElement('link');
  934. link.type='text/css';
  935. link.rel = 'stylesheet';
  936. link.href = url;
  937. head.appendChild(link);
  938. }
  939. function _getCommonParams(treeNode) {
  940. let rstParmas = {};
  941. rstParmas.pageSize = rptControlObj.getCurrentPageSize();
  942. rstParmas.rpt_tpl_id = treeNode.refId;
  943. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  944. let refRptTplIds = [];
  945. for (let node of zTreeOprObj.checkedRptTplNodes) {
  946. refRptTplIds.push(node.refId);
  947. let flag = null;
  948. if (node.hasOwnProperty('flags')) {
  949. flag = node.flags;
  950. params.prj_ids = rptTplObj.getAllPrjIds();
  951. }
  952. flags.push(flag);
  953. }
  954. params.rpt_ids = refRptTplIds;
  955. }
  956. params.prj_id = projectObj.project.projectInfo.ID;
  957. rstParmas.prj_id = projectObj.project.projectInfo.ID;
  958. // rstParmas.custCfg = me.reportPageCfg;
  959. return rstParmas;
  960. }