rpt_archive.js 40 KB

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