rpt_individual.ejs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. if (currentPageRst.items.length > 1) {
  130. //理论上要清理冗余数据
  131. currentPageRst.items = currentPageRst.items.slice(0,1);
  132. }
  133. let size = JpcCanvasOutput.getReportSizeInPixel(currentPageRst, SCREEN_DPI);
  134. canvas.width = size[0] + 20;
  135. if (size[1] > size[0]) {
  136. canvas.height = size[1] + 100;
  137. } else {
  138. canvas.height = size[1] + 50;
  139. }
  140. JpcCanvasOutput.cleanCanvas(canvas);
  141. JpcCanvasOutput.drawPageBorder(currentPageRst, canvas, SCREEN_DPI);
  142. JpcCanvasOutput.drawToCanvas(currentPageRst, canvas, 1);
  143. } else {
  144. //返回了无数据表
  145. JpcCanvasOutput.cleanCanvas(canvas);
  146. JpcCanvasOutput.drawPageBorder(currentPageRst, canvas, SCREEN_DPI);
  147. }
  148. }, function(err){
  149. console.log(err);
  150. }, function(ex){
  151. console.log(ex);
  152. }
  153. );
  154. }
  155. function _replaceKeyValue(pageRst) {
  156. if (sessionStorage.replace_key_params) {
  157. let replace_key_params = JSON.parse(sessionStorage.replace_key_params);
  158. if (pageRst.items && pageRst.items.length > 0) {
  159. for (let pageItem of pageRst.items) {
  160. for (let cell of pageItem.cells) {
  161. for (let keyP in replace_key_params) {
  162. if (cell.Value === keyP) {
  163. cell.Value = replace_key_params[keyP];
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. function _addQRCode(pageRst, qrCodePath) {
  172. if (pageRst && pageRst.items && pageRst.items.length > 0) {
  173. for (pageItem of pageRst.items) {
  174. let maxRight = 0, minTop = 10000;
  175. for (let cell of pageItem.cells) {
  176. maxRight = (cell.area.Right > maxRight) ? cell.area.Right : maxRight;
  177. minTop = (cell.area.Top < minTop) ? cell.area.Top : minTop;
  178. }
  179. // let offset = pageRst.MergeBand.Top - minTop - 5;
  180. let offset = 86;
  181. let left = maxRight - offset;
  182. let bottom = minTop + offset;
  183. 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};
  184. pageItem.signature_cells.push(signCell);
  185. //注:这里不用async方式,只有一个二维图,一瞬间就能下载完
  186. _getBlob(qrCodePath).then(blob => {
  187. // saveAs(blob, filename);
  188. let oFileReader = new FileReader();
  189. oFileReader.onloadend = function (e) {
  190. let base64 = e.target.result;
  191. // console.log("方式一》》》》》》》》》", base64)
  192. signCell.pic = base64;
  193. };
  194. oFileReader.readAsDataURL(blob);
  195. });
  196. }
  197. }
  198. }
  199. function exportPDF() {
  200. //导出PDF
  201. if (currentPageRst) {
  202. if (pdfFont['SmartSimsun'].length === 2) {
  203. JpcJsPDFHelper.outputAsPdf(currentPageRst, PAGE_SIZE, currentReportName, [], []);
  204. } else {
  205. // dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal.js', 'normal', _getPdfFontCallback);
  206. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', _getPdfFontCallback);
  207. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', _getPdfFontCallback);
  208. }
  209. }
  210. }
  211. function dynamicLoadJs(url, type, callback) {
  212. let head = document.getElementsByTagName('head')[0];
  213. let script = document.createElement('script');
  214. script.type = 'text/javascript';
  215. script.src = url;
  216. if (callback) {
  217. script.onload = script.onreadystatechange = function (event) {
  218. callback(type);
  219. script.onload = script.onreadystatechange = null;
  220. };
  221. }
  222. head.appendChild(script);
  223. }
  224. function _getPdfFontCallback(fontProperty) {
  225. if (pdfFont['SmartSimsun'].indexOf(fontProperty) < 0) {
  226. pdfFont['SmartSimsun'].push(fontProperty);
  227. }
  228. if (pdfFont['SmartSimsun'].length === 2) {
  229. JpcJsPDFHelper.outputAsPdf(currentPageRst, PAGE_SIZE, currentReportName, [], []);
  230. }
  231. }
  232. function downloadReport(urls) {
  233. //考虑到多个报表下载,一些浏览器(如chrome)不允许一下子下载多个文件,得缓缓处理,统一在这处理
  234. currentDownloadUrl = null;
  235. currentDownloadIdx = 0;
  236. const private_download = function() {
  237. if (currentDownloadIdx >= 0 && currentDownloadIdx < urls.length) {
  238. currentDownloadUrl = urls[currentDownloadIdx];
  239. currentDownloadIdx++;
  240. window.location = currentDownloadUrl;
  241. if (currentDownloadIdx < urls.length) setTimeout(private_download, 2000);
  242. }
  243. }
  244. private_download();
  245. }
  246. function _getBlob(url) {
  247. return new Promise(resolve => {
  248. const xhr = new XMLHttpRequest();
  249. xhr.open('GET', url, true);
  250. xhr.responseType = 'blob';
  251. xhr.onload = () => {
  252. if (xhr.status === 200) {
  253. resolve(xhr.response);
  254. }
  255. };
  256. xhr.send();
  257. });
  258. }
  259. </SCRIPT>
  260. </html>