rpt_archive.js 48 KB

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