rpt_archive.js 58 KB

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