rpt_archive.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. },
  69. toggleBtn: function (enabled) {
  70. if (current_stage_status === 3 && enabled) {
  71. $('#btnArchiveRpt').removeAttr('disabled');
  72. $('#btnArchiveList').removeAttr('disabled');
  73. $('#btnBatchArchiveRpt').removeAttr('disabled');
  74. } else {
  75. $('#btnArchiveRpt').attr('disabled', '');
  76. $('#btnArchiveList').attr('disabled', '');
  77. $('#btnBatchArchiveRpt').attr('disabled', '');
  78. }
  79. },
  80. refreshNodes: function() {
  81. let me = this;
  82. let private_setupIsParent = function(node){
  83. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  84. if (node.items && node.items.length) {
  85. for (let i = 0; i < node.items.length; i++) {
  86. private_setupIsParent(node.items[i]);
  87. }
  88. }
  89. };
  90. let topNodes = me.treeObj.getNodes();
  91. for (let i = 0; i < topNodes.length; i++) {
  92. private_setupIsParent(topNodes[i]);
  93. }
  94. me.treeObj.refresh();
  95. },
  96. onCheck: function(event, treeId, treeNode) {
  97. rptArchiveObj._countChkedRptTpl();
  98. if (treeNode.isParent) {
  99. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  100. }
  101. },
  102. onClick: function(event,treeId,treeNode) {
  103. let me = rptArchiveObj;
  104. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  105. me.currentNode = treeNode;
  106. for (let aItem of ARCHIVE_LIST) {
  107. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  108. me.currentArchiveUuid = null;
  109. me.currentArchiveDateStr = null;
  110. me.currentArchivePdfPath = null;
  111. if (aItem.items && aItem.items.length > 0) {
  112. // me.currentArchiveUuid = aItem.items[0].uuid;
  113. // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  114. const newItems = _.orderBy(aItem.items, ['updateDate_time'], ['desc']);
  115. me.currentArchiveUuid = newItems[0].uuid;
  116. me.currentArchiveDateStr = '#' + (_.findIndex(aItem.items, { updateDate_time: newItems[0].updateDate_time})+1) + ' ' + newItems[0].updateDate_time;
  117. if (can_netcasign) {
  118. for (const [i,item] of aItem.items.entries()) {
  119. if (_.find(signLogList, { uuid: item.uuid })) {
  120. me.currentArchiveUuid = item.uuid;
  121. me.currentArchiveDateStr = '#' + (i+1) + ' ' + item.updateDate_time;
  122. break;
  123. }
  124. }
  125. }
  126. }
  127. break;
  128. }
  129. }
  130. me._countChkedRptTpl();
  131. me._buildeArchiveDateSelect();
  132. me._requestArchiveReport();
  133. }
  134. },
  135. batchArchive: function() {
  136. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  137. indexDbOprObj.storeReportRequest(current_stage_id, zTreeOprObj.checkedRptTplNodes, indexDbOprObj.startRequestReport);
  138. }
  139. },
  140. _requestArchiveReport: function () {
  141. let me = rptArchiveObj;
  142. if (me.currentNode && me.currentArchiveUuid) {
  143. try {
  144. if (can_netcasign) {
  145. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  146. if (!msgSign) {
  147. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  148. }
  149. console.log(current_stage_id, msgSign, me.currentArchiveUuid);
  150. me.currentEncryptionList = msgSign;
  151. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  152. let html = '';
  153. let pagetr = '';
  154. if (msgSign) {
  155. const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
  156. for (const [index,role] of msgSign.encryption.entries()) {
  157. const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
  158. html += '<div class="'+ rows +'">\n' +
  159. ' <div class="custom-control custom-radio custom-control-inline">\n' +
  160. ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
  161. ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
  162. ' </div>\n' +
  163. ' </div>';
  164. }
  165. let uhtml = '';
  166. for (const us of uSignLogList) {
  167. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  168. }
  169. for (let i = 1; i <= msgSign.total_page; i++) {
  170. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  171. }
  172. }
  173. $('#dateStr').html(me.currentArchiveDateStr);
  174. $('#role-list').html(html);
  175. $('#page-list').html(pagetr);
  176. $('#sign_num').text(uSignLogList.length);
  177. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  178. // 是否显示撤销按钮
  179. if(uHadSign && uHadSign.length > 0) {
  180. $('#show-removesign-modal-btn').show();
  181. } else {
  182. $('#show-removesign-modal-btn').hide();
  183. }
  184. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  185. 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();
  186. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  187. }, function () {
  188. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  189. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  190. })
  191. } else {
  192. me.currentArchivePdfPath = 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. console.log(me.currentArchivePdfPath);
  195. }
  196. // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  197. // console.log(uuIdUrl);
  198. // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  199. // NetcaPDFSeal.openPDFWithUrl(window.location.href);
  200. // window.location = uuIdUrl;
  201. } catch (ex) {
  202. console.log(ex.toString());
  203. }
  204. }
  205. },
  206. _changeArchiveDateSelect: function (dom) {
  207. let me = rptArchiveObj;
  208. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  209. me.currentArchiveDateStr = dom.innerHTML;
  210. if(can_netcasign) {
  211. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  212. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  213. 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();
  214. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  215. me._buildeArchiveDateSelect();
  216. }, function () {
  217. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  218. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="750px" width="100%" style="border: none;"></iframe>');
  219. me._buildeArchiveDateSelect();
  220. });
  221. // me._updateSignHtmlAndFrame();
  222. me._requestArchiveReport();
  223. } else {
  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. },
  229. _buildeArchiveDateSelect: function () {
  230. let me = rptArchiveObj;
  231. let targetDom = document.getElementById("currentDrpArchiveSelect");
  232. targetDom.innerHTML = me.currentArchiveDateStr;
  233. let drpDom = $("#drpArchiveSelect");
  234. drpDom.empty();
  235. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  236. for (let aItem of ARCHIVE_LIST) {
  237. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  238. for (let [index,item] of aItem.items.entries()) {
  239. if (item.uuid !== me.currentArchiveUuid) {
  240. const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + '#' + (index+1) + ' ' + item.updateDate_time + '</a>';
  241. drpDom.append(str);
  242. }
  243. }
  244. }
  245. }
  246. }
  247. },
  248. _updateSignHtmlAndFrame: function (needFrame = false) {
  249. const me = rptArchiveObj;
  250. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  251. for (let i = 0; i < $('#role-list div').length; i++) {
  252. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  253. $('#role-list div').eq(i).find('input').attr('disabled', true);
  254. } else {
  255. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  256. }
  257. $('#role-list div').eq(i).find('input').prop('checked', false);
  258. }
  259. let uhtml = '';
  260. let pagetr = '';
  261. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  262. if (!msgSign) {
  263. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  264. }
  265. for (const us of uSignLogList) {
  266. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  267. }
  268. for (let i = 1; i <= msgSign.total_page; i++) {
  269. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  270. }
  271. $('#page-list').html(pagetr);
  272. if (needFrame) {
  273. 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();
  274. $('#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>');
  275. }
  276. $('#dateStr').html(me.currentArchiveDateStr);
  277. $('#sign_num').text(uSignLogList.length);
  278. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  279. // 是否显示撤销按钮
  280. if(uHadSign && uHadSign.length > 0) {
  281. $('#show-removesign-modal-btn').show();
  282. } else {
  283. $('#show-removesign-modal-btn').hide();
  284. }
  285. },
  286. _countChkedRptTpl: function () {
  287. let me = rptArchiveObj;
  288. if (me.treeObj) {
  289. me.checkedRptTplNodes = [];
  290. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  291. for (let node of chkNodes) {
  292. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  293. cnt++;
  294. me.checkedRptTplNodes.push(node);
  295. if (me.currentNode === node) hasCurrentNode = true;
  296. }
  297. }
  298. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  299. //这里根据实际需求再做处理
  300. cnt++;
  301. me.checkedRptTplNodes.push(me.currentNode);
  302. }
  303. $("#print_div").find("span").each(function(cIdx,elementSpan){
  304. elementSpan.innerText = cnt;
  305. });
  306. $("#export_div").find("span").each(function(cIdx,elementSpan){
  307. elementSpan.innerText = cnt;
  308. });
  309. }
  310. },
  311. showArchivedItem: function(currentNode) {
  312. //初始化当前报表已经归档的信息
  313. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  314. if (currentNode) {
  315. //1. cardArchiveInfo
  316. let cardArchiveInfo = $('#cardArchiveInfo');
  317. cardArchiveInfo.empty();
  318. let auditDate = null;
  319. let achivedAmt = 0;
  320. let achivedItem = null;
  321. for (let item of ARCHIVE_LIST) {
  322. if (parseInt(item.rpt_id) === currentNode.refId) {
  323. if (LAST_AUDITOR.end_time) {
  324. auditDate = new Date(LAST_AUDITOR.end_time);
  325. } else {
  326. auditDate = new Date(LAST_AUDITOR.begin_time);
  327. }
  328. achivedAmt = item.items?item.items.length:0;
  329. achivedItem = item;
  330. break;
  331. }
  332. }
  333. if (auditDate) {
  334. cardArchiveInfo.append('<h6>第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  335. } else {
  336. cardArchiveInfo.append('<h6>第' + current_stage_order + '期');
  337. }
  338. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  339. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  340. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  341. }
  342. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  343. if (achivedAmt > 0) {
  344. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  345. cardArchiveInfo.append('<div class="form-check">');
  346. // if (achivedAmt === 3) {
  347. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  348. // }
  349. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  350. // let ad = new Date(achivedItem.items[idx].update_time);
  351. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  352. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  353. cardArchiveInfo.append('</label>');
  354. cardArchiveInfo.append('</div>');
  355. }
  356. }
  357. cardArchiveInfo.append('</div>');
  358. //2. selectionArchiveInfo
  359. let selectionArchiveInfo = $('#selectionArchiveInfo');
  360. selectionArchiveInfo.empty();
  361. if (achivedAmt > 0) {
  362. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  363. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  364. }
  365. }
  366. }
  367. },
  368. _getCurrentArchives: function (currentNode) {
  369. let rst = null;
  370. if (ARCHIVE_LIST.length > 0 && currentNode) {
  371. for (let aItem of ARCHIVE_LIST) {
  372. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  373. rst = aItem;
  374. break;
  375. }
  376. }
  377. }
  378. return rst;
  379. },
  380. _chkIfFullArchives: function(currentNode) {
  381. let aItem = this._getCurrentArchives(currentNode);
  382. let rst = (aItem && aItem.items && aItem.items.length === 3);
  383. return rst;
  384. },
  385. _getPageSignatureInfo: function(pageData, rpt_id) {
  386. let psInfo = [], psInfoStr = [];
  387. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  388. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  389. const _getProperSignatureArea = function(cell, control) {
  390. // 约定默认长宽比例是2:1,图片分辨率是600*300
  391. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  392. if (cell && cell[JV.PROP_AREA]) {
  393. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  394. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  395. if (width > height * 2) {
  396. width = height * 2;
  397. } else {
  398. height = width / 2;
  399. }
  400. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  401. case 'left':
  402. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  403. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  404. rst[2] = rst[0] + width;
  405. rst[3] = rst[1] + height;
  406. break;
  407. case 'right':
  408. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  409. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  410. rst[0] = rst[2] - width;
  411. rst[1] = rst[3] - height;
  412. break;
  413. default:
  414. //center
  415. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  416. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  417. rst[2] = rst[0] + width;
  418. rst[3] = rst[1] + height;
  419. break;
  420. }
  421. }
  422. rst[0] = rst[0] + offsetX;
  423. rst[2] = rst[2] + offsetX;
  424. rst[1] = rst[1] + offsetY;
  425. rst[3] = rst[3] + offsetY;
  426. return rst;
  427. }
  428. for(let i = 0; i < pageData.items.length; i++) {
  429. let page = pageData.items[i];
  430. for (let sCell of page.signature_cells) {
  431. // sCell.signature_name 草图不用加密
  432. if (sCell.signature_name !== 'dummy_pic') {
  433. let control = null;
  434. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  435. control = controls[sCell[JV.PROP_CONTROL]];
  436. } else {
  437. control = sCell[JV.PROP_CONTROL];
  438. }
  439. let idx = psInfoStr.indexOf(sCell.signature_name);
  440. let actSignArea = _getProperSignatureArea(sCell, control);
  441. if (idx < 0) {
  442. psInfoStr.push(sCell.signature_name);
  443. let newPsInfo = {'name': sCell.signature_name, areas: []};
  444. 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: []};
  445. area.pages.push(i + 1);
  446. newPsInfo.areas.push(area);
  447. psInfo.push(newPsInfo);
  448. } else {
  449. let hasArea = false;
  450. for (let areaItem of psInfo[idx].areas) {
  451. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  452. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  453. areaItem.pages.push(i + 1);
  454. hasArea = true;
  455. break;
  456. }
  457. }
  458. if (!hasArea) {
  459. 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: []};
  460. area.pages.push(i + 1);
  461. psInfo[idx].areas.push(area);
  462. }
  463. }
  464. }
  465. }
  466. }
  467. return psInfo;
  468. },
  469. archiveCurrentReport: function (currentRptPageRst, currentNode, cb) {
  470. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  471. // 1. 找草图路径
  472. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  473. // 每页
  474. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  475. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  476. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  477. if (sCell.signature_name === 'dummy_pic') {
  478. //1. 草图就不考虑重复问题,重复就重复吧;
  479. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  480. let picIdx = picKeys.indexOf(sCell.path);
  481. if (picIdx < 0) {
  482. picKeys.push(sCell.path);
  483. picCells.push(sCell);
  484. } else {
  485. let dPicIdx = dupPicPath.indexOf(sCell.path);
  486. if (dPicIdx < 0) {
  487. dupPicPath.push(sCell.path);
  488. dupPicCell.push([]);
  489. dPicIdx = dupPicPath.length - 1;
  490. }
  491. dupPicCell[dPicIdx].push(sCell);
  492. }
  493. }
  494. }
  495. }
  496. // 2. 下载草图,下载完毕后upload
  497. if (picCells.length > 0) {
  498. $.bootstrapLoading.start();
  499. let picAmt = picCells.length, picCnt = 0;
  500. let exceptionAmt = 0;
  501. for (let idx = 0; idx < picCells.length; idx++) {
  502. let dCell = picCells[idx];
  503. getBlob(picKeys[idx]).then(blob => {
  504. if (blob === 'not found!') {
  505. exceptionAmt++;
  506. if ((picCnt + exceptionAmt) === picAmt) {
  507. $.bootstrapLoading.end();
  508. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  509. }
  510. } else {
  511. let oFileReader = new FileReader();
  512. oFileReader.onloadend = function (e) {
  513. picCnt++;
  514. let base64 = e.target.result;
  515. picCells[idx].pic = base64;
  516. let pPathIdx = dupPicPath.indexOf(dCell.path);
  517. if (pPathIdx >= 0) {
  518. for (let dupCell of dupPicCell[pPathIdx]) {
  519. dupCell.pic = base64;
  520. }
  521. }
  522. if ((picCnt + exceptionAmt) === picAmt) {
  523. $.bootstrapLoading.end();
  524. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  525. }
  526. };
  527. oFileReader.readAsDataURL(blob);
  528. }
  529. });
  530. }
  531. } else {
  532. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb);
  533. }
  534. },
  535. _archiveCurrentReport: function(currentRptPageRst, currentNode, cb) {
  536. // 归档当前报表
  537. if (currentRptPageRst !== null) {
  538. try {
  539. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
  540. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, currentNode.refId);
  541. // console.log(pageEncryptInfo);
  542. let formData = new FormData();
  543. formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
  544. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  545. postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
  546. // 成功后,更新当前页面
  547. if (result.addedRst) {
  548. // console.log(result);
  549. ARCHIVE_LIST = result.addedRst;
  550. rptArchiveObj.showArchivedItem(currentNode);
  551. zTreeOprObj.refreshNodes();
  552. //第二步:增加加密信息
  553. let params = {};
  554. params.prjId = PROJECT_ID;
  555. params.stgId = current_stage_id;
  556. params.rptId = currentNode.refId;
  557. params.ttlPgs = currentRptPageRst.items.length;
  558. params.content = pageEncryptInfo;
  559. params.uuid = result.uuid; //正确返回时,带着uuid回来
  560. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  561. function(rst){
  562. if (cb) {
  563. cb(null, 'add archive encryption succeed!', params.uuid);
  564. }
  565. }, function(err){
  566. if (cb) {
  567. cb('err', 'add archive encryption err!', params.uuid);
  568. }
  569. }, function(ex){
  570. if (cb) {
  571. cb('err', 'add archive encryption err!', params.uuid);
  572. }
  573. }
  574. );
  575. } else {
  576. // 有冲突,需要删除
  577. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken_j'),
  578. function(result){
  579. if (cb) {
  580. cb('err', 'add archive conflict!', null);
  581. }
  582. }
  583. );
  584. }
  585. }, function (error){
  586. if (cb) {
  587. cb('err', 'add archive err!', null);
  588. }
  589. });
  590. } else {
  591. let aItem = this._getCurrentArchives(currentNode);
  592. if (aItem && aItem.items && aItem.items.length > 0) {
  593. let orgName = aItem.items[0].uuid;
  594. let compStr = aItem.items[0].updateDate_time;
  595. for (let idx = 1; idx < aItem.items.length; idx++) {
  596. if (aItem.items[idx].updateDate_time < compStr) {
  597. compStr = aItem.items[idx].updateDate_time;
  598. orgName = aItem.items[idx].uuid;
  599. }
  600. }
  601. postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) {
  602. // 成功后,更新当前页面
  603. if (result.updatedRst) {
  604. // console.log(result);
  605. ARCHIVE_LIST = result.updatedRst;
  606. rptArchiveObj.showArchivedItem(currentNode);
  607. zTreeOprObj.refreshNodes();
  608. //第二步:更新加密信息
  609. let params = {};
  610. params.prjId = PROJECT_ID;
  611. params.stgId = current_stage_id;
  612. params.rptId = currentNode.refId;
  613. params.ttlPgs = currentRptPageRst.items.length;
  614. params.content = pageEncryptInfo;
  615. params.uuid = orgName;
  616. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  617. function(result){
  618. if (cb) {
  619. cb(null, 'update archive succeed!', params.uuid);
  620. }
  621. }, function(err){
  622. if (cb) {
  623. cb('err', 'update archive err!', params.uuid);
  624. }
  625. }, function(ex){
  626. if (cb) {
  627. cb('err', 'update archive err!', params.uuid);
  628. }
  629. }
  630. );
  631. } else {
  632. // 有冲突,需要删除
  633. CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
  634. function(result){
  635. if (cb) {
  636. cb('err', 'update archive conflict!', null);
  637. }
  638. }
  639. );
  640. }
  641. }, function (error){
  642. // alert(error);
  643. if (cb) {
  644. cb('err', 'update archive conflict!', null);
  645. }
  646. });
  647. }
  648. }
  649. } catch (ex) {
  650. console.log(ex);
  651. console.log(ex.toString());
  652. if (cb) {
  653. cb('err', 'has exception!', null);
  654. }
  655. }
  656. } else {
  657. alert('请选择打开一个报表!');
  658. }
  659. }
  660. };
  661. /**
  662. * 获取 blob
  663. * @param {String} url 目标文件地址
  664. * @return {Promise}
  665. */
  666. function getBlob(url) {
  667. return new Promise(resolve => {
  668. const xhr = new XMLHttpRequest();
  669. xhr.open('GET', url, true);
  670. xhr.responseType = 'blob';
  671. xhr.onload = () => {
  672. if (xhr.status === 200) {
  673. resolve(xhr.response);
  674. } else {
  675. resolve('not found!');
  676. }
  677. };
  678. xhr.send();
  679. });
  680. }
  681. /**
  682. * pdf base64 转 blob
  683. * @param {String} dataUrl base64码
  684. * @return {Promise}
  685. */
  686. function convertBase64UrlToBlob(dataUrl) {
  687. //去掉url的头,并转换为byte
  688. var bytes = window.atob(dataUrl);
  689. //处理异常,将ascii码小于0的转换为大于0
  690. var ab = new Uint8Array(bytes.length);
  691. for (var i = 0; i < bytes.length; i++) {
  692. ab[i] = bytes.charCodeAt(i);
  693. }
  694. return new Blob([ab], { type: 'application/pdf' });
  695. }
  696. /**
  697. * 保存
  698. * @param {Blob} blob
  699. * @param {String} filename 想要保存的文件名称
  700. */
  701. function saveAs(blob, filename) {
  702. if (window.navigator.msSaveOrOpenBlob) {
  703. navigator.msSaveBlob(blob, filename);
  704. } else {
  705. const link = document.createElement('a');
  706. const body = document.querySelector('body');
  707. link.href = window.URL.createObjectURL(blob);
  708. link.download = filename;
  709. // fix Firefox
  710. link.style.display = 'none';
  711. body.appendChild(link);
  712. link.click();
  713. body.removeChild(link);
  714. window.URL.revokeObjectURL(link.href);
  715. }
  716. }
  717. /**
  718. * 下载
  719. * @param {String} url 目标文件地址
  720. * @param {String} filename 想要保存的文件名称
  721. */
  722. function download(url, filename) {
  723. getBlob(url).then(blob => {
  724. saveAs(blob, filename);
  725. });
  726. }
  727. $(function () {
  728. $('#download_file').click(function () {
  729. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  730. console.log(rptArchiveObj.currentArchivePdfPath);
  731. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  732. } else {
  733. alert('请选择打开一个报表!');
  734. }
  735. });
  736. $('#print_file').click(function () {
  737. if (rptArchiveObj.currentArchiveUuid) {
  738. $('#iframe_made iframe')[0].contentWindow.print();
  739. } else {
  740. alert('请选择打开一个报表!');
  741. }
  742. });
  743. })