rpt_archive.js 36 KB

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