rpt_individual.ejs 10 KB

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