rpt_archive.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /**
  2. * Created by Tony on 2021/4/2.
  3. */
  4. let rptArchiveObj = {
  5. treeObj: null,
  6. currentNode: null,
  7. currentArchiveUuid: null,
  8. currentArchiveDateStr: null,
  9. currentEncryptionList: null,
  10. currentArchivePdfPath: null,
  11. iniPage: function() {
  12. //初始化页面的归档信息
  13. let me = rptArchiveObj;
  14. me.currentNode = null;
  15. me.currentArchiveUuid = null;
  16. me.currentArchiveDateStr = null;
  17. me.currentEncryptionList = null;
  18. me.currentArchivePdfPath = null;
  19. const archivedRptIds = [];
  20. for (let aItem of ARCHIVE_LIST) {
  21. archivedRptIds.push(parseInt(aItem.rpt_id));
  22. }
  23. let private_remove_hide_item = function (items, nlv) {
  24. if (items && items.length > 0) {
  25. for (let i = items.length - 1; i >= 0; i--) {
  26. if (!(items[i].released) && items[i].nodeType === 2) {
  27. items.splice(i, 1);
  28. } else {
  29. if (items[i].items && items[i].items.length > 0) {
  30. private_remove_hide_item(items[i].items, nlv + 1);
  31. if (items[i].items.length === 0 && nlv > 0) {
  32. items.splice(i, 1);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. };
  39. const private_remove_un_archive_item = function(items, nlv) {
  40. if (items && items.length > 0) {
  41. for (let i = items.length - 1; i >= 0; i--) {
  42. if (items[i].nodeType === 2) {
  43. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  44. items.splice(i, 1);
  45. }
  46. } else {
  47. if (items[i].items && items[i].items.length > 0) {
  48. private_remove_un_archive_item(items[i].items, nlv + 1);
  49. if (items[i].items.length === 0 && nlv > 0) {
  50. items.splice(i, 1);
  51. }
  52. } else {
  53. //items[i]是目录,但又没有items子项,
  54. items.splice(i, 1);
  55. }
  56. }
  57. }
  58. }
  59. };
  60. let nodeLv = 0;
  61. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  62. private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
  63. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
  64. me.treeObj.expandAll(true);
  65. me.refreshNodes();
  66. rptArchiveObj._countChkedRptTpl();
  67. rptArchiveObj._buildeArchiveDateSelect();
  68. },
  69. toggleBtn: function (enabled) {
  70. if (current_stage_status === 3 && enabled) {
  71. $('#btnArchiveRpt').removeAttr('disabled');
  72. $('#btnArchiveList').removeAttr('disabled');
  73. } else {
  74. $('#btnArchiveRpt').attr('disabled', '');
  75. $('#btnArchiveList').attr('disabled', '');
  76. }
  77. },
  78. refreshNodes: function() {
  79. let me = this;
  80. let private_setupIsParent = function(node){
  81. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  82. if (node.items && node.items.length) {
  83. for (let i = 0; i < node.items.length; i++) {
  84. private_setupIsParent(node.items[i]);
  85. }
  86. }
  87. };
  88. let topNodes = me.treeObj.getNodes();
  89. for (let i = 0; i < topNodes.length; i++) {
  90. private_setupIsParent(topNodes[i]);
  91. }
  92. me.treeObj.refresh();
  93. },
  94. onCheck: function(event, treeId, treeNode) {
  95. rptArchiveObj._countChkedRptTpl();
  96. if (treeNode.isParent) {
  97. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  98. }
  99. },
  100. onClick: function(event,treeId,treeNode) {
  101. let me = rptArchiveObj;
  102. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  103. me.currentNode = treeNode;
  104. for (let aItem of ARCHIVE_LIST) {
  105. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  106. me.currentArchiveUuid = null;
  107. me.currentArchiveDateStr = null;
  108. me.currentArchivePdfPath = null;
  109. if (aItem.items && aItem.items.length > 0) {
  110. // me.currentArchiveUuid = aItem.items[0].uuid;
  111. me.currentArchiveUuid = aItem.items[aItem.items.length - 1].uuid;
  112. // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  113. me.currentArchiveDateStr = '#' + (aItem.items.length) + ' ' + aItem.items[aItem.items.length - 1].updateDate_time;
  114. }
  115. break;
  116. }
  117. }
  118. me._countChkedRptTpl();
  119. me._buildeArchiveDateSelect();
  120. me._requestArchiveReport();
  121. }
  122. },
  123. _requestArchiveReport: function () {
  124. let me = rptArchiveObj;
  125. if (me.currentNode && me.currentArchiveUuid) {
  126. try {
  127. if (can_netcasign) {
  128. const msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  129. me.currentEncryptionList = msgSign;
  130. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  131. let html = '';
  132. let pagetr = '';
  133. if (msgSign) {
  134. const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
  135. for (const [index,role] of msgSign.encryption.entries()) {
  136. const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
  137. html += '<div class="'+ rows +'">\n' +
  138. ' <div class="custom-control custom-radio custom-control-inline">\n' +
  139. ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
  140. ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
  141. ' </div>\n' +
  142. ' </div>';
  143. }
  144. let uhtml = '';
  145. for (const us of uSignLogList) {
  146. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  147. }
  148. for (let i = 1; i <= msgSign.total_page; i++) {
  149. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  150. }
  151. }
  152. $('#role-list').html(html);
  153. $('#page-list').html(pagetr);
  154. $('#sign_num').text(uSignLogList.length);
  155. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  156. me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
  157. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  158. }, function () {
  159. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF';
  160. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  161. })
  162. } else {
  163. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF';
  164. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  165. }
  166. // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  167. // console.log(uuIdUrl);
  168. // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  169. // NetcaPDFSeal.openPDFWithUrl(window.location.href);
  170. // window.location = uuIdUrl;
  171. } catch (ex) {
  172. console.log(ex.toString());
  173. }
  174. }
  175. },
  176. _changeArchiveDateSelect: function (dom) {
  177. let me = rptArchiveObj;
  178. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  179. me.currentArchiveDateStr = dom.innerHTML;
  180. if(can_netcasign) {
  181. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  182. me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' : oss_path + '/'+ me.currentArchiveUuid +'.PDF';
  183. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  184. me._buildeArchiveDateSelect();
  185. }, function () {
  186. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF';
  187. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  188. me._buildeArchiveDateSelect();
  189. });
  190. me._updateSignHtmlAndFrame();
  191. } else {
  192. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF';
  193. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  194. me._buildeArchiveDateSelect();
  195. }
  196. },
  197. _buildeArchiveDateSelect: function () {
  198. let me = rptArchiveObj;
  199. let targetDom = document.getElementById("currentDrpArchiveSelect");
  200. targetDom.innerHTML = me.currentArchiveDateStr;
  201. let drpDom = $("#drpArchiveSelect");
  202. drpDom.empty();
  203. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  204. for (let aItem of ARCHIVE_LIST) {
  205. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  206. for (let [index,item] of aItem.items.entries()) {
  207. if (item.uuid !== me.currentArchiveUuid) {
  208. const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + '#' + (index+1) + ' ' + item.updateDate_time + '</a>';
  209. drpDom.append(str);
  210. }
  211. }
  212. }
  213. }
  214. }
  215. },
  216. _updateSignHtmlAndFrame: function (needFrame = false) {
  217. const me = rptArchiveObj;
  218. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  219. for (let i = 0; i < $('#role-list div').length; i++) {
  220. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  221. $('#role-list div').eq(i).find('input').attr('disabled', true);
  222. } else {
  223. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  224. }
  225. $('#role-list div').eq(i).find('input').prop('checked', false);
  226. }
  227. let uhtml = '';
  228. let pagetr = '';
  229. const msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  230. for (const us of uSignLogList) {
  231. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  232. }
  233. for (let i = 1; i <= msgSign.total_page; i++) {
  234. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  235. }
  236. $('#page-list').html(pagetr);
  237. if (needFrame) {
  238. me.currentArchivePdfPath = oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF';
  239. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  240. }
  241. $('#sign_num').text(uSignLogList.length);
  242. },
  243. _countChkedRptTpl: function () {
  244. let me = rptArchiveObj;
  245. if (me.treeObj) {
  246. me.checkedRptTplNodes = [];
  247. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  248. for (let node of chkNodes) {
  249. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  250. cnt++;
  251. me.checkedRptTplNodes.push(node);
  252. if (me.currentNode === node) hasCurrentNode = true;
  253. }
  254. }
  255. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  256. //这里根据实际需求再做处理
  257. cnt++;
  258. me.checkedRptTplNodes.push(me.currentNode);
  259. }
  260. $("#print_div").find("span").each(function(cIdx,elementSpan){
  261. elementSpan.innerText = cnt;
  262. });
  263. $("#export_div").find("span").each(function(cIdx,elementSpan){
  264. elementSpan.innerText = cnt;
  265. });
  266. }
  267. },
  268. showArchivedItem: function(currentNode) {
  269. //初始化当前报表已经归档的信息
  270. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  271. if (currentNode) {
  272. //1. cardArchiveInfo
  273. let cardArchiveInfo = $('#cardArchiveInfo');
  274. cardArchiveInfo.empty();
  275. let auditDate = null;
  276. let achivedAmt = 0;
  277. let achivedItem = null;
  278. for (let item of ARCHIVE_LIST) {
  279. if (parseInt(item.rpt_id) === currentNode.refId) {
  280. auditDate = new Date(LAST_AUDITOR.begin_time);
  281. achivedAmt = item.items?item.items.length:0;
  282. achivedItem = item;
  283. break;
  284. }
  285. }
  286. if (auditDate) {
  287. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  288. } else {
  289. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  290. }
  291. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  292. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  293. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  294. }
  295. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  296. if (achivedAmt > 0) {
  297. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  298. cardArchiveInfo.append('<div class="form-check">');
  299. // if (achivedAmt === 3) {
  300. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  301. // }
  302. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  303. // let ad = new Date(achivedItem.items[idx].update_time);
  304. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  305. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  306. cardArchiveInfo.append('</label>');
  307. cardArchiveInfo.append('</div>');
  308. }
  309. }
  310. cardArchiveInfo.append('</div>');
  311. //2. selectionArchiveInfo
  312. let selectionArchiveInfo = $('#selectionArchiveInfo');
  313. selectionArchiveInfo.empty();
  314. if (achivedAmt > 0) {
  315. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  316. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  317. }
  318. }
  319. }
  320. },
  321. _getCurrentArchives: function (currentNode) {
  322. let rst = null;
  323. if (ARCHIVE_LIST.length > 0 && currentNode) {
  324. for (let aItem of ARCHIVE_LIST) {
  325. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  326. rst = aItem;
  327. break;
  328. }
  329. }
  330. }
  331. return rst;
  332. },
  333. _chkIfFullArchives: function(currentNode) {
  334. let aItem = this._getCurrentArchives(currentNode);
  335. let rst = (aItem && aItem.items && aItem.items.length === 3);
  336. return rst;
  337. },
  338. _getPageSignatureInfo: function(pageData, rpt_id) {
  339. let psInfo = [], psInfoStr = [];
  340. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  341. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  342. const _getProperSignatureArea = function(cell, control) {
  343. // 约定默认长宽比例是2:1,图片分辨率是600*300
  344. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  345. if (cell && cell[JV.PROP_AREA]) {
  346. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  347. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  348. if (width > height * 2) {
  349. width = height * 2;
  350. } else {
  351. height = width / 2;
  352. }
  353. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  354. case 'left':
  355. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  356. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  357. rst[2] = rst[0] + width;
  358. rst[3] = rst[1] + height;
  359. break;
  360. case 'right':
  361. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  362. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  363. rst[0] = rst[2] - width;
  364. rst[1] = rst[3] - height;
  365. break;
  366. default:
  367. //center
  368. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  369. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  370. rst[2] = rst[0] + width;
  371. rst[3] = rst[1] + height;
  372. break;
  373. }
  374. }
  375. rst[0] = rst[0] + offsetX;
  376. rst[2] = rst[2] + offsetX;
  377. rst[1] = rst[1] + offsetY;
  378. rst[3] = rst[3] + offsetY;
  379. return rst;
  380. }
  381. for(let i = 0; i < pageData.items.length; i++) {
  382. let page = pageData.items[i];
  383. for (let sCell of page.signature_cells) {
  384. let control = null;
  385. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  386. control = controls[sCell[JV.PROP_CONTROL]];
  387. } else {
  388. control = sCell[JV.PROP_CONTROL];
  389. }
  390. let idx = psInfoStr.indexOf(sCell.signature_name);
  391. let actSignArea = _getProperSignatureArea(sCell, control);
  392. if (idx < 0) {
  393. psInfoStr.push(sCell.signature_name);
  394. let newPsInfo = {'name': sCell.signature_name, areas: []};
  395. let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []};
  396. area.pages.push(i + 1);
  397. newPsInfo.areas.push(area);
  398. psInfo.push(newPsInfo);
  399. } else {
  400. let hasArea = false;
  401. for (let areaItem of psInfoStr[idx].areas) {
  402. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  403. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  404. areaItem.pages.push(i + 1);
  405. hasArea = true;
  406. break;
  407. }
  408. }
  409. if (!hasArea) {
  410. let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []};
  411. area.pages.push(i + 1);
  412. psInfoStr[idx].areas.push(area);
  413. }
  414. }
  415. // sCell.signature_name
  416. }
  417. }
  418. return psInfo;
  419. },
  420. archiveCurrentReport: function(currentRptPageRst, currentNode) {
  421. // 归档当前报表
  422. if (currentRptPageRst !== null) {
  423. try {
  424. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  425. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, currentNode.refId);
  426. // console.log(pageEncryptInfo);
  427. let formData = new FormData();
  428. formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
  429. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  430. postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
  431. // 成功后,更新当前页面
  432. if (result.addedRst) {
  433. // console.log(result);
  434. ARCHIVE_LIST = result.addedRst;
  435. rptArchiveObj.showArchivedItem(currentNode);
  436. zTreeOprObj.refreshNodes();
  437. //第二步:增加
  438. let params = {};
  439. params.prjId = PROJECT_ID;
  440. params.stgId = current_stage_id;
  441. params.rptId = currentNode.refId;
  442. params.ttlPgs = currentRptPageRst.items.length;
  443. params.content = pageEncryptInfo;
  444. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  445. function(result){
  446. //
  447. }, function(err){
  448. //
  449. }, function(ex){
  450. //
  451. }
  452. );
  453. } else {
  454. // 有冲突,需要删除
  455. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  456. function(result){
  457. //
  458. }
  459. );
  460. }
  461. }, function (error){
  462. // alert(error);
  463. });
  464. } else {
  465. let aItem = this._getCurrentArchives(currentNode);
  466. if (aItem && aItem.items && aItem.items.length > 0) {
  467. let orgName = aItem.items[0].uuid;
  468. let compStr = aItem.items[0].updateDate_time;
  469. for (let idx = 1; idx < aItem.items.length; idx++) {
  470. if (aItem.items[idx].updateDate_time < compStr) {
  471. compStr = aItem.items[idx].updateDate_time;
  472. orgName = aItem.items[idx].uuid;
  473. }
  474. }
  475. postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  476. // 成功后,更新当前页面
  477. if (result.updatedRst) {
  478. // console.log(result);
  479. ARCHIVE_LIST = result.updatedRst;
  480. rptArchiveObj.showArchivedItem();
  481. zTreeOprObj.refreshNodes();
  482. } else {
  483. // 有冲突,需要删除
  484. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  485. function(result){
  486. //
  487. }
  488. );
  489. }
  490. }, function (error){
  491. // alert(error);
  492. });
  493. }
  494. }
  495. } catch (ex) {
  496. console.log(ex.toString());
  497. }
  498. } else {
  499. alert('请选择打开一个报表!');
  500. }
  501. }
  502. };
  503. function dataURLtoFile(dataurl, filename) {
  504. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  505. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  506. while(n--){
  507. u8arr[n] = bstr.charCodeAt(n);
  508. }
  509. return new File([u8arr], filename, {type:mime});
  510. };
  511. /**
  512. * 获取 blob
  513. * @param {String} url 目标文件地址
  514. * @return {Promise}
  515. */
  516. function getBlob(url) {
  517. return new Promise(resolve => {
  518. const xhr = new XMLHttpRequest();
  519. xhr.open('GET', url, true);
  520. xhr.responseType = 'blob';
  521. xhr.onload = () => {
  522. if (xhr.status === 200) {
  523. resolve(xhr.response);
  524. }
  525. };
  526. xhr.send();
  527. });
  528. }
  529. /**
  530. * 保存
  531. * @param {Blob} blob
  532. * @param {String} filename 想要保存的文件名称
  533. */
  534. function saveAs(blob, filename) {
  535. if (window.navigator.msSaveOrOpenBlob) {
  536. navigator.msSaveBlob(blob, filename);
  537. } else {
  538. const link = document.createElement('a');
  539. const body = document.querySelector('body');
  540. link.href = window.URL.createObjectURL(blob);
  541. link.download = filename;
  542. // fix Firefox
  543. link.style.display = 'none';
  544. body.appendChild(link);
  545. link.click();
  546. body.removeChild(link);
  547. window.URL.revokeObjectURL(link.href);
  548. }
  549. }
  550. /**
  551. * 下载
  552. * @param {String} url 目标文件地址
  553. * @param {String} filename 想要保存的文件名称
  554. */
  555. function download(url, filename) {
  556. getBlob(url).then(blob => {
  557. saveAs(blob, filename);
  558. });
  559. }
  560. $(function () {
  561. $('#download_file').click(function () {
  562. if (rptArchiveObj.currentArchiveUuid) {
  563. download(`${oss_path}/${rptArchiveObj.currentArchiveUuid}.PDF`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  564. } else {
  565. alert('请选择打开一个报表!');
  566. }
  567. });
  568. $('#print_file').click(function () {
  569. if (rptArchiveObj.currentArchiveUuid) {
  570. $('#iframe_made iframe')[0].contentWindow.print();
  571. } else {
  572. alert('请选择打开一个报表!');
  573. }
  574. });
  575. })