rpt_archive.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /**
  2. * Created by Tony on 2021/4/2.
  3. */
  4. let rptArchiveObj = {
  5. treeObj: null,
  6. currentNode: null,
  7. currentArchiveUuid: null,
  8. currentArchiveDateStr: null,
  9. currentEncryptionList: null,
  10. currentArchivePdfPath: null,
  11. iniPage: function() {
  12. //初始化页面的归档信息
  13. let me = rptArchiveObj;
  14. me.currentNode = null;
  15. me.currentArchiveUuid = null;
  16. me.currentArchiveDateStr = null;
  17. me.currentEncryptionList = null;
  18. me.currentArchivePdfPath = null;
  19. const archivedRptIds = [];
  20. for (let aItem of ARCHIVE_LIST) {
  21. archivedRptIds.push(parseInt(aItem.rpt_id));
  22. }
  23. let private_remove_hide_item = function (items, nlv) {
  24. if (items && items.length > 0) {
  25. for (let i = items.length - 1; i >= 0; i--) {
  26. if (!(items[i].released) && items[i].nodeType === 2) {
  27. items.splice(i, 1);
  28. } else {
  29. if (items[i].items && items[i].items.length > 0) {
  30. private_remove_hide_item(items[i].items, nlv + 1);
  31. if (items[i].items.length === 0 && nlv > 0) {
  32. items.splice(i, 1);
  33. }
  34. }
  35. }
  36. }
  37. }
  38. };
  39. const private_remove_un_archive_item = function(items, nlv) {
  40. if (items && items.length > 0) {
  41. for (let i = items.length - 1; i >= 0; i--) {
  42. if (items[i].nodeType === 2) {
  43. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  44. items.splice(i, 1);
  45. }
  46. } else {
  47. if (items[i].items && items[i].items.length > 0) {
  48. private_remove_un_archive_item(items[i].items, nlv + 1);
  49. if (items[i].items.length === 0 && nlv > 0) {
  50. items.splice(i, 1);
  51. }
  52. } else {
  53. //items[i]是目录,但又没有items子项,
  54. items.splice(i, 1);
  55. }
  56. }
  57. }
  58. }
  59. };
  60. let nodeLv = 0;
  61. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  62. private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
  63. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
  64. me.treeObj.expandAll(true);
  65. me.refreshNodes();
  66. rptArchiveObj._countChkedRptTpl();
  67. rptArchiveObj._buildeArchiveDateSelect();
  68. rptArchiveObj._iniArchiveItemForDeleteShow();
  69. rptArchiveObj._iniArchiveItemForDeleteShow();
  70. },
  71. toggleBtn: function (enabled) {
  72. if (current_stage_status === 3 && enabled) {
  73. $('#btnArchiveRpt').removeAttr('disabled');
  74. $('#btnArchiveList').removeAttr('disabled');
  75. $('#btnBatchArchiveRpt').removeAttr('disabled');
  76. } else {
  77. $('#btnArchiveRpt').attr('disabled', '');
  78. $('#btnArchiveList').attr('disabled', '');
  79. $('#btnBatchArchiveRpt').attr('disabled', '');
  80. }
  81. },
  82. refreshNodes: function() {
  83. let me = this;
  84. let private_setupIsParent = function(node){
  85. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  86. if (node.items && node.items.length) {
  87. for (let i = 0; i < node.items.length; i++) {
  88. private_setupIsParent(node.items[i]);
  89. }
  90. }
  91. };
  92. let topNodes = me.treeObj.getNodes();
  93. for (let i = 0; i < topNodes.length; i++) {
  94. private_setupIsParent(topNodes[i]);
  95. }
  96. me.treeObj.refresh();
  97. },
  98. onCheck: function(event, treeId, treeNode) {
  99. rptArchiveObj._countChkedRptTpl();
  100. if (treeNode.isParent) {
  101. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  102. }
  103. },
  104. onClick: function(event,treeId,treeNode) {
  105. let me = rptArchiveObj;
  106. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  107. me.currentNode = treeNode;
  108. for (let aItem of ARCHIVE_LIST) {
  109. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  110. me.currentArchiveUuid = null;
  111. me.currentArchiveDateStr = null;
  112. me.currentArchivePdfPath = null;
  113. if (aItem.items && aItem.items.length > 0) {
  114. // me.currentArchiveUuid = aItem.items[0].uuid;
  115. // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  116. const newItems = _.orderBy(aItem.items, ['updateDate_time'], ['desc']);
  117. me.currentArchiveUuid = newItems[0].uuid;
  118. me.currentArchiveDateStr = '#' + (_.findIndex(aItem.items, { updateDate_time: newItems[0].updateDate_time})+1) + ' ' + newItems[0].updateDate_time;
  119. if (can_netcasign) {
  120. for (const [i,item] of aItem.items.entries()) {
  121. if (_.find(signLogList, { uuid: item.uuid })) {
  122. me.currentArchiveUuid = item.uuid;
  123. me.currentArchiveDateStr = '#' + (i+1) + ' ' + item.updateDate_time;
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. break;
  130. }
  131. }
  132. me._countChkedRptTpl();
  133. me._buildeArchiveDateSelect();
  134. me._requestArchiveReport();
  135. rptArchiveObj._iniArchiveItemForDeleteShow();
  136. }
  137. },
  138. batchArchive: function() {
  139. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  140. if (zTreeOprObj.checkedRptTplNodes.length <= 10) {
  141. indexDbOprObj.storeReportRequest(current_stage_id, zTreeOprObj.checkedRptTplNodes, indexDbOprObj.startRequestReport);
  142. } else {
  143. alert('批量归档上限为10,请勾选10张以内');
  144. }
  145. }
  146. },
  147. _requestArchiveReport: function () {
  148. let me = rptArchiveObj;
  149. if (me.currentNode && me.currentArchiveUuid) {
  150. try {
  151. if (can_netcasign) {
  152. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  153. if (!msgSign) {
  154. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  155. }
  156. console.log(current_stage_id, msgSign, me.currentArchiveUuid);
  157. me.currentEncryptionList = msgSign;
  158. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  159. let html = '';
  160. let pagetr = '';
  161. if (msgSign) {
  162. const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
  163. for (const [index,role] of msgSign.encryption.entries()) {
  164. const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
  165. html += '<div class="'+ rows +'">\n' +
  166. ' <div class="custom-control custom-radio custom-control-inline">\n' +
  167. ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
  168. ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
  169. ' </div>\n' +
  170. ' </div>';
  171. }
  172. let uhtml = '';
  173. for (const us of uSignLogList) {
  174. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  175. }
  176. for (let i = 1; i <= msgSign.total_page; i++) {
  177. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  178. }
  179. }
  180. $('#dateStr').html(me.currentArchiveDateStr);
  181. $('#role-list').html(html);
  182. $('#page-list').html(pagetr);
  183. $('#sign_num').text(uSignLogList.length);
  184. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  185. // 是否显示撤销按钮
  186. if(uHadSign && uHadSign.length > 0) {
  187. $('#show-removesign-modal-btn').show();
  188. } else {
  189. $('#show-removesign-modal-btn').hide();
  190. }
  191. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  192. 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();
  193. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  194. }, function () {
  195. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  196. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  197. })
  198. } else {
  199. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  200. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  201. console.log(me.currentArchivePdfPath);
  202. }
  203. // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  204. // console.log(uuIdUrl);
  205. // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  206. // NetcaPDFSeal.openPDFWithUrl(window.location.href);
  207. // window.location = uuIdUrl;
  208. } catch (ex) {
  209. console.log(ex.toString());
  210. }
  211. }
  212. },
  213. _changeArchiveDateSelect: function (dom) {
  214. let me = rptArchiveObj;
  215. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  216. me.currentArchiveDateStr = dom.innerHTML;
  217. if(can_netcasign) {
  218. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  219. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  220. 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();
  221. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  222. me._buildeArchiveDateSelect();
  223. }, function () {
  224. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  225. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  226. me._buildeArchiveDateSelect();
  227. });
  228. // me._updateSignHtmlAndFrame();
  229. me._requestArchiveReport();
  230. } else {
  231. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  232. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  233. me._buildeArchiveDateSelect();
  234. }
  235. },
  236. _buildeArchiveDateSelect: function () {
  237. let me = rptArchiveObj;
  238. let targetDom = document.getElementById("currentDrpArchiveSelect");
  239. targetDom.innerHTML = me.currentArchiveDateStr;
  240. let drpDom = $("#drpArchiveSelect");
  241. drpDom.empty();
  242. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  243. for (let aItem of ARCHIVE_LIST) {
  244. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  245. for (let [index,item] of aItem.items.entries()) {
  246. if (item.uuid !== me.currentArchiveUuid) {
  247. const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + '#' + (index+1) + ' ' + item.updateDate_time + '</a>';
  248. drpDom.append(str);
  249. }
  250. }
  251. }
  252. }
  253. }
  254. },
  255. _updateSignHtmlAndFrame: function (needFrame = false) {
  256. const me = rptArchiveObj;
  257. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  258. for (let i = 0; i < $('#role-list div').length; i++) {
  259. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  260. $('#role-list div').eq(i).find('input').attr('disabled', true);
  261. } else {
  262. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  263. }
  264. $('#role-list div').eq(i).find('input').prop('checked', false);
  265. }
  266. let uhtml = '';
  267. let pagetr = '';
  268. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  269. if (!msgSign) {
  270. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  271. }
  272. for (const us of uSignLogList) {
  273. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  274. }
  275. for (let i = 1; i <= msgSign.total_page; i++) {
  276. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  277. }
  278. $('#page-list').html(pagetr);
  279. if (needFrame) {
  280. 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();
  281. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') + '" height="750px" width="100%" style="border: none;"></iframe>');
  282. }
  283. $('#dateStr').html(me.currentArchiveDateStr);
  284. $('#sign_num').text(uSignLogList.length);
  285. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  286. // 是否显示撤销按钮
  287. if(uHadSign && uHadSign.length > 0) {
  288. $('#show-removesign-modal-btn').show();
  289. } else {
  290. $('#show-removesign-modal-btn').hide();
  291. }
  292. },
  293. _countChkedRptTpl: function () {
  294. let me = rptArchiveObj;
  295. if (me.treeObj) {
  296. me.checkedRptTplNodes = [];
  297. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  298. for (let node of chkNodes) {
  299. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  300. cnt++;
  301. me.checkedRptTplNodes.push(node);
  302. if (me.currentNode === node) hasCurrentNode = true;
  303. }
  304. }
  305. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  306. //这里根据实际需求再做处理
  307. cnt++;
  308. me.checkedRptTplNodes.push(me.currentNode);
  309. }
  310. $("#print_div").find("span").each(function(cIdx,elementSpan){
  311. elementSpan.innerText = cnt;
  312. });
  313. $("#export_div").find("span").each(function(cIdx,elementSpan){
  314. elementSpan.innerText = cnt;
  315. });
  316. }
  317. },
  318. _iniArchiveItemForDeleteShow: function() {
  319. let me = rptArchiveObj;
  320. const dispArchInfoBody = $('#disp_archive_info_body');
  321. dispArchInfoBody.empty();
  322. let targetDom = document.getElementById("currentDrpArchiveSelect");
  323. let firstStr = `<h6>确认删除本张【${targetDom.innerText}】归档报表?</h6>`;
  324. let secondStr = `<h6>删除后,数据无法恢复,请谨慎操作。</h6>`;
  325. dispArchInfoBody.append(firstStr);
  326. dispArchInfoBody.append(secondStr);
  327. },
  328. showArchivedItem: function(currentNode) {
  329. //初始化当前报表已经归档的信息
  330. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  331. if (currentNode) {
  332. //1. cardArchiveInfo
  333. let cardArchiveInfo = $('#cardArchiveInfo');
  334. cardArchiveInfo.empty();
  335. let auditDate = null;
  336. let achivedAmt = 0;
  337. let achivedItem = null;
  338. for (let item of ARCHIVE_LIST) {
  339. if (parseInt(item.rpt_id) === currentNode.refId) {
  340. if (LAST_AUDITOR.end_time) {
  341. auditDate = new Date(LAST_AUDITOR.end_time);
  342. } else {
  343. auditDate = new Date(LAST_AUDITOR.begin_time);
  344. }
  345. achivedAmt = item.items?item.items.length:0;
  346. achivedItem = item;
  347. break;
  348. }
  349. }
  350. if (auditDate) {
  351. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  352. } else {
  353. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  354. }
  355. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  356. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  357. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  358. }
  359. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  360. if (achivedAmt > 0) {
  361. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  362. cardArchiveInfo.append('<div class="form-check">');
  363. // if (achivedAmt === 3) {
  364. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  365. // }
  366. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  367. // let ad = new Date(achivedItem.items[idx].update_time);
  368. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  369. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  370. cardArchiveInfo.append('</label>');
  371. cardArchiveInfo.append('</div>');
  372. }
  373. }
  374. cardArchiveInfo.append('</div>');
  375. //2. selectionArchiveInfo
  376. let selectionArchiveInfo = $('#selectionArchiveInfo');
  377. selectionArchiveInfo.empty();
  378. if (achivedAmt > 0) {
  379. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  380. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  381. }
  382. }
  383. }
  384. },
  385. _getCurrentArchives: function (currentNode) {
  386. let rst = null;
  387. if (ARCHIVE_LIST.length > 0 && currentNode) {
  388. for (let aItem of ARCHIVE_LIST) {
  389. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  390. rst = aItem;
  391. break;
  392. }
  393. }
  394. }
  395. return rst;
  396. },
  397. _chkIfFullArchives: function(currentNode) {
  398. let aItem = this._getCurrentArchives(currentNode);
  399. let rst = (aItem && aItem.items && aItem.items.length === 3);
  400. return rst;
  401. },
  402. _getPageSignatureInfo: function(pageData, rpt_id) {
  403. let psInfo = [], psInfoStr = [];
  404. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  405. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  406. const _getProperSignatureArea = function(cell, control) {
  407. // 约定默认长宽比例是2:1,图片分辨率是600*300
  408. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  409. if (cell && cell[JV.PROP_AREA]) {
  410. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  411. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  412. if (width > height * 2) {
  413. width = height * 2;
  414. } else {
  415. height = width / 2;
  416. }
  417. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  418. case 'left':
  419. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  420. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  421. rst[2] = rst[0] + width;
  422. rst[3] = rst[1] + height;
  423. break;
  424. case 'right':
  425. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  426. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  427. rst[0] = rst[2] - width;
  428. rst[1] = rst[3] - height;
  429. break;
  430. default:
  431. //center
  432. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  433. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  434. rst[2] = rst[0] + width;
  435. rst[3] = rst[1] + height;
  436. break;
  437. }
  438. }
  439. rst[0] = rst[0] + offsetX;
  440. rst[2] = rst[2] + offsetX;
  441. rst[1] = rst[1] + offsetY;
  442. rst[3] = rst[3] + offsetY;
  443. return rst;
  444. }
  445. for(let i = 0; i < pageData.items.length; i++) {
  446. let page = pageData.items[i];
  447. for (let sCell of page.signature_cells) {
  448. // sCell.signature_name 草图不用加密
  449. if (sCell.signature_name !== 'dummy_pic') {
  450. let control = null;
  451. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  452. control = controls[sCell[JV.PROP_CONTROL]];
  453. } else {
  454. control = sCell[JV.PROP_CONTROL];
  455. }
  456. let idx = psInfoStr.indexOf(sCell.signature_name);
  457. let actSignArea = _getProperSignatureArea(sCell, control);
  458. if (idx < 0) {
  459. psInfoStr.push(sCell.signature_name);
  460. let newPsInfo = {'name': sCell.signature_name, areas: []};
  461. let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []};
  462. area.pages.push(i + 1);
  463. newPsInfo.areas.push(area);
  464. psInfo.push(newPsInfo);
  465. } else {
  466. let hasArea = false;
  467. for (let areaItem of psInfo[idx].areas) {
  468. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  469. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  470. areaItem.pages.push(i + 1);
  471. hasArea = true;
  472. break;
  473. }
  474. }
  475. if (!hasArea) {
  476. let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []};
  477. area.pages.push(i + 1);
  478. psInfo[idx].areas.push(area);
  479. }
  480. }
  481. }
  482. }
  483. }
  484. return psInfo;
  485. },
  486. archiveCurrentReport: function (currentRptPageRst, currentNode, cb) {
  487. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  488. // 1. 找草图路径
  489. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  490. // 每页
  491. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  492. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  493. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  494. if (sCell.signature_name === 'dummy_pic') {
  495. //1. 草图就不考虑重复问题,重复就重复吧;
  496. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  497. let picIdx = picKeys.indexOf(sCell.path);
  498. if (picIdx < 0) {
  499. picKeys.push(sCell.path);
  500. picCells.push(sCell);
  501. } else {
  502. let dPicIdx = dupPicPath.indexOf(sCell.path);
  503. if (dPicIdx < 0) {
  504. dupPicPath.push(sCell.path);
  505. dupPicCell.push([]);
  506. dPicIdx = dupPicPath.length - 1;
  507. }
  508. dupPicCell[dPicIdx].push(sCell);
  509. }
  510. }
  511. }
  512. }
  513. // 2. 下载草图,下载完毕后upload
  514. if (picCells.length > 0) {
  515. $.bootstrapLoading.start();
  516. let picAmt = picCells.length, picCnt = 0;
  517. let exceptionAmt = 0;
  518. for (let idx = 0; idx < picCells.length; idx++) {
  519. let dCell = picCells[idx];
  520. getBlob(picKeys[idx]).then(blob => {
  521. if (blob === 'not found!') {
  522. exceptionAmt++;
  523. if ((picCnt + exceptionAmt) === picAmt) {
  524. $.bootstrapLoading.end();
  525. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  526. }
  527. } else {
  528. let oFileReader = new FileReader();
  529. oFileReader.onloadend = function (e) {
  530. picCnt++;
  531. let base64 = e.target.result;
  532. picCells[idx].pic = base64;
  533. let pPathIdx = dupPicPath.indexOf(dCell.path);
  534. if (pPathIdx >= 0) {
  535. for (let dupCell of dupPicCell[pPathIdx]) {
  536. dupCell.pic = base64;
  537. }
  538. }
  539. if ((picCnt + exceptionAmt) === picAmt) {
  540. $.bootstrapLoading.end();
  541. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  542. }
  543. };
  544. oFileReader.readAsDataURL(blob);
  545. }
  546. });
  547. }
  548. } else {
  549. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  550. }
  551. },
  552. _archiveCurrentReport: function(currentRptPageRst, currentNode, cb) {
  553. // 归档当前报表
  554. if (currentRptPageRst !== null) {
  555. try {
  556. let signCells = [];
  557. if (PAGE_SHOW.isTextSignature) {
  558. // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
  559. // 批量归档的数据后台会处理(已经移除相关签名)
  560. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  561. const dtlSignCells = [];
  562. signCells.push(dtlSignCells);
  563. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  564. let sCell = pageItem.signature_cells[sCellIdx];
  565. if (sCell.signature_name !== 'dummy_pic') {
  566. dtlSignCells.push(sCell);
  567. pageItem.signature_cells.splice(sCellIdx, 1);
  568. }
  569. }
  570. });
  571. }
  572. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  573. if (PAGE_SHOW.isTextSignature) {
  574. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  575. signCells[pageIdx].forEach((signCell) => {
  576. pageItem.signature_cells.push(signCell);
  577. });
  578. signCells[pageIdx] = null;
  579. });
  580. signCells = null;
  581. }
  582. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, currentNode.refId);
  583. // console.log(pageEncryptInfo);
  584. let formData = new FormData();
  585. formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
  586. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  587. postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
  588. // 成功后,更新当前页面
  589. if (result.addedRst) {
  590. // console.log(result);
  591. ARCHIVE_LIST = result.addedRst;
  592. rptArchiveObj.showArchivedItem(currentNode);
  593. zTreeOprObj.refreshNodes();
  594. //第二步:增加加密信息
  595. let params = {};
  596. params.prjId = PROJECT_ID;
  597. params.stgId = current_stage_id;
  598. params.rptId = currentNode.refId;
  599. params.ttlPgs = currentRptPageRst.items.length;
  600. params.content = pageEncryptInfo;
  601. params.uuid = result.uuid; //正确返回时,带着uuid回来
  602. params.reportName = currentNode.name;
  603. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  604. function(rst){
  605. if (cb) {
  606. cb(null, 'add archive encryption succeed!', params.uuid);
  607. }
  608. }, function(err){
  609. if (cb) {
  610. cb('err', 'add archive encryption err!', params.uuid);
  611. }
  612. }, function(ex){
  613. if (cb) {
  614. cb('err', 'add archive encryption err!', params.uuid);
  615. }
  616. }
  617. );
  618. } else {
  619. // 有冲突,需要删除
  620. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  621. function(result){
  622. if (cb) {
  623. cb('err', 'add archive conflict!', null);
  624. }
  625. }
  626. );
  627. }
  628. }, function (error){
  629. if (cb) {
  630. cb('err', 'add archive err!', null);
  631. }
  632. });
  633. } else {
  634. let aItem = this._getCurrentArchives(currentNode);
  635. if (aItem && aItem.items && aItem.items.length > 0) {
  636. let orgName = aItem.items[0].uuid;
  637. let compStr = aItem.items[0].updateDate_time;
  638. for (let idx = 1; idx < aItem.items.length; idx++) {
  639. if (aItem.items[idx].updateDate_time < compStr) {
  640. compStr = aItem.items[idx].updateDate_time;
  641. orgName = aItem.items[idx].uuid;
  642. }
  643. }
  644. postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  645. // 成功后,更新当前页面
  646. if (result.updatedRst) {
  647. // console.log(result);
  648. ARCHIVE_LIST = result.updatedRst;
  649. rptArchiveObj.showArchivedItem(currentNode);
  650. zTreeOprObj.refreshNodes();
  651. //第二步:更新加密信息
  652. let params = {};
  653. params.prjId = PROJECT_ID;
  654. params.stgId = current_stage_id;
  655. params.rptId = currentNode.refId;
  656. params.ttlPgs = currentRptPageRst.items.length;
  657. params.content = pageEncryptInfo;
  658. params.uuid = orgName;
  659. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  660. function(result){
  661. if (cb) {
  662. cb(null, 'update archive succeed!', params.uuid);
  663. }
  664. }, function(err){
  665. if (cb) {
  666. cb('err', 'update archive err!', params.uuid);
  667. }
  668. }, function(ex){
  669. if (cb) {
  670. cb('err', 'update archive err!', params.uuid);
  671. }
  672. }
  673. );
  674. } else {
  675. // 有冲突,需要删除
  676. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  677. function(result){
  678. if (cb) {
  679. cb('err', 'update archive conflict!', null);
  680. }
  681. }
  682. );
  683. }
  684. }, function (error){
  685. // alert(error);
  686. if (cb) {
  687. cb('err', 'update archive conflict!', null);
  688. }
  689. });
  690. }
  691. }
  692. } catch (ex) {
  693. console.log(ex);
  694. console.log(ex.toString());
  695. if (cb) {
  696. cb('err', 'has exception!', null);
  697. }
  698. }
  699. } else {
  700. alert('请选择打开一个报表!');
  701. }
  702. },
  703. _getOneValidLeafNode: function(node) {
  704. let rst = null;
  705. let me = rptArchiveObj;
  706. if (node) {
  707. const preNode = node.getPreNode();
  708. if (preNode) {
  709. rst = preNode;
  710. } else {
  711. const nodes = me.treeObj.getNodes();
  712. for (let dtlNode of nodes) {
  713. if (dtlNode !== node && dtlNode.nodeType === 2) {
  714. rst = dtlNode;
  715. break;
  716. }
  717. }
  718. }
  719. }
  720. return rst;
  721. },
  722. removeArchive: function() {
  723. let me = rptArchiveObj;
  724. const bkRefId = parseInt(me.currentNode.refId);
  725. const bkUuid = me.currentArchiveUuid;
  726. if (me.currentNode && me.currentArchiveUuid) {
  727. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  728. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  729. function(result){
  730. // console.log(result.data);
  731. let hasRemovedAll = false;
  732. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  733. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  734. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  735. if (ARCHIVE_LIST[idx].items[dtIdx].uuid = bkUuid) {
  736. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  737. break;
  738. }
  739. }
  740. if (ARCHIVE_LIST[idx].items.length === 0) {
  741. ARCHIVE_LIST.splice(idx, 0);
  742. hasRemovedAll = true;
  743. break;
  744. }
  745. }
  746. }
  747. //要刷新当前归档
  748. if (hasRemovedAll) {
  749. const validNode = me._getOneValidLeafNode(me.currentNode);
  750. // me.iniPage();
  751. me.treeObj.removeNode(me.currentNode);
  752. if (validNode) {
  753. me.currentNode = validNode;
  754. me.onClick(null, null, me.currentNode);
  755. me.treeObj.selectNode(me.currentNode, false);
  756. me._iniArchiveItemForDeleteShow();
  757. }
  758. } else {
  759. me.currentArchiveUuid = null;
  760. me.currentArchiveDateStr = null;
  761. me.currentArchivePdfPath = null;
  762. me.onClick(null, null, me.currentNode);
  763. }
  764. }
  765. );
  766. }
  767. }
  768. };
  769. /**
  770. * 获取 blob
  771. * @param {String} url 目标文件地址
  772. * @return {Promise}
  773. */
  774. function getBlob(url) {
  775. return new Promise(resolve => {
  776. const xhr = new XMLHttpRequest();
  777. xhr.open('GET', url, true);
  778. xhr.responseType = 'blob';
  779. xhr.onload = () => {
  780. if (xhr.status === 200) {
  781. resolve(xhr.response);
  782. } else {
  783. resolve('not found!');
  784. }
  785. };
  786. xhr.send();
  787. });
  788. }
  789. /**
  790. * pdf base64 转 blob
  791. * @param {String} dataUrl base64码
  792. * @return {Promise}
  793. */
  794. function convertBase64UrlToBlob(dataUrl) {
  795. //去掉url的头,并转换为byte
  796. var bytes = window.atob(dataUrl);
  797. //处理异常,将ascii码小于0的转换为大于0
  798. var ab = new Uint8Array(bytes.length);
  799. for (var i = 0; i < bytes.length; i++) {
  800. ab[i] = bytes.charCodeAt(i);
  801. }
  802. return new Blob([ab], { type: 'application/pdf' });
  803. }
  804. /**
  805. * 保存
  806. * @param {Blob} blob
  807. * @param {String} filename 想要保存的文件名称
  808. */
  809. function saveAs(blob, filename) {
  810. if (window.navigator.msSaveOrOpenBlob) {
  811. navigator.msSaveBlob(blob, filename);
  812. } else {
  813. const link = document.createElement('a');
  814. const body = document.querySelector('body');
  815. link.href = window.URL.createObjectURL(blob);
  816. link.download = filename;
  817. // fix Firefox
  818. link.style.display = 'none';
  819. body.appendChild(link);
  820. link.click();
  821. body.removeChild(link);
  822. window.URL.revokeObjectURL(link.href);
  823. }
  824. }
  825. /**
  826. * 下载
  827. * @param {String} url 目标文件地址
  828. * @param {String} filename 想要保存的文件名称
  829. */
  830. function download(url, filename) {
  831. getBlob(url).then(blob => {
  832. saveAs(blob, filename);
  833. });
  834. }
  835. $(function () {
  836. $('#download_file').click(function () {
  837. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  838. console.log(rptArchiveObj.currentArchivePdfPath);
  839. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  840. } else {
  841. alert('请选择打开一个报表!');
  842. }
  843. });
  844. $('#print_file').click(function () {
  845. if (rptArchiveObj.currentArchiveUuid) {
  846. $('#iframe_made iframe')[0].contentWindow.print();
  847. } else {
  848. alert('请选择打开一个报表!');
  849. }
  850. });
  851. $('#delete_file').click(function () {
  852. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  853. console.log(rptArchiveObj.currentArchivePdfPath);
  854. rptArchiveObj.removeArchive();
  855. } else {
  856. alert('请选择打开一个报表!');
  857. }
  858. });
  859. })