detail.ejs 17 KB

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