rpt_archive.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /**
  2. * Created by Tony on 2021/4/2.
  3. */
  4. const A4_PIXEL_HEIGHT = 1122;
  5. const A4_PIXEL_WIDTH = 793;
  6. let rptArchiveObj = {
  7. treeObj: null,
  8. currentNode: null,
  9. currentArchiveUuid: null,
  10. currentChildArchiveUuids: null,
  11. currentArchiveDateStr: null,
  12. currentEncryptionList: null,
  13. currentArchivePdfPath: null,
  14. iniPage: function() {
  15. //初始化页面的归档信息
  16. let me = rptArchiveObj;
  17. me.currentNode = null;
  18. me.currentArchiveUuid = null;
  19. me.currentChildArchiveUuids = null;
  20. me.currentArchiveDateStr = null;
  21. me.currentEncryptionList = null;
  22. me.currentArchivePdfPath = null;
  23. const archivedRptIds = [];
  24. for (let aItem of ARCHIVE_LIST) {
  25. archivedRptIds.push(parseInt(aItem.rpt_id));
  26. }
  27. let private_remove_hide_item = function (items, nlv) {
  28. if (items && items.length > 0) {
  29. for (let i = items.length - 1; i >= 0; i--) {
  30. if (!(items[i].released) && items[i].nodeType === 2) {
  31. items.splice(i, 1);
  32. } else {
  33. if (items[i].items && items[i].items.length > 0) {
  34. private_remove_hide_item(items[i].items, nlv + 1);
  35. if (items[i].items.length === 0 && nlv > 0) {
  36. items.splice(i, 1);
  37. }
  38. }
  39. }
  40. }
  41. }
  42. };
  43. const private_remove_un_archive_item = function(items, nlv) {
  44. if (items && items.length > 0) {
  45. for (let i = items.length - 1; i >= 0; i--) {
  46. if (items[i].nodeType === 2) {
  47. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  48. items.splice(i, 1);
  49. }
  50. } else {
  51. if (items[i].items && items[i].items.length > 0) {
  52. private_remove_un_archive_item(items[i].items, nlv + 1);
  53. if (items[i].items.length === 0 && nlv > 0) {
  54. items.splice(i, 1);
  55. }
  56. } else {
  57. //items[i]是目录,但又没有items子项,
  58. items.splice(i, 1);
  59. }
  60. }
  61. }
  62. }
  63. };
  64. let nodeLv = 0;
  65. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  66. private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
  67. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
  68. me.treeObj.expandAll(true);
  69. me.refreshNodes();
  70. rptArchiveObj._countChkedRptTpl();
  71. rptArchiveObj._buildeArchiveDateSelect();
  72. rptArchiveObj._iniArchiveItemForDeleteShow();
  73. rptArchiveObj._iniArchiveItemForDeleteShow();
  74. },
  75. toggleBtn: function (enabled) {
  76. if (current_stage_status === 3 && enabled) {
  77. $('#btnArchiveRpt').removeAttr('disabled');
  78. $('#btnArchiveList').removeAttr('disabled');
  79. $('#btnBatchArchiveRpt').removeAttr('disabled');
  80. } else {
  81. $('#btnArchiveRpt').attr('disabled', '');
  82. $('#btnArchiveList').attr('disabled', '');
  83. $('#btnBatchArchiveRpt').attr('disabled', '');
  84. }
  85. },
  86. refreshNodes: function() {
  87. let me = this;
  88. let private_setupIsParent = function(node){
  89. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  90. if (node.items && node.items.length) {
  91. for (let i = 0; i < node.items.length; i++) {
  92. private_setupIsParent(node.items[i]);
  93. }
  94. }
  95. };
  96. let topNodes = me.treeObj.getNodes();
  97. for (let i = 0; i < topNodes.length; i++) {
  98. private_setupIsParent(topNodes[i]);
  99. }
  100. me.treeObj.refresh();
  101. },
  102. onCheck: function(event, treeId, treeNode) {
  103. rptArchiveObj._countChkedRptTpl();
  104. if (treeNode.isParent) {
  105. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  106. }
  107. },
  108. onClick: function(event,treeId,treeNode) {
  109. let me = rptArchiveObj;
  110. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  111. me.currentNode = treeNode;
  112. for (let aItem of ARCHIVE_LIST) {
  113. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  114. me.currentArchiveUuid = null;
  115. me.currentArchiveDateStr = null;
  116. me.currentArchivePdfPath = null;
  117. if (aItem.items && aItem.items.length > 0) {
  118. // me.currentArchiveUuid = aItem.items[0].uuid;
  119. // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  120. const newItems = _.orderBy(aItem.items, ['updateDate_time'], ['desc']);
  121. me.currentArchiveUuid = newItems[0].uuid;
  122. me.currentChildArchiveUuids = newItems[0].childUuids;
  123. me.currentArchiveDateStr = '#' + (_.findIndex(aItem.items, { updateDate_time: newItems[0].updateDate_time})+1) + ' ' + newItems[0].updateDate_time;
  124. if (can_netcasign) {
  125. for (const [i,item] of aItem.items.entries()) {
  126. if (_.find(signLogList, { uuid: item.uuid })) {
  127. me.currentArchiveUuid = item.uuid;
  128. me.currentChildArchiveUuids = item.childUuids;
  129. me.currentArchiveDateStr = '#' + (i+1) + ' ' + item.updateDate_time;
  130. break;
  131. }
  132. }
  133. }
  134. }
  135. break;
  136. }
  137. }
  138. me._countChkedRptTpl();
  139. me._buildeArchiveDateSelect();
  140. me._requestArchiveReport();
  141. rptArchiveObj._iniArchiveItemForDeleteShow();
  142. }
  143. },
  144. batchArchive: function() {
  145. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  146. if (zTreeOprObj.checkedRptTplNodes.length <= 10) {
  147. indexDbOprObj.storeReportRequest(current_stage_id, zTreeOprObj.checkedRptTplNodes, indexDbOprObj.startRequestReport);
  148. } else {
  149. alert('批量归档上限为10,请勾选10张以内');
  150. }
  151. }
  152. },
  153. _requestArchiveReport: function () {
  154. let me = rptArchiveObj;
  155. if (me.currentNode && me.currentArchiveUuid) {
  156. try {
  157. if (can_netcasign) {
  158. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  159. if (!msgSign) {
  160. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  161. }
  162. console.log(current_stage_id, msgSign, me.currentArchiveUuid);
  163. me.currentEncryptionList = msgSign;
  164. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  165. let html = '';
  166. let pagetr = '';
  167. if (msgSign) {
  168. const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
  169. for (const [index,role] of msgSign.encryption.entries()) {
  170. const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
  171. html += '<div class="'+ rows +'">\n' +
  172. ' <div class="custom-control custom-radio custom-control-inline">\n' +
  173. ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
  174. ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
  175. ' </div>\n' +
  176. ' </div>';
  177. }
  178. let uhtml = '';
  179. for (const us of uSignLogList) {
  180. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  181. }
  182. for (let i = 1; i <= msgSign.total_page; i++) {
  183. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  184. }
  185. }
  186. $('#dateStr').html(me.currentArchiveDateStr);
  187. $('#role-list').html(html);
  188. $('#page-list').html(pagetr);
  189. $('#sign_num').text(uSignLogList.length);
  190. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  191. // 是否显示撤销按钮
  192. if(uHadSign && uHadSign.length > 0) {
  193. $('#show-removesign-modal-btn').show();
  194. } else {
  195. $('#show-removesign-modal-btn').hide();
  196. }
  197. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  198. 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();
  199. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  200. }, function () {
  201. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  202. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  203. })
  204. } else {
  205. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  206. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  207. console.log(me.currentArchivePdfPath);
  208. }
  209. // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  210. // console.log(uuIdUrl);
  211. // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  212. // NetcaPDFSeal.openPDFWithUrl(window.location.href);
  213. // window.location = uuIdUrl;
  214. } catch (ex) {
  215. console.log(ex.toString());
  216. }
  217. }
  218. },
  219. _setChildUuidsByCurUuid: () => {
  220. let me = rptArchiveObj;
  221. me.currentChildArchiveUuids = null;
  222. if (me.currentNode && me.currentArchiveUuid) {
  223. for (let aItem of ARCHIVE_LIST) {
  224. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  225. for (let [index,item] of aItem.items.entries()) {
  226. if (item.uuid === me.currentArchiveUuid) {
  227. me.currentChildArchiveUuids = item.childUuids;
  228. break;
  229. }
  230. }
  231. break;
  232. }
  233. }
  234. }
  235. },
  236. _changeArchiveDateSelect: function (dom, archiveIdx) {
  237. let me = rptArchiveObj;
  238. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  239. me.currentArchiveDateStr = dom.innerHTML;
  240. me._setChildUuidsByCurUuid();
  241. if(can_netcasign) {
  242. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  243. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  244. 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();
  245. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  246. me._buildeArchiveDateSelect();
  247. }, function () {
  248. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  249. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  250. me._buildeArchiveDateSelect();
  251. });
  252. // me._updateSignHtmlAndFrame();
  253. me._requestArchiveReport();
  254. me._iniArchiveItemForDeleteShow();
  255. } else {
  256. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  257. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  258. me._buildeArchiveDateSelect();
  259. me._iniArchiveItemForDeleteShow();
  260. }
  261. },
  262. _buildeArchiveDateSelect: function () {
  263. let me = rptArchiveObj;
  264. let targetDom = document.getElementById("currentDrpArchiveSelect");
  265. targetDom.innerHTML = me.currentArchiveDateStr;
  266. let drpDom = $("#drpArchiveSelect");
  267. drpDom.empty();
  268. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  269. for (let aItem of ARCHIVE_LIST) {
  270. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  271. for (let [index,item] of aItem.items.entries()) {
  272. if (item.uuid !== me.currentArchiveUuid) {
  273. const str = `<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = '${item.uuid}'; rptArchiveObj._changeArchiveDateSelect(this)">#${index+1} ${item.updateDate_time}</a>`
  274. drpDom.append(str);
  275. }
  276. }
  277. }
  278. }
  279. }
  280. },
  281. _updateSignHtmlAndFrame: function (needFrame = false) {
  282. const me = rptArchiveObj;
  283. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  284. for (let i = 0; i < $('#role-list div').length; i++) {
  285. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  286. $('#role-list div').eq(i).find('input').attr('disabled', true);
  287. } else {
  288. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  289. }
  290. $('#role-list div').eq(i).find('input').prop('checked', false);
  291. }
  292. let uhtml = '';
  293. let pagetr = '';
  294. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  295. if (!msgSign) {
  296. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  297. }
  298. for (const us of uSignLogList) {
  299. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  300. }
  301. for (let i = 1; i <= msgSign.total_page; i++) {
  302. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  303. }
  304. $('#page-list').html(pagetr);
  305. if (needFrame) {
  306. 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();
  307. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') + '" height="100%" width="100%" style="border: none;"></iframe>');
  308. }
  309. $('#dateStr').html(me.currentArchiveDateStr);
  310. $('#sign_num').text(uSignLogList.length);
  311. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  312. // 是否显示撤销按钮
  313. if(uHadSign && uHadSign.length > 0) {
  314. $('#show-removesign-modal-btn').show();
  315. } else {
  316. $('#show-removesign-modal-btn').hide();
  317. }
  318. },
  319. _countChkedRptTpl: function () {
  320. let me = rptArchiveObj;
  321. $('#delete_archive_btn').attr('disabled', '');
  322. if (me.treeObj) {
  323. me.checkedRptTplNodes = [];
  324. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  325. for (let node of chkNodes) {
  326. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  327. cnt++;
  328. me.checkedRptTplNodes.push(node);
  329. if (me.currentNode === node) hasCurrentNode = true;
  330. }
  331. }
  332. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  333. //这里根据实际需求再做处理
  334. cnt++;
  335. me.checkedRptTplNodes.push(me.currentNode);
  336. }
  337. $("#print_div").find("span").each(function(cIdx,elementSpan){
  338. elementSpan.innerText = cnt;
  339. });
  340. $("#export_div").find("span").each(function(cIdx,elementSpan){
  341. elementSpan.innerText = cnt;
  342. });
  343. if (cnt) {
  344. $('#delete_archive_btn').removeAttr('disabled');
  345. }
  346. }
  347. },
  348. _iniArchiveItemForDeleteShow: function() {
  349. let me = rptArchiveObj;
  350. const dispArchInfoBody = $('#disp_archive_info_body');
  351. dispArchInfoBody.empty();
  352. let targetDom = document.getElementById("currentDrpArchiveSelect");
  353. let firstStr = `<h6>确认删除本张【${targetDom.innerText}】归档报表?</h6>`;
  354. let secondStr = `<h6>删除后,数据无法恢复,请谨慎操作。</h6>`;
  355. dispArchInfoBody.append(firstStr);
  356. dispArchInfoBody.append(secondStr);
  357. },
  358. showArchivedItem: function(currentNode) {
  359. //初始化当前报表已经归档的信息
  360. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  361. if (currentNode) {
  362. //1. cardArchiveInfo
  363. let cardArchiveInfo = $('#cardArchiveInfo');
  364. cardArchiveInfo.empty();
  365. let auditDate = null;
  366. let achivedAmt = 0;
  367. let achivedItem = null;
  368. for (let item of ARCHIVE_LIST) {
  369. if (parseInt(item.rpt_id) === currentNode.refId) {
  370. if (LAST_AUDITOR.end_time) {
  371. auditDate = new Date(LAST_AUDITOR.end_time);
  372. } else {
  373. auditDate = new Date(LAST_AUDITOR.begin_time);
  374. }
  375. achivedAmt = item.items?item.items.length:0;
  376. achivedItem = item;
  377. break;
  378. }
  379. }
  380. if (auditDate) {
  381. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  382. } else {
  383. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  384. }
  385. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  386. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  387. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  388. }
  389. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  390. if (achivedAmt > 0) {
  391. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  392. cardArchiveInfo.append('<div class="form-check">');
  393. // if (achivedAmt === 3) {
  394. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  395. // }
  396. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  397. // let ad = new Date(achivedItem.items[idx].update_time);
  398. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  399. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  400. cardArchiveInfo.append('</label>');
  401. cardArchiveInfo.append('</div>');
  402. }
  403. }
  404. cardArchiveInfo.append('</div>');
  405. //2. selectionArchiveInfo
  406. let selectionArchiveInfo = $('#selectionArchiveInfo');
  407. selectionArchiveInfo.empty();
  408. if (achivedAmt > 0) {
  409. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  410. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  411. }
  412. }
  413. }
  414. },
  415. _getCurrentArchives: function (currentNode) {
  416. let rst = null;
  417. if (ARCHIVE_LIST.length > 0 && currentNode) {
  418. for (let aItem of ARCHIVE_LIST) {
  419. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  420. rst = aItem;
  421. break;
  422. }
  423. }
  424. }
  425. return rst;
  426. },
  427. _chkIfFullArchives: function(currentNode) {
  428. let aItem = this._getCurrentArchives(currentNode);
  429. let rst = (aItem && aItem.items && aItem.items.length === 3);
  430. return rst;
  431. },
  432. _getPageSignatureInfo: function(pageData, rpt_id) {
  433. // 因接口方是这样的单位:A4(297*210 -> pt 814.68 * 595.44),那么需要把像素转换成pt的系数,经过测试发现这个系数就是PDF_SCALE,不用再设置了
  434. let psInfo = [], psInfoStr = [];
  435. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  436. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  437. const _getAreasProperty = (srcArea) => {
  438. const width = (srcArea[JV.IDX_RIGHT] - srcArea[JV.IDX_LEFT]);
  439. const height = (srcArea[JV.IDX_BOTTOM] - srcArea[JV.IDX_TOP]);
  440. let rst = {
  441. Left: srcArea[JV.IDX_LEFT] + offsetX, Top: srcArea[JV.IDX_TOP] + offsetY, width, height,
  442. PtCenterX: +((srcArea[JV.IDX_LEFT] + offsetX + width / 2) * PDF_SCALE).toFixed(2),
  443. PtCenterY: +((A4_PIXEL_HEIGHT - (srcArea[JV.IDX_TOP] + offsetX + height / 2)) * PDF_SCALE).toFixed(2),
  444. PtWidth: +(width * PDF_SCALE).toFixed(2), PtHeight: +(height * PDF_SCALE).toFixed(2),
  445. pages: []
  446. };
  447. return rst;
  448. };
  449. const _getProperSignatureArea = function(cell, control) {
  450. // 约定默认长宽比例是2:1,图片分辨率是600*300
  451. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  452. if (cell && cell[JV.PROP_AREA]) {
  453. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  454. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  455. if (width > height * 2) {
  456. width = height * 2;
  457. } else {
  458. height = width / 2;
  459. }
  460. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  461. case 'left':
  462. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  463. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  464. rst[2] = rst[0] + width;
  465. rst[3] = rst[1] + height;
  466. break;
  467. case 'right':
  468. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  469. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  470. rst[0] = rst[2] - width;
  471. rst[1] = rst[3] - height;
  472. break;
  473. default:
  474. //center
  475. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  476. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  477. rst[2] = rst[0] + width;
  478. rst[3] = rst[1] + height;
  479. break;
  480. }
  481. }
  482. rst[0] = rst[0] + offsetX;
  483. rst[2] = rst[2] + offsetX;
  484. rst[1] = rst[1] + offsetY;
  485. rst[3] = rst[3] + offsetY;
  486. return rst;
  487. };
  488. const _getStampArea = (stampCell) => {
  489. const rst = [0, 0, 0, 0];
  490. if (stampCell && stampCell[JV.PROP_AREA]) {
  491. const left = Math.round(stampCell[JV.PROP_AREA][JV.PROP_LEFT]);
  492. const right = Math.round(stampCell[JV.PROP_AREA][JV.PROP_RIGHT]);
  493. const top = Math.round(stampCell[JV.PROP_AREA][JV.PROP_TOP]);
  494. const bottom = Math.round(stampCell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  495. let width = right - left,
  496. height = bottom - top;
  497. rst[0] = left;
  498. rst[1] = top;
  499. rst[2] = rst[0] + width;
  500. rst[3] = rst[1] + height;
  501. }
  502. rst[0] = rst[0] + offsetX;
  503. rst[2] = rst[2] + offsetX;
  504. rst[1] = rst[1] + offsetY;
  505. rst[3] = rst[3] + offsetY;
  506. return rst;
  507. };
  508. const _areaKeyCache = {
  509. normal: 'areas',
  510. company_stamp: 'company_stamp_areas',
  511. private_stamp: 'private_stamp_areas'
  512. };
  513. const _chkAndSetArea = (sCell, actSignArea, pageIdx, signNameKey) => {
  514. let idx = psInfoStr.indexOf(sCell[signNameKey]);
  515. const signType = sCell.signType || 'normal';
  516. const areaKey = _areaKeyCache[signType] || 'areas';
  517. if (idx < 0) {
  518. psInfoStr.push(sCell[signNameKey]);
  519. let newPsInfo = {'name': sCell[signNameKey], areas: [], company_stamp_areas: [], private_stamp_areas: [], order: psInfoStr.length};
  520. const area = _getAreasProperty(actSignArea);
  521. area.pages.push(pageIdx + 1);
  522. newPsInfo[areaKey].push(area);
  523. psInfo.push(newPsInfo);
  524. } else {
  525. let hasArea = false;
  526. for (let areaItem of psInfo[idx][areaKey]) {
  527. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  528. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  529. areaItem.pages.push(pageIdx + 1);
  530. hasArea = true;
  531. break;
  532. }
  533. }
  534. if (!hasArea) {
  535. const area = _getAreasProperty(actSignArea);
  536. area.pages.push(pageIdx + 1);
  537. psInfo[idx][areaKey].push(area);
  538. }
  539. }
  540. };
  541. for(let i = 0; i < pageData.items.length; i++) {
  542. let page = pageData.items[i];
  543. for (let sCell of page.signature_cells) {
  544. // sCell.signature_name 草图不用加密
  545. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  546. let control = null;
  547. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  548. control = controls[sCell[JV.PROP_CONTROL]];
  549. } else {
  550. control = sCell[JV.PROP_CONTROL];
  551. }
  552. let actSignArea = _getProperSignatureArea(sCell, control);
  553. _chkAndSetArea(sCell, actSignArea, i, 'signature_name');
  554. } else {
  555. let stampArea = _getStampArea(sCell);
  556. _chkAndSetArea(sCell, stampArea, i, 'signatureName'); // 注意:这里的判断不是signature_name(含dummy的),而是signatureName属性(之前的章信息设计导致)
  557. }
  558. }
  559. }
  560. return psInfo;
  561. },
  562. archiveCurrentReport: function (currentRptPageRst, currentNode, cb) {
  563. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  564. // 1. 找草图路径
  565. if (!PAGE_SHOW.closeArchiveSignature) {
  566. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  567. // 每页
  568. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  569. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  570. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  571. if (sCell.signature_name.indexOf('dummy_pic') >= 0) {
  572. //1. 草图就不考虑重复问题,重复就重复吧;
  573. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  574. let picIdx = picKeys.indexOf(sCell.path);
  575. if (picIdx < 0) {
  576. picKeys.push(sCell.path);
  577. picCells.push(sCell);
  578. } else {
  579. let dPicIdx = dupPicPath.indexOf(sCell.path);
  580. if (dPicIdx < 0) {
  581. dupPicPath.push(sCell.path);
  582. dupPicCell.push([]);
  583. dPicIdx = dupPicPath.length - 1;
  584. }
  585. dupPicCell[dPicIdx].push(sCell);
  586. }
  587. }
  588. }
  589. }
  590. }
  591. // 2. 下载草图,下载完毕后upload
  592. if (picCells.length > 0) {
  593. $.bootstrapLoading.start();
  594. let picAmt = picCells.length, picCnt = 0;
  595. let exceptionAmt = 0;
  596. for (let idx = 0; idx < picCells.length; idx++) {
  597. let dCell = picCells[idx];
  598. getBlob(picKeys[idx]).then(blob => {
  599. if (blob === 'not found!') {
  600. exceptionAmt++;
  601. if ((picCnt + exceptionAmt) === picAmt) {
  602. $.bootstrapLoading.end();
  603. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  604. }
  605. } else {
  606. let oFileReader = new FileReader();
  607. oFileReader.onloadend = function (e) {
  608. picCnt++;
  609. let base64 = e.target.result;
  610. picCells[idx].pic = base64;
  611. let pPathIdx = dupPicPath.indexOf(dCell.path);
  612. if (pPathIdx >= 0) {
  613. for (let dupCell of dupPicCell[pPathIdx]) {
  614. dupCell.pic = base64;
  615. }
  616. }
  617. if ((picCnt + exceptionAmt) === picAmt) {
  618. $.bootstrapLoading.end();
  619. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  620. }
  621. };
  622. oFileReader.readAsDataURL(blob);
  623. }
  624. });
  625. }
  626. } else {
  627. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  628. }
  629. },
  630. _archiveCurrentReport: function(currentRptPageRst, currentNode, cb) {
  631. // 归档当前报表
  632. if (currentRptPageRst !== null) {
  633. try {
  634. let signCells = [];
  635. let txtSignCells = [];
  636. let dummyTxtSignCells = [];
  637. const restoreCells = (srcCells, targetCellsStr) => {
  638. if (srcCells.length > 0) {
  639. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  640. srcCells[pageIdx].forEach((srcCell) => {
  641. pageItem[targetCellsStr].push(srcCell);
  642. });
  643. srcCells[pageIdx] = null;
  644. });
  645. }
  646. };
  647. if (PAGE_SHOW.isTextSignature) {
  648. // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
  649. // 批量归档的数据后台会处理(已经移除相关签名)
  650. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  651. const dtlSignCells = [];
  652. signCells.push(dtlSignCells);
  653. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  654. let sCell = pageItem.signature_cells[sCellIdx];
  655. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  656. dtlSignCells.push(sCell);
  657. pageItem.signature_cells.splice(sCellIdx, 1);
  658. } else if (PAGE_SHOW.closeArchiveSignature) {
  659. // 如果还有closeArchiveSignature标记,那么不显示文本文档(需要删除cells目录下的匹配cell(Value不为空串))
  660. for (let cIdx = pageItem.cells.length - 1; cIdx >= 0; cIdx--) {
  661. const cCell = pageItem.cells[cIdx];
  662. if (cCell.area.Left === sCell.orgArea.Left && cCell.area.Right === sCell.orgArea.Right &&
  663. cCell.area.Top === sCell.orgArea.Top && cCell.area.Bottom === sCell.orgArea.Bottom &&
  664. cCell.Value !== '') {
  665. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  666. cCell.Value = '';
  667. break;
  668. }
  669. }
  670. }
  671. }
  672. });
  673. } else if (PAGE_SHOW.closeArchiveSignature) {
  674. // 这里还有一个场景需要考虑:签名是图片且选择了签名,又不归档输出,
  675. const rrSigns = [];
  676. ROLE_REL_LIST.forEach(role_rel => {
  677. if (role_rel.sign_output && role_rel.sign_output.includes(NORMAL_SIGN_STR)) {
  678. rrSigns.push(role_rel.signature_name);
  679. }
  680. });
  681. if (rrSigns.length > 0) {
  682. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  683. const dtlSignCells = [];
  684. const dtlDummyCells = [];
  685. signCells.push(dtlSignCells);
  686. dummyTxtSignCells.push(dtlDummyCells);
  687. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  688. let sCell = pageItem.signature_cells[sCellIdx];
  689. if (rrSigns.includes(sCell.signature_name)) {
  690. dtlSignCells.push(sCell);
  691. pageItem.signature_cells.splice(sCellIdx, 1);
  692. // 还得加一个dummy cell,处理边框用的
  693. const newCell = {
  694. font: 'Footer',
  695. control: sCell.control,
  696. style: sCell.style,
  697. Value: '',
  698. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  699. };
  700. dtlDummyCells.push(newCell);
  701. pageItem.cells.push(newCell);
  702. }
  703. }
  704. });
  705. }
  706. }
  707. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  708. restoreCells(signCells, 'signature_cells');
  709. signCells = null;
  710. txtSignCells.forEach(txtCellBkObj => {
  711. txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
  712. });
  713. txtSignCells = null;
  714. if (dummyTxtSignCells.length === currentRptPageRst.items.length) {
  715. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  716. dummyTxtSignCells[pageIdx].forEach((dummyCell) => {
  717. const idx = pageItem.cells.indexOf(dummyCell);
  718. if (idx >= 0) pageItem.cells.splice(idx, 1);
  719. });
  720. dummyTxtSignCells[pageIdx] = null;
  721. });
  722. dummyTxtSignCells = null;
  723. }
  724. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, currentNode.refId);
  725. // console.log(pageEncryptInfo);
  726. let formData = new FormData();
  727. formData.append('file', doc.output('blob'), 'upload.pdf');
  728. // formData.append('size', pFile.size);
  729. if (currentRptPageRst.splitArcPages) {
  730. let docs = JpcJsPDFHelper.getChildrenDocs(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  731. for (let docIdx = 0; docIdx < docs.length; docIdx++) {
  732. let file = docs[docIdx].output('blob');
  733. formData.append('file', file, `upload_child_${docIdx}.pdf`);
  734. }
  735. }
  736. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  737. let archiveUrl = `/tender/report_api/addArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}`;
  738. if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
  739. archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`;
  740. }
  741. postDataWithFile(archiveUrl, formData, function (result) {
  742. // 成功后,更新当前页面
  743. //*
  744. if (result.updatedRst) {
  745. // console.log(result);
  746. ARCHIVE_LIST = result.updatedRst;
  747. rptArchiveObj.showArchivedItem(currentNode);
  748. zTreeOprObj.refreshNodes();
  749. //第二步:增加加密信息
  750. let params = {};
  751. params.prjId = PROJECT_ID;
  752. params.stgId = current_stage_id;
  753. params.rptId = currentNode.refId;
  754. params.ttlPgs = currentRptPageRst.items.length;
  755. params.content = pageEncryptInfo;
  756. params.uuid = result.uuid; //正确返回时,带着uuid回来
  757. params.childUuids = result.childUuids; //还有子uuid
  758. params.splitArcPages = currentRptPageRst.splitArcPages ? currentRptPageRst.splitArcPages : [];
  759. params.splitArcPagesInfo = currentRptPageRst.splitArcPagesInfo ? currentRptPageRst.splitArcPagesInfo : {};
  760. params.reportName = currentNode.name;
  761. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  762. function(rst){
  763. if (cb) {
  764. cb(null, 'add archive encryption succeed!', params.uuid);
  765. }
  766. }, function(err){
  767. if (cb) {
  768. cb('err', 'add archive encryption err!', params.uuid);
  769. }
  770. }, function(ex){
  771. if (cb) {
  772. cb('err', 'add archive encryption err!', params.uuid);
  773. }
  774. }
  775. );
  776. } else {
  777. // 有冲突,需要删除
  778. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  779. function(result){
  780. if (cb) {
  781. cb('err', 'add archive conflict!', null);
  782. }
  783. }
  784. );
  785. }
  786. //*/
  787. }, function (error){
  788. if (cb) {
  789. cb('err', 'add archive err!', null);
  790. }
  791. });
  792. } else {
  793. let aItem = this._getCurrentArchives(currentNode);
  794. if (aItem && aItem.items && aItem.items.length > 0) {
  795. let orgName = aItem.items[0].uuid;
  796. let compStr = aItem.items[0].updateDate_time;
  797. for (let idx = 1; idx < aItem.items.length; idx++) {
  798. if (aItem.items[idx].updateDate_time < compStr) {
  799. compStr = aItem.items[idx].updateDate_time;
  800. orgName = aItem.items[idx].uuid;
  801. }
  802. }
  803. let archiveUrl = `/tender/report_api/updateArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${orgName}`;
  804. if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
  805. // archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${orgName}`;
  806. archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`; // 分页方式不需要 orgName
  807. }
  808. postDataWithFile(archiveUrl, formData, function (result) {
  809. // postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  810. // 成功后,更新当前页面
  811. if (result.updatedRst) {
  812. // console.log(result);
  813. ARCHIVE_LIST = result.updatedRst;
  814. rptArchiveObj.showArchivedItem(currentNode);
  815. zTreeOprObj.refreshNodes();
  816. //第二步:更新加密信息
  817. let params = {};
  818. params.prjId = PROJECT_ID;
  819. params.stgId = current_stage_id;
  820. params.rptId = currentNode.refId;
  821. params.ttlPgs = currentRptPageRst.items.length;
  822. params.content = pageEncryptInfo;
  823. params.childUuids = result.childUuids;
  824. params.removeUuid = result.removeUuid;
  825. params.splitArcPages = (currentRptPageRst.splitArcPages) ? currentRptPageRst.splitArcPages : [];
  826. // params.uuid = orgName;
  827. params.uuid = result.uuid;
  828. params.reportName = currentNode.name;
  829. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  830. function(result){
  831. if (cb) {
  832. cb(null, 'update archive succeed!', params.uuid);
  833. }
  834. }, function(err){
  835. if (cb) {
  836. cb('err', 'update archive err!', params.uuid);
  837. }
  838. }, function(ex){
  839. if (cb) {
  840. cb('err', 'update archive err!', params.uuid);
  841. }
  842. }
  843. );
  844. } else {
  845. // 有冲突,需要删除
  846. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  847. function(result){
  848. if (cb) {
  849. cb('err', 'update archive conflict!', null);
  850. }
  851. }
  852. );
  853. }
  854. }, function (error){
  855. // alert(error);
  856. if (cb) {
  857. cb('err', 'update archive conflict!', null);
  858. }
  859. });
  860. }
  861. }
  862. } catch (ex) {
  863. console.log(ex);
  864. console.log(ex.toString());
  865. if (cb) {
  866. cb('err', 'has exception!', null);
  867. }
  868. }
  869. } else {
  870. alert('请选择打开一个报表!');
  871. }
  872. },
  873. _getOneValidLeafNode: function(node) {
  874. let rst = null;
  875. let me = rptArchiveObj;
  876. if (node) {
  877. const preNode = node.getPreNode();
  878. if (preNode) {
  879. rst = preNode;
  880. } else {
  881. const nodes = me.treeObj.getNodes();
  882. for (let dtlNode of nodes) {
  883. if (dtlNode !== node && dtlNode.nodeType === 2) {
  884. rst = dtlNode;
  885. break;
  886. }
  887. }
  888. }
  889. }
  890. return rst;
  891. },
  892. removeArchive: function() {
  893. let me = rptArchiveObj;
  894. const bkRefId = parseInt(me.currentNode.refId);
  895. const bkUuid = me.currentArchiveUuid;
  896. if (me.currentNode && me.currentArchiveUuid) {
  897. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  898. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  899. function(result){
  900. // console.log(result.data);
  901. let hasRemovedAll = false;
  902. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  903. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  904. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  905. if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
  906. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  907. break;
  908. }
  909. }
  910. if (ARCHIVE_LIST[idx].items.length === 0) {
  911. ARCHIVE_LIST.splice(idx, 0);
  912. hasRemovedAll = true;
  913. break;
  914. }
  915. }
  916. }
  917. //要刷新当前归档
  918. if (hasRemovedAll) {
  919. const validNode = me._getOneValidLeafNode(me.currentNode);
  920. // me.iniPage();
  921. me.treeObj.removeNode(me.currentNode);
  922. if (validNode) {
  923. me.currentNode = validNode;
  924. me.onClick(null, null, me.currentNode);
  925. me.treeObj.selectNode(me.currentNode, false);
  926. me._iniArchiveItemForDeleteShow();
  927. }
  928. } else {
  929. me.currentArchiveUuid = null;
  930. me.currentArchiveDateStr = null;
  931. me.currentArchivePdfPath = null;
  932. me.onClick(null, null, me.currentNode);
  933. }
  934. }
  935. );
  936. }
  937. }
  938. };
  939. /**
  940. * 获取 blob
  941. * @param {String} url 目标文件地址
  942. * @return {Promise}
  943. */
  944. function getBlob(url) {
  945. return new Promise(resolve => {
  946. const xhr = new XMLHttpRequest();
  947. // let fullUrl = url + '?x-oss-process=image/info';
  948. xhr.open('GET', url, true);
  949. xhr.responseType = 'blob';
  950. xhr.onload = () => {
  951. if (xhr.status === 200) {
  952. resolve(xhr.response);
  953. } else {
  954. resolve('not found!');
  955. }
  956. };
  957. xhr.send();
  958. });
  959. }
  960. /**
  961. * pdf base64 转 blob
  962. * @param {String} dataUrl base64码
  963. * @return {Promise}
  964. */
  965. function convertBase64UrlToBlob(dataUrl) {
  966. //去掉url的头,并转换为byte
  967. var bytes = window.atob(dataUrl);
  968. //处理异常,将ascii码小于0的转换为大于0
  969. var ab = new Uint8Array(bytes.length);
  970. for (var i = 0; i < bytes.length; i++) {
  971. ab[i] = bytes.charCodeAt(i);
  972. }
  973. return new Blob([ab], { type: 'application/pdf' });
  974. }
  975. /**
  976. * 保存
  977. * @param {Blob} blob
  978. * @param {String} filename 想要保存的文件名称
  979. */
  980. function saveAs(blob, filename) {
  981. if (window.navigator.msSaveOrOpenBlob) {
  982. navigator.msSaveBlob(blob, filename);
  983. } else {
  984. const link = document.createElement('a');
  985. const body = document.querySelector('body');
  986. link.href = window.URL.createObjectURL(blob);
  987. link.download = filename;
  988. // fix Firefox
  989. link.style.display = 'none';
  990. body.appendChild(link);
  991. link.click();
  992. body.removeChild(link);
  993. window.URL.revokeObjectURL(link.href);
  994. }
  995. }
  996. /**
  997. * 下载
  998. * @param {String} url 目标文件地址
  999. * @param {String} filename 想要保存的文件名称
  1000. */
  1001. function download(url, filename) {
  1002. getBlob(url).then(blob => {
  1003. saveAs(blob, filename);
  1004. });
  1005. }
  1006. $(function () {
  1007. $('#download_file').click(function () {
  1008. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1009. console.log(rptArchiveObj.currentArchivePdfPath);
  1010. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  1011. } else {
  1012. alert('请选择打开一个报表!');
  1013. }
  1014. });
  1015. $('#print_file').click(function () {
  1016. if (rptArchiveObj.currentArchiveUuid) {
  1017. $('#iframe_made iframe')[0].contentWindow.print();
  1018. } else {
  1019. alert('请选择打开一个报表!');
  1020. }
  1021. });
  1022. $('#delete_file').click(function () {
  1023. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1024. console.log(rptArchiveObj.currentArchivePdfPath);
  1025. rptArchiveObj.removeArchive();
  1026. } else {
  1027. alert('请选择打开一个报表!');
  1028. }
  1029. });
  1030. })