rpt_archive.js 30 KB

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