rpt_archive.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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 (current_stage_status === 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.end_time) {
  373. auditDate = new Date(LAST_AUDITOR.end_time);
  374. } else {
  375. auditDate = new Date(LAST_AUDITOR.begin_time);
  376. }
  377. achivedAmt = item.items?item.items.length:0;
  378. achivedItem = item;
  379. break;
  380. }
  381. }
  382. if (auditDate) {
  383. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  384. } else {
  385. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  386. }
  387. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  388. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  389. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  390. }
  391. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  392. if (achivedAmt > 0) {
  393. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  394. cardArchiveInfo.append('<div class="form-check">');
  395. // if (achivedAmt === 3) {
  396. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  397. // }
  398. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  399. // let ad = new Date(achivedItem.items[idx].update_time);
  400. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  401. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  402. cardArchiveInfo.append('</label>');
  403. cardArchiveInfo.append('</div>');
  404. }
  405. }
  406. cardArchiveInfo.append('</div>');
  407. //2. selectionArchiveInfo
  408. let selectionArchiveInfo = $('#selectionArchiveInfo');
  409. selectionArchiveInfo.empty();
  410. if (achivedAmt > 0) {
  411. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  412. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  413. }
  414. }
  415. }
  416. },
  417. _getCurrentArchives: function (currentNode) {
  418. let rst = null;
  419. if (ARCHIVE_LIST.length > 0 && currentNode) {
  420. for (let aItem of ARCHIVE_LIST) {
  421. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  422. rst = aItem;
  423. break;
  424. }
  425. }
  426. }
  427. return rst;
  428. },
  429. _chkIfFullArchives: function(currentNode) {
  430. let aItem = this._getCurrentArchives(currentNode);
  431. let rst = (aItem && aItem.items && aItem.items.length === 3);
  432. return rst;
  433. },
  434. _getPageSignatureInfo: function(pageData, pageSize, rpt_id) {
  435. // 因接口方是这样的单位:A4(297*210 -> pt 814.68 * 595.44),那么需要把像素转换成pt的系数,经过测试发现这个系数就是PDF_SCALE,不用再设置了
  436. let psInfo = [], psInfoStr = [];
  437. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  438. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  439. let ptChkHeight = pageSize === 'A4' ? A4_PIXEL_HEIGHT : A3_PIXEL_HEIGHT;
  440. const signatureOrderObj = {};
  441. pageData.items[0].signature_cells.forEach(sCell => {
  442. if (sCell.hasOwnProperty('Order')) {
  443. signatureOrderObj[sCell.signature_name] = sCell.Order + 1;
  444. }
  445. });
  446. const _getAreasProperty = (srcArea) => {
  447. const width = (srcArea[JV.IDX_RIGHT] - srcArea[JV.IDX_LEFT]);
  448. const height = (srcArea[JV.IDX_BOTTOM] - srcArea[JV.IDX_TOP]);
  449. let rst = {
  450. Left: srcArea[JV.IDX_LEFT] + offsetX, Top: srcArea[JV.IDX_TOP] + offsetY, width, height,
  451. PtCenterX: +((srcArea[JV.IDX_LEFT] + offsetX + width / 2) * PDF_SCALE).toFixed(2),
  452. PtCenterY: +((ptChkHeight - (srcArea[JV.IDX_TOP] + offsetX + height / 2)) * PDF_SCALE).toFixed(2),
  453. PtWidth: +(width * PDF_SCALE).toFixed(2), PtHeight: +(height * PDF_SCALE).toFixed(2),
  454. pages: []
  455. };
  456. return rst;
  457. };
  458. const _getProperSignatureArea = function(cell, control) {
  459. // 约定默认长宽比例是2:1,图片分辨率是600*300
  460. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  461. if (cell && cell[JV.PROP_AREA]) {
  462. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  463. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  464. if (width > height * 2) {
  465. width = height * 2;
  466. } else {
  467. height = width / 2;
  468. }
  469. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  470. case 'left':
  471. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  472. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  473. rst[2] = rst[0] + width;
  474. rst[3] = rst[1] + height;
  475. break;
  476. case 'right':
  477. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  478. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  479. rst[0] = rst[2] - width;
  480. rst[1] = rst[3] - height;
  481. break;
  482. default:
  483. //center
  484. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  485. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  486. rst[2] = rst[0] + width;
  487. rst[3] = rst[1] + height;
  488. break;
  489. }
  490. }
  491. rst[0] = rst[0] + offsetX;
  492. rst[2] = rst[2] + offsetX;
  493. rst[1] = rst[1] + offsetY;
  494. rst[3] = rst[3] + offsetY;
  495. return rst;
  496. };
  497. const _getStampArea = (stampCell) => {
  498. const rst = [0, 0, 0, 0];
  499. if (stampCell && stampCell[JV.PROP_AREA]) {
  500. const left = Math.round(stampCell[JV.PROP_AREA][JV.PROP_LEFT]);
  501. const right = Math.round(stampCell[JV.PROP_AREA][JV.PROP_RIGHT]);
  502. const top = Math.round(stampCell[JV.PROP_AREA][JV.PROP_TOP]);
  503. const bottom = Math.round(stampCell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  504. let width = right - left,
  505. height = bottom - top;
  506. rst[0] = left;
  507. rst[1] = top;
  508. rst[2] = rst[0] + width;
  509. rst[3] = rst[1] + height;
  510. }
  511. rst[0] = rst[0] + offsetX;
  512. rst[2] = rst[2] + offsetX;
  513. rst[1] = rst[1] + offsetY;
  514. rst[3] = rst[3] + offsetY;
  515. return rst;
  516. };
  517. const _areaKeyCache = {
  518. normal: 'areas',
  519. company_stamp: 'company_stamp_areas',
  520. private_stamp: 'private_stamp_areas'
  521. };
  522. const _chkAndSetArea = (sCell, actSignArea, pageIdx, signNameKey) => {
  523. let idx = psInfoStr.indexOf(sCell[signNameKey]);
  524. const signType = sCell.signType || 'normal';
  525. const areaKey = _areaKeyCache[signType] || 'areas';
  526. if (idx < 0) {
  527. psInfoStr.push(sCell[signNameKey]);
  528. let newPsInfo = {'name': sCell[signNameKey], areas: [], company_stamp_areas: [], private_stamp_areas: [], order: signatureOrderObj[sCell[signNameKey]]};
  529. const area = _getAreasProperty(actSignArea);
  530. area.pages.push(pageIdx + 1);
  531. newPsInfo[areaKey].push(area);
  532. psInfo.push(newPsInfo);
  533. } else {
  534. let hasArea = false;
  535. for (let areaItem of psInfo[idx][areaKey]) {
  536. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  537. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  538. areaItem.pages.push(pageIdx + 1);
  539. hasArea = true;
  540. break;
  541. }
  542. }
  543. if (!hasArea) {
  544. const area = _getAreasProperty(actSignArea);
  545. area.pages.push(pageIdx + 1);
  546. psInfo[idx][areaKey].push(area);
  547. }
  548. }
  549. };
  550. for(let i = 0; i < pageData.items.length; i++) {
  551. let page = pageData.items[i];
  552. if (i === 0) {
  553. let maxX = 0;
  554. let maxY = 0;
  555. page.cells.forEach(cell => {
  556. if (cell.area.Right > maxX) maxX = cell.area.Right;
  557. if (cell.area.Bottom > maxY) maxY = cell.area.Bottom;
  558. });
  559. if (maxX > maxY) ptChkHeight = pageSize === 'A4' ? A4_PIXEL_WIDTH : A3_PIXEL_WIDTH;
  560. }
  561. for (let sCell of page.signature_cells) {
  562. // sCell.signature_name 草图不用加密
  563. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  564. let control = null;
  565. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  566. control = controls[sCell[JV.PROP_CONTROL]];
  567. } else {
  568. control = sCell[JV.PROP_CONTROL];
  569. }
  570. let actSignArea = _getProperSignatureArea(sCell, control);
  571. _chkAndSetArea(sCell, actSignArea, i, 'signature_name');
  572. } else {
  573. let stampArea = _getStampArea(sCell);
  574. _chkAndSetArea(sCell, stampArea, i, 'signatureName'); // 注意:这里的判断不是signature_name(含dummy的),而是signatureName属性(之前的章信息设计导致)
  575. }
  576. }
  577. }
  578. return psInfo;
  579. },
  580. archiveCurrentReport: function (currentRptPageRst, currentNode, cb) {
  581. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  582. // 1. 找草图路径
  583. if (!PAGE_SHOW.closeArchiveSignature) {
  584. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  585. // 每页
  586. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  587. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  588. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  589. if (sCell.signature_name.indexOf('dummy_pic') >= 0) {
  590. //1. 草图就不考虑重复问题,重复就重复吧;
  591. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  592. let picIdx = picKeys.indexOf(sCell.path);
  593. if (picIdx < 0) {
  594. picKeys.push(sCell.path);
  595. picCells.push(sCell);
  596. } else {
  597. let dPicIdx = dupPicPath.indexOf(sCell.path);
  598. if (dPicIdx < 0) {
  599. dupPicPath.push(sCell.path);
  600. dupPicCell.push([]);
  601. dPicIdx = dupPicPath.length - 1;
  602. }
  603. dupPicCell[dPicIdx].push(sCell);
  604. }
  605. }
  606. }
  607. }
  608. }
  609. // 2. 下载草图,下载完毕后upload
  610. if (picCells.length > 0) {
  611. $.bootstrapLoading.start();
  612. let picAmt = picCells.length, picCnt = 0;
  613. let exceptionAmt = 0;
  614. for (let idx = 0; idx < picCells.length; idx++) {
  615. let dCell = picCells[idx];
  616. getBlob(picKeys[idx]).then(blob => {
  617. if (blob === 'not found!') {
  618. exceptionAmt++;
  619. if ((picCnt + exceptionAmt) === picAmt) {
  620. $.bootstrapLoading.end();
  621. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  622. }
  623. } else {
  624. let oFileReader = new FileReader();
  625. oFileReader.onloadend = function (e) {
  626. picCnt++;
  627. let base64 = e.target.result;
  628. picCells[idx].pic = base64;
  629. let pPathIdx = dupPicPath.indexOf(dCell.path);
  630. if (pPathIdx >= 0) {
  631. for (let dupCell of dupPicCell[pPathIdx]) {
  632. dupCell.pic = base64;
  633. }
  634. }
  635. if ((picCnt + exceptionAmt) === picAmt) {
  636. $.bootstrapLoading.end();
  637. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  638. }
  639. };
  640. oFileReader.readAsDataURL(blob);
  641. }
  642. });
  643. }
  644. } else {
  645. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  646. }
  647. },
  648. _archiveCurrentReport: function(currentRptPageRst, currentNode, cb) {
  649. // 归档当前报表
  650. if (currentRptPageRst !== null) {
  651. try {
  652. let signCells = [];
  653. let txtSignCells = [];
  654. let dummyTxtSignCells = [];
  655. const restoreCells = (srcCells, targetCellsStr) => {
  656. if (srcCells.length > 0) {
  657. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  658. srcCells[pageIdx].forEach((srcCell) => {
  659. pageItem[targetCellsStr].push(srcCell);
  660. });
  661. srcCells[pageIdx] = null;
  662. });
  663. }
  664. };
  665. if (PAGE_SHOW.isTextSignature) {
  666. // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
  667. // 批量归档的数据后台会处理(已经移除相关签名)
  668. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  669. const dtlSignCells = [];
  670. signCells.push(dtlSignCells);
  671. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  672. let sCell = pageItem.signature_cells[sCellIdx];
  673. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  674. dtlSignCells.push(sCell);
  675. pageItem.signature_cells.splice(sCellIdx, 1);
  676. if (PAGE_SHOW.closeArchiveSignature) {
  677. // 如果还有closeArchiveSignature标记,那么不显示文本文档(只是清除匹配cell的Value,后续需要恢复)
  678. const cCell = pageItem.cells.find(cell => cell.area.Left === sCell.area.Left && cell.area.Top === sCell.area.Top && cell.Value === sCell.Value);
  679. if (cCell) {
  680. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  681. cCell.Value = '';
  682. }
  683. }
  684. } else if (PAGE_SHOW.closeArchiveSignature) {
  685. // 这个跟上面的判断属性不同,是orgArea(签章的)
  686. for (let cIdx = pageItem.cells.length - 1; cIdx >= 0; cIdx--) {
  687. const cCell = pageItem.cells[cIdx];
  688. if (cCell.area.Left === sCell.orgArea.Left && cCell.area.Right === sCell.orgArea.Right &&
  689. cCell.area.Top === sCell.orgArea.Top && cCell.area.Bottom === sCell.orgArea.Bottom &&
  690. cCell.Value !== '') {
  691. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  692. cCell.Value = '';
  693. break;
  694. }
  695. }
  696. }
  697. }
  698. });
  699. } else if (PAGE_SHOW.closeArchiveSignature) {
  700. // 这里还有一个场景需要考虑:签名是图片且选择了签名,又不归档输出,
  701. const rrSigns = [];
  702. ROLE_REL_LIST.forEach(role_rel => {
  703. if (role_rel.sign_output && role_rel.sign_output.includes(NORMAL_SIGN_STR)) {
  704. rrSigns.push(role_rel.signature_name);
  705. }
  706. });
  707. if (rrSigns.length > 0) {
  708. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  709. const dtlSignCells = [];
  710. const dtlDummyCells = [];
  711. signCells.push(dtlSignCells);
  712. dummyTxtSignCells.push(dtlDummyCells);
  713. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  714. let sCell = pageItem.signature_cells[sCellIdx];
  715. if (rrSigns.includes(sCell.signature_name)) {
  716. dtlSignCells.push(sCell);
  717. pageItem.signature_cells.splice(sCellIdx, 1);
  718. // 还得加一个dummy cell,处理边框用的
  719. const newCell = {
  720. font: 'Footer',
  721. control: sCell.control,
  722. style: sCell.style,
  723. Value: '',
  724. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  725. };
  726. dtlDummyCells.push(newCell);
  727. pageItem.cells.push(newCell);
  728. }
  729. }
  730. });
  731. }
  732. }
  733. const pageSize = rptControlObj.getCurrentPageSize();
  734. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, pageSize, ROLE_REL_LIST, STAGE_AUDIT);
  735. restoreCells(signCells, 'signature_cells');
  736. signCells = null;
  737. txtSignCells.forEach(txtCellBkObj => {
  738. txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
  739. });
  740. txtSignCells = null;
  741. if (dummyTxtSignCells.length === currentRptPageRst.items.length) {
  742. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  743. dummyTxtSignCells[pageIdx].forEach((dummyCell) => {
  744. const idx = pageItem.cells.indexOf(dummyCell);
  745. if (idx >= 0) pageItem.cells.splice(idx, 1);
  746. });
  747. dummyTxtSignCells[pageIdx] = null;
  748. });
  749. dummyTxtSignCells = null;
  750. }
  751. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, pageSize, currentNode.refId);
  752. // console.log(pageEncryptInfo);
  753. let formData = new FormData();
  754. formData.append('file', doc.output('blob'), 'upload.pdf');
  755. // formData.append('size', pFile.size);
  756. if (currentRptPageRst.splitArcPages) {
  757. let docs = JpcJsPDFHelper.getChildrenDocs(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  758. for (let docIdx = 0; docIdx < docs.length; docIdx++) {
  759. let file = docs[docIdx].output('blob');
  760. formData.append('file', file, `upload_child_${docIdx}.pdf`);
  761. }
  762. }
  763. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  764. let archiveUrl = `/tender/report_api/addArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}`;
  765. if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
  766. archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`;
  767. }
  768. postDataWithFile(archiveUrl, formData, function (result) {
  769. // 成功后,更新当前页面
  770. //*
  771. if (result.updatedRst) {
  772. // console.log(result);
  773. ARCHIVE_LIST = result.updatedRst;
  774. rptArchiveObj.showArchivedItem(currentNode);
  775. zTreeOprObj.refreshNodes();
  776. //第二步:增加加密信息
  777. let params = {};
  778. params.prjId = PROJECT_ID;
  779. params.stgId = current_stage_id;
  780. params.rptId = currentNode.refId;
  781. params.ttlPgs = currentRptPageRst.items.length;
  782. params.content = pageEncryptInfo;
  783. params.uuid = result.uuid; //正确返回时,带着uuid回来
  784. params.childUuids = result.childUuids; //还有子uuid
  785. params.splitArcPages = currentRptPageRst.splitArcPages ? currentRptPageRst.splitArcPages : [];
  786. params.splitArcPagesInfo = currentRptPageRst.splitArcPagesInfo ? currentRptPageRst.splitArcPagesInfo : {};
  787. params.reportName = currentNode.name;
  788. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  789. function(rst){
  790. if (cb) {
  791. cb(null, 'add archive encryption succeed!', params.uuid);
  792. }
  793. }, function(err){
  794. if (cb) {
  795. cb('err', 'add archive encryption err!', params.uuid);
  796. }
  797. }, function(ex){
  798. if (cb) {
  799. cb('err', 'add archive encryption err!', params.uuid);
  800. }
  801. }
  802. );
  803. } else {
  804. // 有冲突,需要删除
  805. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  806. function(result){
  807. if (cb) {
  808. cb('err', 'add archive conflict!', null);
  809. }
  810. }
  811. );
  812. }
  813. //*/
  814. }, function (error){
  815. if (cb) {
  816. cb('err', 'add archive err!', null);
  817. }
  818. });
  819. } else {
  820. let aItem = this._getCurrentArchives(currentNode);
  821. if (aItem && aItem.items && aItem.items.length > 0) {
  822. let orgName = aItem.items[0].uuid;
  823. let compStr = aItem.items[0].updateDate_time;
  824. for (let idx = 1; idx < aItem.items.length; idx++) {
  825. if (aItem.items[idx].updateDate_time < compStr) {
  826. compStr = aItem.items[idx].updateDate_time;
  827. orgName = aItem.items[idx].uuid;
  828. }
  829. }
  830. let archiveUrl = `/tender/report_api/updateArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${orgName}`;
  831. if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
  832. // archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${orgName}`;
  833. archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`; // 分页方式不需要 orgName
  834. }
  835. postDataWithFile(archiveUrl, formData, function (result) {
  836. // postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  837. // 成功后,更新当前页面
  838. if (result.updatedRst) {
  839. // console.log(result);
  840. ARCHIVE_LIST = result.updatedRst;
  841. rptArchiveObj.showArchivedItem(currentNode);
  842. zTreeOprObj.refreshNodes();
  843. //第二步:更新加密信息
  844. let params = {};
  845. params.prjId = PROJECT_ID;
  846. params.stgId = current_stage_id;
  847. params.rptId = currentNode.refId;
  848. params.ttlPgs = currentRptPageRst.items.length;
  849. params.content = pageEncryptInfo;
  850. params.childUuids = result.childUuids;
  851. params.removeUuid = result.removeUuid;
  852. params.splitArcPages = (currentRptPageRst.splitArcPages) ? currentRptPageRst.splitArcPages : [];
  853. // params.uuid = orgName;
  854. params.uuid = result.uuid;
  855. params.reportName = currentNode.name;
  856. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  857. function(result){
  858. if (cb) {
  859. cb(null, 'update archive succeed!', params.uuid);
  860. }
  861. }, function(err){
  862. if (cb) {
  863. cb('err', 'update archive err!', params.uuid);
  864. }
  865. }, function(ex){
  866. if (cb) {
  867. cb('err', 'update archive err!', params.uuid);
  868. }
  869. }
  870. );
  871. } else {
  872. // 有冲突,需要删除
  873. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  874. function(result){
  875. if (cb) {
  876. cb('err', 'update archive conflict!', null);
  877. }
  878. }
  879. );
  880. }
  881. }, function (error){
  882. // alert(error);
  883. if (cb) {
  884. cb('err', 'update archive conflict!', null);
  885. }
  886. });
  887. }
  888. }
  889. } catch (ex) {
  890. console.log(ex);
  891. console.log(ex.toString());
  892. if (cb) {
  893. cb('err', 'has exception!', null);
  894. }
  895. }
  896. } else {
  897. alert('请选择打开一个报表!');
  898. }
  899. },
  900. _getOneValidLeafNode: function(node) {
  901. let rst = null;
  902. let me = rptArchiveObj;
  903. if (node) {
  904. const preNode = node.getPreNode();
  905. if (preNode) {
  906. rst = preNode;
  907. } else {
  908. const nodes = me.treeObj.getNodes();
  909. for (let dtlNode of nodes) {
  910. if (dtlNode !== node && dtlNode.nodeType === 2) {
  911. rst = dtlNode;
  912. break;
  913. }
  914. }
  915. }
  916. }
  917. return rst;
  918. },
  919. removeArchive: function() {
  920. let me = rptArchiveObj;
  921. const bkRefId = parseInt(me.currentNode.refId);
  922. const bkUuid = me.currentArchiveUuid;
  923. if (me.currentNode && me.currentArchiveUuid) {
  924. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  925. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  926. function(result){
  927. // console.log(result.data);
  928. let hasRemovedAll = false;
  929. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  930. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  931. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  932. if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
  933. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  934. break;
  935. }
  936. }
  937. if (ARCHIVE_LIST[idx].items.length === 0) {
  938. ARCHIVE_LIST.splice(idx, 0);
  939. hasRemovedAll = true;
  940. break;
  941. }
  942. }
  943. }
  944. //要刷新当前归档
  945. if (hasRemovedAll) {
  946. const validNode = me._getOneValidLeafNode(me.currentNode);
  947. // me.iniPage();
  948. me.treeObj.removeNode(me.currentNode);
  949. if (validNode) {
  950. me.currentNode = validNode;
  951. me.onClick(null, null, me.currentNode);
  952. me.treeObj.selectNode(me.currentNode, false);
  953. me._iniArchiveItemForDeleteShow();
  954. }
  955. } else {
  956. me.currentArchiveUuid = null;
  957. me.currentArchiveDateStr = null;
  958. me.currentArchivePdfPath = null;
  959. me.onClick(null, null, me.currentNode);
  960. }
  961. }
  962. );
  963. }
  964. }
  965. };
  966. /**
  967. * 获取 blob
  968. * @param {String} url 目标文件地址
  969. * @return {Promise}
  970. */
  971. function getBlob(url) {
  972. return new Promise(resolve => {
  973. const xhr = new XMLHttpRequest();
  974. // let fullUrl = url + '?x-oss-process=image/info';
  975. xhr.open('GET', url, true);
  976. xhr.responseType = 'blob';
  977. xhr.onload = () => {
  978. if (xhr.status === 200) {
  979. resolve(xhr.response);
  980. } else {
  981. resolve('not found!');
  982. }
  983. };
  984. xhr.send();
  985. });
  986. }
  987. /**
  988. * pdf base64 转 blob
  989. * @param {String} dataUrl base64码
  990. * @return {Promise}
  991. */
  992. function convertBase64UrlToBlob(dataUrl) {
  993. //去掉url的头,并转换为byte
  994. var bytes = window.atob(dataUrl);
  995. //处理异常,将ascii码小于0的转换为大于0
  996. var ab = new Uint8Array(bytes.length);
  997. for (var i = 0; i < bytes.length; i++) {
  998. ab[i] = bytes.charCodeAt(i);
  999. }
  1000. return new Blob([ab], { type: 'application/pdf' });
  1001. }
  1002. /**
  1003. * 保存
  1004. * @param {Blob} blob
  1005. * @param {String} filename 想要保存的文件名称
  1006. */
  1007. function saveAs(blob, filename) {
  1008. if (window.navigator.msSaveOrOpenBlob) {
  1009. navigator.msSaveBlob(blob, filename);
  1010. } else {
  1011. const link = document.createElement('a');
  1012. const body = document.querySelector('body');
  1013. link.href = window.URL.createObjectURL(blob);
  1014. link.download = filename;
  1015. // fix Firefox
  1016. link.style.display = 'none';
  1017. body.appendChild(link);
  1018. link.click();
  1019. body.removeChild(link);
  1020. window.URL.revokeObjectURL(link.href);
  1021. }
  1022. }
  1023. /**
  1024. * 下载
  1025. * @param {String} url 目标文件地址
  1026. * @param {String} filename 想要保存的文件名称
  1027. */
  1028. function download(url, filename) {
  1029. getBlob(url).then(blob => {
  1030. saveAs(blob, filename);
  1031. });
  1032. }
  1033. $(function () {
  1034. $('#download_file').click(function () {
  1035. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1036. console.log(rptArchiveObj.currentArchivePdfPath);
  1037. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  1038. } else {
  1039. alert('请选择打开一个报表!');
  1040. }
  1041. });
  1042. $('#print_file').click(function () {
  1043. if (rptArchiveObj.currentArchiveUuid) {
  1044. $('#iframe_made iframe')[0].contentWindow.print();
  1045. } else {
  1046. alert('请选择打开一个报表!');
  1047. }
  1048. });
  1049. $('#delete_file').click(function () {
  1050. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1051. console.log(rptArchiveObj.currentArchivePdfPath);
  1052. rptArchiveObj.removeArchive();
  1053. } else {
  1054. alert('请选择打开一个报表!');
  1055. }
  1056. });
  1057. })