rpt_individual.ejs 11 KB

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