rpt_archive.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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. me._iniArchiveItemForDeleteShow();
  231. } else {
  232. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  233. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  234. me._buildeArchiveDateSelect();
  235. me._iniArchiveItemForDeleteShow();
  236. }
  237. },
  238. _buildeArchiveDateSelect: function () {
  239. let me = rptArchiveObj;
  240. let targetDom = document.getElementById("currentDrpArchiveSelect");
  241. targetDom.innerHTML = me.currentArchiveDateStr;
  242. let drpDom = $("#drpArchiveSelect");
  243. drpDom.empty();
  244. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  245. for (let aItem of ARCHIVE_LIST) {
  246. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  247. for (let [index,item] of aItem.items.entries()) {
  248. if (item.uuid !== me.currentArchiveUuid) {
  249. const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + '#' + (index+1) + ' ' + item.updateDate_time + '</a>';
  250. drpDom.append(str);
  251. }
  252. }
  253. }
  254. }
  255. }
  256. },
  257. _updateSignHtmlAndFrame: function (needFrame = false) {
  258. const me = rptArchiveObj;
  259. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  260. for (let i = 0; i < $('#role-list div').length; i++) {
  261. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  262. $('#role-list div').eq(i).find('input').attr('disabled', true);
  263. } else {
  264. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  265. }
  266. $('#role-list div').eq(i).find('input').prop('checked', false);
  267. }
  268. let uhtml = '';
  269. let pagetr = '';
  270. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  271. if (!msgSign) {
  272. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  273. }
  274. for (const us of uSignLogList) {
  275. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  276. }
  277. for (let i = 1; i <= msgSign.total_page; i++) {
  278. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  279. }
  280. $('#page-list').html(pagetr);
  281. if (needFrame) {
  282. 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();
  283. $('#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>');
  284. }
  285. $('#dateStr').html(me.currentArchiveDateStr);
  286. $('#sign_num').text(uSignLogList.length);
  287. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  288. // 是否显示撤销按钮
  289. if(uHadSign && uHadSign.length > 0) {
  290. $('#show-removesign-modal-btn').show();
  291. } else {
  292. $('#show-removesign-modal-btn').hide();
  293. }
  294. },
  295. _countChkedRptTpl: function () {
  296. let me = rptArchiveObj;
  297. $('#delete_archive_btn').attr('disabled', '');
  298. if (me.treeObj) {
  299. me.checkedRptTplNodes = [];
  300. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  301. for (let node of chkNodes) {
  302. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  303. cnt++;
  304. me.checkedRptTplNodes.push(node);
  305. if (me.currentNode === node) hasCurrentNode = true;
  306. }
  307. }
  308. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  309. //这里根据实际需求再做处理
  310. cnt++;
  311. me.checkedRptTplNodes.push(me.currentNode);
  312. }
  313. $("#print_div").find("span").each(function(cIdx,elementSpan){
  314. elementSpan.innerText = cnt;
  315. });
  316. $("#export_div").find("span").each(function(cIdx,elementSpan){
  317. elementSpan.innerText = cnt;
  318. });
  319. if (cnt) {
  320. $('#delete_archive_btn').removeAttr('disabled');
  321. }
  322. }
  323. },
  324. _iniArchiveItemForDeleteShow: function() {
  325. let me = rptArchiveObj;
  326. const dispArchInfoBody = $('#disp_archive_info_body');
  327. dispArchInfoBody.empty();
  328. let targetDom = document.getElementById("currentDrpArchiveSelect");
  329. let firstStr = `<h6>确认删除本张【${targetDom.innerText}】归档报表?</h6>`;
  330. let secondStr = `<h6>删除后,数据无法恢复,请谨慎操作。</h6>`;
  331. dispArchInfoBody.append(firstStr);
  332. dispArchInfoBody.append(secondStr);
  333. },
  334. showArchivedItem: function(currentNode) {
  335. //初始化当前报表已经归档的信息
  336. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  337. if (currentNode) {
  338. //1. cardArchiveInfo
  339. let cardArchiveInfo = $('#cardArchiveInfo');
  340. cardArchiveInfo.empty();
  341. let auditDate = null;
  342. let achivedAmt = 0;
  343. let achivedItem = null;
  344. for (let item of ARCHIVE_LIST) {
  345. if (parseInt(item.rpt_id) === currentNode.refId) {
  346. if (LAST_AUDITOR.end_time) {
  347. auditDate = new Date(LAST_AUDITOR.end_time);
  348. } else {
  349. auditDate = new Date(LAST_AUDITOR.begin_time);
  350. }
  351. achivedAmt = item.items?item.items.length:0;
  352. achivedItem = item;
  353. break;
  354. }
  355. }
  356. if (auditDate) {
  357. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  358. } else {
  359. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  360. }
  361. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  362. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  363. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  364. }
  365. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  366. if (achivedAmt > 0) {
  367. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  368. cardArchiveInfo.append('<div class="form-check">');
  369. // if (achivedAmt === 3) {
  370. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  371. // }
  372. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  373. // let ad = new Date(achivedItem.items[idx].update_time);
  374. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  375. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  376. cardArchiveInfo.append('</label>');
  377. cardArchiveInfo.append('</div>');
  378. }
  379. }
  380. cardArchiveInfo.append('</div>');
  381. //2. selectionArchiveInfo
  382. let selectionArchiveInfo = $('#selectionArchiveInfo');
  383. selectionArchiveInfo.empty();
  384. if (achivedAmt > 0) {
  385. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  386. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  387. }
  388. }
  389. }
  390. },
  391. _getCurrentArchives: function (currentNode) {
  392. let rst = null;
  393. if (ARCHIVE_LIST.length > 0 && currentNode) {
  394. for (let aItem of ARCHIVE_LIST) {
  395. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  396. rst = aItem;
  397. break;
  398. }
  399. }
  400. }
  401. return rst;
  402. },
  403. _chkIfFullArchives: function(currentNode) {
  404. let aItem = this._getCurrentArchives(currentNode);
  405. let rst = (aItem && aItem.items && aItem.items.length === 3);
  406. return rst;
  407. },
  408. _getPageSignatureInfo: function(pageData, rpt_id) {
  409. let psInfo = [], psInfoStr = [];
  410. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  411. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  412. const _getProperSignatureArea = function(cell, control) {
  413. // 约定默认长宽比例是2:1,图片分辨率是600*300
  414. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  415. if (cell && cell[JV.PROP_AREA]) {
  416. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  417. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  418. if (width > height * 2) {
  419. width = height * 2;
  420. } else {
  421. height = width / 2;
  422. }
  423. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  424. case 'left':
  425. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  426. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  427. rst[2] = rst[0] + width;
  428. rst[3] = rst[1] + height;
  429. break;
  430. case 'right':
  431. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  432. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  433. rst[0] = rst[2] - width;
  434. rst[1] = rst[3] - height;
  435. break;
  436. default:
  437. //center
  438. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  439. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  440. rst[2] = rst[0] + width;
  441. rst[3] = rst[1] + height;
  442. break;
  443. }
  444. }
  445. rst[0] = rst[0] + offsetX;
  446. rst[2] = rst[2] + offsetX;
  447. rst[1] = rst[1] + offsetY;
  448. rst[3] = rst[3] + offsetY;
  449. return rst;
  450. }
  451. for(let i = 0; i < pageData.items.length; i++) {
  452. let page = pageData.items[i];
  453. for (let sCell of page.signature_cells) {
  454. // sCell.signature_name 草图不用加密
  455. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  456. // if (sCell.signature_name !== 'dummy_pic') {
  457. let control = null;
  458. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  459. control = controls[sCell[JV.PROP_CONTROL]];
  460. } else {
  461. control = sCell[JV.PROP_CONTROL];
  462. }
  463. let idx = psInfoStr.indexOf(sCell.signature_name);
  464. let actSignArea = _getProperSignatureArea(sCell, control);
  465. if (idx < 0) {
  466. psInfoStr.push(sCell.signature_name);
  467. let newPsInfo = {'name': sCell.signature_name, areas: []};
  468. 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: []};
  469. area.pages.push(i + 1);
  470. newPsInfo.areas.push(area);
  471. psInfo.push(newPsInfo);
  472. } else {
  473. let hasArea = false;
  474. for (let areaItem of psInfo[idx].areas) {
  475. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  476. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  477. areaItem.pages.push(i + 1);
  478. hasArea = true;
  479. break;
  480. }
  481. }
  482. if (!hasArea) {
  483. 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: []};
  484. area.pages.push(i + 1);
  485. psInfo[idx].areas.push(area);
  486. }
  487. }
  488. }
  489. }
  490. }
  491. return psInfo;
  492. },
  493. archiveCurrentReport: function (currentRptPageRst, currentNode, cb) {
  494. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  495. // 1. 找草图路径
  496. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  497. // 每页
  498. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  499. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  500. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  501. if (sCell.signature_name.indexOf('dummy_pic') >= 0) {
  502. // if (sCell.signature_name === 'dummy_pic') {
  503. //1. 草图就不考虑重复问题,重复就重复吧;
  504. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  505. let picIdx = picKeys.indexOf(sCell.path);
  506. if (picIdx < 0) {
  507. picKeys.push(sCell.path);
  508. picCells.push(sCell);
  509. } else {
  510. let dPicIdx = dupPicPath.indexOf(sCell.path);
  511. if (dPicIdx < 0) {
  512. dupPicPath.push(sCell.path);
  513. dupPicCell.push([]);
  514. dPicIdx = dupPicPath.length - 1;
  515. }
  516. dupPicCell[dPicIdx].push(sCell);
  517. }
  518. }
  519. }
  520. }
  521. // 2. 下载草图,下载完毕后upload
  522. if (picCells.length > 0) {
  523. $.bootstrapLoading.start();
  524. let picAmt = picCells.length, picCnt = 0;
  525. let exceptionAmt = 0;
  526. for (let idx = 0; idx < picCells.length; idx++) {
  527. let dCell = picCells[idx];
  528. getBlob(picKeys[idx]).then(blob => {
  529. if (blob === 'not found!') {
  530. exceptionAmt++;
  531. if ((picCnt + exceptionAmt) === picAmt) {
  532. $.bootstrapLoading.end();
  533. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  534. }
  535. } else {
  536. let oFileReader = new FileReader();
  537. oFileReader.onloadend = function (e) {
  538. picCnt++;
  539. let base64 = e.target.result;
  540. picCells[idx].pic = base64;
  541. let pPathIdx = dupPicPath.indexOf(dCell.path);
  542. if (pPathIdx >= 0) {
  543. for (let dupCell of dupPicCell[pPathIdx]) {
  544. dupCell.pic = base64;
  545. }
  546. }
  547. if ((picCnt + exceptionAmt) === picAmt) {
  548. $.bootstrapLoading.end();
  549. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  550. }
  551. };
  552. oFileReader.readAsDataURL(blob);
  553. }
  554. });
  555. }
  556. } else {
  557. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  558. }
  559. },
  560. _archiveCurrentReport: function(currentRptPageRst, currentNode, cb) {
  561. // 归档当前报表
  562. if (currentRptPageRst !== null) {
  563. try {
  564. let signCells = [];
  565. if (PAGE_SHOW.isTextSignature) {
  566. // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
  567. // 批量归档的数据后台会处理(已经移除相关签名)
  568. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  569. const dtlSignCells = [];
  570. signCells.push(dtlSignCells);
  571. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  572. let sCell = pageItem.signature_cells[sCellIdx];
  573. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  574. // if (sCell.signature_name !== 'dummy_pic') {
  575. dtlSignCells.push(sCell);
  576. pageItem.signature_cells.splice(sCellIdx, 1);
  577. }
  578. }
  579. });
  580. }
  581. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  582. if (PAGE_SHOW.isTextSignature) {
  583. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  584. signCells[pageIdx].forEach((signCell) => {
  585. pageItem.signature_cells.push(signCell);
  586. });
  587. signCells[pageIdx] = null;
  588. });
  589. signCells = null;
  590. }
  591. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, currentNode.refId);
  592. // console.log(pageEncryptInfo);
  593. let formData = new FormData();
  594. formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
  595. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  596. postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
  597. // 成功后,更新当前页面
  598. if (result.addedRst) {
  599. // console.log(result);
  600. ARCHIVE_LIST = result.addedRst;
  601. rptArchiveObj.showArchivedItem(currentNode);
  602. zTreeOprObj.refreshNodes();
  603. //第二步:增加加密信息
  604. let params = {};
  605. params.prjId = PROJECT_ID;
  606. params.stgId = current_stage_id;
  607. params.rptId = currentNode.refId;
  608. params.ttlPgs = currentRptPageRst.items.length;
  609. params.content = pageEncryptInfo;
  610. params.uuid = result.uuid; //正确返回时,带着uuid回来
  611. params.reportName = currentNode.name;
  612. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  613. function(rst){
  614. if (cb) {
  615. cb(null, 'add archive encryption succeed!', params.uuid);
  616. }
  617. }, function(err){
  618. if (cb) {
  619. cb('err', 'add archive encryption err!', params.uuid);
  620. }
  621. }, function(ex){
  622. if (cb) {
  623. cb('err', 'add archive encryption err!', params.uuid);
  624. }
  625. }
  626. );
  627. } else {
  628. // 有冲突,需要删除
  629. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  630. function(result){
  631. if (cb) {
  632. cb('err', 'add archive conflict!', null);
  633. }
  634. }
  635. );
  636. }
  637. }, function (error){
  638. if (cb) {
  639. cb('err', 'add archive err!', null);
  640. }
  641. });
  642. } else {
  643. let aItem = this._getCurrentArchives(currentNode);
  644. if (aItem && aItem.items && aItem.items.length > 0) {
  645. let orgName = aItem.items[0].uuid;
  646. let compStr = aItem.items[0].updateDate_time;
  647. for (let idx = 1; idx < aItem.items.length; idx++) {
  648. if (aItem.items[idx].updateDate_time < compStr) {
  649. compStr = aItem.items[idx].updateDate_time;
  650. orgName = aItem.items[idx].uuid;
  651. }
  652. }
  653. postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  654. // 成功后,更新当前页面
  655. if (result.updatedRst) {
  656. // console.log(result);
  657. ARCHIVE_LIST = result.updatedRst;
  658. rptArchiveObj.showArchivedItem(currentNode);
  659. zTreeOprObj.refreshNodes();
  660. //第二步:更新加密信息
  661. let params = {};
  662. params.prjId = PROJECT_ID;
  663. params.stgId = current_stage_id;
  664. params.rptId = currentNode.refId;
  665. params.ttlPgs = currentRptPageRst.items.length;
  666. params.content = pageEncryptInfo;
  667. params.uuid = orgName;
  668. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  669. function(result){
  670. if (cb) {
  671. cb(null, 'update archive succeed!', params.uuid);
  672. }
  673. }, function(err){
  674. if (cb) {
  675. cb('err', 'update archive err!', params.uuid);
  676. }
  677. }, function(ex){
  678. if (cb) {
  679. cb('err', 'update archive err!', params.uuid);
  680. }
  681. }
  682. );
  683. } else {
  684. // 有冲突,需要删除
  685. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  686. function(result){
  687. if (cb) {
  688. cb('err', 'update archive conflict!', null);
  689. }
  690. }
  691. );
  692. }
  693. }, function (error){
  694. // alert(error);
  695. if (cb) {
  696. cb('err', 'update archive conflict!', null);
  697. }
  698. });
  699. }
  700. }
  701. } catch (ex) {
  702. console.log(ex);
  703. console.log(ex.toString());
  704. if (cb) {
  705. cb('err', 'has exception!', null);
  706. }
  707. }
  708. } else {
  709. alert('请选择打开一个报表!');
  710. }
  711. },
  712. _getOneValidLeafNode: function(node) {
  713. let rst = null;
  714. let me = rptArchiveObj;
  715. if (node) {
  716. const preNode = node.getPreNode();
  717. if (preNode) {
  718. rst = preNode;
  719. } else {
  720. const nodes = me.treeObj.getNodes();
  721. for (let dtlNode of nodes) {
  722. if (dtlNode !== node && dtlNode.nodeType === 2) {
  723. rst = dtlNode;
  724. break;
  725. }
  726. }
  727. }
  728. }
  729. return rst;
  730. },
  731. removeArchive: function() {
  732. let me = rptArchiveObj;
  733. const bkRefId = parseInt(me.currentNode.refId);
  734. const bkUuid = me.currentArchiveUuid;
  735. if (me.currentNode && me.currentArchiveUuid) {
  736. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  737. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  738. function(result){
  739. // console.log(result.data);
  740. let hasRemovedAll = false;
  741. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  742. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  743. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  744. if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
  745. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  746. break;
  747. }
  748. }
  749. if (ARCHIVE_LIST[idx].items.length === 0) {
  750. ARCHIVE_LIST.splice(idx, 0);
  751. hasRemovedAll = true;
  752. break;
  753. }
  754. }
  755. }
  756. //要刷新当前归档
  757. if (hasRemovedAll) {
  758. const validNode = me._getOneValidLeafNode(me.currentNode);
  759. // me.iniPage();
  760. me.treeObj.removeNode(me.currentNode);
  761. if (validNode) {
  762. me.currentNode = validNode;
  763. me.onClick(null, null, me.currentNode);
  764. me.treeObj.selectNode(me.currentNode, false);
  765. me._iniArchiveItemForDeleteShow();
  766. }
  767. } else {
  768. me.currentArchiveUuid = null;
  769. me.currentArchiveDateStr = null;
  770. me.currentArchivePdfPath = null;
  771. me.onClick(null, null, me.currentNode);
  772. }
  773. }
  774. );
  775. }
  776. }
  777. };
  778. /**
  779. * 获取 blob
  780. * @param {String} url 目标文件地址
  781. * @return {Promise}
  782. */
  783. function getBlob(url) {
  784. return new Promise(resolve => {
  785. const xhr = new XMLHttpRequest();
  786. // let fullUrl = url + '?x-oss-process=image/info';
  787. xhr.open('GET', url, true);
  788. xhr.responseType = 'blob';
  789. xhr.onload = () => {
  790. if (xhr.status === 200) {
  791. resolve(xhr.response);
  792. } else {
  793. resolve('not found!');
  794. }
  795. };
  796. xhr.send();
  797. });
  798. }
  799. /**
  800. * pdf base64 转 blob
  801. * @param {String} dataUrl base64码
  802. * @return {Promise}
  803. */
  804. function convertBase64UrlToBlob(dataUrl) {
  805. //去掉url的头,并转换为byte
  806. var bytes = window.atob(dataUrl);
  807. //处理异常,将ascii码小于0的转换为大于0
  808. var ab = new Uint8Array(bytes.length);
  809. for (var i = 0; i < bytes.length; i++) {
  810. ab[i] = bytes.charCodeAt(i);
  811. }
  812. return new Blob([ab], { type: 'application/pdf' });
  813. }
  814. /**
  815. * 保存
  816. * @param {Blob} blob
  817. * @param {String} filename 想要保存的文件名称
  818. */
  819. function saveAs(blob, filename) {
  820. if (window.navigator.msSaveOrOpenBlob) {
  821. navigator.msSaveBlob(blob, filename);
  822. } else {
  823. const link = document.createElement('a');
  824. const body = document.querySelector('body');
  825. link.href = window.URL.createObjectURL(blob);
  826. link.download = filename;
  827. // fix Firefox
  828. link.style.display = 'none';
  829. body.appendChild(link);
  830. link.click();
  831. body.removeChild(link);
  832. window.URL.revokeObjectURL(link.href);
  833. }
  834. }
  835. /**
  836. * 下载
  837. * @param {String} url 目标文件地址
  838. * @param {String} filename 想要保存的文件名称
  839. */
  840. function download(url, filename) {
  841. getBlob(url).then(blob => {
  842. saveAs(blob, filename);
  843. });
  844. }
  845. $(function () {
  846. $('#download_file').click(function () {
  847. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  848. console.log(rptArchiveObj.currentArchivePdfPath);
  849. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  850. } else {
  851. alert('请选择打开一个报表!');
  852. }
  853. });
  854. $('#print_file').click(function () {
  855. if (rptArchiveObj.currentArchiveUuid) {
  856. $('#iframe_made iframe')[0].contentWindow.print();
  857. } else {
  858. alert('请选择打开一个报表!');
  859. }
  860. });
  861. $('#delete_file').click(function () {
  862. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  863. console.log(rptArchiveObj.currentArchivePdfPath);
  864. rptArchiveObj.removeArchive();
  865. } else {
  866. alert('请选择打开一个报表!');
  867. }
  868. });
  869. })