rpt_main.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. pdfFont: {'SmartSimsun': [], 'simhei': [], 'simkai': []},
  14. iniPage: function() {
  15. let me = this;
  16. if (!me.hasInitialized) {
  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. dynamicLoadJs('/public/jspdf/Arial Narrow-normal.js');
  24. dynamicLoadJs('/public/jspdf/Arial Narrow-bold.js');
  25. dynamicLoadJs('/public/jspdf/Arial Narrow-italic.js');
  26. dynamicLoadJs('/public/jspdf/Arial Narrow-bolditalic.js');
  27. // dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js');
  28. // dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js', me.pdfFontSimsunCallBack);
  29. }
  30. },
  31. pdfFontSimsunCallBack: function() {
  32. rptTplObj.pdfFont['SmartSimsun'].push('normal');
  33. rptTplObj.pdfFont['SmartSimsun'].push('bold');
  34. },
  35. pdfFontSimkaiCallBack: function() {
  36. rptTplObj.pdfFont['simkai'].push('normal');
  37. rptTplObj.pdfFont['simkai'].push('bold');
  38. },
  39. pdfFontSimheiCallBack: function() {
  40. rptTplObj.pdfFont['simhei'].push('normal');
  41. rptTplObj.pdfFont['simhei'].push('bold');
  42. }
  43. }
  44. let zTreeOprObj = {
  45. treeObj: null,
  46. prjFolderTreeObj: null,
  47. currentNode: null,
  48. checkedRptTplNodes: null,
  49. currentRptPageRst: null,
  50. defReportPageCfg: null,
  51. currentPage: 1,
  52. maxPages: 0,
  53. canvas: null,
  54. selectedPrjIDs: [],
  55. countChkedRptTpl: function () {
  56. let me = zTreeOprObj;
  57. if (me.treeObj) {
  58. me.checkedRptTplNodes = [];
  59. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  60. for (let node of chkNodes) {
  61. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  62. cnt++;
  63. me.checkedRptTplNodes.push(node);
  64. if (me.currentNode === node) hasCurrentNode = true;
  65. }
  66. }
  67. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  68. //这里根据实际需求再做处理
  69. cnt++;
  70. me.checkedRptTplNodes.push(me.currentNode);
  71. }
  72. $("#print_div").find("span").each(function(cIdx,elementSpan){
  73. elementSpan.innerText = cnt;
  74. });
  75. $("#export_div").find("span").each(function(cIdx,elementSpan){
  76. elementSpan.innerText = cnt;
  77. });
  78. }
  79. },
  80. getReportTemplateTree: function() {
  81. let me = zTreeOprObj;
  82. let private_remove_hide_item = function (items, nlv) {
  83. if (items && items.length > 0) {
  84. for (let i = items.length - 1; i >= 0; i--) {
  85. if (!(items[i].released) && items[i].nodeType === 2) {
  86. items.splice(i, 1);
  87. } else {
  88. if (items[i].items && items[i].items.length > 0) {
  89. private_remove_hide_item(items[i].items, nlv + 1);
  90. if (items[i].items.length === 0 && nlv > 0) {
  91. items.splice(i, 1);
  92. }
  93. }
  94. }
  95. }
  96. }
  97. };
  98. let nodeLv = 0;
  99. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  100. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_tpl_setting, "rptTplTree", me);
  101. me.refreshNodes();
  102. },
  103. getCustomerCfg: function() {
  104. let me = zTreeOprObj;
  105. me.defReportPageCfg = {};
  106. Object.assign(me.defReportPageCfg, CUST_CFG);
  107. me.defReportPageCfg.margins = {};
  108. Object.assign(me.defReportPageCfg.margins, CUST_CFG.margins);
  109. me.defReportPageCfg.fonts = [];
  110. for (let fi = 0; fi < CUST_CFG.fonts.length; fi++) {
  111. me.defReportPageCfg.fonts.push({});
  112. Object.assign(me.defReportPageCfg.fonts[fi], CUST_CFG.fonts[fi]);
  113. }
  114. },
  115. iniFontCfgDom: function (cfg) {
  116. for (let font of cfg.fonts) {
  117. let domArrs = [];
  118. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  119. domArrs.push("<div class='row mb-1'>");
  120. //1. label
  121. domArrs.push("<div class='col-3'>" + font.CfgDispName + "</div>");
  122. //2. font name
  123. domArrs.push("<div class='col-3'>");
  124. domArrs.push("<select class='form-control input-sm' id='fontName_" + fontPropSuffix + "' onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"Name\", this)'>");
  125. domArrs.push("<option>宋体</option>");
  126. // <option>楷体</option><option>黑体</option> // 因导出PDF调整到前端输出,字体文件大,支持的字体要谨慎些,不轻易多加字体
  127. domArrs.push("</select>");
  128. domArrs.push("</div>");
  129. //3. font height
  130. domArrs.push("<div class='col-3'>");
  131. domArrs.push("<input class='form-control input-sm' id='fontHeight_" + fontPropSuffix + "' type='number' value='30' step='1' min='6' max='66' " +
  132. "onchange='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)' " +
  133. "onkeyup='rptControlObj.changeFontMain(\"" + font.CfgDispName + "\", \"FontHeight\", this)'>");
  134. domArrs.push("</div>");
  135. //4. font bold italic underline
  136. domArrs.push("<div class='col-3'>");
  137. 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>");
  138. 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>");
  139. 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>");
  140. domArrs.push("</div>");
  141. //
  142. domArrs.push("</div>");
  143. $(domArrs.join("")).insertBefore($("#font_cfg_blank_flag"));
  144. }
  145. },
  146. renderRptCfg: function (cfg) {
  147. this.renderMargin(cfg);
  148. this.renderFormat(cfg);
  149. },
  150. renderMargin: function (cfg) {
  151. $("#elementMargin_Left")[0].value = cfg.margins.Left;
  152. $("#elementMargin_Right")[0].value = cfg.margins.Right;
  153. $("#elementMargin_Top")[0].value = cfg.margins.Top;
  154. $("#elementMargin_Bottom")[0].value = cfg.margins.Bottom;
  155. },
  156. renderFormat: function (cfg) {
  157. for (let font of cfg.fonts) {
  158. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  159. document.getElementById("fontName_" + fontPropSuffix).value = font.Name;
  160. document.getElementById("fontHeight_" + fontPropSuffix).value = font.FontHeight;
  161. document.getElementById("font_bold_" + fontPropSuffix).className = (font.FontBold === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  162. document.getElementById("font_italic_" + fontPropSuffix).className = (font.FontItalic === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  163. document.getElementById("font_underline_" + fontPropSuffix).className = (font.FontUnderline === "T")?"btn btn-sm btn-outline-secondary active":"btn btn-sm btn-outline-secondary";
  164. }
  165. document.getElementById("cfg_border_thick").value = cfg.borderThick;
  166. document.getElementById("cfg_rpt_vertical_line").checked = cfg.showVerticalLine;
  167. document.getElementById("cfg_rpt_fill_zero").checked = cfg.fillZero;
  168. document.getElementById("cfg_rpt_narrow").checked = cfg.isNarrow;
  169. },
  170. extractRptCfg: function (cfg) {
  171. cfg.margins.Left = $("#elementMargin_Left")[0].value;
  172. cfg.margins.Right = $("#elementMargin_Right")[0].value;
  173. cfg.margins.Top = $("#elementMargin_Top")[0].value;
  174. cfg.margins.Bottom = $("#elementMargin_Bottom")[0].value;
  175. for (let font of cfg.fonts) {
  176. let fontPropSuffix = fontSuffixMapObj[font.CfgDispName];
  177. font.Name = document.getElementById("fontName_" + fontPropSuffix).value;
  178. font.FontHeight = document.getElementById("fontHeight_" + fontPropSuffix).value;
  179. font.FontBold = (document.getElementById("font_bold_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  180. font.FontItalic = (document.getElementById("font_italic_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  181. font.FontUnderline = (document.getElementById("font_underline_" + fontPropSuffix).className === "btn btn-sm btn-outline-secondary active")?"T":"F";
  182. }
  183. cfg.showVerticalLine = document.getElementById("cfg_rpt_vertical_line").checked;
  184. cfg.isNarrow = document.getElementById("cfg_rpt_narrow").checked;
  185. cfg.fillZero = document.getElementById("cfg_rpt_fill_zero").checked;
  186. cfg.borderThick = document.getElementById("cfg_border_thick").value;
  187. },
  188. refreshNodes: function() {
  189. let me = this;
  190. let private_setupIsParent = function(node){
  191. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  192. if (node.items && node.items.length) {
  193. for (let i = 0; i < node.items.length; i++) {
  194. private_setupIsParent(node.items[i]);
  195. }
  196. }
  197. };
  198. let topNodes = me.treeObj.getNodes();
  199. for (let i = 0; i < topNodes.length; i++) {
  200. private_setupIsParent(topNodes[i]);
  201. }
  202. me.treeObj.refresh();
  203. },
  204. onCheck: function(event, treeId, treeNode) {
  205. zTreeOprObj.countChkedRptTpl();
  206. },
  207. onClick: function(event,treeId,treeNode) {
  208. let me = zTreeOprObj;
  209. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  210. me.currentNode = treeNode;
  211. let params = {};
  212. let pageSize = rptControlObj.getCurrentPageSize();
  213. params.pageSize = pageSize;
  214. params.rpt_tpl_id = treeNode.refId;
  215. params.project_id = PROJECT_ID;
  216. params.tender_id = TENDER_ID;
  217. params.stage_id = getStageId();
  218. params.stage_status = getStageStatus();
  219. params.stage_order = getStageOrder();
  220. params.stage_times = getStageTimes();
  221. params.custCfg = CUST_CFG;
  222. const gather_select = customSelects.gather_select.find(function (x) {
  223. return x.id === treeNode.refId;
  224. });
  225. if (gather_select) {
  226. rptCustomObj.init(gather_select.custom_define, customSelects.stageFlow, gather_select);
  227. return;
  228. }
  229. me.requestNormalReport(params);
  230. me.countChkedRptTpl();
  231. }
  232. },
  233. changePageSize: function(dom) {
  234. let me = zTreeOprObj,
  235. targetDom = document.getElementById("btnRptPageSize");
  236. let tmpStr = targetDom.innerHTML.trim();
  237. targetDom.innerHTML = dom.innerHTML.trim();
  238. dom.innerHTML = tmpStr;
  239. me.changeCfg();
  240. },
  241. changeOrientation: function(dom) {
  242. let me = zTreeOprObj,
  243. targetDom = document.getElementById("btnRptOrientation");
  244. let tmpStr = targetDom.innerHTML.trim();
  245. targetDom.innerHTML = dom.innerHTML.trim();
  246. dom.innerHTML = tmpStr;
  247. me.changeCfg();
  248. },
  249. changeCfg: function() {
  250. let me = zTreeOprObj;
  251. if (me.currentNode) {
  252. let params = {};
  253. params.pageSize = rptControlObj.getCurrentPageSize();
  254. params.orientation = rptControlObj.getCurrentOrientation();
  255. params.rpt_tpl_id = me.currentNode.refId;
  256. params.custCfg = CUST_CFG;
  257. params.project_id = PROJECT_ID;
  258. params.tender_id = TENDER_ID;
  259. params.stage_id = getStageId();
  260. params.stage_status = getStageStatus();
  261. params.stage_order = getStageOrder();
  262. params.stage_times = getStageTimes();
  263. me.requestNormalReport(params);
  264. }
  265. },
  266. resetAfter: function (pageRst) {
  267. let size = pageRst[JV.NODE_PAGE_INFO][JV.NODE_PAGE_SIZE].slice(0);
  268. if (size[0] > size[1]) {
  269. document.getElementById("btnRptOrientation").innerHTML = "横向";
  270. document.getElementById("hrefRptOrientation").innerHTML = "纵向";
  271. } else {
  272. document.getElementById("btnRptOrientation").innerHTML = "纵向";
  273. document.getElementById("hrefRptOrientation").innerHTML = "横向";
  274. }
  275. },
  276. _parseRoleRelList: function(org_rel_content) {
  277. const rst = JSON.parse(org_rel_content);
  278. for (const role_rel of rst) {
  279. if (role_rel.sign_date !== null && role_rel.sign_date !== undefined && role_rel.sign_date.length >= 8) {
  280. role_rel.sign_date = new Date(role_rel.sign_date);
  281. }
  282. }
  283. return rst;
  284. },
  285. requestNormalReport: function (params) {
  286. let me = zTreeOprObj;
  287. // hintBox.waitBox();
  288. CommonAjax.postXsrfEx("/tender/report_api/getReport", params, 60000, true, getCookie('csrfToken'),
  289. function(result){
  290. // hintBox.unWaitBox();
  291. let pageRst = result.data;
  292. STAGE_AUDIT = result.stageAudit;
  293. STAGE_AUDIT_ORG = result.stageAuditOrg;
  294. STAGE_FLOW = result.stageFlow;
  295. //stageAuditOrg
  296. if (result.signatureRelInfo && result.signatureRelInfo.length > 0) {
  297. CURRENT_ROLE_REL_ID = result.signatureRelInfo[0].id;
  298. ROLE_REL_LIST = me._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  299. rptSignatureHelper.originalRoleRelList = me._parseRoleRelList(result.signatureRelInfo[0].rel_content);
  300. if (current_stage_status === 3) {
  301. rptSignatureHelper.mergeSignDate(pageRst, ROLE_REL_LIST);
  302. rptSignatureHelper.mergeSignature(pageRst, ROLE_REL_LIST);
  303. rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT);
  304. }
  305. } else {
  306. CURRENT_ROLE_REL_ID = -1;
  307. ROLE_REL_LIST = [];
  308. }
  309. // if (ROLE_REL_LIST)
  310. let canvas = zTreeOprObj.canvas;
  311. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  312. me.resetAfter(pageRst);
  313. me.currentRptPageRst = pageRst;
  314. me.maxPages = pageRst.items.length;
  315. me.currentPage = 1;
  316. me.displayPageValue();
  317. let size = JpcCanvasOutput.getReportSizeInPixel(me.currentRptPageRst, getScreenDPI());
  318. canvas.width = size[0] + 20;
  319. if (size[1] > size[0]) {
  320. canvas.height = size[1] + 100;
  321. } else {
  322. canvas.height = size[1] + 50;
  323. }
  324. // zTreeOprObj.resetESignature(zTreeOprObj.currentRptPageRst);
  325. rptSignatureHelper.buildSelectableAccount();
  326. rptSignatureHelper.buildSelectableAccountUsed();
  327. rptSignatureHelper.buildRoleDom(ROLE_LIST);
  328. me.showPage(1, canvas);
  329. } else {
  330. //返回了无数据表
  331. JpcCanvasOutput.cleanCanvas(canvas);
  332. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  333. }
  334. rptCustomObj.init(result.customDefine, result.stageFlow, result.customSelect);
  335. try {
  336. if (is_debug && result.debugInfo) {
  337. console.log('含有key的debug信息:');
  338. for (const k in result.debugInfo.key) {
  339. console.log(k + ':', ...result.debugInfo.key[k]);
  340. }
  341. //console.log(result.debugInfo.key);
  342. console.log('其他debug信息:');
  343. for (const di of result.debugInfo.other) {
  344. console.log(...di);
  345. }
  346. }
  347. } catch(err) {
  348. }
  349. }, function(err){
  350. // hintBox.unWaitBox();
  351. }, function(ex){
  352. // hintBox.unWaitBox();
  353. }
  354. );
  355. },
  356. scaleReport: function (accScale) {
  357. let me = zTreeOprObj;
  358. let canvas = zTreeOprObj.canvas;
  359. if (accScale !== 0) {
  360. JpcCanvasOutput.scaleFactor += accScale;
  361. if (JpcCanvasOutput.scaleFactor < 0.5) JpcCanvasOutput.scaleFactor = 0.5;
  362. if (JpcCanvasOutput.scaleFactor > 1.5) JpcCanvasOutput.scaleFactor = 1.5;
  363. } else {
  364. JpcCanvasOutput.scaleFactor = 1;
  365. }
  366. document.getElementById("btnNormalScale").innerText = (JpcCanvasOutput.scaleFactor * 100) + '%';
  367. me.showPage(me.currentPage, canvas);
  368. },
  369. requestPrjFolderCommon: function () {
  370. //
  371. },
  372. showPage: function (pageNum, canvas) {
  373. let me = zTreeOprObj;
  374. if (pageNum >= 1 && pageNum <= me.maxPages) {
  375. me.currentPage = pageNum;
  376. JpcCanvasOutput.cleanCanvas(canvas);
  377. JpcCanvasOutput.drawPageBorder(me.currentRptPageRst, canvas, getScreenDPI());
  378. JpcCanvasOutput.drawToCanvas(me.currentRptPageRst, canvas, me.currentPage);
  379. }
  380. me.displayPageValue();
  381. },
  382. displayPageValue: function() {
  383. let me = zTreeOprObj;
  384. $("#rpt_page_num")[0].value = me.currentPage + "/" + me.maxPages;
  385. }
  386. };
  387. let canvasOprObj = {
  388. canvasOnMouseMove: function (event) {
  389. if (zTreeOprObj.currentNode) {
  390. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  391. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  392. if (x < FIRST_PAGE_OFFSET) {
  393. canvas.style.cursor = "url(/web/building_saas/img/FirstPageSimple.cur), auto";
  394. } else if (x < PRE_PAGE_OFFSET) {
  395. canvas.style.cursor = "url(/web/building_saas/img/PreviousPageSimple.cur), auto";
  396. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  397. canvas.style.cursor = "url(/web/building_saas/img/LastPageSimple.cur), auto";
  398. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  399. canvas.style.cursor = "url(/web/building_saas/img/NextPageSimple.cur), auto";
  400. } else {
  401. canvas.style.cursor = "";
  402. }
  403. }
  404. },
  405. canvasOnClick: function(event){
  406. if (zTreeOprObj.currentNode) {
  407. let x = event.offsetX - JpcCanvasOutput.offsetX, canvas = event.originalTarget;
  408. if (!(canvas)) canvas = event.target; //chrome浏览器不认event.originalTarget,只认event.target或event.currentTarget
  409. if (x < FIRST_PAGE_OFFSET) {
  410. zTreeOprObj.showPage(1, canvas);
  411. } else if (x < PRE_PAGE_OFFSET) {
  412. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, canvas);
  413. } else if ((canvas.width - x) < LAST_PAGE_OFFSET) {
  414. zTreeOprObj.showPage(zTreeOprObj.maxPages, canvas);
  415. } else if ((canvas.width - x) < NEXT_PAGE_OFFSET) {
  416. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, canvas);
  417. }
  418. }
  419. }
  420. };
  421. let rptControlObj = {
  422. currentOutputType: "Excel",
  423. currentDownloadUrl: null,
  424. currentDownloadIdx: 0,
  425. getCurrentPageSize: function() {
  426. // let rst = "A4";
  427. let rst = document.getElementById("btnRptPageSize").innerHTML.trim();
  428. //btnRptPageSize
  429. return rst;
  430. },
  431. getCurrentOrientation: function() {
  432. // let rst = "横向";
  433. let rst = document.getElementById("btnRptOrientation").innerHTML.trim();
  434. return rst;
  435. },
  436. changeType: function(newType) {
  437. let me = rptControlObj;
  438. let excelDom = document.getElementById("EXCEL_TYPE");
  439. let pdfDom = document.getElementById("PDF_TYPE");
  440. if (newType === "Excel") {
  441. excelDom.className = "btn btn-block btn-primary";
  442. pdfDom.className = "btn btn-block btn-outline-secondary";
  443. me.currentOutputType = newType;
  444. } else if (newType === "PDF") {
  445. excelDom.className = "btn btn-block btn-outline-secondary";
  446. pdfDom.className = "btn btn-block btn-primary";
  447. me.currentOutputType = newType;
  448. } else {
  449. //me.currentOutputType = newType;
  450. }
  451. },
  452. getTplIdsCommon: function (refRptTplIds, rpt_names) {
  453. for (let node of zTreeOprObj.checkedRptTplNodes) {
  454. if (node.hasOwnProperty('flags') && node.flags.hasOwnProperty('reportType') && node['flags']['reportType'] !== 'NA') {
  455. // 未来可能会有这些处理,目前空着
  456. } else {
  457. refRptTplIds.push(node.refId);
  458. if (rpt_names) rpt_names.push(node.name);
  459. }
  460. }
  461. },
  462. creatCommonExportParam: function (refRptTplIds) {
  463. let rst = {};
  464. rst.rpt_ids = refRptTplIds;
  465. rst.pageSize = rptControlObj.getCurrentPageSize();
  466. rst.orientation = ((zTreeOprObj.checkedRptTplNodes.length > 1)?null:rptControlObj.getCurrentOrientation());
  467. rst.project_id = PROJECT_ID;
  468. rst.tender_id = TENDER_ID;
  469. rst.stage_id = getStageId();
  470. rst.stage_status = getStageStatus();
  471. rst.stage_order = getStageOrder();
  472. rst.stage_times = getStageTimes();
  473. rst.custCfg = CUST_CFG;
  474. return rst;
  475. },
  476. getAllInOneBook: async function () {
  477. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  478. let me = rptControlObj;
  479. let refRptTplIds = [], rpt_sheet_names = [];
  480. rptControlObj.getTplIdsCommon(refRptTplIds, rpt_sheet_names);
  481. let params = rptControlObj.creatCommonExportParam(refRptTplIds);
  482. await rptCustomObj.getCustomSelect(params);
  483. params.rpt_names = rpt_sheet_names;
  484. params.rptName = TENDER_NAME;
  485. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  486. if (chkNodes.length > 0) {
  487. delete params.orientation; // 打印时有勾选的话,不需要提供方向
  488. }
  489. CommonAjax.postXsrfEx("/tender/report_api/createExcelFilesInOneBook", params, 300000, true, getCookie('csrfToken'), function(result){
  490. if (result) {
  491. let uuIdUrls = [];
  492. let uuIdUrl = "/getFileByUUID/" + result.data[0].uuid + "/" + stringUtil.replaceAll(result.data[0].reportName, "#", "_") + "/xlsx";
  493. uuIdUrls.push(uuIdUrl);
  494. downloadReport(uuIdUrls);
  495. } else {
  496. //
  497. }
  498. }, null, null
  499. );
  500. }
  501. },
  502. getAllIndividualExcelBook: async function () {
  503. let me = rptControlObj;
  504. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  505. let refRptTplIds = [];
  506. let rpt_names = [];
  507. rptControlObj.getTplIdsCommon(refRptTplIds, rpt_names);
  508. let params = rptControlObj.creatCommonExportParam(refRptTplIds);
  509. await rptCustomObj.getCustomSelect(params);
  510. params.isOneSheet = true;
  511. params.rpt_names = rpt_names;
  512. params.rptName = 'All';
  513. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  514. if (chkNodes.length > 0) {
  515. delete params.orientation; // 打印时有勾选的话,不需要提供方向
  516. }
  517. CommonAjax.postXsrfEx("/tender/report_api/createExcelFiles", params, 300000, true, getCookie('csrfToken'), function(result){
  518. if (result) {
  519. let uuIdUrls = [];
  520. for (let uuIdObj of result.data) {
  521. let uuIdUrl = "/getFileByUUID/" + uuIdObj.uuid + "/" + stringUtil.replaceAll(uuIdObj.reportName, "#", "_") + "/xlsx";
  522. uuIdUrls.push(uuIdUrl);
  523. }
  524. downloadReport(uuIdUrls);
  525. } else {
  526. //
  527. }
  528. }, null, null
  529. );
  530. }
  531. },
  532. checkAndGetExcel: function () {
  533. if (zTreeOprObj.treeObj) {
  534. let chkNodes = zTreeOprObj.treeObj.getCheckedNodes(true);
  535. if (chkNodes.length > 0) {
  536. $("#show_excel_output_cfg").trigger("click");
  537. } else {
  538. rptControlObj.getAllIndividualExcelBook();
  539. }
  540. }
  541. },
  542. getExcel: function () {
  543. let me = rptControlObj;
  544. if ($("#excelExportType_AllInOneBook")[0].checked) {
  545. me.getAllInOneBook();
  546. } else if ($("#excelExportType_IndividualBook")[0].checked) {
  547. me.getAllIndividualExcelBook();
  548. }
  549. },
  550. getPdfFontCallback: function(fontProperty) {
  551. let me = rptControlObj;
  552. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  553. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  554. me.getPDFEx();
  555. }
  556. },
  557. getPDFPre: function () {
  558. let me = rptControlObj;
  559. // showWaitingView();
  560. if (rptTplObj.pdfFont['SmartSimsun'].length === 2) {
  561. me.getPDFEx();
  562. } else {
  563. dynamicLoadJs('/public/jspdf/SmartSimsun-normal.js',"normal", me.getPdfFontCallback);
  564. dynamicLoadJs('/public/jspdf/SmartSimsun-bold.js',"bold", me.getPdfFontCallback);
  565. // dynamicLoadJs('http://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', "normal", me.getPdfFontCallback('normal'));
  566. // dynamicLoadJs('http://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', "normal", me.getPdfFontCallback('bold'));
  567. }
  568. },
  569. getPDFEx: async function () {
  570. let me = rptControlObj;
  571. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  572. let refRptTplIds = [];
  573. let rpt_names = [];
  574. rptControlObj.getTplIdsCommon(refRptTplIds, rpt_names);
  575. const signatureRelArr = [];
  576. if (refRptTplIds.length > 0) {
  577. let params = rptControlObj.creatCommonExportParam(refRptTplIds);
  578. await rptCustomObj.getCustomSelect(params);
  579. delete params.orientation; // 打印时有勾选的话,不需要提供方向
  580. $.bootstrapLoading.start();
  581. CommonAjax.postXsrfEx("/tender/report_api/getMultiReports", params, 300000, true, getCookie('csrfToken'),
  582. function(result){
  583. // closeWaitingView();
  584. $.bootstrapLoading.end();
  585. let pageSize = rptControlObj.getCurrentPageSize();
  586. for (const signatureRel of result.signatureRelInfo) {
  587. signatureRelArr.push(JSON.parse(signatureRel.rel_content));
  588. }
  589. for (let idx = 0; idx < result.data.length; idx++) {
  590. let pageData = result.data[idx];
  591. // if (current_stage_status === 3) {
  592. // rptSignatureHelper.mergeSignDate(pageData);
  593. // rptSignatureHelper.mergeSignature(pageData);
  594. // rptSignatureHelper.mergeSignAudit(pageRst, ROLE_REL_LIST, STAGE_AUDIT);
  595. // }
  596. // 备注:因多表的原因,无需merge电子签名,在下面处理
  597. let singleSignatureRelArr = [];
  598. for (let rIdx = 0; rIdx < result.signatureRelInfo.length; rIdx++) {
  599. if (result.signatureRelInfo[rIdx].rpt_id === refRptTplIds[idx]) {
  600. // singleSignatureRelArr.push(signatureRelArr[rIdx]);
  601. singleSignatureRelArr = signatureRelArr[rIdx]; // 有些报表可能没有签名
  602. break;
  603. }
  604. }
  605. // JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx], signatureRelArr);
  606. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[idx], singleSignatureRelArr, STAGE_AUDIT); // 精确控制签名
  607. }
  608. },
  609. function(failRst){
  610. // closeWaitingView();
  611. $.bootstrapLoading.end();
  612. console.log(failRst);
  613. },
  614. function(exceptionRst){
  615. // closeWaitingView();
  616. $.bootstrapLoading.end();
  617. console.log(exceptionRst);
  618. }
  619. );
  620. } else {
  621. //这个分支是为了减少请求,用户已经点过的表,又没有勾选,那么就直接导出成PDF
  622. let pageSize = rptControlObj.getCurrentPageSize();
  623. let pageData = zTreeOprObj.currentRptPageRst;
  624. signatureRelArr.push(ROLE_REL_LIST);
  625. // closeWaitingView();
  626. $.bootstrapLoading.end();
  627. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rpt_names[0], signatureRelArr);
  628. }
  629. }
  630. },
  631. firstPage: function(dom) {
  632. zTreeOprObj.showPage(1, zTreeOprObj.canvas);
  633. },
  634. prePage: function(dom) {
  635. zTreeOprObj.showPage(zTreeOprObj.currentPage - 1, zTreeOprObj.canvas);
  636. },
  637. nextPage: function(dom) {
  638. zTreeOprObj.showPage(zTreeOprObj.currentPage + 1, zTreeOprObj.canvas);
  639. },
  640. lastPage: function(dom) {
  641. let me = zTreeOprObj;
  642. zTreeOprObj.showPage(me.maxPages, zTreeOprObj.canvas);
  643. },
  644. onKeydown: function (event, dom) {
  645. let me = zTreeOprObj, keyPressed = null;
  646. if (window.event) {
  647. keyPressed = window.event.keyCode; // IE/Chrome
  648. } else {
  649. keyPressed = event.which; // Firefox
  650. }
  651. if (keyPressed === 13) {
  652. let pageNum = 1;
  653. try {
  654. pageNum = parseInt(dom.value);
  655. } catch (e) {
  656. pageNum = 1;
  657. }
  658. if (pageNum < 1) {
  659. pageNum = 1;
  660. } else if (pageNum > me.maxPages) {
  661. pageNum = me.maxPages;
  662. }
  663. zTreeOprObj.showPage(pageNum, zTreeOprObj.canvas);
  664. return false;
  665. }
  666. },
  667. changeMargin: function(marginPropStr, marginDom) {
  668. CUST_CFG.margins[marginPropStr] = marginDom.value;
  669. },
  670. changeFontMain: function(CfgDispName, fontProperty, fontDom) {
  671. for (let font of CUST_CFG.fonts) {
  672. if (font["CfgDispName"] === CfgDispName) {
  673. font[fontProperty] = fontDom.value;
  674. break;
  675. }
  676. }
  677. },
  678. changeBorderWeight: function (dom) {
  679. CUST_CFG.borderThick = dom.value;
  680. },
  681. changeCfgOption: function (optStr, dom) {
  682. CUST_CFG[optStr] = dom.checked;
  683. },
  684. changeFontAdhoc: function(CfgDispName, fontProperty, fontDom) {
  685. for (let font of CUST_CFG.fonts) {
  686. if (font["CfgDispName"] === CfgDispName) {
  687. if (font[fontProperty] === 'T') {
  688. font[fontProperty] = 'F';
  689. fontDom.className = "btn btn-sm btn-outline-secondary";
  690. } else {
  691. font[fontProperty] = 'T';
  692. fontDom.className = "btn btn-sm btn-outline-secondary active";
  693. }
  694. break;
  695. }
  696. }
  697. },
  698. restoreMargine: function () {
  699. zTreeOprObj.renderMargin(zTreeOprObj.defReportPageCfg);
  700. zTreeOprObj.extractRptCfg(CUST_CFG);
  701. },
  702. restoreFormat: function () {
  703. zTreeOprObj.renderFormat(zTreeOprObj.defReportPageCfg);
  704. zTreeOprObj.extractRptCfg(CUST_CFG);
  705. },
  706. restoreCustCFG: function () {
  707. let me = this;
  708. zTreeOprObj.renderRptCfg(zTreeOprObj.defReportPageCfg);
  709. zTreeOprObj.extractRptCfg(CUST_CFG);
  710. // me.saveCustCfg();
  711. },
  712. saveCustCfg: function() {
  713. let params = {};
  714. params.custCfg = CUST_CFG;
  715. CommonAjax.postEx("report_tpl_api/saveCustomerCfg", params, 20000, true, function(result){
  716. // alert("Save successfully!");
  717. $("#update_msg_response")[0].style.color = "green";
  718. $("#update_msg_response")[0].innerHTML = " (保存成功!)";
  719. setTimeout(function(){
  720. $("#update_msg_response")[0].innerHTML = "";
  721. }, 1000);
  722. }, function (failRst) {
  723. $("#update_msg_response")[0].style.color = "red";
  724. $("#update_msg_response")[0].innerHTML = " (保存失败!)";
  725. setTimeout(function(){
  726. $("#update_msg_response")[0].innerHTML = "";
  727. }, 1000);
  728. }, null
  729. );
  730. },
  731. confirmCfgChange: function() {
  732. zTreeOprObj.changeCfg();
  733. }
  734. };
  735. function downloadReport(urls) {
  736. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  737. rptControlObj.currentDownloadUrl = null;
  738. rptControlObj.currentDownloadIdx = 0;
  739. const private_download = function() {
  740. if (rptControlObj.currentDownloadIdx >= 0 && rptControlObj.currentDownloadIdx < urls.length) {
  741. rptControlObj.currentDownloadUrl = urls[rptControlObj.currentDownloadIdx];
  742. rptControlObj.currentDownloadIdx++;
  743. window.location = rptControlObj.currentDownloadUrl;
  744. if (rptControlObj.currentDownloadIdx < urls.length) setTimeout(private_download, 2000);
  745. }
  746. }
  747. private_download();
  748. }
  749. // function dynamicLoadJs(url, callback) {
  750. // let head = document.getElementsByTagName('head')[0];
  751. // let script = document.createElement('script');
  752. // script.type = 'text/javascript';
  753. // script.src = url;
  754. // if(callback) {
  755. // script.onload = script.onreadystatechange = function () {
  756. // if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"){
  757. // callback();
  758. // script.onload = script.onreadystatechange = null;
  759. // }
  760. // };
  761. // }
  762. // head.appendChild(script);
  763. // }
  764. function dynamicLoadJs(url, type, callback) {
  765. let head = document.getElementsByTagName('head')[0];
  766. let script = document.createElement('script');
  767. script.type = 'text/javascript';
  768. script.src = url;
  769. if(callback) {
  770. script.onload = script.onreadystatechange = function (event) {
  771. callback(type);
  772. script.onload = script.onreadystatechange = null;
  773. };
  774. }
  775. head.appendChild(script);
  776. }
  777. function getStageStatus() {
  778. return current_stage_status;
  779. }
  780. function getStageId() {
  781. return current_stage_id;
  782. }
  783. function getStageOrder() {
  784. return CUR_ORDER;
  785. }
  786. function getStageTimes() {
  787. return current_stage_times;
  788. }