rpt_archive.js 53 KB

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