rpt_archive.js 44 KB

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