rpt_main.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  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. const canvasWidth = 60;
  285. const canvasHeight = 30;
  286. for (let scIdx = 0; scIdx < signature_cells.length; scIdx++) {
  287. const sCell = signature_cells[scIdx];
  288. elementsStrArr.push('<div class="form-group row">');
  289. elementsStrArr.push('<label for="staticEmail" class="col-sm-3 col-form-label pr-0">' + sCell.signature_name + '</label>');
  290. elementsStrArr.push('<div class="col-sm-9">');
  291. elementsStrArr.push('<ul class="list-group">');
  292. elementsStrArr.push('<li class="list-group-item">');
  293. if (sCell.path || sCell.pic) {
  294. elementsStrArr.push('<p class=" d-flex justify-content-between m-0"><canvas id="signCanvas' + scIdx + '" width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas><a onclick="zTreeOprObj.removeSignature(this)" class="text-danger"><i class="fa fa-remove" title="移除签名"></i></a></p>');
  295. let imgObj = new Image();
  296. if (sCell.path) {
  297. imgObj.src = sCell.path;
  298. } else {
  299. imgObj.src = sCell.pic;
  300. }
  301. imgObj.onload = function(){
  302. let canvasNode = document.getElementById('signCanvas' + scIdx);
  303. let ctx = canvasNode.getContext('2d');
  304. ctx.drawImage(this, 0, 0, canvasWidth, canvasHeight);
  305. }
  306. } else {
  307. elementsStrArr.push('<a href="#add-sign" onclick="zTreeOprObj.currentSelectedESignAccDom = this.parentNode; zTreeOprObj.currentSelectedESignAccName = \'' + sCell.signature_name + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  308. }
  309. elementsStrArr.push('</li>');
  310. elementsStrArr.push('</ul>');
  311. elementsStrArr.push('</div>');
  312. elementsStrArr.push('</div>');
  313. }
  314. body.append(elementsStrArr.join(' '));
  315. }
  316. },
  317. buildSelectableAccount: function () {
  318. //PRJ_ACCOUNT_LIST
  319. //1. 清理所有选择项
  320. // $("#project_account_select_div").empty();
  321. let accDiv = $('#project_account_select_div');
  322. accDiv.empty();
  323. //2. 一个个加可选用户项
  324. const prj_accounts = [];
  325. const acc_role_keys = [];
  326. for (const prjAccount of PRJ_ACCOUNT_LIST) {
  327. let companyKey = prjAccount.company;
  328. let roleKey = prjAccount.role;
  329. if (companyKey === '') {
  330. companyKey = '其他单位';
  331. }
  332. if (roleKey === '') {
  333. roleKey = '工程师';
  334. }
  335. let keyIdx = acc_role_keys.indexOf(companyKey);
  336. if (keyIdx < 0) {
  337. acc_role_keys.push(companyKey);
  338. prj_accounts.push([]);
  339. keyIdx = prj_accounts.length - 1;
  340. //这里先push一些 html prefix,在后面统一在push html suffix
  341. prj_accounts[keyIdx].push('<ul class="list-group">');
  342. prj_accounts[keyIdx].push('<li class="px-2 text-muted"><i class="fa fa-caret-down"></i> ' + companyKey + '</li>');
  343. }
  344. //push item
  345. 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>' +
  346. prjAccount.name + '-<small class="text-muted">' + roleKey + '</small></li>');
  347. }
  348. for (const prjAccList of prj_accounts) {
  349. prjAccList.push('</ul>');
  350. }
  351. for (let idx = 0; idx < prj_accounts.length; idx++) {
  352. prj_accounts[idx] = prj_accounts[idx].join('');
  353. }
  354. accDiv.append(prj_accounts.join(''));
  355. },
  356. drawEsignature: function (accIdx) {
  357. let dftSignSrc = '/public/images/user-sign.PNG';
  358. if (PRJ_ACCOUNT_LIST[accIdx].sign_path !== '') {
  359. dftSignSrc = PRJ_ACCOUNT_LIST[accIdx].sign_path;
  360. }
  361. //找到相关签名地方,stamp!
  362. if (zTreeOprObj.currentSelectedESignAccName !== null) {
  363. for (const page of zTreeOprObj.currentRptPageRst.items) {
  364. if (page.signature_cells) {
  365. for (const sCell of page.signature_cells) {
  366. if (sCell.signature_name === zTreeOprObj.currentSelectedESignAccName) {
  367. sCell.pre_path = dftSignSrc;
  368. }
  369. }
  370. }
  371. }
  372. // 1. 删除不需要的child dom
  373. let list = zTreeOprObj.currentSelectedESignAccDom.childNodes;
  374. if (list && list.length > 0) {
  375. for (let domIdx = list.length - 1; domIdx >= 0; domIdx--) {
  376. zTreeOprObj.currentSelectedESignAccDom.removeChild(list[domIdx]);
  377. }
  378. }
  379. // 2. 创建已选择签名相关 dom
  380. const canvasWidth = 60;
  381. const canvasHeight = 30;
  382. // 2.1 canvas / X
  383. const elementsStrArr = [];
  384. elementsStrArr.push('<p class=" d-flex justify-content-between m-0"><canvas id="signCanvas' + accIdx + '" width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas><a onclick="zTreeOprObj.removeSignature(this)" class="text-danger"><i class="fa fa-remove" title="移除签名"></i></a></p>');
  385. let imgObj = new Image();
  386. imgObj.src = dftSignSrc;
  387. imgObj.onload = function(){
  388. let canvasNode = document.getElementById('signCanvas' + accIdx);
  389. let ctx = canvasNode.getContext('2d');
  390. ctx.drawImage(this, 0, 0, canvasWidth, canvasHeight);
  391. }
  392. //.appendChild(pNode);
  393. $(zTreeOprObj.currentSelectedESignAccDom).append(elementsStrArr.join(' '));
  394. //*/
  395. // 2.2 date-picker
  396. }
  397. },
  398. removeSignature: function (dom) {
  399. let accTxtName = $(dom.parentNode.parentNode.parentNode.parentNode.parentNode).find('label')[0].innerText;
  400. let jDom = $(dom.parentNode.parentNode);
  401. jDom.empty();
  402. jDom.append('<a href="#add-sign" onclick="zTreeOprObj.currentSelectedESignAccDom = dom.parentNode; zTreeOprObj.currentSelectedESignAccName = \'' +
  403. accTxtName + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  404. //要记得清空相关pre_path属性
  405. for (const page of zTreeOprObj.currentRptPageRst.items) {
  406. if (page.signature_cells) {
  407. for (const sCell of page.signature_cells) {
  408. if (sCell.signature_name === accTxtName) {
  409. sCell.pre_path = '';
  410. }
  411. }
  412. }
  413. }
  414. },
  415. removeSelectSignature: function () {
  416. for (const page of zTreeOprObj.currentRptPageRst.items) {
  417. if (page.signature_cells) {
  418. for (const sCell of page.signature_cells) {
  419. if (sCell.hasOwnProperty('pre_path')) {
  420. delete sCell.pre_path;
  421. }
  422. }
  423. }
  424. }
  425. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  426. },
  427. setupAfterSelectSignature: function () {
  428. for (const page of zTreeOprObj.currentRptPageRst.items) {
  429. if (page.signature_cells) {
  430. for (const sCell of page.signature_cells) {
  431. if (sCell.hasOwnProperty('pre_path')) {
  432. sCell.path = sCell.pre_path;
  433. delete sCell.pre_path;
  434. }
  435. }
  436. }
  437. }
  438. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  439. },
  440. scaleReport: function (accScale) {
  441. let me = zTreeOprObj;
  442. let canvas = zTreeOprObj.canvas;
  443. if (accScale !== 0) {
  444. JpcCanvasOutput.scaleFactor += accScale;
  445. if (JpcCanvasOutput.scaleFactor < 0.5) JpcCanvasOutput.scaleFactor = 0.5;
  446. if (JpcCanvasOutput.scaleFactor > 1.5) JpcCanvasOutput.scaleFactor = 1.5;
  447. } else {
  448. JpcCanvasOutput.scaleFactor = 1;
  449. }
  450. document.getElementById("btnNormalScale").innerText = (JpcCanvasOutput.scaleFactor * 100) + '%';
  451. me.showPage(me.currentPage, canvas);
  452. },
  453. requestPrjFolderCommon: function () {
  454. //
  455. },
  456. showPage: function (pageNum, canvas) {
  457. let me = zTreeOprObj;
  458. if (pageNum >= 1 && pageNum <= me.maxPages) {
  459. me.currentPage = pageNum;
  460. JpcCanvasOutput.cleanCanvas(canvas);
  461. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  462. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  463. }
  464. me.displayPageValue();
  465. },
  466. displayPageValue: function() {
  467. let me = zTreeOprObj;
  468. $("#rpt_page_num").get(0).value = me.currentPage + "/" + me.maxPages;
  469. }
  470. };
  471. let canvasOprObj = {
  472. canvasOnMouseMove: function (event) {
  473. if (zTreeOprObj.currentNode) {
  474. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  475. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  476. if (x < FIRST_PAGE_OFFSET) {
  477. canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
  478. } else if (x < PRE_PAGE_OFFSET) {
  479. canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
  480. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  481. canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
  482. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  483. canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
  484. } else {
  485. canvas.style.cursor = "";
  486. }
  487. }
  488. },
  489. canvasOnClick: function(event){
  490. if (zTreeOprObj.currentNode) {
  491. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  492. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  493. if (x < FIRST_PAGE_OFFSET) {
  494. zTreeOprObj.showPage(1, canvas);
  495. } else if (x < PRE_PAGE_OFFSET) {
  496. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  497. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  498. zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
  499. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  500. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  501. }
  502. }
  503. }
  504. };
  505. let rptControlObj = {
  506. currentOutputType: "Excel",
  507. currentDownloadUrl: null,
  508. currentDownloadIdx: 0,
  509. getCurrentPageSize: function() {
  510. // let rst = "A4";
  511. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  512. //btnRptPageSize
  513. return rst;
  514. },
  515. getCurrentOrientation: function() {
  516. // let rst = "横向";
  517. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  518. return rst;
  519. },
  520. getCurrentReportOption: function() {
  521. //
  522. },
  523. changeType: function(newType) {
  524. let me = rptControlObj;
  525. let excelDom = document.getElementById("EXCEL_TYPE");
  526. let pdfDom = document.getElementById("PDF_TYPE");
  527. if (newType === "Excel") {
  528. excelDom.className = "btn btn-block btn-primary";
  529. pdfDom.className = "btn btn-block btn-outline-secondary";
  530. me.currentOutputType = newType;
  531. } else if (newType === "PDF") {
  532. excelDom.className = "btn btn-block btn-outline-secondary";
  533. pdfDom.className = "btn btn-block btn-primary";
  534. me.currentOutputType = newType;
  535. } else {
  536. //me.currentOutputType = newType;
  537. }
  538. },
  539. outputRpt: function() {
  540. let me = rptControlObj;
  541. if (me.currentOutputType === "Excel") {
  542. me.getExcel();
  543. } else if (me.currentOutputType === "PDF") {
  544. me.getPDF();
  545. } else {
  546. //other types if needed.
  547. }
  548. },
  549. getTplIdsCommon: function (refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names) {
  550. for (let node of zTreeOprObj.checkedRptTplNodes) {
  551. if (node.hasOwnProperty('flags') && node.flags.hasOwnProperty('reportType') && node['flags']['reportType'] !== 'NA') {
  552. if (node['flags']['reportType'] === 'billSummary') {
  553. refBillSumPrjsIds.push(node.refId);
  554. if (bill_rpt_names) bill_rpt_names.push(node.name);
  555. } else if (node['flags']['reportType'] === 'gljSummary') {
  556. refGljSumPrjsIds.push(node.refId);
  557. if (glj_rpt_names) glj_rpt_names.push(node.name);
  558. }
  559. } else {
  560. refRptTplIds.push(node.refId);
  561. if (rpt_names) rpt_names.push(node.name);
  562. }
  563. }
  564. },
  565. creatCommonExportParam: function (refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds) {
  566. let nodes = (zTreeOprObj.prjFolderTreeObj === null)?[]:zTreeOprObj.prjFolderTreeObj.getCheckedNodes(true);
  567. let rst = {};
  568. rst.prj_id = projectObj.project.projectInfo.ID;
  569. rst.rpt_ids = refRptTplIds;
  570. rst.rpt_bill_tpl_ids = refBillSumPrjsIds;
  571. rst.rpt_glj_tpl_ids = refGljSumPrjsIds;
  572. rst.prjIds = [];
  573. zTreeOprObj.selectedPrjIDs = [];
  574. for (let node of nodes) {
  575. rst.prjIds.push(node.ID);
  576. zTreeOprObj.selectedPrjIDs.push(node.ID);
  577. }
  578. // rst.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  579. // rst.rpt_names = rpt_names;
  580. // rst.isOneSheet = true;
  581. rst.pageSize = rptControlObj.getCurrentPageSize();
  582. rst.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  583. rst.custCfg = CUST_CFG;
  584. rst.option = "normal";
  585. return rst;
  586. },
  587. getAllInOneBook: function () {
  588. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  589. let me = rptControlObj;
  590. let orgRptName = projectObj.project.projectInfo.name;
  591. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  592. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  593. if (zTreeOprObj.selectedPrjIDs.length > 0 && (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0)) {
  594. let params = rptControlObj.creatCommonExportParam(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  595. params.rptName = orgRptName;
  596. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  597. if (result) {
  598. let uuIdUrls = [];
  599. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  600. uuIdUrls.push(uuIdUrl);
  601. downloadReport(uuIdUrls);
  602. } else {
  603. //
  604. }
  605. }, null, null
  606. );
  607. } else {
  608. let params = {};
  609. params.prj_id = PROJECT_ID;
  610. params.rpt_ids = refRptTplIds;
  611. params.rptName = orgRptName;
  612. params.pageSize = me.getCurrentPageSize();
  613. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  614. params.custCfg = CUST_CFG;
  615. params.option = "normal";
  616. CommonAjax.postEx("report_api/createExcelFilesInOneBook", params, WAIT_TIME_EXPORT, true, function(result){
  617. if (result) {
  618. let uuIdUrls = [];
  619. let uuIdUrl = "/report_api/getFileByUUID/" + result.uuid + "/" + stringUtil.replaceAll(result.reportName, "#", "_") + "/xlsx";
  620. uuIdUrls.push(uuIdUrl);
  621. downloadReport(uuIdUrls);
  622. } else {
  623. //
  624. }
  625. }, null, null
  626. );
  627. }
  628. }
  629. },
  630. getAllIndividualExcelBook: function () {
  631. let me = rptControlObj;
  632. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  633. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  634. let rpt_names = [], bill_rpt_names = [], glj_rpt_names = [];
  635. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names);
  636. if (zTreeOprObj.selectedPrjIDs.length > 0 && (glj_rpt_names.length > 0 || bill_rpt_names.length > 0)) {
  637. let params = rptControlObj.creatCommonExportParam(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds);
  638. params.prj_id = PROJECT_ID;
  639. params.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  640. params.rpt_names = rpt_names;
  641. params.isOneSheet = true;
  642. params.rptName = projectObj.project.projectInfo.name;
  643. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  644. if (result) {
  645. let uuIdUrls = [];
  646. for (let uuIdObj of result) {
  647. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  648. uuIdUrls.push(uuIdUrl);
  649. }
  650. downloadReport(uuIdUrls);
  651. } else {
  652. //
  653. }
  654. }, null, null
  655. );
  656. } else {
  657. if (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0) {
  658. $("#divReqBillSummary")[0].style.display = "none";
  659. $("#divReqGljSummary")[0].style.display = "none";
  660. $("#divReqCommonSummaryExcel")[0].style.display = "none";
  661. $("#divReqCommonSummaryMultiExcel")[0].style.display = "";
  662. $("#divReqCommonSummaryPDF")[0].style.display = "none";
  663. zTreeOprObj.requestPrjFolderCommon(); //先处理需要汇总的报表,走另外一个分支
  664. } else if (refRptTplIds.length > 0) {
  665. let params = {};
  666. params.prj_id = PROJECT_ID;
  667. params.rpt_ids = refRptTplIds;
  668. params.rpt_names = rpt_names;
  669. params.pageSize = me.getCurrentPageSize();
  670. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  671. params.isOneSheet = true;
  672. params.custCfg = CUST_CFG;
  673. params.option = "normal";
  674. CommonAjax.postEx("report_api/createExcelFiles", params, WAIT_TIME_EXPORT, true, function(result){
  675. if (result) {
  676. let uuIdUrls = [];
  677. for (let uuIdObj of result) {
  678. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  679. uuIdUrls.push(uuIdUrl);
  680. }
  681. downloadReport(uuIdUrls);
  682. } else {
  683. //
  684. }
  685. }, null, null
  686. );
  687. }
  688. }
  689. }
  690. },
  691. checkAndGetExcel: function () {
  692. if (zTreeOprObj.treeObj) {
  693. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  694. if (chkNodes.length > 0) {
  695. $("#show_excel_output_cfg").trigger("click");
  696. } else {
  697. rptControlObj.getAllIndividualExcelBook();
  698. }
  699. }
  700. },
  701. getExcel: function () {
  702. let me = rptControlObj;
  703. if ($("#excelExportType_AllInOneBook").get(0).checked) {
  704. me.getAllInOneBook();
  705. } else if ($("#excelExportType_IndividualBook").get(0).checked) {
  706. me.getAllIndividualExcelBook();
  707. }
  708. },
  709. getPDF: function () {
  710. let me = rptControlObj;
  711. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  712. let refRptTplIds = [], refBillSumPrjsIds = [], refGljSumPrjsIds = [];
  713. let rpt_names = [], bill_rpt_names = [], glj_rpt_names = [];
  714. rptControlObj.getTplIdsCommon(refRptTplIds, refBillSumPrjsIds, refGljSumPrjsIds, rpt_names, bill_rpt_names, glj_rpt_names);
  715. if (zTreeOprObj.selectedPrjIDs.length > 0 && (glj_rpt_names.length > 0 || bill_rpt_names.length > 0)) {
  716. let params = rptControlObj.creatCommonExportParam();
  717. params.prj_id = PROJECT_ID;
  718. params.sum_rpt_names = bill_rpt_names.concat(glj_rpt_names);
  719. params.rpt_ids = refRptTplIds;
  720. params.rpt_bill_tpl_ids = refBillSumPrjsIds;
  721. params.rpt_glj_tpl_ids = refGljSumPrjsIds;
  722. params.rpt_names = rpt_names;
  723. params.isOneSheet = true;
  724. params.rptName = projectObj.project.projectInfo.name;
  725. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  726. if (result) {
  727. let uuIdUrls = [];
  728. for (let uuIdObj of result) {
  729. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  730. uuIdUrls.push(uuIdUrl);
  731. }
  732. downloadReport(uuIdUrls);
  733. } else {
  734. //
  735. }
  736. }, null, null
  737. );
  738. } else {
  739. if (refBillSumPrjsIds.length > 0 || refGljSumPrjsIds.length > 0) {
  740. $("#divReqBillSummary")[0].style.display = "none";
  741. $("#divReqGljSummary")[0].style.display = "none";
  742. $("#divReqCommonSummaryExcel")[0].style.display = "none";
  743. $("#divReqCommonSummaryMultiExcel")[0].style.display = "none";
  744. $("#divReqCommonSummaryPDF")[0].style.display = "";
  745. zTreeOprObj.requestPrjFolderCommon(); //先处理需要汇总的报表,走另外一个分支
  746. } else if (refRptTplIds.length > 0) {
  747. let params = {};
  748. params.prj_id = PROJECT_ID;
  749. params.rpt_ids = refRptTplIds;
  750. params.rpt_names = rpt_names;
  751. params.pageSize = me.getCurrentPageSize();
  752. params.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:me.getCurrentOrientation());
  753. params.custCfg = CUST_CFG;
  754. params.option = "normal";
  755. CommonAjax.postEx("report_api/createPdfFiles", params, WAIT_TIME_EXPORT, true, function(result){
  756. if (result) {
  757. let uuIdUrls = [];
  758. for (let uuIdObj of result) {
  759. let uuIdUrl = "/report_api/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/pdf";
  760. uuIdUrls.push(uuIdUrl);
  761. }
  762. downloadReport(uuIdUrls);
  763. } else {
  764. //
  765. }
  766. }, null, null
  767. );
  768. }
  769. }
  770. }
  771. },
  772. firstPage: function(dom) {
  773. zTreeOprObj.showPage(1, zTreeOprObj.canvas);
  774. },
  775. prePage: function(dom) {
  776. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, zTreeOprObj.canvas);
  777. },
  778. nextPage: function(dom) {
  779. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, zTreeOprObj.canvas);
  780. },
  781. lastPage: function(dom) {
  782. let me = zTreeOprObj;
  783. zTreeOprObj.showPage(me.maxPages, zTreeOprObj.canvas);
  784. },
  785. onKeydown: function (event, dom) {
  786. let me = zTreeOprObj, keyPressed = null;
  787. if (window.event) {
  788. keyPressed = window.event.keyCode; // IE/Chrome
  789. } else {
  790. keyPressed = event.which; // Firefox
  791. }
  792. if (keyPressed === 13) {
  793. let pageNum = 1;
  794. try {
  795. pageNum = parseInt(dom.value);
  796. } catch (e) {
  797. pageNum = 1;
  798. }
  799. if (pageNum < 1) {
  800. pageNum = 1;
  801. } else if (pageNum > me.maxPages) {
  802. pageNum = me.maxPages;
  803. }
  804. zTreeOprObj.showPage(pageNum, zTreeOprObj.canvas);
  805. return false;
  806. }
  807. },
  808. changeMargin: function(marginPropStr, marginDom) {
  809. CUST_CFG.margins[marginPropStr] = marginDom.value;
  810. },
  811. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  812. for (let font of CUST_CFG.fonts) {
  813. if (font["CfgDispName"] === CfgDispName) {
  814. font[fontProperty] = fontDom.value;
  815. break;
  816. }
  817. }
  818. },
  819. changeCfgOption: function (optStr, dom) {
  820. CUST_CFG[optStr] = dom.checked;
  821. },
  822. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  823. for (let font of CUST_CFG.fonts) {
  824. if (font["CfgDispName"] === CfgDispName) {
  825. if (font[fontProperty] === 'T') {
  826. font[fontProperty] = 'F';
  827. fontDom.className = "btn btn-sm btn-outline-secondary";
  828. } else {
  829. font[fontProperty] = 'T';
  830. fontDom.className = "btn btn-sm btn-outline-secondary active";
  831. }
  832. break;
  833. }
  834. }
  835. },
  836. restoreCustCFG: function () {
  837. let me = this;
  838. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  839. zTreeOprObj.extractRptCfg(CUST_CFG);
  840. me.saveCustCfg();
  841. },
  842. saveCustCfg: function() {
  843. let params = {};
  844. params.custCfg = CUST_CFG;
  845. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  846. // alert("Save successfully!");
  847. $("#update_msg_response")[0].style.color = "green";
  848. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  849. setTimeout(function(){
  850. $("#update_msg_response")[0].innerHTML = "";
  851. }, 1000);
  852. }, function (failRst) {
  853. $("#update_msg_response")[0].style.color = "red";
  854. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  855. setTimeout(function(){
  856. $("#update_msg_response")[0].innerHTML = "";
  857. }, 1000);
  858. }, null
  859. );
  860. },
  861. confirmCfgChange: function() {
  862. zTreeOprObj.changeCfg();
  863. }
  864. };
  865. function downloadReport(urls) {
  866. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  867. rptControlObj.currentDownloadUrl = null;
  868. rptControlObj.currentDownloadIdx = 0;
  869. let private_download = function() {
  870. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  871. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  872. rptControlObj.currentDownloadIdx++;
  873. window.location = rptControlObj.currentDownloadUrl;
  874. setTimeout(private_download, 2000);
  875. }
  876. }
  877. private_download();
  878. }
  879. function getStageId() {
  880. return current_stage_id;
  881. }
  882. function getStageOrder() {
  883. return current_stage_order;
  884. }
  885. function getStageTimes() {
  886. return current_stage_times;
  887. }