rpt_archive.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. iniPage: function() {
  10. //初始化页面的归档信息
  11. let me = rptArchiveObj;
  12. me.currentNode = null;
  13. me.currentArchiveUuid = null;
  14. me.currentArchiveDateStr = null;
  15. const archivedRptIds = [];
  16. for (let aItem of ARCHIVE_LIST) {
  17. archivedRptIds.push(parseInt(aItem.rpt_id));
  18. }
  19. let private_remove_hide_item = function (items, nlv) {
  20. if (items && items.length > 0) {
  21. for (let i = items.length - 1; i >= 0; i--) {
  22. if (!(items[i].released) && items[i].nodeType === 2) {
  23. items.splice(i, 1);
  24. } else {
  25. if (items[i].items && items[i].items.length > 0) {
  26. private_remove_hide_item(items[i].items, nlv + 1);
  27. if (items[i].items.length === 0 && nlv > 0) {
  28. items.splice(i, 1);
  29. }
  30. }
  31. }
  32. }
  33. }
  34. };
  35. const private_remove_un_archive_item = function(items, nlv) {
  36. if (items && items.length > 0) {
  37. for (let i = items.length - 1; i >= 0; i--) {
  38. if (items[i].nodeType === 2) {
  39. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  40. items.splice(i, 1);
  41. }
  42. } else {
  43. if (items[i].items && items[i].items.length > 0) {
  44. private_remove_un_archive_item(items[i].items, nlv + 1);
  45. if (items[i].items.length === 0 && nlv > 0) {
  46. items.splice(i, 1);
  47. }
  48. } else {
  49. //items[i]是目录,但又没有items子项,
  50. items.splice(i, 1);
  51. }
  52. }
  53. }
  54. }
  55. };
  56. let nodeLv = 0;
  57. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  58. private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
  59. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
  60. me.treeObj.expandAll(true);
  61. me.refreshNodes();
  62. rptArchiveObj._countChkedRptTpl();
  63. rptArchiveObj._buildeArchiveDateSelect();
  64. },
  65. toggleBtn: function (enabled) {
  66. if (current_stage_status === 3 && enabled) {
  67. $('#btnArchiveRpt').removeAttr('disabled');
  68. $('#btnArchiveList').removeAttr('disabled');
  69. } else {
  70. $('#btnArchiveRpt').attr('disabled', '');
  71. $('#btnArchiveList').attr('disabled', '');
  72. }
  73. },
  74. refreshNodes: function() {
  75. let me = this;
  76. let private_setupIsParent = function(node){
  77. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  78. if (node.items && node.items.length) {
  79. for (let i = 0; i < node.items.length; i++) {
  80. private_setupIsParent(node.items[i]);
  81. }
  82. }
  83. };
  84. let topNodes = me.treeObj.getNodes();
  85. for (let i = 0; i < topNodes.length; i++) {
  86. private_setupIsParent(topNodes[i]);
  87. }
  88. me.treeObj.refresh();
  89. },
  90. onCheck: function(event, treeId, treeNode) {
  91. rptArchiveObj._countChkedRptTpl();
  92. if (treeNode.isParent) {
  93. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  94. }
  95. },
  96. onClick: function(event,treeId,treeNode) {
  97. let me = rptArchiveObj;
  98. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  99. me.currentNode = treeNode;
  100. for (let aItem of ARCHIVE_LIST) {
  101. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  102. me.currentArchiveUuid = null;
  103. me.currentArchiveDateStr = null;
  104. if (aItem.items && aItem.items.length > 0) {
  105. me.currentArchiveUuid = aItem.items[0].uuid;
  106. me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  107. }
  108. break;
  109. }
  110. }
  111. me._countChkedRptTpl();
  112. me._buildeArchiveDateSelect();
  113. me._requestArchiveReport();
  114. }
  115. },
  116. _requestArchiveReport: function () {
  117. let me = rptArchiveObj;
  118. if (me.currentNode && me.currentArchiveUuid) {
  119. try {
  120. let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  121. // window.location = uuIdUrl;
  122. } catch (ex) {
  123. console.log(ex.toString());
  124. }
  125. }
  126. },
  127. _changeArchiveDateSelect: function (dom) {
  128. let me = rptArchiveObj;
  129. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  130. me.currentArchiveDateStr = dom.innerHTML;
  131. me._buildeArchiveDateSelect();
  132. },
  133. _buildeArchiveDateSelect: function () {
  134. let me = rptArchiveObj;
  135. let targetDom = document.getElementById("currentDrpArchiveSelect");
  136. targetDom.innerHTML = me.currentArchiveDateStr;
  137. let drpDom = $("#drpArchiveSelect");
  138. drpDom.empty();
  139. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  140. for (let aItem of ARCHIVE_LIST) {
  141. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  142. for (let item of aItem.items) {
  143. if (item.uuid !== me.currentArchiveUuid) {
  144. const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + item.updateDate_time + '</a>';
  145. drpDom.append(str);
  146. }
  147. }
  148. }
  149. }
  150. }
  151. },
  152. _countChkedRptTpl: function () {
  153. let me = rptArchiveObj;
  154. if (me.treeObj) {
  155. me.checkedRptTplNodes = [];
  156. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  157. for (let node of chkNodes) {
  158. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  159. cnt++;
  160. me.checkedRptTplNodes.push(node);
  161. if (me.currentNode === node) hasCurrentNode = true;
  162. }
  163. }
  164. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  165. //这里根据实际需求再做处理
  166. cnt++;
  167. me.checkedRptTplNodes.push(me.currentNode);
  168. }
  169. $("#print_div").find("span").each(function(cIdx,elementSpan){
  170. elementSpan.innerText = cnt;
  171. });
  172. $("#export_div").find("span").each(function(cIdx,elementSpan){
  173. elementSpan.innerText = cnt;
  174. });
  175. }
  176. },
  177. showArchivedItem: function(currentNode) {
  178. //初始化当前报表已经归档的信息
  179. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  180. if (currentNode) {
  181. //1. cardArchiveInfo
  182. let cardArchiveInfo = $('#cardArchiveInfo');
  183. cardArchiveInfo.empty();
  184. let auditDate = null;
  185. let achivedAmt = 0;
  186. let achivedItem = null;
  187. for (let item of ARCHIVE_LIST) {
  188. if (parseInt(item.rpt_id) === currentNode.refId) {
  189. auditDate = new Date(LAST_AUDITOR.begin_time);
  190. achivedAmt = item.items?item.items.length:0;
  191. achivedItem = item;
  192. break;
  193. }
  194. }
  195. if (auditDate) {
  196. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  197. } else {
  198. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  199. }
  200. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  201. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  202. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  203. }
  204. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  205. if (achivedAmt > 0) {
  206. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  207. cardArchiveInfo.append('<div class="form-check">');
  208. // if (achivedAmt === 3) {
  209. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  210. // }
  211. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  212. // let ad = new Date(achivedItem.items[idx].update_time);
  213. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  214. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  215. cardArchiveInfo.append('</label>');
  216. cardArchiveInfo.append('</div>');
  217. }
  218. }
  219. cardArchiveInfo.append('</div>');
  220. //2. selectionArchiveInfo
  221. let selectionArchiveInfo = $('#selectionArchiveInfo');
  222. selectionArchiveInfo.empty();
  223. if (achivedAmt > 0) {
  224. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  225. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  226. }
  227. }
  228. }
  229. },
  230. _getCurrentArchives: function (currentNode) {
  231. let rst = null;
  232. if (ARCHIVE_LIST.length > 0 && currentNode) {
  233. for (let aItem of ARCHIVE_LIST) {
  234. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  235. rst = aItem;
  236. break;
  237. }
  238. }
  239. }
  240. return rst;
  241. },
  242. _chkIfFullArchives: function(currentNode) {
  243. let aItem = this._getCurrentArchives(currentNode);
  244. let rst = (aItem && aItem.items && aItem.items.length === 3);
  245. return rst;
  246. },
  247. archiveCurrentReport: function(currentRptPageRst, currentNode) {
  248. // 归档当前报表
  249. if (currentRptPageRst !== null) {
  250. try {
  251. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  252. let formData = new FormData();
  253. formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
  254. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  255. postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
  256. // 成功后,更新当前页面
  257. if (result.addedRst) {
  258. // console.log(result);
  259. ARCHIVE_LIST = result.addedRst;
  260. rptArchiveObj.showArchivedItem(currentNode);
  261. } else {
  262. // 有冲突,需要删除
  263. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  264. function(result){
  265. //
  266. }
  267. );
  268. }
  269. }, function (error){
  270. // alert(error);
  271. });
  272. } else {
  273. let aItem = this._getCurrentArchives(currentNode);
  274. if (aItem && aItem.items && aItem.items.length > 0) {
  275. let orgName = aItem.items[0].uuid;
  276. let compStr = aItem.items[0].updateDate_time;
  277. for (let idx = 1; idx < aItem.items.length; idx++) {
  278. if (aItem.items[idx].updateDate_time < compStr) {
  279. compStr = aItem.items[idx].updateDate_time;
  280. orgName = aItem.items[idx].uuid;
  281. }
  282. }
  283. postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  284. // 成功后,更新当前页面
  285. if (result.updatedRst) {
  286. // console.log(result);
  287. ARCHIVE_LIST = result.updatedRst;
  288. rptArchiveObj.showArchivedItem();
  289. } else {
  290. // 有冲突,需要删除
  291. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  292. function(result){
  293. //
  294. }
  295. );
  296. }
  297. }, function (error){
  298. // alert(error);
  299. });
  300. }
  301. }
  302. } catch (ex) {
  303. console.log(ex.toString());
  304. }
  305. } else {
  306. alert('请选择打开一个报表!');
  307. }
  308. }
  309. };
  310. function _dataURLtoFile(dataurl, filename) {
  311. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  312. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  313. while(n--){
  314. u8arr[n] = bstr.charCodeAt(n);
  315. }
  316. return new File([u8arr], filename, {type:mime});
  317. };