rpt_archive.js 58 KB

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