rpt_archive.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  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. default:
  674. break;
  675. }
  676. return rst;
  677. },
  678. _archiveCurrentReport: function(currentRptPageRst, currentNode, currentRolRel, cb) {
  679. // 归档当前报表
  680. const bzId = rptArchiveObj._getBusinessId();
  681. const _prepareEncryptionParam = function(result, pageEncryptInfo) {
  682. const params = {};
  683. params.prjId = PROJECT_ID;
  684. params.stgId = current_stage_id;
  685. params.tenderId = TENDER_ID;
  686. params.businessId = bzId;
  687. params.rptId = currentNode.refId;
  688. params.ttlPgs = currentRptPageRst.items.length;
  689. params.content = pageEncryptInfo;
  690. params.uuid = result.uuid; //正确返回时,带着uuid回来
  691. params.childUuids = result.childUuids; //还有子uuid
  692. params.splitArcPages = currentRptPageRst.splitArcPages ? currentRptPageRst.splitArcPages : [];
  693. // params.splitArcPagesInfo = currentRptPageRst.splitArcPagesInfo ? currentRptPageRst.splitArcPagesInfo : {};
  694. params.reportName = currentNode.name;
  695. return params;
  696. };
  697. const _prepareArchiveUrl = function(archiveOprStr, suffix) {
  698. let rst = `/tender/report_api/${archiveOprStr}/${PROJECT_ID}/${current_stage_id}/${bzId}/${TENDER_ID}/${currentNode.refId}${suffix}`;
  699. if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
  700. 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}`;
  701. }
  702. return rst;
  703. }
  704. if (currentRptPageRst !== null) {
  705. try {
  706. let signCells = [];
  707. let txtSignCells = [];
  708. let dummyTxtSignCells = [];
  709. const restoreCells = (srcCells, targetCellsStr) => {
  710. if (srcCells.length > 0) {
  711. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  712. srcCells[pageIdx].forEach((srcCell) => {
  713. pageItem[targetCellsStr].push(srcCell);
  714. });
  715. srcCells[pageIdx] = null;
  716. });
  717. }
  718. };
  719. if (PAGE_SHOW.isTextSignature) {
  720. // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
  721. // 批量归档的数据后台会处理(已经移除相关签名)
  722. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  723. const dtlSignCells = [];
  724. signCells.push(dtlSignCells);
  725. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  726. let sCell = pageItem.signature_cells[sCellIdx];
  727. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  728. dtlSignCells.push(sCell);
  729. pageItem.signature_cells.splice(sCellIdx, 1);
  730. if (PAGE_SHOW.closeArchiveSignature) {
  731. // 如果还有closeArchiveSignature标记,那么不显示文本文档(只是清除匹配cell的Value,后续需要恢复)
  732. const cCell = pageItem.cells.find(cell => cell.area.Left === sCell.area.Left && cell.area.Top === sCell.area.Top && cell.Value === sCell.Value);
  733. if (cCell) {
  734. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  735. cCell.Value = '';
  736. }
  737. }
  738. } else if (PAGE_SHOW.closeArchiveSignature) {
  739. // 这个跟上面的判断属性不同,是orgArea(签章的)
  740. for (let cIdx = pageItem.cells.length - 1; cIdx >= 0; cIdx--) {
  741. const cCell = pageItem.cells[cIdx];
  742. if (cCell.area.Left === sCell.orgArea.Left && cCell.area.Right === sCell.orgArea.Right &&
  743. cCell.area.Top === sCell.orgArea.Top && cCell.area.Bottom === sCell.orgArea.Bottom &&
  744. cCell.Value !== '') {
  745. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  746. cCell.Value = '';
  747. break;
  748. }
  749. }
  750. }
  751. }
  752. });
  753. } else if (PAGE_SHOW.closeArchiveSignature) {
  754. // 这里还有一个场景需要考虑:签名是图片且选择了签名,又不归档输出,
  755. const rrSigns = [];
  756. currentRolRel.forEach(role_rel => {
  757. if (role_rel.sign_output && role_rel.sign_output.includes(NORMAL_SIGN_STR)) {
  758. rrSigns.push(role_rel.signature_name);
  759. }
  760. });
  761. if (rrSigns.length > 0) {
  762. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  763. const dtlSignCells = [];
  764. const dtlDummyCells = [];
  765. signCells.push(dtlSignCells);
  766. dummyTxtSignCells.push(dtlDummyCells);
  767. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  768. let sCell = pageItem.signature_cells[sCellIdx];
  769. if (rrSigns.includes(sCell.signature_name)) {
  770. dtlSignCells.push(sCell);
  771. pageItem.signature_cells.splice(sCellIdx, 1);
  772. // 还得加一个dummy cell,处理边框用的
  773. const newCell = {
  774. font: 'Footer',
  775. control: sCell.control,
  776. style: sCell.style,
  777. Value: '',
  778. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  779. };
  780. dtlDummyCells.push(newCell);
  781. pageItem.cells.push(newCell);
  782. }
  783. }
  784. });
  785. }
  786. }
  787. const pageSize = rptControlObj.getCurrentPageSize();
  788. const relForArchive = PAGE_SHOW.closeArchiveSignature ? [] : currentRolRel;
  789. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, pageSize, relForArchive, STAGE_AUDIT);
  790. restoreCells(signCells, 'signature_cells');
  791. signCells = null;
  792. txtSignCells.forEach(txtCellBkObj => {
  793. txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
  794. });
  795. txtSignCells = null;
  796. if (dummyTxtSignCells.length === currentRptPageRst.items.length) {
  797. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  798. dummyTxtSignCells[pageIdx].forEach((dummyCell) => {
  799. const idx = pageItem.cells.indexOf(dummyCell);
  800. if (idx >= 0) pageItem.cells.splice(idx, 1);
  801. });
  802. dummyTxtSignCells[pageIdx] = null;
  803. });
  804. dummyTxtSignCells = null;
  805. }
  806. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, pageSize, currentNode.refId);
  807. // console.log(pageEncryptInfo);
  808. let formData = new FormData();
  809. formData.append('file', doc.output('blob'), 'upload.pdf');
  810. // formData.append('size', pFile.size);
  811. if (currentRptPageRst.splitArcPages) {
  812. let docs = JpcJsPDFHelper.getChildrenDocs(currentRptPageRst, rptControlObj.getCurrentPageSize(), currentRolRel, STAGE_AUDIT);
  813. for (let docIdx = 0; docIdx < docs.length; docIdx++) {
  814. let file = docs[docIdx].output('blob');
  815. formData.append('file', file, `upload_child_${docIdx}.pdf`);
  816. }
  817. }
  818. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  819. const archiveUrl = _prepareArchiveUrl('addArchive', '');
  820. postDataWithFile(archiveUrl, formData, function (result) {
  821. // 成功后,更新当前页面
  822. //*
  823. if (result.updatedRst) {
  824. // console.log(result);
  825. ARCHIVE_LIST = result.updatedRst;
  826. rptArchiveObj.showArchivedItem(currentNode);
  827. zTreeOprObj.refreshNodes();
  828. //第二步:增加加密信息
  829. let params = _prepareEncryptionParam(result, pageEncryptInfo);
  830. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  831. function(rst){
  832. if (cb) {
  833. cb(null, 'add archive encryption succeed!', params.uuid);
  834. }
  835. }, function(err){
  836. if (cb) {
  837. cb('err', 'add archive encryption err!', params.uuid);
  838. }
  839. }, function(ex){
  840. if (cb) {
  841. cb('err', 'add archive encryption err!', params.uuid);
  842. }
  843. }
  844. );
  845. } else {
  846. // 有冲突,需要删除
  847. CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken_j'),
  848. function(result){
  849. if (cb) {
  850. cb('err', 'add archive conflict!', null);
  851. }
  852. }
  853. );
  854. }
  855. //*/
  856. }, function (error){
  857. if (cb) {
  858. cb('err', 'add archive err!', null);
  859. }
  860. });
  861. } else {
  862. let aItem = this._getCurrentArchives(currentNode);
  863. if (aItem && aItem.items && aItem.items.length > 0) {
  864. let orgName = aItem.items[0].uuid;
  865. let compStr = aItem.items[0].updateDate_time;
  866. for (let idx = 1; idx < aItem.items.length; idx++) {
  867. if (aItem.items[idx].updateDate_time < compStr) {
  868. compStr = aItem.items[idx].updateDate_time;
  869. orgName = aItem.items[idx].uuid;
  870. }
  871. }
  872. const archiveUrl = _prepareArchiveUrl('updateArchive', `/${orgName}`);
  873. postDataWithFile(archiveUrl, formData, function (result) {
  874. // 成功后,更新当前页面
  875. if (result.updatedRst) {
  876. // console.log(result);
  877. ARCHIVE_LIST = result.updatedRst;
  878. rptArchiveObj.showArchivedItem(currentNode);
  879. zTreeOprObj.refreshNodes();
  880. //第二步:更新加密信息
  881. // let params = {};
  882. let params = _prepareEncryptionParam(result, pageEncryptInfo);
  883. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  884. function(result){
  885. if (cb) {
  886. cb(null, 'update archive succeed!', params.uuid);
  887. }
  888. }, function(err){
  889. if (cb) {
  890. cb('err', 'update archive err!', params.uuid);
  891. }
  892. }, function(ex){
  893. if (cb) {
  894. cb('err', 'update archive err!', params.uuid);
  895. }
  896. }
  897. );
  898. } else {
  899. // 有冲突,需要删除
  900. CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken'),
  901. function(result){
  902. if (cb) {
  903. cb('err', 'update archive conflict!', null);
  904. }
  905. }
  906. );
  907. }
  908. }, function (error){
  909. // alert(error);
  910. if (cb) {
  911. cb('err', 'update archive conflict!', null);
  912. }
  913. });
  914. }
  915. }
  916. } catch (ex) {
  917. console.log(ex);
  918. console.log(ex.toString());
  919. if (cb) {
  920. cb('err', 'has exception!', null);
  921. }
  922. }
  923. } else {
  924. alert('请选择打开一个报表!');
  925. }
  926. },
  927. _getOneValidLeafNode: function(node) {
  928. let rst = null;
  929. let me = rptArchiveObj;
  930. if (node) {
  931. const preNode = node.getPreNode();
  932. if (preNode) {
  933. rst = preNode;
  934. } else {
  935. const nodes = me.treeObj.getNodes();
  936. for (let dtlNode of nodes) {
  937. if (dtlNode !== node && dtlNode.nodeType === 2) {
  938. rst = dtlNode;
  939. break;
  940. }
  941. }
  942. }
  943. }
  944. return rst;
  945. },
  946. removeArchive: function() {
  947. // 这个是从'归档报表'界面进来的
  948. let me = rptArchiveObj;
  949. const bkRefId = parseInt(me.currentNode.refId);
  950. const bkUuid = me.currentArchiveUuid;
  951. if (me.currentNode && me.currentArchiveUuid) {
  952. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${rptArchiveObj._getBusinessId()}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  953. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  954. function(result){
  955. // console.log(result.data);
  956. let hasRemovedAll = false;
  957. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  958. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  959. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  960. if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
  961. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  962. break;
  963. }
  964. }
  965. if (ARCHIVE_LIST[idx].items.length === 0) {
  966. ARCHIVE_LIST.splice(idx, 0);
  967. hasRemovedAll = true;
  968. break;
  969. }
  970. }
  971. }
  972. //要刷新当前归档
  973. if (hasRemovedAll) {
  974. const validNode = me._getOneValidLeafNode(me.currentNode);
  975. // me.iniPage();
  976. me.treeObj.removeNode(me.currentNode);
  977. if (validNode) {
  978. me.currentNode = validNode;
  979. me.onClick(null, null, me.currentNode);
  980. me.treeObj.selectNode(me.currentNode, false);
  981. me._iniArchiveItemForDeleteShow();
  982. }
  983. } else {
  984. me.currentArchiveUuid = null;
  985. me.currentArchiveDateStr = null;
  986. me.currentArchivePdfPath = null;
  987. me.onClick(null, null, me.currentNode);
  988. }
  989. }
  990. );
  991. }
  992. }
  993. };
  994. /**
  995. * 获取 blob
  996. * @param {String} url 目标文件地址
  997. * @return {Promise}
  998. */
  999. function getBlob(url) {
  1000. return new Promise(resolve => {
  1001. const xhr = new XMLHttpRequest();
  1002. // let fullUrl = url + '?x-oss-process=image/info';
  1003. xhr.open('GET', url, true);
  1004. xhr.responseType = 'blob';
  1005. xhr.onload = () => {
  1006. if (xhr.status === 200) {
  1007. resolve(xhr.response);
  1008. } else {
  1009. resolve('not found!');
  1010. }
  1011. };
  1012. xhr.send();
  1013. });
  1014. }
  1015. /**
  1016. * pdf base64 转 blob
  1017. * @param {String} dataUrl base64码
  1018. * @return {Promise}
  1019. */
  1020. function convertBase64UrlToBlob(dataUrl) {
  1021. //去掉url的头,并转换为byte
  1022. var bytes = window.atob(dataUrl);
  1023. //处理异常,将ascii码小于0的转换为大于0
  1024. var ab = new Uint8Array(bytes.length);
  1025. for (var i = 0; i < bytes.length; i++) {
  1026. ab[i] = bytes.charCodeAt(i);
  1027. }
  1028. return new Blob([ab], { type: 'application/pdf' });
  1029. }
  1030. /**
  1031. * 保存
  1032. * @param {Blob} blob
  1033. * @param {String} filename 想要保存的文件名称
  1034. */
  1035. function saveAs(blob, filename) {
  1036. if (window.navigator.msSaveOrOpenBlob) {
  1037. navigator.msSaveBlob(blob, filename);
  1038. } else {
  1039. const link = document.createElement('a');
  1040. const body = document.querySelector('body');
  1041. link.href = window.URL.createObjectURL(blob);
  1042. link.download = filename;
  1043. // fix Firefox
  1044. link.style.display = 'none';
  1045. body.appendChild(link);
  1046. link.click();
  1047. body.removeChild(link);
  1048. window.URL.revokeObjectURL(link.href);
  1049. }
  1050. }
  1051. /**
  1052. * 下载
  1053. * @param {String} url 目标文件地址
  1054. * @param {String} filename 想要保存的文件名称
  1055. */
  1056. function download(url, filename) {
  1057. getBlob(url).then(blob => {
  1058. saveAs(blob, filename);
  1059. });
  1060. }
  1061. $(function () {
  1062. $('#download_file').click(function () {
  1063. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1064. console.log(rptArchiveObj.currentArchivePdfPath);
  1065. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  1066. } else {
  1067. alert('请选择打开一个报表!');
  1068. }
  1069. });
  1070. $('#print_file').click(function () {
  1071. if (rptArchiveObj.currentArchiveUuid) {
  1072. $('#iframe_made iframe')[0].contentWindow.print();
  1073. } else {
  1074. alert('请选择打开一个报表!');
  1075. }
  1076. });
  1077. $('#delete_file').click(function () {
  1078. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1079. console.log(rptArchiveObj.currentArchivePdfPath);
  1080. rptArchiveObj.removeArchive();
  1081. } else {
  1082. alert('请选择打开一个报表!');
  1083. }
  1084. });
  1085. })