rpt_archive.js 55 KB

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