rpt_main.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /**
  2. * Created by Tony on 2017/6/26.
  3. */
  4. 'use strict'
  5. const PRE_PAGE_OFFSET = 150;
  6. const NEXT_PAGE_OFFSET = 160;
  7. const FIRST_PAGE_OFFSET = 50;
  8. const LAST_PAGE_OFFSET = 60;
  9. const WAIT_TIME_EXPORT = 12000;
  10. let fontSuffixMapObj = {"表标题": "title", "列标题": "column", "正文内容": "content", "合计": "summary", "表眉/表脚": "header_footer"};
  11. let rptTplObj = {
  12. hasInitialized: false,
  13. iniPage: function() {
  14. let me = this;
  15. if (!me.hasInitialized) {
  16. // zTreeOprObj.getCustomerCfg();
  17. zTreeOprObj.getReportTemplateTree();
  18. zTreeOprObj.selectedPrjIDs = [];
  19. me.hasInitialized = true;
  20. zTreeOprObj.canvas = document.getElementById("rptCanvas");
  21. // canvas.onclick = canvasOprObj.canvasOnClick;
  22. // canvas.onmousemove = canvasOprObj.canvasOnMouseMove;
  23. }
  24. }
  25. }
  26. let zTreeOprObj = {
  27. treeObj: null,
  28. prjFolderTreeObj: null,
  29. currentNode: null,
  30. currentSelectedESignAccDom: null,
  31. currentSelectedESignAccName: null,
  32. checkedRptTplNodes: null,
  33. currentRptPageRst: null,
  34. defReportPageCfg: null,
  35. currentPage: 1,
  36. maxPages: 0,
  37. canvas: null,
  38. selectedPrjIDs: [],
  39. countChkedRptTpl: function () {
  40. let me = zTreeOprObj;
  41. if (me.treeObj) {
  42. me.checkedRptTplNodes = [];
  43. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  44. for (let node of chkNodes) {
  45. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  46. cnt++;
  47. me.checkedRptTplNodes.push(node);
  48. if (me.currentNode === node) hasCurrentNode = true;
  49. }
  50. }
  51. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  52. //这里根据实际需求再做处理
  53. cnt++;
  54. me.checkedRptTplNodes.push(me.currentNode);
  55. }
  56. $("#print_div").find("span").each(function(cIdx,elementSpan){
  57. elementSpan.innerText = cnt;
  58. });
  59. $("#export_div").find("span").each(function(cIdx,elementSpan){
  60. elementSpan.innerText = cnt;
  61. });
  62. }
  63. },
  64. getReportTemplateTree: function() {
  65. let me = zTreeOprObj;
  66. let private_remove_hide_item = function (items, nlv) {
  67. if (items && items.length > 0) {
  68. for (let i = items.length - 1; i >= 0; i--) {
  69. if (!(items[i].released) && items[i].nodeType === 2) {
  70. items.splice(i, 1);
  71. } else {
  72. if (items[i].items && items[i].items.length > 0) {
  73. private_remove_hide_item(items[i].items, nlv + 1);
  74. if (items[i].items.length === 0 && nlv > 0) {
  75. items.splice(i, 1);
  76. }
  77. }
  78. }
  79. }
  80. }
  81. };
  82. let nodeLv = 0;
  83. private_remove_hide_item(topTreeNodesValue, nodeLv);
  84. zTreeHelper.createTreeDirectly(topTreeNodesValue, rpt_tpl_setting, "rptTplTree", me);
  85. me.refreshNodes();
  86. },
  87. iniFontCfgDom: function (cfg) {
  88. for (let font of cfg.fonts) {
  89. let domArrs = [];
  90. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  91. domArrs.push("<div class='row mb-1'>");
  92. //1. label
  93. domArrs.push("<div class='col-3'>" + font.CfgDispName + "</div>");
  94. //2. font name
  95. domArrs.push("<div class='col-3'>");
  96. domArrs.push("<select class='form-control input-sm' id='fontName_" + fontPropSuffix + "' onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"Name\", this)'>");
  97. domArrs.push("<option>宋体</option><option>楷体</option><option>黑体</option>");
  98. domArrs.push("</select>");
  99. domArrs.push("</div>");
  100. //3. font height
  101. domArrs.push("<div class='col-3'>");
  102. domArrs.push("<input class='form-control input-sm' id='fontHeight_" + fontPropSuffix + "' type='number' value='30' step='1' min='6' max='66' " +
  103. "onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)' " +
  104. "onkeyup='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)'>");
  105. domArrs.push("</div>");
  106. //4. font bold italic underline
  107. domArrs.push("<div class='col-3'>");
  108. 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>");
  109. 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>");
  110. 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>");
  111. domArrs.push("</div>");
  112. //
  113. domArrs.push("</div>");
  114. $(domArrs.join("")).insertBefore($("#font_cfg_blank_flag"));
  115. }
  116. },
  117. renderRptCfg: function (cfg) {
  118. $("#elementMargin_Left").get(0).value = cfg.margins.Left;
  119. $("#elementMargin_Right").get(0).value = cfg.margins.Right;
  120. $("#elementMargin_Top").get(0).value = cfg.margins.Top;
  121. $("#elementMargin_Bottom").get(0).value = cfg.margins.Bottom;
  122. for (let font of cfg.fonts) {
  123. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  124. document.getElementById("fontName_" + fontPropSuffix).value = font.Name;
  125. document.getElementById("fontHeight_" + fontPropSuffix).value = font.FontHeight;
  126. document.getElementById("font_bold_" + fontPropSuffix).className = (font.FontBold === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  127. document.getElementById("font_italic_" + fontPropSuffix).className = (font.FontItalic === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  128. document.getElementById("font_underline_" + fontPropSuffix).className = (font.FontUnderline === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  129. }
  130. document.getElementById("rpt_vertical_line").checked = cfg.showVerticalLine;
  131. document.getElementById("rpt_narrow").checked = cfg.isNarrow;
  132. // document.getElementById("rpt_narrow").checked = false;
  133. document.getElementById("rpt_fill_zero").checked = cfg.fillZero;
  134. },
  135. extractRptCfg: function (cfg) {
  136. cfg.margins.Left = $("#elementMargin_Left").get(0).value;
  137. cfg.margins.Right = $("#elementMargin_Right").get(0).value;
  138. cfg.margins.Top = $("#elementMargin_Top").get(0).value;
  139. cfg.margins.Bottom = $("#elementMargin_Bottom").get(0).value;
  140. for (let font of cfg.fonts) {
  141. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  142. font.Name = document.getElementById("fontName_" + fontPropSuffix).value;
  143. font.FontHeight = document.getElementById("fontHeight_" + fontPropSuffix).value;
  144. font.FontBold = (document.getElementById("font_bold_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  145. font.FontItalic = (document.getElementById("font_italic_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  146. font.FontUnderline = (document.getElementById("font_underline_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  147. }
  148. cfg.showVerticalLine = document.getElementById("rpt_vertical_line").checked;
  149. cfg.isNarrow = document.getElementById("rpt_narrow").checked;
  150. cfg.fillZero = document.getElementById("rpt_fill_zero").checked;
  151. },
  152. refreshNodes: function() {
  153. let me = this;
  154. let private_setupIsParent = function(node){
  155. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  156. if (node.items && node.items.length) {
  157. for (let i = 0; i < node.items.length; i++) {
  158. private_setupIsParent(node.items[i]);
  159. }
  160. }
  161. };
  162. let topNodes = me.treeObj.getNodes();
  163. for (let i = 0; i < topNodes.length; i++) {
  164. private_setupIsParent(topNodes[i]);
  165. }
  166. me.treeObj.refresh();
  167. },
  168. onCheck: function(event, treeId, treeNode) {
  169. zTreeOprObj.countChkedRptTpl();
  170. },
  171. onClick: function(event,treeId,treeNode) {
  172. let me = zTreeOprObj;
  173. if (treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  174. me.currentNode = treeNode;
  175. let params = {};
  176. let pageSize = rptControlObj.getCurrentPageSize();
  177. params.pageSize = pageSize;
  178. params.rpt_tpl_id = treeNode.refId;
  179. params.project_id = PROJECT_ID;
  180. params.tender_id = TENDER_ID;
  181. params.stage_id = getStageId();
  182. params.stage_order = getStageOrder();
  183. params.stage_times = getStageTimes();
  184. params.custCfg = CUST_CFG;
  185. me.requestNormalReport(params);
  186. me.countChkedRptTpl();
  187. }
  188. },
  189. changePageSize: function(dom) {
  190. let me = zTreeOprObj,
  191. targetDom = document.getElementById("btnRptPageSize");
  192. let tmpStr = targetDom.innerHTML.trim();
  193. targetDom.innerHTML = dom.innerHTML.trim();
  194. dom.innerHTML = tmpStr;
  195. me.changeCfg();
  196. },
  197. changeOrientation: function(dom) {
  198. let me = zTreeOprObj,
  199. targetDom = document.getElementById("btnRptOrientation");
  200. let tmpStr = targetDom.innerHTML.trim();
  201. targetDom.innerHTML = dom.innerHTML.trim();
  202. dom.innerHTML = tmpStr;
  203. me.changeCfg();
  204. },
  205. changeCfg: function() {
  206. let me = zTreeOprObj;
  207. if (me.currentNode) {
  208. let params = {};
  209. params.pageSize = rptControlObj.getCurrentPageSize();
  210. params.orientation = rptControlObj.getCurrentOrientation();
  211. params.rpt_tpl_id = me.currentNode.refId;
  212. params.custCfg = CUST_CFG;
  213. params.project_id = PROJECT_ID;
  214. params.tender_id = TENDER_ID;
  215. params.stage_id = getStageId();
  216. params.stage_order = getStageOrder();
  217. params.stage_times = getStageTimes();
  218. me.requestNormalReport(params);
  219. }
  220. },
  221. resetAfter: function (pageRst) {
  222. let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
  223. if (size[0] > size[1]) {
  224. document.getElementById("btnRptOrientation").innerHTML = "横向";
  225. document.getElementById("hrefRptOrientation").innerHTML = "纵向";
  226. } else {
  227. document.getElementById("btnRptOrientation").innerHTML = "纵向";
  228. document.getElementById("hrefRptOrientation").innerHTML = "横向";
  229. }
  230. },
  231. requestNormalReport: function (params) {
  232. let me = zTreeOprObj;
  233. // hintBox.waitBox();
  234. CommonAjax.postXsrfEx("/tender/report_api/getReport", params, 60000, true, getCookie('csrfToken'),
  235. function(result){
  236. // hintBox.unWaitBox();
  237. let pageRst = result.data;
  238. let canvas = zTreeOprObj.canvas;
  239. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  240. me.resetAfter(pageRst);
  241. me.currentRptPageRst = pageRst;
  242. me.maxPages = pageRst.items.length;
  243. me.currentPage = 1;
  244. me.displayPageValue();
  245. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  246. canvas.width = size[0] + 20;
  247. if (size[1] > size[0]) {
  248. canvas.height = size[1] + 100;
  249. } else {
  250. canvas.height = size[1] + 50;
  251. }
  252. me.resetESignature(pageRst);
  253. me.buildSelectableAccount();
  254. me.showPage(1, canvas);
  255. } else {
  256. //返回了无数据表
  257. JpcCanvasOutput.cleanCanvas(canvas);
  258. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  259. }
  260. }, function(err){
  261. // hintBox.unWaitBox();
  262. }, function(ex){
  263. // hintBox.unWaitBox();
  264. }
  265. );
  266. },
  267. resetESignature: function (pageRst) {
  268. let body = $('#eSignatureBodyDiv');
  269. body.empty();
  270. const signature_cells = [];
  271. const singatureNameArr = [];
  272. for (const page of pageRst.items) {
  273. if (page.signature_cells) {
  274. for (const sCell of page.signature_cells) {
  275. if (singatureNameArr.indexOf(sCell.signature_name) < 0) {
  276. signature_cells.push(sCell);
  277. singatureNameArr.push(sCell.signature_name);
  278. }
  279. }
  280. }
  281. }
  282. if (signature_cells.length > 0) {
  283. const elementsStrArr = [];
  284. for (const sCell of signature_cells) {
  285. elementsStrArr.push('<div class="form-group row">');
  286. elementsStrArr.push('<label for="staticEmail" class="col-sm-3 col-form-label pr-0">' + sCell.signature_name + '</label>');
  287. elementsStrArr.push('<div class="col-sm-9">');
  288. elementsStrArr.push('<ul class="list-group">');
  289. elementsStrArr.push('<li class="list-group-item">');
  290. if (sCell.path || sCell.pic) {
  291. //
  292. } else {
  293. elementsStrArr.push('<a href="#add-sign" onclick="zTreeOprObj.currentSelectedESignAccDom = this; zTreeOprObj.currentSelectedESignAccName = \'' + sCell.signature_name + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  294. }
  295. elementsStrArr.push('</li>');
  296. elementsStrArr.push('</ul>');
  297. elementsStrArr.push('</div>');
  298. elementsStrArr.push('</div>');
  299. }
  300. body.append(elementsStrArr.join(' '));
  301. }
  302. },
  303. buildSelectableAccount: function () {
  304. //PRJ_ACCOUNT_LIST
  305. //1. 清理所有选择项
  306. // $("#project_account_select_div").empty();
  307. let accDiv = $('#project_account_select_div');
  308. accDiv.empty();
  309. //2. 一个个加可选用户项
  310. const prj_accounts = [];
  311. const acc_role_keys = [];
  312. for (const prjAccount of PRJ_ACCOUNT_LIST) {
  313. let companyKey = prjAccount.company;
  314. let roleKey = prjAccount.role;
  315. if (companyKey === '') {
  316. companyKey = '其他单位';
  317. }
  318. if (roleKey === '') {
  319. roleKey = '工程师';
  320. }
  321. let keyIdx = acc_role_keys.indexOf(companyKey);
  322. if (keyIdx < 0) {
  323. acc_role_keys.push(companyKey);
  324. prj_accounts.push([]);
  325. keyIdx = prj_accounts.length - 1;
  326. //这里先push一些 html prefix,在后面统一在push html suffix
  327. prj_accounts[keyIdx].push('<ul class="list-group">');
  328. prj_accounts[keyIdx].push('<li class="px-2 text-muted"><i class="fa fa-caret-down"></i> ' + companyKey + '</li>');
  329. }
  330. //push item
  331. prj_accounts[keyIdx].push('<li class="add-sign-list-item"><a onclick="zTreeOprObj.drawEsignature(' + keyIdx + ')" class="btn-link pull-right" title="添加" data-dismiss="modal"><i class="fa fa-plus"></i></a>' +
  332. prjAccount.name + '-<small class="text-muted">' + roleKey + '</small></li>');
  333. }
  334. for (const prjAccList of prj_accounts) {
  335. prjAccList.push('</ul>');
  336. }
  337. for (let idx = 0; idx < prj_accounts.length; idx++) {
  338. prj_accounts[idx] = prj_accounts[idx].join('');
  339. }
  340. accDiv.append(prj_accounts.join(''));
  341. },
  342. drawEsignature: function (accIdx) {
  343. let dftSignSrc = '/public/images/user-sign.PNG';
  344. if (PRJ_ACCOUNT_LIST[accIdx].sign_path !== '') {
  345. dftSignSrc = PRJ_ACCOUNT_LIST[accIdx].sign_path;
  346. }
  347. //找到相关签名地方,stamp!
  348. if (zTreeOprObj.currentSelectedESignAccName !== null) {
  349. for (const page of zTreeOprObj.currentRptPageRst.items) {
  350. if (page.signature_cells) {
  351. for (const sCell of page.signature_cells) {
  352. if (sCell.signature_name === zTreeOprObj.currentSelectedESignAccName) {
  353. sCell.path = dftSignSrc;
  354. }
  355. }
  356. }
  357. }
  358. // 1. 删除不需要的child dom
  359. let list = zTreeOprObj.currentSelectedESignAccDom.childNodes;
  360. if (list && list.length > 0) {
  361. for (let domIdx = list.length - 1; domIdx >= 0; domIdx--) {
  362. zTreeOprObj.currentSelectedESignAccDom.removeChild(list[domIdx]);
  363. }
  364. }
  365. // 2. 创建已选择签名相关 dom
  366. // let newDomArr = [];
  367. // 2.1 canvas
  368. let canvasNode = document.createElement("CANVAS");
  369. canvasNode.height = "30";
  370. canvasNode.style = "width: 100%";
  371. //newDomArr.push('<canvas height="30" style="width: 100%"></canvas>');
  372. zTreeOprObj.currentSelectedESignAccDom.appendChild(canvasNode);
  373. let imgObj = new Image();
  374. imgObj.src = dftSignSrc;
  375. imgObj.onload = function(){
  376. let ctx = canvasNode.getContext('2d');
  377. ctx.drawImage(this, 0, 0, 60, 30);
  378. }
  379. // 2.2 date-picker
  380. }
  381. },
  382. scaleReport: function (accScale) {
  383. let me = zTreeOprObj;
  384. let canvas = zTreeOprObj.canvas;
  385. if (accScale !== 0) {
  386. JpcCanvasOutput.scaleFactor += accScale;
  387. if (JpcCanvasOutput.scaleFactor < 0.5) JpcCanvasOutput.scaleFactor = 0.5;
  388. if (JpcCanvasOutput.scaleFactor > 1.5) JpcCanvasOutput.scaleFactor = 1.5;
  389. } else {
  390. JpcCanvasOutput.scaleFactor = 1;
  391. }
  392. document.getElementById("btnNormalScale").innerText = (JpcCanvasOutput.scaleFactor * 100) + '%';
  393. me.showPage(me.currentPage, canvas);
  394. },
  395. requestPrjFolderCommon: function () {
  396. //
  397. },
  398. showPage: function (pageNum, canvas) {
  399. let me = zTreeOprObj;
  400. if (pageNum >= 1 && pageNum <= me.maxPages) {
  401. me.currentPage = pageNum;
  402. JpcCanvasOutput.cleanCanvas(canvas);
  403. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  404. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  405. }
  406. me.displayPageValue();
  407. },
  408. displayPageValue: function() {
  409. let me = zTreeOprObj;
  410. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  411. }
  412. };
  413. let canvasOprObj = {
  414. canvasOnMouseMove: 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 < FIRST_PAGE_OFFSET) {
  419. canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
  420. } else if (x < PRE_PAGE_OFFSET) {
  421. canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
  422. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  423. canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
  424. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  425. canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
  426. } else {
  427. canvas.style.cursor = "";
  428. }
  429. }
  430. },
  431. canvasOnClick: function(event){
  432. if (zTreeOprObj.currentNode) {
  433. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  434. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  435. if (x < FIRST_PAGE_OFFSET) {
  436. zTreeOprObj.showPage(1, canvas);
  437. } else if (x < PRE_PAGE_OFFSET) {
  438. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  439. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  440. zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
  441. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  442. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  443. }
  444. }
  445. }
  446. };
  447. let rptControlObj = {
  448. currentOutputType: "Excel",
  449. currentDownloadUrl: null,
  450. currentDownloadIdx: 0,
  451. getCurrentPageSize: function() {
  452. // let rst = "A4";
  453. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  454. //btnRptPageSize
  455. return rst;
  456. },
  457. getCurrentOrientation: function() {
  458. // let rst = "横向";
  459. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  460. return rst;
  461. },
  462. getCurrentReportOption: function() {
  463. //
  464. },
  465. changeType: function(newType) {
  466. let me = rptControlObj;
  467. let excelDom = document.getElementById("EXCEL_TYPE");
  468. let pdfDom = document.getElementById("PDF_TYPE");
  469. if (newType === "Excel") {
  470. excelDom.className = "btn btn-block btn-primary";
  471. pdfDom.className = "btn btn-block btn-outline-secondary";
  472. me.currentOutputType = newType;
  473. } else if (newType === "PDF") {
  474. excelDom.className = "btn btn-block btn-outline-secondary";
  475. pdfDom.className = "btn btn-block btn-primary";
  476. me.currentOutputType = newType;
  477. } else {
  478. //me.currentOutputType = newType;
  479. }
  480. },
  481. outputRpt: function() {
  482. let me = rptControlObj;
  483. if (me.currentOutputType === "Excel") {
  484. me.getExcel();
  485. } else if (me.currentOutputType === "PDF") {
  486. me.getPDF();
  487. } else {
  488. //other types if needed.
  489. }
  490. },
  491. getTplIdsCommon: function (refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names) {
  492. for (let node of zTreeOprObj.checkedRptTplNodes) {
  493. if (node.hasOwnProperty('flags') && node.flags.hasOwnProperty('reportType') && node['flags']['reportType'] !== 'NA') {
  494. if (node['flags']['reportType'] === 'billSummary') {
  495. refBillSumPrjsIds.push(node.refId);
  496. if (bill_rpt_names) bill_rpt_names.push(node.name);
  497. } else if (node['flags']['reportType'] === 'gljSummary') {
  498. refGljSumPrjsIds.push(node.refId);
  499. if (glj_rpt_names) glj_rpt_names.push(node.name);
  500. }
  501. } else {
  502. refRptTplIds.push(node.refId);
  503. if (rpt_names) rpt_names.push(node.name);
  504. }
  505. }
  506. },
  507. creatCommonExportParam: function (refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds) {
  508. let nodes = (zTreeOprObj.prjFolderTreeObj === null)?[]:zTreeOprObj.prjFolderTreeObj.getCheckedNodes(true);
  509. let rst = {};
  510. rst.prj_id = projectObj.project.projectInfo.ID;
  511. rst.rpt_ids = refRptTplIds;
  512. rst.rpt_bill_tpl_ids = refBillSumPrjsIds;
  513. rst.rpt_glj_tpl_ids = refGljSumPrjsIds;
  514. rst.prjIds = [];
  515. zTreeOprObj.selectedPrjIDs = [];
  516. for (let node of nodes) {
  517. rst.prjIds.push(node.ID);
  518. zTreeOprObj.selectedPrjIDs.push(node.ID);
  519. }
  520. // rst.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  521. // rst.rpt_names = rpt_names;
  522. // rst.isOneSheet = true;
  523. rst.pageSize = rptControlObj.getCurrentPageSize();
  524. rst.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  525. rst.custCfg = CUST_CFG;
  526. rst.option = "normal";
  527. return rst;
  528. },
  529. getAllInOneBook: function () {
  530. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  531. let me = rptControlObj;
  532. let orgRptName = projectObj.project.projectInfo.name;
  533. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  534. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  535. if (zTreeOprObj.selectedPrjIDs.length > 0 && (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0)) {
  536. let params = rptControlObj.creatCommonExportParam(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  537. params.rptName = orgRptName;
  538. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  539. if (result) {
  540. let uuIdUrls = [];
  541. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  542. uuIdUrls.push(uuIdUrl);
  543. downloadReport(uuIdUrls);
  544. } else {
  545. //
  546. }
  547. }, null, null
  548. );
  549. } else {
  550. let params = {};
  551. params.prj_id = PROJECT_ID;
  552. params.rpt_ids = refRptTplIds;
  553. params.rptName = orgRptName;
  554. params.pageSize = me.getCurrentPageSize();
  555. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  556. params.custCfg = CUST_CFG;
  557. params.option = "normal";
  558. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  559. if (result) {
  560. let uuIdUrls = [];
  561. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  562. uuIdUrls.push(uuIdUrl);
  563. downloadReport(uuIdUrls);
  564. } else {
  565. //
  566. }
  567. }, null, null
  568. );
  569. }
  570. }
  571. },
  572. getAllIndividualExcelBook: function () {
  573. let me = rptControlObj;
  574. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  575. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  576. let rpt_names = [], bill_rpt_names = [], glj_rpt_names = [];
  577. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names);
  578. if (zTreeOprObj.selectedPrjIDs.length > 0 && (glj_rpt_names.length > 0 || bill_rpt_names.length > 0)) {
  579. let params = rptControlObj.creatCommonExportParam(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  580. params.prj_id = PROJECT_ID;
  581. params.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  582. params.rpt_names = rpt_names;
  583. params.isOneSheet = true;
  584. params.rptName = projectObj.project.projectInfo.name;
  585. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  586. if (result) {
  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. //
  595. }
  596. }, null, null
  597. );
  598. } else {
  599. if (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0) {
  600. $("#divReqBillSummary")[0].style.display = "none";
  601. $("#divReqGljSummary")[0].style.display = "none";
  602. $("#divReqCommonSummaryExcel")[0].style.display = "none";
  603. $("#divReqCommonSummaryMultiExcel")[0].style.display = "";
  604. $("#divReqCommonSummaryPDF")[0].style.display = "none";
  605. zTreeOprObj.requestPrjFolderCommon(); //先处理需要汇总的报表,走另外一个分支
  606. } else if (refRptTplIds.length > 0) {
  607. let params = {};
  608. params.prj_id = PROJECT_ID;
  609. params.rpt_ids = refRptTplIds;
  610. params.rpt_names = rpt_names;
  611. params.pageSize = me.getCurrentPageSize();
  612. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  613. params.isOneSheet = true;
  614. params.custCfg = CUST_CFG;
  615. params.option = "normal";
  616. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  617. if (result) {
  618. let uuIdUrls = [];
  619. for (let uuIdObj of result) {
  620. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  621. uuIdUrls.push(uuIdUrl);
  622. }
  623. downloadReport(uuIdUrls);
  624. } else {
  625. //
  626. }
  627. }, null, null
  628. );
  629. }
  630. }
  631. }
  632. },
  633. checkAndGetExcel: function () {
  634. if (zTreeOprObj.treeObj) {
  635. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  636. if (chkNodes.length > 0) {
  637. $("#show_excel_output_cfg").trigger("click");
  638. } else {
  639. rptControlObj.getAllIndividualExcelBook();
  640. }
  641. }
  642. },
  643. getExcel: function () {
  644. let me = rptControlObj;
  645. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  646. me.getAllInOneBook();
  647. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  648. me.getAllIndividualExcelBook();
  649. }
  650. },
  651. getPDF: function () {
  652. let me = rptControlObj;
  653. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  654. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  655. let rpt_names = [], bill_rpt_names = [], glj_rpt_names = [];
  656. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names);
  657. if (zTreeOprObj.selectedPrjIDs.length > 0 && (glj_rpt_names.length > 0 || bill_rpt_names.length > 0)) {
  658. let params = rptControlObj.creatCommonExportParam();
  659. params.prj_id = PROJECT_ID;
  660. params.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  661. params.rpt_ids = refRptTplIds;
  662. params.rpt_bill_tpl_ids = refBillSumPrjsIds;
  663. params.rpt_glj_tpl_ids = refGljSumPrjsIds;
  664. params.rpt_names = rpt_names;
  665. params.isOneSheet = true;
  666. params.rptName = projectObj.project.projectInfo.name;
  667. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  668. if (result) {
  669. let uuIdUrls = [];
  670. for (let uuIdObj of result) {
  671. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  672. uuIdUrls.push(uuIdUrl);
  673. }
  674. downloadReport(uuIdUrls);
  675. } else {
  676. //
  677. }
  678. }, null, null
  679. );
  680. } else {
  681. if (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0) {
  682. $("#divReqBillSummary")[0].style.display = "none";
  683. $("#divReqGljSummary")[0].style.display = "none";
  684. $("#divReqCommonSummaryExcel")[0].style.display = "none";
  685. $("#divReqCommonSummaryMultiExcel")[0].style.display = "none";
  686. $("#divReqCommonSummaryPDF")[0].style.display = "";
  687. zTreeOprObj.requestPrjFolderCommon(); //先处理需要汇总的报表,走另外一个分支
  688. } else if (refRptTplIds.length > 0) {
  689. let params = {};
  690. params.prj_id = PROJECT_ID;
  691. params.rpt_ids = refRptTplIds;
  692. params.rpt_names = rpt_names;
  693. params.pageSize = me.getCurrentPageSize();
  694. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  695. params.custCfg = CUST_CFG;
  696. params.option = "normal";
  697. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  698. if (result) {
  699. let uuIdUrls = [];
  700. for (let uuIdObj of result) {
  701. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  702. uuIdUrls.push(uuIdUrl);
  703. }
  704. downloadReport(uuIdUrls);
  705. } else {
  706. //
  707. }
  708. }, null, null
  709. );
  710. }
  711. }
  712. }
  713. },
  714. firstPage: function(dom) {
  715. zTreeOprObj.showPage(1, zTreeOprObj.canvas);
  716. },
  717. prePage: function(dom) {
  718. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, zTreeOprObj.canvas);
  719. },
  720. nextPage: function(dom) {
  721. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, zTreeOprObj.canvas);
  722. },
  723. lastPage: function(dom) {
  724. let me = zTreeOprObj;
  725. zTreeOprObj.showPage(me.maxPages, zTreeOprObj.canvas);
  726. },
  727. onKeydown: function (event, dom) {
  728. let me = zTreeOprObj, keyPressed = null;
  729. if (window.event) {
  730. keyPressed = window.event.keyCode; // IE/Chrome
  731. } else {
  732. keyPressed = event.which; // Firefox
  733. }
  734. if (keyPressed === 13) {
  735. let pageNum = 1;
  736. try {
  737. pageNum = parseInt(dom.value);
  738. } catch (e) {
  739. pageNum = 1;
  740. }
  741. if (pageNum < 1) {
  742. pageNum = 1;
  743. } else if (pageNum > me.maxPages) {
  744. pageNum = me.maxPages;
  745. }
  746. zTreeOprObj.showPage(pageNum, zTreeOprObj.canvas);
  747. return false;
  748. }
  749. },
  750. changeMargin: function(marginPropStr, marginDom) {
  751. CUST_CFG.margins[marginPropStr] = marginDom.value;
  752. },
  753. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  754. for (let font of CUST_CFG.fonts) {
  755. if (font["CfgDispName"] === CfgDispName) {
  756. font[fontProperty] = fontDom.value;
  757. break;
  758. }
  759. }
  760. },
  761. changeCfgOption: function (optStr, dom) {
  762. CUST_CFG[optStr] = dom.checked;
  763. },
  764. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  765. for (let font of CUST_CFG.fonts) {
  766. if (font["CfgDispName"] === CfgDispName) {
  767. if (font[fontProperty] === 'T') {
  768. font[fontProperty] = 'F';
  769. fontDom.className = "btn btn-sm btn-outline-secondary";
  770. } else {
  771. font[fontProperty] = 'T';
  772. fontDom.className = "btn btn-sm btn-outline-secondary active";
  773. }
  774. break;
  775. }
  776. }
  777. },
  778. restoreCustCFG: function () {
  779. let me = this;
  780. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  781. zTreeOprObj.extractRptCfg(CUST_CFG);
  782. me.saveCustCfg();
  783. },
  784. saveCustCfg: function() {
  785. let params = {};
  786. params.custCfg = CUST_CFG;
  787. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  788. // alert("Save successfully!");
  789. $("#update_msg_response")[0].style.color = "green";
  790. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  791. setTimeout(function(){
  792. $("#update_msg_response")[0].innerHTML = "";
  793. }, 1000);
  794. }, function (failRst) {
  795. $("#update_msg_response")[0].style.color = "red";
  796. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  797. setTimeout(function(){
  798. $("#update_msg_response")[0].innerHTML = "";
  799. }, 1000);
  800. }, null
  801. );
  802. },
  803. confirmCfgChange: function() {
  804. zTreeOprObj.changeCfg();
  805. }
  806. };
  807. function downloadReport(urls) {
  808. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  809. rptControlObj.currentDownloadUrl = null;
  810. rptControlObj.currentDownloadIdx = 0;
  811. let private_download = function() {
  812. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  813. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  814. rptControlObj.currentDownloadIdx++;
  815. window.location = rptControlObj.currentDownloadUrl;
  816. setTimeout(private_download, 2000);
  817. }
  818. }
  819. private_download();
  820. }
  821. function getStageId() {
  822. return current_stage_id;
  823. }
  824. function getStageOrder() {
  825. return current_stage_order;
  826. }
  827. function getStageTimes() {
  828. return current_stage_times;
  829. }