rpt_individual.ejs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <script src="/public/js/jquery/jquery-3.2.1.min.js"></script>
  7. <script type="text/javascript" src="/public/jspdf/jspdf.min.js"></script>
  8. <script type="text/javascript" src="/public/js/common_ajax.js"></script>
  9. <script type="text/javascript" src="/public/report/js/jpc_output_value_define.js"></script>
  10. <script type="text/javascript" src="/public/report/js/jpc_output.js"></script>
  11. <script type="text/javascript" src="/public/js/string_util_light.js"></script>
  12. <script type="text/javascript" src="/public/report/js/rpt_signature.js"></script>
  13. <script type="text/javascript" src="/public/report/js/rpt_jspdf.js"></script>
  14. <!--
  15. <link rel="stylesheet" href="/public/css/bootstrap/bootstrap.min.css">
  16. -->
  17. <link rel="shortcut icon" href="/public/images/favicon.ico">
  18. </head>
  19. <style type="text/css">
  20. </style>
  21. <body onload="pageLoading()">
  22. <div class="panel-body" id="print_preview_div" style="display:block">
  23. <button class="btn btn-outline-primary btn-sm" type="button" onclick="exportPDF()">
  24. <i class="fa fa-print"></i>
  25. 导出 <span id="checkCountPrint" class="badge badge-primary"></span>
  26. </button>
  27. <div class="pageContainer">
  28. <canvas id="rptIndividualCanvas" height="100%" width="100%"></canvas>
  29. </div>
  30. </div>
  31. </body>
  32. <SCRIPT type="text/javascript">
  33. const SCREEN_DPI = [96, 96];
  34. const OSS_PATH = '<%- OSS_PATH %>';
  35. const WAIT_TIME_EXPORT = 300000;
  36. const current_stage_status = 3;
  37. const PAGE_SHOW = {closeWatermark: 0, closeExportPdf: 0, closeExportExcel: 0, showArchive: 0};
  38. const pdfFont = {'SmartSimsun': [], 'simhei': [], 'simkai': []};
  39. const CUST_CFG = {
  40. "fonts": [
  41. {
  42. "ID": "ReportTitle_Main",
  43. "Name": "宋体",
  44. "FontBold": "T",
  45. "FontHeight": 32,
  46. "FontItalic": "F",
  47. "CfgDispName": "表标题",
  48. "FontUnderline": "F"
  49. },
  50. {
  51. "ID": "Column",
  52. "Name": "宋体",
  53. "FontBold": "F",
  54. "FontHeight": 12,
  55. "FontItalic": "F",
  56. "CfgDispName": "列标题",
  57. "FontUnderline": "F"
  58. },
  59. {
  60. "ID": "Content",
  61. "Name": "宋体",
  62. "FontBold": "F",
  63. "FontHeight": 12,
  64. "FontItalic": "F",
  65. "CfgDispName": "正文内容",
  66. "FontUnderline": "F"
  67. },
  68. {
  69. "ID": "Total",
  70. "Name": "宋体",
  71. "FontBold": "F",
  72. "FontHeight": 12,
  73. "FontItalic": "F",
  74. "CfgDispName": "合计",
  75. "FontUnderline": "F"
  76. },
  77. {
  78. "ID": "Header",
  79. "Name": "宋体",
  80. "FontBold": "F",
  81. "FontHeight": 12,
  82. "FontItalic": "F",
  83. "CfgDispName": "表眉/表脚",
  84. "FontUnderline": "F"
  85. }
  86. ],
  87. "margins": {
  88. "Top": 12,
  89. "Left": 15,
  90. "Right": 15,
  91. "Bottom": 15
  92. },
  93. "fillZero": false,
  94. "isNarrow": false,
  95. "borderThick": 2,
  96. "showVerticalLine": true,
  97. "closeWarterMark": true,
  98. "continuousOutput": false
  99. };
  100. const PAGE_SIZE = '<%- size %>';
  101. let currentPageRst = null;
  102. let currentDownloadUrl = null;
  103. let currentDownloadIdx = 0;
  104. let currentReportName = '奉建项目现场收方单';
  105. dynamicLoadJs('/public/jspdf/Arial Narrow-normal.js');
  106. dynamicLoadJs('/public/jspdf/Arial Narrow-bold.js');
  107. dynamicLoadJs('/public/jspdf/Arial Narrow-italic.js');
  108. dynamicLoadJs('/public/jspdf/Arial Narrow-bolditalic.js');
  109. function pageLoading() {
  110. let req_params = JSON.parse(sessionStorage.req_params);
  111. currentReportName = sessionStorage.rpt_name;
  112. let params = {};
  113. params.rpt_tpl_id = req_params.rpt_tpl_id;
  114. params.pageSize = PAGE_SIZE;
  115. params.project_id = req_params.project_id;
  116. params.tender_id = req_params.tender_id;
  117. params.stage_id = req_params.stage_id;
  118. params.stage_status = 3;
  119. params.closeWatermark = 1;
  120. params.custCfg = CUST_CFG;
  121. CommonAjax.postXsrfEx("/tender/report_api/getReport", params, 300000, true, getCookie('csrfToken_j'),
  122. function(result){
  123. currentPageRst = result.data;
  124. _replaceKeyValue(currentPageRst);
  125. let qrCodePath = sessionStorage.qrCodePath;
  126. _addQRCode(currentPageRst, qrCodePath);
  127. let canvas = document.getElementById("rptIndividualCanvas");
  128. if (currentPageRst && currentPageRst.items && currentPageRst.items.length > 0) {
  129. let size = JpcCanvasOutput.getReportSizeInPixel(currentPageRst, SCREEN_DPI);
  130. canvas.width = size[0] + 20;
  131. if (size[1] > size[0]) {
  132. canvas.height = size[1] + 100;
  133. } else {
  134. canvas.height = size[1] + 50;
  135. }
  136. JpcCanvasOutput.cleanCanvas(canvas);
  137. JpcCanvasOutput.drawPageBorder(currentPageRst, canvas, SCREEN_DPI);
  138. JpcCanvasOutput.drawToCanvas(currentPageRst, canvas, 1);
  139. } else {
  140. //返回了无数据表
  141. JpcCanvasOutput.cleanCanvas(canvas);
  142. JpcCanvasOutput.drawPageBorder(currentPageRst, canvas, SCREEN_DPI);
  143. }
  144. }, function(err){
  145. console.log(err);
  146. }, function(ex){
  147. console.log(ex);
  148. }
  149. );
  150. }
  151. function _replaceKeyValue(pageRst) {
  152. if (sessionStorage.replace_key_params) {
  153. let replace_key_params = JSON.parse(sessionStorage.replace_key_params);
  154. if (pageRst.items && pageRst.items.length > 0) {
  155. for (let pageItem of pageRst.items) {
  156. for (let cell of pageItem.cells) {
  157. for (let keyP in replace_key_params) {
  158. if (cell.Value === keyP) {
  159. cell.Value = replace_key_params[keyP];
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. function _addQRCode(pageRst, qrCodePath) {
  168. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  169. for (pageItem of pageRst.items) {
  170. let maxRight = 0, minTop = 10000;
  171. for (let cell of pageItem.cells) {
  172. maxRight = (cell.area.Right > maxRight) ? cell.area.Right : maxRight;
  173. minTop = (cell.area.Top < minTop) ? cell.area.Top : minTop;
  174. }
  175. // let offset = pageRst.MergeBand.Top - minTop - 5;
  176. let offset = 86;
  177. let left = maxRight - offset;
  178. let bottom = minTop + offset;
  179. let signCell = {area: {Left: left, Right: maxRight, Top: minTop, Bottom: bottom}, control: 'Column', path: qrCodePath, pic: null, signature_name: 'dummy_pic', style: 'Default_None', isOrgShow: true};
  180. pageItem.signature_cells.push(signCell);
  181. //注:这里不用async方式,只有一个二维图,一瞬间就能下载完
  182. _getBlob(qrCodePath).then(blob => {
  183. // saveAs(blob, filename);
  184. let oFileReader = new FileReader();
  185. oFileReader.onloadend = function (e) {
  186. let base64 = e.target.result;
  187. // console.log("方式一》》》》》》》》》", base64)
  188. signCell.pic = base64;
  189. };
  190. oFileReader.readAsDataURL(blob);
  191. });
  192. }
  193. }
  194. }
  195. function exportPDF() {
  196. //导出PDF
  197. if (currentPageRst) {
  198. if (pdfFont['SmartSimsun'].length === 2) {
  199. JpcJsPDFHelper.outputAsPdf(currentPageRst, PAGE_SIZE, currentReportName, [], []);
  200. } else {
  201. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', _getPdfFontCallback);
  202. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', _getPdfFontCallback);
  203. }
  204. }
  205. }
  206. function dynamicLoadJs(url, type, callback) {
  207. let head = document.getElementsByTagName('head')[0];
  208. let script = document.createElement('script');
  209. script.type = 'text/javascript';
  210. script.src = url;
  211. if (callback) {
  212. script.onload = script.onreadystatechange = function (event) {
  213. callback(type);
  214. script.onload = script.onreadystatechange = null;
  215. };
  216. }
  217. head.appendChild(script);
  218. }
  219. function _getPdfFontCallback(fontProperty) {
  220. if (pdfFont['SmartSimsun'].indexOf(fontProperty) < 0) {
  221. pdfFont['SmartSimsun'].push(fontProperty);
  222. }
  223. if (pdfFont['SmartSimsun'].length === 2) {
  224. JpcJsPDFHelper.outputAsPdf(currentPageRst, PAGE_SIZE, currentReportName, [], []);
  225. }
  226. }
  227. function downloadReport(urls) {
  228. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  229. currentDownloadUrl = null;
  230. currentDownloadIdx = 0;
  231. const private_download = function() {
  232. if (currentDownloadIdx >= 0 && currentDownloadIdx < urls.length) {
  233. currentDownloadUrl = urls[currentDownloadIdx];
  234. currentDownloadIdx++;
  235. window.location = currentDownloadUrl;
  236. if (currentDownloadIdx < urls.length) setTimeout(private_download, 2000);
  237. }
  238. }
  239. private_download();
  240. }
  241. function _getBlob(url) {
  242. return new Promise(resolve => {
  243. const xhr = new XMLHttpRequest();
  244. xhr.open('GET', url, true);
  245. xhr.responseType = 'blob';
  246. xhr.onload = () => {
  247. if (xhr.status === 200) {
  248. resolve(xhr.response);
  249. }
  250. };
  251. xhr.send();
  252. });
  253. }
  254. </SCRIPT>
  255. </html>