rpt_archive.js 54 KB

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