rpt_archive.js 14 KB

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