rpt_archive.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /**
  2. * Created by Tony on 2021/4/2.
  3. */
  4. let rptArchiveObj = {
  5. treeObj: null,
  6. currentNode: null,
  7. currentArchiveUuid: null,
  8. currentArchiveDateStr: null,
  9. currentEncryptionList: null,
  10. currentArchivePdfPath: null,
  11. iniPage: function() {
  12. //初始化页面的归档信息
  13. let me = rptArchiveObj;
  14. me.currentNode = null;
  15. me.currentArchiveUuid = null;
  16. me.currentArchiveDateStr = null;
  17. me.currentEncryptionList = null;
  18. me.currentArchivePdfPath = null;
  19. const archivedRptIds = [];
  20. for (let aItem of ARCHIVE_LIST) {
  21. archivedRptIds.push(parseInt(aItem.rpt_id));
  22. }
  23. let private_remove_hide_item = function (items, nlv) {
  24. if (items && items.length > 0) {
  25. for (let i = items.length - 1; i >= 0; i--) {
  26. if (!(items[i].released) && items[i].nodeType === 2) {
  27. items.splice(i, 1);
  28. } else {
  29. if (items[i].items && items[i].items.length > 0) {
  30. private_remove_hide_item(items[i].items, nlv + 1);
  31. if (items[i].items.length === 0 && nlv > 0) {
  32. items.splice(i, 1);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. };
  39. const private_remove_un_archive_item = function(items, nlv) {
  40. if (items && items.length > 0) {
  41. for (let i = items.length - 1; i >= 0; i--) {
  42. if (items[i].nodeType === 2) {
  43. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  44. items.splice(i, 1);
  45. }
  46. } else {
  47. if (items[i].items && items[i].items.length > 0) {
  48. private_remove_un_archive_item(items[i].items, nlv + 1);
  49. if (items[i].items.length === 0 && nlv > 0) {
  50. items.splice(i, 1);
  51. }
  52. } else {
  53. //items[i]是目录,但又没有items子项,
  54. items.splice(i, 1);
  55. }
  56. }
  57. }
  58. }
  59. };
  60. let nodeLv = 0;
  61. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  62. private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
  63. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
  64. me.treeObj.expandAll(true);
  65. me.refreshNodes();
  66. rptArchiveObj._countChkedRptTpl();
  67. rptArchiveObj._buildeArchiveDateSelect();
  68. },
  69. toggleBtn: function (enabled) {
  70. if (current_stage_status === 3 && enabled) {
  71. $('#btnArchiveRpt').removeAttr('disabled');
  72. $('#btnArchiveList').removeAttr('disabled');
  73. } else {
  74. $('#btnArchiveRpt').attr('disabled', '');
  75. $('#btnArchiveList').attr('disabled', '');
  76. }
  77. },
  78. refreshNodes: function() {
  79. let me = this;
  80. let private_setupIsParent = function(node){
  81. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  82. if (node.items && node.items.length) {
  83. for (let i = 0; i < node.items.length; i++) {
  84. private_setupIsParent(node.items[i]);
  85. }
  86. }
  87. };
  88. let topNodes = me.treeObj.getNodes();
  89. for (let i = 0; i < topNodes.length; i++) {
  90. private_setupIsParent(topNodes[i]);
  91. }
  92. me.treeObj.refresh();
  93. },
  94. onCheck: function(event, treeId, treeNode) {
  95. rptArchiveObj._countChkedRptTpl();
  96. if (treeNode.isParent) {
  97. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  98. }
  99. },
  100. onClick: function(event,treeId,treeNode) {
  101. let me = rptArchiveObj;
  102. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  103. me.currentNode = treeNode;
  104. for (let aItem of ARCHIVE_LIST) {
  105. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  106. me.currentArchiveUuid = null;
  107. me.currentArchiveDateStr = null;
  108. me.currentArchivePdfPath = null;
  109. if (aItem.items && aItem.items.length > 0) {
  110. // me.currentArchiveUuid = aItem.items[0].uuid;
  111. // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  112. const newItems = _.orderBy(aItem.items, ['updateDate_time'], ['desc']);
  113. me.currentArchiveUuid = newItems[0].uuid;
  114. me.currentArchiveDateStr = '#' + (_.findIndex(aItem.items, { updateDate_time: newItems[0].updateDate_time})+1) + ' ' + newItems[0].updateDate_time;
  115. if (can_netcasign) {
  116. for (const [i,item] of aItem.items.entries()) {
  117. if (_.find(signLogList, { uuid: item.uuid })) {
  118. me.currentArchiveUuid = item.uuid;
  119. me.currentArchiveDateStr = '#' + (i+1) + ' ' + item.updateDate_time;
  120. break;
  121. }
  122. }
  123. }
  124. }
  125. break;
  126. }
  127. }
  128. me._countChkedRptTpl();
  129. me._buildeArchiveDateSelect();
  130. me._requestArchiveReport();
  131. }
  132. },
  133. batchArchive: function() {
  134. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  135. indexDbOprObj.storeReportRequest(current_stage_id, zTreeOprObj.checkedRptTplNodes);
  136. }
  137. },
  138. batchArchiveTest: function() {
  139. indexDbOprObj._test();
  140. },
  141. _requestArchiveReport: function () {
  142. let me = rptArchiveObj;
  143. if (me.currentNode && me.currentArchiveUuid) {
  144. try {
  145. if (can_netcasign) {
  146. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  147. if (!msgSign) {
  148. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  149. }
  150. console.log(current_stage_id, msgSign, me.currentArchiveUuid);
  151. me.currentEncryptionList = msgSign;
  152. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  153. let html = '';
  154. let pagetr = '';
  155. if (msgSign) {
  156. const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
  157. for (const [index,role] of msgSign.encryption.entries()) {
  158. const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
  159. html += '<div class="'+ rows +'">\n' +
  160. ' <div class="custom-control custom-radio custom-control-inline">\n' +
  161. ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
  162. ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
  163. ' </div>\n' +
  164. ' </div>';
  165. }
  166. let uhtml = '';
  167. for (const us of uSignLogList) {
  168. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  169. }
  170. for (let i = 1; i <= msgSign.total_page; i++) {
  171. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  172. }
  173. }
  174. $('#dateStr').html(me.currentArchiveDateStr);
  175. $('#role-list').html(html);
  176. $('#page-list').html(pagetr);
  177. $('#sign_num').text(uSignLogList.length);
  178. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  179. // 是否显示撤销按钮
  180. if(uHadSign && uHadSign.length > 0) {
  181. $('#show-removesign-modal-btn').show();
  182. } else {
  183. $('#show-removesign-modal-btn').hide();
  184. }
  185. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  186. me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') : oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  187. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  188. }, function () {
  189. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  190. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  191. })
  192. } else {
  193. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  194. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  195. console.log(me.currentArchivePdfPath);
  196. }
  197. // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  198. // console.log(uuIdUrl);
  199. // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  200. // NetcaPDFSeal.openPDFWithUrl(window.location.href);
  201. // window.location = uuIdUrl;
  202. } catch (ex) {
  203. console.log(ex.toString());
  204. }
  205. }
  206. },
  207. _changeArchiveDateSelect: function (dom) {
  208. let me = rptArchiveObj;
  209. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  210. me.currentArchiveDateStr = dom.innerHTML;
  211. if(can_netcasign) {
  212. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  213. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  214. me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') : oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  215. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  216. me._buildeArchiveDateSelect();
  217. }, function () {
  218. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  219. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  220. me._buildeArchiveDateSelect();
  221. });
  222. // me._updateSignHtmlAndFrame();
  223. me._requestArchiveReport();
  224. } else {
  225. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  226. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  227. me._buildeArchiveDateSelect();
  228. }
  229. },
  230. _buildeArchiveDateSelect: function () {
  231. let me = rptArchiveObj;
  232. let targetDom = document.getElementById("currentDrpArchiveSelect");
  233. targetDom.innerHTML = me.currentArchiveDateStr;
  234. let drpDom = $("#drpArchiveSelect");
  235. drpDom.empty();
  236. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  237. for (let aItem of ARCHIVE_LIST) {
  238. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  239. for (let [index,item] of aItem.items.entries()) {
  240. if (item.uuid !== me.currentArchiveUuid) {
  241. const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + '#' + (index+1) + ' ' + item.updateDate_time + '</a>';
  242. drpDom.append(str);
  243. }
  244. }
  245. }
  246. }
  247. }
  248. },
  249. _updateSignHtmlAndFrame: function (needFrame = false) {
  250. const me = rptArchiveObj;
  251. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  252. for (let i = 0; i < $('#role-list div').length; i++) {
  253. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  254. $('#role-list div').eq(i).find('input').attr('disabled', true);
  255. } else {
  256. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  257. }
  258. $('#role-list div').eq(i).find('input').prop('checked', false);
  259. }
  260. let uhtml = '';
  261. let pagetr = '';
  262. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  263. if (!msgSign) {
  264. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  265. }
  266. for (const us of uSignLogList) {
  267. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  268. }
  269. for (let i = 1; i <= msgSign.total_page; i++) {
  270. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  271. }
  272. $('#page-list').html(pagetr);
  273. if (needFrame) {
  274. me.currentArchivePdfPath = uSignLogList.length > 0 ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' : oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  275. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') + '" height="750px" width="100%" style="border: none;"></iframe>');
  276. }
  277. $('#dateStr').html(me.currentArchiveDateStr);
  278. $('#sign_num').text(uSignLogList.length);
  279. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  280. // 是否显示撤销按钮
  281. if(uHadSign && uHadSign.length > 0) {
  282. $('#show-removesign-modal-btn').show();
  283. } else {
  284. $('#show-removesign-modal-btn').hide();
  285. }
  286. },
  287. _countChkedRptTpl: function () {
  288. let me = rptArchiveObj;
  289. if (me.treeObj) {
  290. me.checkedRptTplNodes = [];
  291. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  292. for (let node of chkNodes) {
  293. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  294. cnt++;
  295. me.checkedRptTplNodes.push(node);
  296. if (me.currentNode === node) hasCurrentNode = true;
  297. }
  298. }
  299. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  300. //这里根据实际需求再做处理
  301. cnt++;
  302. me.checkedRptTplNodes.push(me.currentNode);
  303. }
  304. $("#print_div").find("span").each(function(cIdx,elementSpan){
  305. elementSpan.innerText = cnt;
  306. });
  307. $("#export_div").find("span").each(function(cIdx,elementSpan){
  308. elementSpan.innerText = cnt;
  309. });
  310. }
  311. },
  312. showArchivedItem: function(currentNode) {
  313. //初始化当前报表已经归档的信息
  314. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  315. if (currentNode) {
  316. //1. cardArchiveInfo
  317. let cardArchiveInfo = $('#cardArchiveInfo');
  318. cardArchiveInfo.empty();
  319. let auditDate = null;
  320. let achivedAmt = 0;
  321. let achivedItem = null;
  322. for (let item of ARCHIVE_LIST) {
  323. if (parseInt(item.rpt_id) === currentNode.refId) {
  324. if (LAST_AUDITOR.end_time) {
  325. auditDate = new Date(LAST_AUDITOR.end_time);
  326. } else {
  327. auditDate = new Date(LAST_AUDITOR.begin_time);
  328. }
  329. achivedAmt = item.items?item.items.length:0;
  330. achivedItem = item;
  331. break;
  332. }
  333. }
  334. if (auditDate) {
  335. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  336. } else {
  337. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  338. }
  339. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  340. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  341. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  342. }
  343. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  344. if (achivedAmt > 0) {
  345. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  346. cardArchiveInfo.append('<div class="form-check">');
  347. // if (achivedAmt === 3) {
  348. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  349. // }
  350. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  351. // let ad = new Date(achivedItem.items[idx].update_time);
  352. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  353. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  354. cardArchiveInfo.append('</label>');
  355. cardArchiveInfo.append('</div>');
  356. }
  357. }
  358. cardArchiveInfo.append('</div>');
  359. //2. selectionArchiveInfo
  360. let selectionArchiveInfo = $('#selectionArchiveInfo');
  361. selectionArchiveInfo.empty();
  362. if (achivedAmt > 0) {
  363. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  364. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  365. }
  366. }
  367. }
  368. },
  369. _getCurrentArchives: function (currentNode) {
  370. let rst = null;
  371. if (ARCHIVE_LIST.length > 0 && currentNode) {
  372. for (let aItem of ARCHIVE_LIST) {
  373. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  374. rst = aItem;
  375. break;
  376. }
  377. }
  378. }
  379. return rst;
  380. },
  381. _chkIfFullArchives: function(currentNode) {
  382. let aItem = this._getCurrentArchives(currentNode);
  383. let rst = (aItem && aItem.items && aItem.items.length === 3);
  384. return rst;
  385. },
  386. _getPageSignatureInfo: function(pageData, rpt_id) {
  387. let psInfo = [], psInfoStr = [];
  388. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  389. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  390. const _getProperSignatureArea = function(cell, control) {
  391. // 约定默认长宽比例是2:1,图片分辨率是600*300
  392. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  393. if (cell && cell[JV.PROP_AREA]) {
  394. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  395. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  396. if (width > height * 2) {
  397. width = height * 2;
  398. } else {
  399. height = width / 2;
  400. }
  401. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  402. case 'left':
  403. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  404. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  405. rst[2] = rst[0] + width;
  406. rst[3] = rst[1] + height;
  407. break;
  408. case 'right':
  409. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  410. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  411. rst[0] = rst[2] - width;
  412. rst[1] = rst[3] - height;
  413. break;
  414. default:
  415. //center
  416. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  417. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  418. rst[2] = rst[0] + width;
  419. rst[3] = rst[1] + height;
  420. break;
  421. }
  422. }
  423. rst[0] = rst[0] + offsetX;
  424. rst[2] = rst[2] + offsetX;
  425. rst[1] = rst[1] + offsetY;
  426. rst[3] = rst[3] + offsetY;
  427. return rst;
  428. }
  429. for(let i = 0; i < pageData.items.length; i++) {
  430. let page = pageData.items[i];
  431. for (let sCell of page.signature_cells) {
  432. // sCell.signature_name 草图不用加密
  433. if (sCell.signature_name !== 'dummy_pic') {
  434. let control = null;
  435. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  436. control = controls[sCell[JV.PROP_CONTROL]];
  437. } else {
  438. control = sCell[JV.PROP_CONTROL];
  439. }
  440. let idx = psInfoStr.indexOf(sCell.signature_name);
  441. let actSignArea = _getProperSignatureArea(sCell, control);
  442. if (idx < 0) {
  443. psInfoStr.push(sCell.signature_name);
  444. let newPsInfo = {'name': sCell.signature_name, areas: []};
  445. let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []};
  446. area.pages.push(i + 1);
  447. newPsInfo.areas.push(area);
  448. psInfo.push(newPsInfo);
  449. } else {
  450. let hasArea = false;
  451. for (let areaItem of psInfo[idx].areas) {
  452. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  453. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  454. areaItem.pages.push(i + 1);
  455. hasArea = true;
  456. break;
  457. }
  458. }
  459. if (!hasArea) {
  460. let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []};
  461. area.pages.push(i + 1);
  462. psInfo[idx].areas.push(area);
  463. }
  464. }
  465. }
  466. }
  467. }
  468. return psInfo;
  469. },
  470. archiveCurrentReport: function (currentRptPageRst, currentNode) {
  471. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  472. // 1. 找草图路径
  473. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  474. // 每页
  475. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  476. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  477. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  478. if (sCell.signature_name === 'dummy_pic') {
  479. //1. 草图就不考虑重复问题,重复就重复吧;
  480. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  481. let picIdx = picKeys.indexOf(sCell.path);
  482. if (picIdx < 0) {
  483. picKeys.push(sCell.path);
  484. picCells.push(sCell);
  485. } else {
  486. let dPicIdx = dupPicPath.indexOf(sCell.path);
  487. if (dPicIdx < 0) {
  488. dupPicPath.push(sCell.path);
  489. dupPicCell.push([]);
  490. dPicIdx = dupPicPath.length - 1;
  491. }
  492. dupPicCell[dPicIdx].push(sCell);
  493. }
  494. }
  495. }
  496. }
  497. // 2. 下载草图,下载完毕后upload
  498. if (picCells.length > 0) {
  499. $.bootstrapLoading.start();
  500. let picAmt = picCells.length, picCnt = 0;
  501. let exceptionAmt = 0;
  502. for (let idx = 0; idx < picCells.length; idx++) {
  503. let dCell = picCells[idx];
  504. getBlob(picKeys[idx]).then(blob => {
  505. if (blob === 'not found!') {
  506. exceptionAmt++;
  507. if ((picCnt + exceptionAmt) === picAmt) {
  508. $.bootstrapLoading.end();
  509. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
  510. }
  511. } else {
  512. let oFileReader = new FileReader();
  513. oFileReader.onloadend = function (e) {
  514. picCnt++;
  515. let base64 = e.target.result;
  516. picCells[idx].pic = base64;
  517. let pPathIdx = dupPicPath.indexOf(dCell.path);
  518. if (pPathIdx >= 0) {
  519. for (let dupCell of dupPicCell[pPathIdx]) {
  520. dupCell.pic = base64;
  521. }
  522. }
  523. if ((picCnt + exceptionAmt) === picAmt) {
  524. $.bootstrapLoading.end();
  525. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
  526. }
  527. };
  528. oFileReader.readAsDataURL(blob);
  529. }
  530. });
  531. }
  532. } else {
  533. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode);
  534. }
  535. },
  536. _archiveCurrentReport: function(currentRptPageRst, currentNode) {
  537. // 归档当前报表
  538. if (currentRptPageRst !== null) {
  539. try {
  540. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  541. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, currentNode.refId);
  542. // console.log(pageEncryptInfo);
  543. let formData = new FormData();
  544. formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
  545. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  546. postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
  547. // 成功后,更新当前页面
  548. if (result.addedRst) {
  549. // console.log(result);
  550. ARCHIVE_LIST = result.addedRst;
  551. rptArchiveObj.showArchivedItem(currentNode);
  552. zTreeOprObj.refreshNodes();
  553. //第二步:增加加密信息
  554. let params = {};
  555. params.prjId = PROJECT_ID;
  556. params.stgId = current_stage_id;
  557. params.rptId = currentNode.refId;
  558. params.ttlPgs = currentRptPageRst.items.length;
  559. params.content = pageEncryptInfo;
  560. params.uuid = result.uuid; //正确返回时,带着uuid回来
  561. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  562. function(result){
  563. //
  564. }, function(err){
  565. //
  566. }, function(ex){
  567. //
  568. }
  569. );
  570. } else {
  571. // 有冲突,需要删除
  572. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  573. function(result){
  574. //
  575. }
  576. );
  577. }
  578. }, function (error){
  579. // alert(error);
  580. });
  581. } else {
  582. let aItem = this._getCurrentArchives(currentNode);
  583. if (aItem && aItem.items && aItem.items.length > 0) {
  584. let orgName = aItem.items[0].uuid;
  585. let compStr = aItem.items[0].updateDate_time;
  586. for (let idx = 1; idx < aItem.items.length; idx++) {
  587. if (aItem.items[idx].updateDate_time < compStr) {
  588. compStr = aItem.items[idx].updateDate_time;
  589. orgName = aItem.items[idx].uuid;
  590. }
  591. }
  592. postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  593. // 成功后,更新当前页面
  594. if (result.updatedRst) {
  595. // console.log(result);
  596. ARCHIVE_LIST = result.updatedRst;
  597. rptArchiveObj.showArchivedItem(currentNode);
  598. zTreeOprObj.refreshNodes();
  599. //第二步:更新加密信息
  600. let params = {};
  601. params.prjId = PROJECT_ID;
  602. params.stgId = current_stage_id;
  603. params.rptId = currentNode.refId;
  604. params.ttlPgs = currentRptPageRst.items.length;
  605. params.content = pageEncryptInfo;
  606. params.uuid = orgName;
  607. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  608. function(result){
  609. //
  610. }, function(err){
  611. //
  612. }, function(ex){
  613. //
  614. }
  615. );
  616. } else {
  617. // 有冲突,需要删除
  618. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  619. function(result){
  620. //
  621. }
  622. );
  623. }
  624. }, function (error){
  625. // alert(error);
  626. });
  627. }
  628. }
  629. } catch (ex) {
  630. console.log(ex.toString());
  631. }
  632. } else {
  633. alert('请选择打开一个报表!');
  634. }
  635. }
  636. };
  637. function dataURLtoFile(dataurl, filename) {
  638. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  639. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  640. while(n--){
  641. u8arr[n] = bstr.charCodeAt(n);
  642. }
  643. return new File([u8arr], filename, {type:mime});
  644. };
  645. /**
  646. * 获取 blob
  647. * @param {String} url 目标文件地址
  648. * @return {Promise}
  649. */
  650. function getBlob(url) {
  651. return new Promise(resolve => {
  652. const xhr = new XMLHttpRequest();
  653. xhr.open('GET', url, true);
  654. xhr.responseType = 'blob';
  655. xhr.onload = () => {
  656. if (xhr.status === 200) {
  657. resolve(xhr.response);
  658. } else {
  659. resolve('not found!');
  660. }
  661. };
  662. xhr.send();
  663. });
  664. }
  665. /**
  666. * pdf base64 转 blob
  667. * @param {String} dataUrl base64码
  668. * @return {Promise}
  669. */
  670. function convertBase64UrlToBlob(dataUrl) {
  671. //去掉url的头,并转换为byte
  672. var bytes = window.atob(dataUrl);
  673. //处理异常,将ascii码小于0的转换为大于0
  674. var ab = new Uint8Array(bytes.length);
  675. for (var i = 0; i < bytes.length; i++) {
  676. ab[i] = bytes.charCodeAt(i);
  677. }
  678. return new Blob([ab], { type: 'application/pdf' });
  679. }
  680. /**
  681. * 保存
  682. * @param {Blob} blob
  683. * @param {String} filename 想要保存的文件名称
  684. */
  685. function saveAs(blob, filename) {
  686. if (window.navigator.msSaveOrOpenBlob) {
  687. navigator.msSaveBlob(blob, filename);
  688. } else {
  689. const link = document.createElement('a');
  690. const body = document.querySelector('body');
  691. link.href = window.URL.createObjectURL(blob);
  692. link.download = filename;
  693. // fix Firefox
  694. link.style.display = 'none';
  695. body.appendChild(link);
  696. link.click();
  697. body.removeChild(link);
  698. window.URL.revokeObjectURL(link.href);
  699. }
  700. }
  701. /**
  702. * 下载
  703. * @param {String} url 目标文件地址
  704. * @param {String} filename 想要保存的文件名称
  705. */
  706. function download(url, filename) {
  707. getBlob(url).then(blob => {
  708. saveAs(blob, filename);
  709. });
  710. }
  711. $(function () {
  712. $('#download_file').click(function () {
  713. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  714. console.log(rptArchiveObj.currentArchivePdfPath);
  715. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  716. } else {
  717. alert('请选择打开一个报表!');
  718. }
  719. });
  720. $('#print_file').click(function () {
  721. if (rptArchiveObj.currentArchiveUuid) {
  722. $('#iframe_made iframe')[0].contentWindow.print();
  723. } else {
  724. alert('请选择打开一个报表!');
  725. }
  726. });
  727. })