detail.ejs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <script type="text/javascript" src="/public/jspdf/jspdf.min.js"></script>
  2. <script type="text/javascript" src="/public/report/js/rpt_public.js"></script>
  3. <script type="text/javascript" src="/public/js/common_ajax.js"></script>
  4. <script type="text/javascript" src="/public/report/js/jpc_output_value_define.js"></script>
  5. <script type="text/javascript" src="/public/report/js/rpt_signature.js"></script>
  6. <script type="text/javascript" src="/public/report/js/jpc_output.js"></script>
  7. <script type="text/javascript" src="/public/report/js/rpt_move_signature.js"></script>
  8. <script type="text/javascript" src="/public/report/js/rpt_jspdf.js"></script>
  9. <div class="panel-content">
  10. <div class="panel-title fluid">
  11. <div class="title-main d-flex justify-content-between">
  12. <div><a href="/payment/<%- ctx.tender.id %>/list/<%- trInfo.id %>"><i class="fa fa-chevron-left mr-2"></i></a><%- ctx.tender.name %> / <%- trInfo.rpt_name %> / <%- ctx.detail.code %></div>
  13. <div>
  14. <% if ((ctx.detail.status == auditConst.status.uncheck || ctx.detail.status == auditConst.status.checkNo) && trInfo.is_change) { %>
  15. <span class="text-danger pull-right">报表内容已发生变化,请删除并重新生成详情</span>
  16. <% } else { %>
  17. <% include ./audit_btn.ejs %>
  18. <% if (rptAudit &&
  19. ((ctx.detail.status !== auditConst.status.checkNo && ctx.detail.status !== auditConst.status.checked) ||
  20. (ctx.detail.status === auditConst.status.checked && !nextDetail) ||
  21. (ctx.detail.status === auditConst.status.checkNo && ctx.detail.uid === ctx.session.sessionUser.accountId))
  22. ) { %>
  23. <a href="#sub-sp5" data-toggle="modal" data-target="#sub-sp5" class="btn btn-sm btn-primary pull-right mr-2">签字意见</a>
  24. <% } %>
  25. <% } %>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="content-wrap">
  30. <div class="c-body">
  31. <div class="sjs-height-0">
  32. <div class="row m-0 mt-3">
  33. <div id="rpt-form" class="col-5 mr-3">
  34. <% for (const c of content) { %>
  35. <div>
  36. <h5><%- c.title %>内容</h5>
  37. <% for (const item of c.items) { %>
  38. <div class="form-group">
  39. <label><%- item.label %></label>
  40. <% if (item.type === 'textarea') { %>
  41. <textarea <% if (ctx.detail.readOnly) { %>readonly<% } %> class="form-control form-control-sm" data-index="<%- item.index %>"><%- item.value %></textarea>
  42. <% } else { %>
  43. <input <% if (ctx.detail.readOnly) { %>readonly<% } %> type="<%- item.type %>" value="<%- item.value %>" data-index="<%- item.index %>" class="form-control form-control-sm" placeholder="请输入">
  44. <% } %>
  45. </div>
  46. <% } %>
  47. </div>
  48. <% } %>
  49. </div>
  50. <div class="col-6 ml-5">
  51. <div class="d-flex flex-row">
  52. <a href="javascript: void(0);" onclick="auditRptPrintHelper.showPage()" class="mr-2" >刷新</a>
  53. <a href="javascript: void(0);" class="mr-2" onclick="auditRptPrintHelper.directPDF()">导出pdf</a>
  54. <a href="javascript: void(0);" onclick="auditRptPrintHelper.directPrint()">打印</a>
  55. </div>
  56. <div align="center">
  57. <canvas id="auditRptCanvas" height="1200" width="920"></canvas>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <script type="text/javascript">
  66. const tenderId = parseInt('<%- ctx.tender.id %>');
  67. const detailId = parseInt('<%- ctx.detail.id %>');
  68. const rptAudit = JSON.parse(unescape('<%- escape(JSON.stringify(rptAudit)) %>'));
  69. console.log(rptAudit);
  70. <% if (ctx.detail.status !== auditConst.status.checked && rptAudit) { %>
  71. let currentStamp = JSON.parse(unescape('<%- escape(JSON.stringify(currentStamp)) %>'));
  72. <% } %>
  73. let tesRpttData = JSON.parse(unescape('<%- escape(JSON.stringify(report_json)) %>'));
  74. console.log(tesRpttData);
  75. const SCREEN_DPI = [];
  76. const PAGE_SHOW = {closeWaterMark: 1};
  77. const current_stage_status = -1;
  78. const VIEW_CANVAS = document.getElementById("auditRptCanvas");
  79. const OSS_PATH = '<%- OSS_PATH %>';
  80. const CUST_CFG = {
  81. "fonts": [
  82. {
  83. "ID": "ReportTitle_Main",
  84. "Name": "宋体",
  85. "FontBold": "T",
  86. "FontHeight": 32,
  87. "FontItalic": "F",
  88. "CfgDispName": "表标题",
  89. "FontUnderline": "F"
  90. },
  91. {
  92. "ID": "Column",
  93. "Name": "宋体",
  94. "FontBold": "F",
  95. "FontHeight": 12,
  96. "FontItalic": "F",
  97. "CfgDispName": "列标题",
  98. "FontUnderline": "F"
  99. },
  100. {
  101. "ID": "Content",
  102. "Name": "宋体",
  103. "FontBold": "F",
  104. "FontHeight": 12,
  105. "FontItalic": "F",
  106. "CfgDispName": "正文内容",
  107. "FontUnderline": "F"
  108. },
  109. {
  110. "ID": "Total",
  111. "Name": "宋体",
  112. "FontBold": "F",
  113. "FontHeight": 12,
  114. "FontItalic": "F",
  115. "CfgDispName": "合计",
  116. "FontUnderline": "F"
  117. },
  118. {
  119. "ID": "Header",
  120. "Name": "宋体",
  121. "FontBold": "F",
  122. "FontHeight": 12,
  123. "FontItalic": "F",
  124. "CfgDispName": "表眉/表脚",
  125. "FontUnderline": "F"
  126. }
  127. ],
  128. "margins": {
  129. "Top": 12,
  130. "Left": 15,
  131. "Right": 15,
  132. "Bottom": 15
  133. },
  134. "fillZero": false,
  135. "isNarrow": false,
  136. "borderThick": 2,
  137. "showVerticalLine": true,
  138. "closeWarterMark": false,
  139. "continuousOutput": true
  140. }
  141. let zTreeOprObj = {
  142. _chkPrePayStatus: function() {
  143. return -1;
  144. }
  145. };
  146. let rptTplObj = {
  147. pdfFont: {'SmartSimsun': [], 'simhei': [], 'simkai': []},
  148. isLoading: false,
  149. };
  150. let auditRptPrintHelper = {
  151. currentPageData: null,
  152. currentDownloadIdx: 0,
  153. chkPicFeatures: async function(pageData) {
  154. for (let page of pageData.items) {
  155. for (let signCell of page.signature_cells) {
  156. if (typeof signCell.path === 'string' && signCell.path.length > 10) {
  157. let paths = signCell.path.split('!;!');
  158. signCell.picFeatures = [];
  159. if (!signCell.orgArea) {
  160. signCell.orgArea = JSON.parse(JSON.stringify(signCell.area));
  161. }
  162. signCell.signType = 'mixed';
  163. for (let path of paths) {
  164. let imgSrc = path;
  165. if (path.indexOf(OSS_PATH) < 0 && path[0] !== '/') {
  166. imgSrc = OSS_PATH + path;
  167. }
  168. const picFeature = await getPicFeature(imgSrc);
  169. signCell.picFeatures.push(picFeature);
  170. }
  171. }
  172. }
  173. }
  174. },
  175. showPage: async function() {
  176. await auditRptPrintHelper.chkPicFeatures(tesRpttData);
  177. JpcCanvasOutput.cleanCanvas(VIEW_CANVAS);
  178. JpcCanvasOutput.drawPageBorder(tesRpttData, VIEW_CANVAS, getScreenDPI());
  179. JpcCanvasOutput.drawToCanvas(tesRpttData, VIEW_CANVAS, 1, false, true);
  180. },
  181. directPrint: function() {
  182. sessionStorage.report_direct_data = JSON.stringify(tesRpttData);
  183. sessionStorage.closeWaterMark = 1;
  184. sessionStorage.pageSize = 'A4';
  185. sessionStorage.OSS_PATH = OSS_PATH;
  186. window.open('/printReport/A4');
  187. },
  188. _getPdfFontCallback: function(fontProperty) {
  189. let me = auditRptPrintHelper;
  190. if (rptTplObj.pdfFont['SmartSimsun'].indexOf(fontProperty) < 0) {
  191. rptTplObj.pdfFont['SmartSimsun'].push(fontProperty);
  192. }
  193. if (rptTplObj.pdfFont['SmartSimsun'].length >= 2) {
  194. $.bootstrapLoading.end();
  195. downloadPDFReport([tesRpttData], 'A4', [tesRpttData['打印页面_信息']['报表名称']], [], [], [-1], []);
  196. }
  197. },
  198. directPDF: function() {
  199. if (rptTplObj.pdfFont['SmartSimsun'].length >= 2) {
  200. downloadPDFReport([tesRpttData], 'A4', [tesRpttData['打印页面_信息']['报表名称']], [], [], [-1], []);
  201. } else {
  202. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-normal2.js', 'normal', this._getPdfFontCallback);
  203. dynamicLoadJs('https://d2.smartcost.com.cn/cach/SmartSimsun-bold.js', 'bold', this._getPdfFontCallback);
  204. }
  205. },
  206. };
  207. // $(document).ready(() => {
  208. // autoFlashHeight();
  209. // auditRptPrintHelper.showPage();
  210. // iniPage();
  211. // });
  212. function _getAdhocDummyCells(srcCell, rstCells) {
  213. if (typeof srcCell.path === 'string') {
  214. let paths = srcCell.path.split('!;!');
  215. for (let dtlPathIdx = 0; dtlPathIdx < paths.length; dtlPathIdx++) {
  216. dtlPath = paths[dtlPathIdx];
  217. // srcCell.picFeatures
  218. if (dtlPath.length > 10) {
  219. let imgSrc = dtlPath;
  220. if (dtlPath.indexOf(OSS_PATH) < 0 && dtlPath[0] !== '/') {
  221. imgSrc = OSS_PATH + dtlPath;
  222. }
  223. let couldCreate = true;
  224. if (srcCell.picFeatures && srcCell.picFeatures.length === paths.length && srcCell.picFeatures[dtlPathIdx] === 'not found!') {
  225. couldCreate = false;
  226. }
  227. if (couldCreate) {
  228. const newStampCell = {
  229. signature_name: 'dummy_pic',
  230. control: srcCell.control,
  231. style: srcCell.style,
  232. path: imgSrc,
  233. isStamp: true,
  234. area: srcCell.area,
  235. };
  236. rstCells.push(newStampCell);
  237. }
  238. }
  239. }
  240. }
  241. }
  242. function downloadPDFReport(pageDataArr, pageSize, rpt_names, signatureRelArr, signatureRelInfo, refRptTplIds, STAGE_AUDIT) {
  243. auditRptPrintHelper.currentDownloadIdx = 0;
  244. const private_download = function(newPageDataArr, new_rpt_names, dummyCells) {
  245. if (auditRptPrintHelper.currentDownloadIdx < newPageDataArr.length) {
  246. let singleSignatureRelArr = [];
  247. for (let rIdx = 0; rIdx < signatureRelInfo.length; rIdx++) {
  248. let rptId = refRptTplIds[auditRptPrintHelper.currentDownloadIdx];
  249. if (signatureRelInfo[rIdx].rpt_id === rptId) {
  250. singleSignatureRelArr = signatureRelArr[rIdx]; // 有些报表可能没有签名
  251. break;
  252. }
  253. }
  254. let pageData = newPageDataArr[auditRptPrintHelper.currentDownloadIdx];
  255. let rptName = new_rpt_names[auditRptPrintHelper.currentDownloadIdx];
  256. auditRptPrintHelper.currentDownloadIdx++;
  257. JpcJsPDFHelper.outputAsPdf(pageData, pageSize, rptName, singleSignatureRelArr, STAGE_AUDIT); // 精确控制签名
  258. if (auditRptPrintHelper.currentDownloadIdx < newPageDataArr.length) {
  259. setTimeout(private_download(newPageDataArr, new_rpt_names), 2000);
  260. } else {
  261. for (let pd of newPageDataArr) {
  262. for (let pItem of pd.items) {
  263. for (let idx = pItem.signature_cells.length - 1; idx >= 0; idx--) {
  264. let pIdx = dummyCells.indexOf(pItem.signature_cells[idx]);
  265. if (pIdx >= 0) {
  266. pItem.signature_cells.splice(idx, 1);
  267. dummyCells.splice(pIdx, 1);
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. };
  275. // 导出PDF审核优化代码
  276. let picPaths = [], dummyPicAmt = 0, dummyCells = [];
  277. // 1. 先找有没有dummy
  278. for (let pageData of pageDataArr) {
  279. let tmpDummyCells = [];
  280. for (let page of pageData.items) {
  281. for (let dCell of page.signature_cells) {
  282. _getAdhocDummyCells(dCell, tmpDummyCells);
  283. }
  284. if (tmpDummyCells.length > 0) {
  285. page.signature_cells = page.signature_cells.concat(tmpDummyCells);
  286. dummyCells = dummyCells.concat(tmpDummyCells);
  287. }
  288. }
  289. }
  290. dummyPicAmt = dummyCells.length;
  291. if (dummyPicAmt > 0) {
  292. // 2. 有则一个个请求下载图片,下载完后统一导出PDF
  293. $.bootstrapLoading.start();
  294. let handledAmt = 0, exceptionAmt = 0;
  295. for (let pIdx = 0; pIdx < dummyCells.length; pIdx++) {
  296. let dCell = dummyCells[pIdx];
  297. getBlobPublic(dCell.path).then(blob => {
  298. if (blob === 'not found!') {
  299. exceptionAmt++;
  300. if ((handledAmt + exceptionAmt) === dummyPicAmt) {
  301. $.bootstrapLoading.end();
  302. private_download(pageDataArr, rpt_names, dummyCells);
  303. }
  304. } else {
  305. let oFileReader = new FileReader();
  306. oFileReader.onloadend = function (e) {
  307. let base64 = e.target.result;
  308. dCell.pic = base64;
  309. handledAmt++;
  310. if ((handledAmt + exceptionAmt) === dummyPicAmt) {
  311. $.bootstrapLoading.end();
  312. private_download(pageDataArr, rpt_names, dummyCells);
  313. }
  314. };
  315. oFileReader.readAsDataURL(blob);
  316. }
  317. });
  318. }
  319. } else {
  320. // 3. 无则普通导出
  321. private_download(pageDataArr, rpt_names);
  322. }
  323. //*/
  324. }
  325. </script>