rpt_archive.js 33 KB

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