rpt_archive.js 56 KB

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