rpt_archive.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  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, currentRolRel, 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, currentRolRel, 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(CHANGE_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. const relForArchive = PAGE_SHOW.closeArchiveSignature ? [] : currentRolRel;
  786. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, pageSize, relForArchive, STAGE_AUDIT);
  787. restoreCells(signCells, 'signature_cells');
  788. signCells = null;
  789. txtSignCells.forEach(txtCellBkObj => {
  790. txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
  791. });
  792. txtSignCells = null;
  793. if (dummyTxtSignCells.length === currentRptPageRst.items.length) {
  794. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  795. dummyTxtSignCells[pageIdx].forEach((dummyCell) => {
  796. const idx = pageItem.cells.indexOf(dummyCell);
  797. if (idx >= 0) pageItem.cells.splice(idx, 1);
  798. });
  799. dummyTxtSignCells[pageIdx] = null;
  800. });
  801. dummyTxtSignCells = null;
  802. }
  803. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, pageSize, currentNode.refId);
  804. // console.log(pageEncryptInfo);
  805. let formData = new FormData();
  806. formData.append('file', doc.output('blob'), 'upload.pdf');
  807. // formData.append('size', pFile.size);
  808. if (currentRptPageRst.splitArcPages) {
  809. let docs = JpcJsPDFHelper.getChildrenDocs(currentRptPageRst, rptControlObj.getCurrentPageSize(), currentRolRel, STAGE_AUDIT);
  810. for (let docIdx = 0; docIdx < docs.length; docIdx++) {
  811. let file = docs[docIdx].output('blob');
  812. formData.append('file', file, `upload_child_${docIdx}.pdf`);
  813. }
  814. }
  815. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  816. const archiveUrl = _prepareArchiveUrl('addArchive', '');
  817. postDataWithFile(archiveUrl, formData, function (result) {
  818. // 成功后,更新当前页面
  819. //*
  820. if (result.updatedRst) {
  821. // console.log(result);
  822. ARCHIVE_LIST = result.updatedRst;
  823. rptArchiveObj.showArchivedItem(currentNode);
  824. zTreeOprObj.refreshNodes();
  825. //第二步:增加加密信息
  826. let params = _prepareEncryptionParam(result, pageEncryptInfo);
  827. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  828. function(rst){
  829. if (cb) {
  830. cb(null, 'add archive encryption succeed!', params.uuid);
  831. }
  832. }, function(err){
  833. if (cb) {
  834. cb('err', 'add archive encryption err!', params.uuid);
  835. }
  836. }, function(ex){
  837. if (cb) {
  838. cb('err', 'add archive encryption err!', params.uuid);
  839. }
  840. }
  841. );
  842. } else {
  843. // 有冲突,需要删除
  844. CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken_j'),
  845. function(result){
  846. if (cb) {
  847. cb('err', 'add archive conflict!', null);
  848. }
  849. }
  850. );
  851. }
  852. //*/
  853. }, function (error){
  854. if (cb) {
  855. cb('err', 'add archive err!', null);
  856. }
  857. });
  858. } else {
  859. let aItem = this._getCurrentArchives(currentNode);
  860. if (aItem && aItem.items && aItem.items.length > 0) {
  861. let orgName = aItem.items[0].uuid;
  862. let compStr = aItem.items[0].updateDate_time;
  863. for (let idx = 1; idx < aItem.items.length; idx++) {
  864. if (aItem.items[idx].updateDate_time < compStr) {
  865. compStr = aItem.items[idx].updateDate_time;
  866. orgName = aItem.items[idx].uuid;
  867. }
  868. }
  869. const archiveUrl = _prepareArchiveUrl('updateArchive', `/${orgName}`);
  870. postDataWithFile(archiveUrl, formData, function (result) {
  871. // 成功后,更新当前页面
  872. if (result.updatedRst) {
  873. // console.log(result);
  874. ARCHIVE_LIST = result.updatedRst;
  875. rptArchiveObj.showArchivedItem(currentNode);
  876. zTreeOprObj.refreshNodes();
  877. //第二步:更新加密信息
  878. // let params = {};
  879. let params = _prepareEncryptionParam(result, pageEncryptInfo);
  880. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  881. function(result){
  882. if (cb) {
  883. cb(null, 'update archive succeed!', params.uuid);
  884. }
  885. }, function(err){
  886. if (cb) {
  887. cb('err', 'update archive err!', params.uuid);
  888. }
  889. }, function(ex){
  890. if (cb) {
  891. cb('err', 'update archive err!', params.uuid);
  892. }
  893. }
  894. );
  895. } else {
  896. // 有冲突,需要删除
  897. CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken'),
  898. function(result){
  899. if (cb) {
  900. cb('err', 'update archive conflict!', null);
  901. }
  902. }
  903. );
  904. }
  905. }, function (error){
  906. // alert(error);
  907. if (cb) {
  908. cb('err', 'update archive conflict!', null);
  909. }
  910. });
  911. }
  912. }
  913. } catch (ex) {
  914. console.log(ex);
  915. console.log(ex.toString());
  916. if (cb) {
  917. cb('err', 'has exception!', null);
  918. }
  919. }
  920. } else {
  921. alert('请选择打开一个报表!');
  922. }
  923. },
  924. _getOneValidLeafNode: function(node) {
  925. let rst = null;
  926. let me = rptArchiveObj;
  927. if (node) {
  928. const preNode = node.getPreNode();
  929. if (preNode) {
  930. rst = preNode;
  931. } else {
  932. const nodes = me.treeObj.getNodes();
  933. for (let dtlNode of nodes) {
  934. if (dtlNode !== node && dtlNode.nodeType === 2) {
  935. rst = dtlNode;
  936. break;
  937. }
  938. }
  939. }
  940. }
  941. return rst;
  942. },
  943. removeArchive: function() {
  944. // 这个是从'归档报表'界面进来的
  945. let me = rptArchiveObj;
  946. const bkRefId = parseInt(me.currentNode.refId);
  947. const bkUuid = me.currentArchiveUuid;
  948. if (me.currentNode && me.currentArchiveUuid) {
  949. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${rptArchiveObj._getBusinessId()}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  950. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  951. function(result){
  952. // console.log(result.data);
  953. let hasRemovedAll = false;
  954. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  955. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  956. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  957. if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
  958. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  959. break;
  960. }
  961. }
  962. if (ARCHIVE_LIST[idx].items.length === 0) {
  963. ARCHIVE_LIST.splice(idx, 0);
  964. hasRemovedAll = true;
  965. break;
  966. }
  967. }
  968. }
  969. //要刷新当前归档
  970. if (hasRemovedAll) {
  971. const validNode = me._getOneValidLeafNode(me.currentNode);
  972. // me.iniPage();
  973. me.treeObj.removeNode(me.currentNode);
  974. if (validNode) {
  975. me.currentNode = validNode;
  976. me.onClick(null, null, me.currentNode);
  977. me.treeObj.selectNode(me.currentNode, false);
  978. me._iniArchiveItemForDeleteShow();
  979. }
  980. } else {
  981. me.currentArchiveUuid = null;
  982. me.currentArchiveDateStr = null;
  983. me.currentArchivePdfPath = null;
  984. me.onClick(null, null, me.currentNode);
  985. }
  986. }
  987. );
  988. }
  989. }
  990. };
  991. /**
  992. * 获取 blob
  993. * @param {String} url 目标文件地址
  994. * @return {Promise}
  995. */
  996. function getBlob(url) {
  997. return new Promise(resolve => {
  998. const xhr = new XMLHttpRequest();
  999. // let fullUrl = url + '?x-oss-process=image/info';
  1000. xhr.open('GET', url, true);
  1001. xhr.responseType = 'blob';
  1002. xhr.onload = () => {
  1003. if (xhr.status === 200) {
  1004. resolve(xhr.response);
  1005. } else {
  1006. resolve('not found!');
  1007. }
  1008. };
  1009. xhr.send();
  1010. });
  1011. }
  1012. /**
  1013. * pdf base64 转 blob
  1014. * @param {String} dataUrl base64码
  1015. * @return {Promise}
  1016. */
  1017. function convertBase64UrlToBlob(dataUrl) {
  1018. //去掉url的头,并转换为byte
  1019. var bytes = window.atob(dataUrl);
  1020. //处理异常,将ascii码小于0的转换为大于0
  1021. var ab = new Uint8Array(bytes.length);
  1022. for (var i = 0; i < bytes.length; i++) {
  1023. ab[i] = bytes.charCodeAt(i);
  1024. }
  1025. return new Blob([ab], { type: 'application/pdf' });
  1026. }
  1027. /**
  1028. * 保存
  1029. * @param {Blob} blob
  1030. * @param {String} filename 想要保存的文件名称
  1031. */
  1032. function saveAs(blob, filename) {
  1033. if (window.navigator.msSaveOrOpenBlob) {
  1034. navigator.msSaveBlob(blob, filename);
  1035. } else {
  1036. const link = document.createElement('a');
  1037. const body = document.querySelector('body');
  1038. link.href = window.URL.createObjectURL(blob);
  1039. link.download = filename;
  1040. // fix Firefox
  1041. link.style.display = 'none';
  1042. body.appendChild(link);
  1043. link.click();
  1044. body.removeChild(link);
  1045. window.URL.revokeObjectURL(link.href);
  1046. }
  1047. }
  1048. /**
  1049. * 下载
  1050. * @param {String} url 目标文件地址
  1051. * @param {String} filename 想要保存的文件名称
  1052. */
  1053. function download(url, filename) {
  1054. getBlob(url).then(blob => {
  1055. saveAs(blob, filename);
  1056. });
  1057. }
  1058. $(function () {
  1059. $('#download_file').click(function () {
  1060. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1061. console.log(rptArchiveObj.currentArchivePdfPath);
  1062. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  1063. } else {
  1064. alert('请选择打开一个报表!');
  1065. }
  1066. });
  1067. $('#print_file').click(function () {
  1068. if (rptArchiveObj.currentArchiveUuid) {
  1069. $('#iframe_made iframe')[0].contentWindow.print();
  1070. } else {
  1071. alert('请选择打开一个报表!');
  1072. }
  1073. });
  1074. $('#delete_file').click(function () {
  1075. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1076. console.log(rptArchiveObj.currentArchivePdfPath);
  1077. rptArchiveObj.removeArchive();
  1078. } else {
  1079. alert('请选择打开一个报表!');
  1080. }
  1081. });
  1082. })