rpt_main.js 43 KB

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