rpt_archive.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. /**
  2. * Created by Tony on 2021/4/2.
  3. */
  4. const A4_PIXEL_HEIGHT = 1122;
  5. const A4_PIXEL_WIDTH = 793;
  6. const A3_PIXEL_HEIGHT = 1586;
  7. const A3_PIXEL_WIDTH = A4_PIXEL_HEIGHT;
  8. let rptArchiveObj = {
  9. treeObj: null,
  10. currentNode: null,
  11. currentArchiveUuid: null,
  12. currentChildArchiveUuids: null,
  13. currentArchiveDateStr: null,
  14. currentEncryptionList: null,
  15. currentArchivePdfPath: null,
  16. iniPage: function() {
  17. //初始化页面的归档信息
  18. let me = rptArchiveObj;
  19. me.currentNode = null;
  20. me.currentArchiveUuid = null;
  21. me.currentChildArchiveUuids = null;
  22. me.currentArchiveDateStr = null;
  23. me.currentEncryptionList = null;
  24. me.currentArchivePdfPath = null;
  25. const archivedRptIds = [];
  26. for (let aItem of ARCHIVE_LIST) {
  27. archivedRptIds.push(parseInt(aItem.rpt_id));
  28. }
  29. const _chkIfShouldFilter = function(rptItem, currentRptType = 'normal') {
  30. let rst = (!(rptItem.released) && rptItem.nodeType === 2 || rptItem.hidden); //未发布判断 或 故意隐藏
  31. if (!rst) {
  32. // 根据当前业务类型判断及检测其他非同类报表,如动态决算类型、支付审批类型
  33. switch(currentRptType) {
  34. case 'normal':
  35. // 检测:预付款
  36. if (CURRENT_SELECTED_BIZ_TYPE && CURRENT_SELECTED_BIZ_TYPE === 'change_prepay' && rptItem.nodeType === 2) {
  37. rst = true;
  38. if (rptItem.flags && rptItem.flags.rptTplType) {
  39. if (current_advance_id > 0) {
  40. rst = !((rptItem.flags.rptTplType || '') === getAdvanceType2());
  41. }
  42. }
  43. }
  44. break;
  45. case 'juesuan':
  46. break;
  47. case 'zhifushenpi':
  48. break;
  49. default:
  50. break;
  51. }
  52. }
  53. return rst;
  54. };
  55. let private_remove_hide_item = function (items, nlv) {
  56. if (items && items.length > 0) {
  57. for (let i = items.length - 1; i >= 0; i--) {
  58. // if (!(items[i].released) && items[i].nodeType === 2) {
  59. // if (archivedRptIds.indexOf(items[i].refId) < 0) {
  60. // // 备注:这里还要再判断是否存在已经归档的报表,如果有,需要保留。否则才真正剔除
  61. // items.splice(i, 1);
  62. // }
  63. // } else {
  64. if (_chkIfShouldFilter(items[i])) {
  65. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  66. // 备注:这里还要再判断是否存在已经归档的报表,如果有,需要保留。否则才真正剔除
  67. items.splice(i, 1);
  68. }
  69. } else {
  70. if (items[i].items && items[i].items.length > 0) {
  71. private_remove_hide_item(items[i].items, nlv + 1);
  72. if (items[i].items.length === 0 && nlv > 0) {
  73. items.splice(i, 1);
  74. }
  75. }
  76. }
  77. }
  78. }
  79. };
  80. const private_remove_un_archive_item = function(items, nlv) {
  81. if (items && items.length > 0) {
  82. for (let i = items.length - 1; i >= 0; i--) {
  83. if (items[i].nodeType === 2) {
  84. if (archivedRptIds.indexOf(items[i].refId) < 0) {
  85. items.splice(i, 1);
  86. }
  87. } else {
  88. if (items[i].items && items[i].items.length > 0) {
  89. private_remove_un_archive_item(items[i].items, nlv + 1);
  90. if (items[i].items.length === 0 && nlv > 0) {
  91. items.splice(i, 1);
  92. }
  93. } else {
  94. //items[i]是目录,但又没有items子项,
  95. items.splice(i, 1);
  96. }
  97. }
  98. }
  99. }
  100. };
  101. let nodeLv = 0;
  102. private_remove_hide_item(TOP_TREE_NODES, nodeLv);
  103. private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
  104. zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
  105. me.treeObj.expandAll(true);
  106. me.refreshNodes();
  107. $('#iframe_made').html('<iframe src="/archive/pdf/show" class="border-0" height="100%" width="100%"></iframe>');
  108. rptArchiveObj._countChkedRptTpl();
  109. rptArchiveObj._buildeArchiveDateSelect();
  110. rptArchiveObj._iniArchiveItemForDeleteShow();
  111. rptArchiveObj._iniArchiveItemForDeleteShow();
  112. },
  113. toggleBtn: function (enabled) {
  114. if (getStageStatus() === 3 && enabled) {
  115. $('#btnArchiveRpt').removeAttr('disabled');
  116. $('#btnArchiveList').removeAttr('disabled');
  117. $('#btnBatchArchiveRpt').removeAttr('disabled');
  118. } else {
  119. $('#btnArchiveRpt').attr('disabled', '');
  120. $('#btnArchiveList').attr('disabled', '');
  121. $('#btnBatchArchiveRpt').attr('disabled', '');
  122. }
  123. },
  124. refreshNodes: function() {
  125. let me = this;
  126. const _set_archive_icon = function (tplNode) {
  127. if (!tplNode.isParent) {
  128. tplNode.icon = "/public/css/ztree/img/diy/11.png"; // 躺枪,ico_docu已换成其他图标,调整的代价大,在这里调整
  129. }
  130. };
  131. let private_setupIsParent = function(node){
  132. node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
  133. _set_archive_icon(node);
  134. if (node.items && node.items.length) {
  135. for (let i = 0; i < node.items.length; i++) {
  136. private_setupIsParent(node.items[i]);
  137. }
  138. }
  139. };
  140. let topNodes = me.treeObj.getNodes();
  141. for (let i = 0; i < topNodes.length; i++) {
  142. private_setupIsParent(topNodes[i]);
  143. }
  144. me.treeObj.refresh();
  145. },
  146. onCheck: function(event, treeId, treeNode) {
  147. rptArchiveObj._countChkedRptTpl();
  148. if (treeNode.isParent) {
  149. rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
  150. }
  151. },
  152. onClick: function(event,treeId,treeNode) {
  153. let me = rptArchiveObj;
  154. if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
  155. me.currentNode = treeNode;
  156. for (let aItem of ARCHIVE_LIST) {
  157. if (treeNode.refId === parseInt(aItem.rpt_id)) {
  158. me.currentArchiveUuid = null;
  159. me.currentArchiveDateStr = null;
  160. me.currentArchivePdfPath = null;
  161. if (aItem.items && aItem.items.length > 0) {
  162. // me.currentArchiveUuid = aItem.items[0].uuid;
  163. // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
  164. const newItems = _.orderBy(aItem.items, ['updateDate_time'], ['desc']);
  165. me.currentArchiveUuid = newItems[0].uuid;
  166. me.currentChildArchiveUuids = newItems[0].childUuids;
  167. me.currentArchiveDateStr = '#' + (_.findIndex(aItem.items, { updateDate_time: newItems[0].updateDate_time})+1) + ' ' + newItems[0].updateDate_time;
  168. if (can_netcasign) {
  169. for (const [i,item] of aItem.items.entries()) {
  170. if (_.find(signLogList, { uuid: item.uuid })) {
  171. me.currentArchiveUuid = item.uuid;
  172. me.currentChildArchiveUuids = item.childUuids;
  173. me.currentArchiveDateStr = '#' + (i+1) + ' ' + item.updateDate_time;
  174. break;
  175. }
  176. }
  177. }
  178. }
  179. break;
  180. }
  181. }
  182. me._countChkedRptTpl();
  183. me._buildeArchiveDateSelect();
  184. me._requestArchiveReport();
  185. rptArchiveObj._iniArchiveItemForDeleteShow();
  186. }
  187. },
  188. batchArchive: function() {
  189. if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
  190. if (zTreeOprObj.checkedRptTplNodes.length <= 10) {
  191. indexDbOprObj.storeReportRequest(current_stage_id, zTreeOprObj.checkedRptTplNodes, true, indexDbOprObj.startRequestReport);
  192. } else {
  193. alert('批量归档上限为10,请勾选10张以内');
  194. }
  195. }
  196. },
  197. _requestArchiveReport: function () {
  198. let me = rptArchiveObj;
  199. if (me.currentNode && me.currentArchiveUuid) {
  200. try {
  201. if (can_netcasign) {
  202. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  203. if (!msgSign) {
  204. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  205. }
  206. console.log(current_stage_id, msgSign, me.currentArchiveUuid);
  207. me.currentEncryptionList = msgSign;
  208. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  209. let html = '';
  210. let pagetr = '';
  211. if (msgSign) {
  212. const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
  213. for (const [index,role] of msgSign.encryption.entries()) {
  214. const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
  215. html += '<div class="'+ rows +'">\n' +
  216. ' <div class="custom-control custom-radio custom-control-inline">\n' +
  217. ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
  218. ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
  219. ' </div>\n' +
  220. ' </div>';
  221. }
  222. let uhtml = '';
  223. for (const us of uSignLogList) {
  224. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  225. }
  226. for (let i = 1; i <= msgSign.total_page; i++) {
  227. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  228. }
  229. }
  230. $('#dateStr').html(me.currentArchiveDateStr);
  231. $('#role-list').html(html);
  232. $('#page-list').html(pagetr);
  233. $('#sign_num').text(uSignLogList.length);
  234. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  235. // 是否显示撤销按钮
  236. if(uHadSign && uHadSign.length > 0) {
  237. $('#show-removesign-modal-btn').show();
  238. } else {
  239. $('#show-removesign-modal-btn').hide();
  240. }
  241. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  242. me.currentArchivePdfPath = result ? oss_path + '/sign/'+ me.currentArchiveUuid +'.PDF' + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') : oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  243. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  244. }, function () {
  245. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  246. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  247. })
  248. } else {
  249. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  250. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  251. console.log(me.currentArchivePdfPath);
  252. }
  253. // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
  254. // console.log(uuIdUrl);
  255. // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
  256. // NetcaPDFSeal.openPDFWithUrl(window.location.href);
  257. // window.location = uuIdUrl;
  258. } catch (ex) {
  259. console.log(ex.toString());
  260. }
  261. }
  262. },
  263. _setChildUuidsByCurUuid: () => {
  264. let me = rptArchiveObj;
  265. me.currentChildArchiveUuids = null;
  266. if (me.currentNode && me.currentArchiveUuid) {
  267. for (let aItem of ARCHIVE_LIST) {
  268. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  269. for (let [index,item] of aItem.items.entries()) {
  270. if (item.uuid === me.currentArchiveUuid) {
  271. me.currentChildArchiveUuids = item.childUuids;
  272. break;
  273. }
  274. }
  275. break;
  276. }
  277. }
  278. }
  279. },
  280. _changeArchiveDateSelect: function (dom, archiveIdx) {
  281. let me = rptArchiveObj;
  282. // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
  283. me.currentArchiveDateStr = dom.innerHTML;
  284. me._setChildUuidsByCurUuid();
  285. if(can_netcasign) {
  286. postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
  287. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  288. 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();
  289. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  290. me._buildeArchiveDateSelect();
  291. }, function () {
  292. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  293. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  294. me._buildeArchiveDateSelect();
  295. });
  296. // me._updateSignHtmlAndFrame();
  297. me._requestArchiveReport();
  298. me._iniArchiveItemForDeleteShow();
  299. } else {
  300. me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
  301. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
  302. me._buildeArchiveDateSelect();
  303. me._iniArchiveItemForDeleteShow();
  304. }
  305. },
  306. _buildeArchiveDateSelect: function () {
  307. let me = rptArchiveObj;
  308. let targetDom = document.getElementById("currentDrpArchiveSelect");
  309. targetDom.innerHTML = me.currentArchiveDateStr;
  310. let drpDom = $("#drpArchiveSelect");
  311. drpDom.empty();
  312. if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
  313. for (let aItem of ARCHIVE_LIST) {
  314. if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
  315. for (let [index,item] of aItem.items.entries()) {
  316. if (item.uuid !== me.currentArchiveUuid) {
  317. const str = `<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = '${item.uuid}'; rptArchiveObj._changeArchiveDateSelect(this)">#${index+1} ${item.updateDate_time}</a>`
  318. drpDom.append(str);
  319. }
  320. }
  321. }
  322. }
  323. }
  324. },
  325. _updateSignHtmlAndFrame: function (needFrame = false) {
  326. const me = rptArchiveObj;
  327. const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
  328. for (let i = 0; i < $('#role-list div').length; i++) {
  329. if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
  330. $('#role-list div').eq(i).find('input').attr('disabled', true);
  331. } else {
  332. $('#role-list div').eq(i).find('input').removeAttr('disabled');
  333. }
  334. $('#role-list div').eq(i).find('input').prop('checked', false);
  335. }
  336. let uhtml = '';
  337. let pagetr = '';
  338. let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
  339. if (!msgSign) {
  340. msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
  341. }
  342. for (const us of uSignLogList) {
  343. uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
  344. }
  345. for (let i = 1; i <= msgSign.total_page; i++) {
  346. pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
  347. }
  348. $('#page-list').html(pagetr);
  349. if (needFrame) {
  350. 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();
  351. $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + (uSignLogList.length !== 0 ? '?' + uSignLogList[uSignLogList.length-1].versionid : '') + '" height="100%" width="100%" style="border: none;"></iframe>');
  352. }
  353. $('#dateStr').html(me.currentArchiveDateStr);
  354. $('#sign_num').text(uSignLogList.length);
  355. const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
  356. // 是否显示撤销按钮
  357. if(uHadSign && uHadSign.length > 0) {
  358. $('#show-removesign-modal-btn').show();
  359. } else {
  360. $('#show-removesign-modal-btn').hide();
  361. }
  362. },
  363. _countChkedRptTpl: function () {
  364. let me = rptArchiveObj;
  365. $('#delete_archive_btn').attr('disabled', '');
  366. if (me.treeObj) {
  367. me.checkedRptTplNodes = [];
  368. let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
  369. for (let node of chkNodes) {
  370. if (node.nodeType === TPL_TYPE_TEMPLATE) {
  371. cnt++;
  372. me.checkedRptTplNodes.push(node);
  373. if (me.currentNode === node) hasCurrentNode = true;
  374. }
  375. }
  376. if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
  377. //这里根据实际需求再做处理
  378. cnt++;
  379. me.checkedRptTplNodes.push(me.currentNode);
  380. }
  381. $("#print_div").find("span").each(function(cIdx,elementSpan){
  382. elementSpan.innerText = cnt;
  383. });
  384. $("#export_div").find("span").each(function(cIdx,elementSpan){
  385. elementSpan.innerText = cnt;
  386. });
  387. if (cnt) {
  388. $('#delete_archive_btn').removeAttr('disabled');
  389. }
  390. }
  391. },
  392. _iniArchiveItemForDeleteShow: function() {
  393. let me = rptArchiveObj;
  394. const dispArchInfoBody = $('#disp_archive_info_body');
  395. dispArchInfoBody.empty();
  396. let targetDom = document.getElementById("currentDrpArchiveSelect");
  397. let firstStr = `<h6>确认删除本张【${targetDom.innerText}】归档报表?</h6>`;
  398. let secondStr = `<h6>删除后,数据无法恢复,请谨慎操作。</h6>`;
  399. dispArchInfoBody.append(firstStr);
  400. dispArchInfoBody.append(secondStr);
  401. },
  402. showArchivedItem: function(currentNode) {
  403. //初始化当前报表已经归档的信息
  404. //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
  405. if (currentNode) {
  406. //1. cardArchiveInfo
  407. let cardArchiveInfo = $('#cardArchiveInfo');
  408. cardArchiveInfo.empty();
  409. let auditDate = null;
  410. let achivedAmt = 0;
  411. let achivedItem = null;
  412. for (let item of ARCHIVE_LIST) {
  413. if (parseInt(item.rpt_id) === currentNode.refId) {
  414. if (LAST_AUDITOR) {
  415. if (LAST_AUDITOR.end_time) {
  416. auditDate = new Date(LAST_AUDITOR.end_time);
  417. } else {
  418. auditDate = new Date(LAST_AUDITOR.begin_time);
  419. }
  420. } else {
  421. // 其他情况(如变更令相关)
  422. }
  423. achivedAmt = item.items?item.items.length:0;
  424. achivedItem = item;
  425. break;
  426. }
  427. }
  428. if (-400 === current_stage_id) {
  429. cardArchiveInfo.append('<h6>预付款 第' + current_advance_order + '期');
  430. cardArchiveInfo.append('<h6>本张报表第' + current_advance_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  431. } else if (-500 === current_stage_id) {
  432. cardArchiveInfo.append('<h6>材料调差 第' + current_material_order + '期');
  433. cardArchiveInfo.append('<h6>本张报表第' + current_material_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  434. } else if (STAGE_ID <= -300 && STAGE_ID > -400) {
  435. if (auditDate) {
  436. cardArchiveInfo.append('<h6>审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  437. }
  438. cardArchiveInfo.append('<h6>已归档' + achivedAmt + '份文件。</h6>');
  439. } else {
  440. if (auditDate) {
  441. cardArchiveInfo.append('<h6>计量期 第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
  442. } else {
  443. cardArchiveInfo.append('<h6>计量期 第' + current_stage_order + '期');
  444. }
  445. cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
  446. }
  447. if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
  448. cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
  449. }
  450. cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
  451. if (achivedAmt > 0) {
  452. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  453. cardArchiveInfo.append('<div class="form-check">');
  454. // if (achivedAmt === 3) {
  455. // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
  456. // }
  457. cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
  458. // let ad = new Date(achivedItem.items[idx].update_time);
  459. // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
  460. cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
  461. cardArchiveInfo.append('</label>');
  462. cardArchiveInfo.append('</div>');
  463. }
  464. }
  465. cardArchiveInfo.append('</div>');
  466. //2. selectionArchiveInfo
  467. let selectionArchiveInfo = $('#selectionArchiveInfo');
  468. selectionArchiveInfo.empty();
  469. if (achivedAmt > 0) {
  470. for (let idx = 0; idx < achivedItem.items.length; idx++) {
  471. selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
  472. }
  473. }
  474. }
  475. },
  476. _getCurrentArchives: function (currentNode) {
  477. let rst = null;
  478. if (ARCHIVE_LIST.length > 0 && currentNode) {
  479. for (let aItem of ARCHIVE_LIST) {
  480. if (parseInt(aItem.rpt_id) === currentNode.refId) {
  481. rst = aItem;
  482. break;
  483. }
  484. }
  485. }
  486. return rst;
  487. },
  488. _chkIfFullArchives: function(currentNode) {
  489. let aItem = this._getCurrentArchives(currentNode);
  490. let rst = (aItem && aItem.items && aItem.items.length === 3);
  491. return rst;
  492. },
  493. _getPageSignatureInfo: function(pageData, pageSize, rpt_id) {
  494. // 因接口方是这样的单位:A4(297*210 -> pt 814.68 * 595.44),那么需要把像素转换成pt的系数,经过测试发现这个系数就是PDF_SCALE,不用再设置了
  495. let psInfo = [], psInfoStr = [];
  496. let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
  497. let controls = pageData[JV.NODE_CONTROL_COLLECTION];
  498. let ptChkHeight = pageSize === 'A4' ? A4_PIXEL_HEIGHT : A3_PIXEL_HEIGHT;
  499. const signatureOrderObj = {};
  500. pageData.items[0].signature_cells.forEach(sCell => {
  501. if (sCell.hasOwnProperty('Order')) {
  502. signatureOrderObj[sCell.signature_name] = sCell.Order + 1;
  503. }
  504. });
  505. const _getAreasProperty = (srcArea) => {
  506. const width = (srcArea[JV.IDX_RIGHT] - srcArea[JV.IDX_LEFT]);
  507. const height = (srcArea[JV.IDX_BOTTOM] - srcArea[JV.IDX_TOP]);
  508. let rst = {
  509. Left: srcArea[JV.IDX_LEFT] + offsetX, Top: srcArea[JV.IDX_TOP] + offsetY, width, height,
  510. PtCenterX: +((srcArea[JV.IDX_LEFT] + offsetX + width / 2) * PDF_SCALE).toFixed(2),
  511. PtCenterY: +((ptChkHeight - (srcArea[JV.IDX_TOP] + offsetX + height / 2)) * PDF_SCALE).toFixed(2),
  512. PtWidth: +(width * PDF_SCALE).toFixed(2), PtHeight: +(height * PDF_SCALE).toFixed(2),
  513. pages: []
  514. };
  515. return rst;
  516. };
  517. const _getProperSignatureArea = function(cell, control) {
  518. // 约定默认长宽比例是2:1,图片分辨率是600*300
  519. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  520. if (cell && cell[JV.PROP_AREA]) {
  521. let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
  522. height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
  523. if (width > height * 2) {
  524. width = height * 2;
  525. } else {
  526. height = width / 2;
  527. }
  528. switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
  529. case 'left':
  530. rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
  531. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  532. rst[2] = rst[0] + width;
  533. rst[3] = rst[1] + height;
  534. break;
  535. case 'right':
  536. rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
  537. rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
  538. rst[0] = rst[2] - width;
  539. rst[1] = rst[3] - height;
  540. break;
  541. default:
  542. //center
  543. rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
  544. rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
  545. rst[2] = rst[0] + width;
  546. rst[3] = rst[1] + height;
  547. break;
  548. }
  549. }
  550. rst[0] = rst[0] + offsetX;
  551. rst[2] = rst[2] + offsetX;
  552. rst[1] = rst[1] + offsetY;
  553. rst[3] = rst[3] + offsetY;
  554. return rst;
  555. };
  556. const _getProperSignDateArea = (orgArea) => {
  557. const rst = [0, 0, 0, 0]; // left, top, right, bottom
  558. // 给全部空间,不考虑对齐方式了
  559. rst[0] = orgArea[JV.PROP_LEFT];
  560. rst[1] = orgArea[JV.PROP_TOP];
  561. rst[2] = orgArea[JV.PROP_RIGHT];
  562. rst[3] = orgArea[JV.PROP_BOTTOM];
  563. return rst;
  564. };
  565. const _getStampArea = (stampCell) => {
  566. const rst = [0, 0, 0, 0];
  567. if (stampCell && stampCell[JV.PROP_AREA]) {
  568. const left = Math.round(stampCell[JV.PROP_AREA][JV.PROP_LEFT]);
  569. const right = Math.round(stampCell[JV.PROP_AREA][JV.PROP_RIGHT]);
  570. const top = Math.round(stampCell[JV.PROP_AREA][JV.PROP_TOP]);
  571. const bottom = Math.round(stampCell[JV.PROP_AREA][JV.PROP_BOTTOM]);
  572. let width = right - left,
  573. height = bottom - top;
  574. rst[0] = left;
  575. rst[1] = top;
  576. rst[2] = rst[0] + width;
  577. rst[3] = rst[1] + height;
  578. }
  579. rst[0] = rst[0] + offsetX;
  580. rst[2] = rst[2] + offsetX;
  581. rst[1] = rst[1] + offsetY;
  582. rst[3] = rst[3] + offsetY;
  583. return rst;
  584. };
  585. const _areaKeyCache = {
  586. normal: 'areas',
  587. company_stamp: 'company_stamp_areas',
  588. private_stamp: 'private_stamp_areas'
  589. };
  590. const _chkAndSetArea = (sCell, actSignArea, signDateArea, pageIdx, signNameKey) => {
  591. let idx = psInfoStr.indexOf(sCell[signNameKey]);
  592. const signType = sCell.signType || 'normal';
  593. const areaKey = _areaKeyCache[signType] || 'areas';
  594. if (idx < 0) {
  595. psInfoStr.push(sCell[signNameKey]);
  596. let newPsInfo = {'name': sCell[signNameKey], areas: [], company_stamp_areas: [], private_stamp_areas: [], sign_date_areas: [], order: signatureOrderObj[sCell[signNameKey]]};
  597. const area = _getAreasProperty(actSignArea);
  598. area.pages.push(pageIdx + 1);
  599. newPsInfo[areaKey].push(area);
  600. // 新需求:要把签名日期的坐标也记录下来,增加 sign_date_areas 属性
  601. if (signDateArea) {
  602. const sArea = _getAreasProperty(signDateArea);
  603. sArea.pages.push(pageIdx + 1);
  604. newPsInfo.sign_date_areas.push(sArea);
  605. }
  606. psInfo.push(newPsInfo);
  607. } else {
  608. let hasArea = false;
  609. for (let aIdx = 0; aIdx < psInfo[idx][areaKey].length; aIdx++) {
  610. const areaItem = psInfo[idx][areaKey][aIdx];
  611. if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
  612. areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
  613. areaItem.pages.push(pageIdx + 1);
  614. if (signDateArea) {
  615. psInfo[idx].sign_date_areas[aIdx].pages.push(pageIdx + 1); // 这里签名的位置不变,那么也假设签字日期的位置也不变
  616. }
  617. hasArea = true;
  618. break;
  619. }
  620. }
  621. if (!hasArea) {
  622. const area = _getAreasProperty(actSignArea);
  623. area.pages.push(pageIdx + 1);
  624. psInfo[idx][areaKey].push(area);
  625. if (signDateArea) {
  626. const sArea = _getAreasProperty(signDateArea);
  627. sArea.pages.push(pageIdx + 1);
  628. psInfo[idx].sign_date_areas.push(sArea);
  629. }
  630. }
  631. }
  632. };
  633. for(let i = 0; i < pageData.items.length; i++) {
  634. let page = pageData.items[i];
  635. if (i === 0) {
  636. let maxX = 0;
  637. let maxY = 0;
  638. page.cells.forEach(cell => {
  639. if (cell.area.Right > maxX) maxX = cell.area.Right;
  640. if (cell.area.Bottom > maxY) maxY = cell.area.Bottom;
  641. });
  642. if (maxX > maxY) ptChkHeight = pageSize === 'A4' ? A4_PIXEL_WIDTH : A3_PIXEL_WIDTH;
  643. }
  644. for (let sCell of page.signature_cells) {
  645. const dtCell = page.signature_date_cells.find(cell => cell.signature_name === `${sCell.signature_name}_签字日期`);
  646. const signDateArea = dtCell ? _getProperSignDateArea(dtCell.area) : null;
  647. // sign_date_areas
  648. // sCell.signature_name 草图不用加密
  649. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  650. let control = null;
  651. if (typeof sCell[JV.PROP_CONTROL] === "string") {
  652. control = controls[sCell[JV.PROP_CONTROL]];
  653. } else {
  654. control = sCell[JV.PROP_CONTROL];
  655. }
  656. let actSignArea = _getProperSignatureArea(sCell, control);
  657. _chkAndSetArea(sCell, actSignArea, signDateArea, i, 'signature_name');
  658. } else {
  659. let stampArea = _getStampArea(sCell);
  660. _chkAndSetArea(sCell, stampArea, signDateArea, i, 'signatureName'); // 注意:这里的判断不是signature_name(含dummy的),而是signatureName属性(之前的章信息设计导致)
  661. }
  662. }
  663. }
  664. return psInfo;
  665. },
  666. archiveCurrentReport: function (currentRptPageRst, currentNode, currentRolRel = ROLE_REL_LIST, cb) {
  667. let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
  668. // 1. 找草图路径
  669. if (!PAGE_SHOW.closeArchiveSignature) {
  670. for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
  671. // 每页
  672. for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
  673. let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
  674. // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
  675. if (sCell.signature_name.indexOf('dummy_pic') >= 0) {
  676. //1. 草图就不考虑重复问题,重复就重复吧;
  677. //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
  678. let picIdx = picKeys.indexOf(sCell.path);
  679. if (picIdx < 0) {
  680. picKeys.push(sCell.path);
  681. picCells.push(sCell);
  682. } else {
  683. let dPicIdx = dupPicPath.indexOf(sCell.path);
  684. if (dPicIdx < 0) {
  685. dupPicPath.push(sCell.path);
  686. dupPicCell.push([]);
  687. dPicIdx = dupPicPath.length - 1;
  688. }
  689. dupPicCell[dPicIdx].push(sCell);
  690. }
  691. }
  692. }
  693. }
  694. }
  695. // 2. 下载草图,下载完毕后upload
  696. if (picCells.length > 0) {
  697. $.bootstrapLoading.start();
  698. let picAmt = picCells.length, picCnt = 0;
  699. let exceptionAmt = 0;
  700. for (let idx = 0; idx < picCells.length; idx++) {
  701. let dCell = picCells[idx];
  702. getBlob(picKeys[idx]).then(blob => {
  703. if (blob === 'not found!') {
  704. exceptionAmt++;
  705. if ((picCnt + exceptionAmt) === picAmt) {
  706. $.bootstrapLoading.end();
  707. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, currentRolRel, cb);
  708. }
  709. } else {
  710. let oFileReader = new FileReader();
  711. oFileReader.onloadend = function (e) {
  712. picCnt++;
  713. let base64 = e.target.result;
  714. picCells[idx].pic = base64;
  715. let pPathIdx = dupPicPath.indexOf(dCell.path);
  716. if (pPathIdx >= 0) {
  717. for (let dupCell of dupPicCell[pPathIdx]) {
  718. dupCell.pic = base64;
  719. }
  720. }
  721. if ((picCnt + exceptionAmt) === picAmt) {
  722. $.bootstrapLoading.end();
  723. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, currentRolRel, cb);
  724. }
  725. };
  726. oFileReader.readAsDataURL(blob);
  727. }
  728. });
  729. }
  730. } else {
  731. rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, currentRolRel, cb);
  732. }
  733. },
  734. _getBusinessId: function() {
  735. let rst = '-1';
  736. switch (current_stage_id) {
  737. case -300: // 变更令
  738. rst = encodeURIComponent(CHANGE_ID);
  739. break;
  740. case -301: // 变更方案
  741. case -302: // 变更立项
  742. case -303: // 变更申请
  743. rst = BUSINESS_ID;
  744. break;
  745. case -400:
  746. rst = current_advance_id; // 预付款
  747. break;
  748. case -500:
  749. rst = current_material_id; // 材差
  750. break;
  751. default:
  752. break;
  753. }
  754. return rst;
  755. },
  756. _archiveCurrentReport: function(currentRptPageRst, currentNode, currentRolRel, cb) {
  757. // 归档当前报表
  758. const bzId = rptArchiveObj._getBusinessId();
  759. const _prepareEncryptionParam = function(result, pageEncryptInfo) {
  760. const params = {};
  761. params.prjId = PROJECT_ID;
  762. params.stgId = current_stage_id;
  763. params.tenderId = TENDER_ID;
  764. params.businessId = bzId;
  765. params.rptId = currentNode.refId;
  766. params.ttlPgs = currentRptPageRst.items.length;
  767. params.content = pageEncryptInfo;
  768. params.uuid = result.uuid; //正确返回时,带着uuid回来
  769. params.childUuids = result.childUuids; //还有子uuid
  770. params.splitArcPages = currentRptPageRst.splitArcPages ? currentRptPageRst.splitArcPages : [];
  771. // params.splitArcPagesInfo = currentRptPageRst.splitArcPagesInfo ? currentRptPageRst.splitArcPagesInfo : {};
  772. params.reportName = currentNode.name;
  773. return params;
  774. };
  775. const _prepareArchiveUrl = function(archiveOprStr, suffix) {
  776. let rst = `/tender/report_api/${archiveOprStr}/${PROJECT_ID}/${current_stage_id}/${bzId}/${TENDER_ID}/${currentNode.refId}${suffix}`;
  777. if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
  778. rst = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${TENDER_ID}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`;
  779. }
  780. return rst;
  781. }
  782. if (currentRptPageRst !== null) {
  783. try {
  784. let signCells = [];
  785. let txtSignCells = [];
  786. let dummyTxtSignCells = [];
  787. const restoreCells = (srcCells, targetCellsStr) => {
  788. if (srcCells.length > 0) {
  789. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  790. srcCells[pageIdx].forEach((srcCell) => {
  791. pageItem[targetCellsStr].push(srcCell);
  792. });
  793. srcCells[pageIdx] = null;
  794. });
  795. }
  796. };
  797. if (PAGE_SHOW.isTextSignature) {
  798. // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
  799. // 批量归档的数据后台会处理(已经移除相关签名)
  800. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  801. const dtlSignCells = [];
  802. signCells.push(dtlSignCells);
  803. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  804. let sCell = pageItem.signature_cells[sCellIdx];
  805. if (sCell.signature_name.indexOf('dummy_pic') < 0) {
  806. dtlSignCells.push(sCell);
  807. pageItem.signature_cells.splice(sCellIdx, 1);
  808. if (PAGE_SHOW.closeArchiveSignature) {
  809. // 如果还有closeArchiveSignature标记,那么不显示文本文档(只是清除匹配cell的Value,后续需要恢复)
  810. const cCell = pageItem.cells.find(cell => cell.area.Left === sCell.area.Left && cell.area.Top === sCell.area.Top && cell.Value === sCell.Value);
  811. if (cCell) {
  812. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  813. cCell.Value = '';
  814. }
  815. }
  816. } else if (PAGE_SHOW.closeArchiveSignature) {
  817. // 这个跟上面的判断属性不同,是orgArea(签章的)
  818. for (let cIdx = pageItem.cells.length - 1; cIdx >= 0; cIdx--) {
  819. const cCell = pageItem.cells[cIdx];
  820. if (cCell.area.Left === sCell.orgArea.Left && cCell.area.Right === sCell.orgArea.Right &&
  821. cCell.area.Top === sCell.orgArea.Top && cCell.area.Bottom === sCell.orgArea.Bottom &&
  822. cCell.Value !== '') {
  823. txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
  824. cCell.Value = '';
  825. break;
  826. }
  827. }
  828. }
  829. }
  830. });
  831. } else if (PAGE_SHOW.closeArchiveSignature) {
  832. // 这里还有一个场景需要考虑:签名是图片且选择了签名,又不归档输出,
  833. const rrSigns = [];
  834. currentRolRel.forEach(role_rel => {
  835. if (role_rel.sign_output && role_rel.sign_output.includes(NORMAL_SIGN_STR)) {
  836. rrSigns.push(role_rel.signature_name);
  837. }
  838. });
  839. if (rrSigns.length > 0) {
  840. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  841. const dtlSignCells = [];
  842. const dtlDummyCells = [];
  843. signCells.push(dtlSignCells);
  844. dummyTxtSignCells.push(dtlDummyCells);
  845. for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
  846. let sCell = pageItem.signature_cells[sCellIdx];
  847. if (rrSigns.includes(sCell.signature_name)) {
  848. dtlSignCells.push(sCell);
  849. pageItem.signature_cells.splice(sCellIdx, 1);
  850. // 还得加一个dummy cell,处理边框用的
  851. const newCell = {
  852. font: 'Footer',
  853. control: sCell.control,
  854. style: sCell.style,
  855. Value: '',
  856. area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
  857. };
  858. dtlDummyCells.push(newCell);
  859. pageItem.cells.push(newCell);
  860. }
  861. }
  862. });
  863. }
  864. }
  865. const pageSize = rptControlObj.getCurrentPageSize();
  866. const relForArchive = PAGE_SHOW.closeArchiveSignature ? [] : currentRolRel;
  867. let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, pageSize, relForArchive, STAGE_AUDIT);
  868. restoreCells(signCells, 'signature_cells');
  869. signCells = null;
  870. txtSignCells.forEach(txtCellBkObj => {
  871. txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
  872. });
  873. txtSignCells = null;
  874. if (dummyTxtSignCells.length === currentRptPageRst.items.length) {
  875. currentRptPageRst.items.forEach((pageItem, pageIdx) => {
  876. dummyTxtSignCells[pageIdx].forEach((dummyCell) => {
  877. const idx = pageItem.cells.indexOf(dummyCell);
  878. if (idx >= 0) pageItem.cells.splice(idx, 1);
  879. });
  880. dummyTxtSignCells[pageIdx] = null;
  881. });
  882. dummyTxtSignCells = null;
  883. }
  884. let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, pageSize, currentNode.refId);
  885. // console.log(pageEncryptInfo);
  886. let formData = new FormData();
  887. formData.append('file', doc.output('blob'), 'upload.pdf');
  888. // formData.append('size', pFile.size);
  889. if (currentRptPageRst.splitArcPages) {
  890. let docs = JpcJsPDFHelper.getChildrenDocs(currentRptPageRst, rptControlObj.getCurrentPageSize(), currentRolRel, STAGE_AUDIT);
  891. for (let docIdx = 0; docIdx < docs.length; docIdx++) {
  892. let file = docs[docIdx].output('blob');
  893. formData.append('file', file, `upload_child_${docIdx}.pdf`);
  894. }
  895. }
  896. if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
  897. const archiveUrl = _prepareArchiveUrl('addArchive', '');
  898. postDataWithFile(archiveUrl, formData, function (result) {
  899. // 成功后,更新当前页面
  900. //*
  901. if (result.updatedRst) {
  902. // console.log(result);
  903. ARCHIVE_LIST = result.updatedRst;
  904. rptArchiveObj.showArchivedItem(currentNode);
  905. zTreeOprObj.refreshNodes();
  906. //第二步:增加加密信息
  907. let params = _prepareEncryptionParam(result, pageEncryptInfo);
  908. CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  909. function(rst){
  910. if (cb) {
  911. cb(null, 'add archive encryption succeed!', params.uuid);
  912. }
  913. }, function(err){
  914. if (cb) {
  915. cb('err', 'add archive encryption err!', params.uuid);
  916. }
  917. }, function(ex){
  918. if (cb) {
  919. cb('err', 'add archive encryption err!', params.uuid);
  920. }
  921. }
  922. );
  923. } else {
  924. // 有冲突,需要删除
  925. CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken_j'),
  926. function(result){
  927. if (cb) {
  928. cb('err', 'add archive conflict!', null);
  929. }
  930. }
  931. );
  932. }
  933. //*/
  934. }, function (error){
  935. if (cb) {
  936. cb('err', 'add archive err!', null);
  937. }
  938. });
  939. } else {
  940. let aItem = this._getCurrentArchives(currentNode);
  941. if (aItem && aItem.items && aItem.items.length > 0) {
  942. let orgName = aItem.items[0].uuid;
  943. let compStr = aItem.items[0].updateDate_time;
  944. for (let idx = 1; idx < aItem.items.length; idx++) {
  945. if (aItem.items[idx].updateDate_time < compStr) {
  946. compStr = aItem.items[idx].updateDate_time;
  947. orgName = aItem.items[idx].uuid;
  948. }
  949. }
  950. const archiveUrl = _prepareArchiveUrl('updateArchive', `/${orgName}`);
  951. postDataWithFile(archiveUrl, formData, function (result) {
  952. // 成功后,更新当前页面
  953. if (result.updatedRst) {
  954. // console.log(result);
  955. ARCHIVE_LIST = result.updatedRst;
  956. rptArchiveObj.showArchivedItem(currentNode);
  957. zTreeOprObj.refreshNodes();
  958. //第二步:更新加密信息
  959. // let params = {};
  960. let params = _prepareEncryptionParam(result, pageEncryptInfo);
  961. CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
  962. function(result){
  963. if (cb) {
  964. cb(null, 'update archive succeed!', params.uuid);
  965. }
  966. }, function(err){
  967. if (cb) {
  968. cb('err', 'update archive err!', params.uuid);
  969. }
  970. }, function(ex){
  971. if (cb) {
  972. cb('err', 'update archive err!', params.uuid);
  973. }
  974. }
  975. );
  976. } else {
  977. // 有冲突,需要删除
  978. CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken'),
  979. function(result){
  980. if (cb) {
  981. cb('err', 'update archive conflict!', null);
  982. }
  983. }
  984. );
  985. }
  986. }, function (error){
  987. // alert(error);
  988. if (cb) {
  989. cb('err', 'update archive conflict!', null);
  990. }
  991. });
  992. }
  993. }
  994. } catch (ex) {
  995. console.log(ex);
  996. console.log(ex.toString());
  997. if (cb) {
  998. cb('err', 'has exception!', null);
  999. }
  1000. }
  1001. } else {
  1002. alert('请选择打开一个报表!');
  1003. }
  1004. },
  1005. _getOneValidLeafNode: function(node) {
  1006. let rst = null;
  1007. let me = rptArchiveObj;
  1008. if (node) {
  1009. const preNode = node.getPreNode();
  1010. if (preNode) {
  1011. rst = preNode;
  1012. } else {
  1013. const nodes = me.treeObj.getNodes();
  1014. for (let dtlNode of nodes) {
  1015. if (dtlNode !== node && dtlNode.nodeType === 2) {
  1016. rst = dtlNode;
  1017. break;
  1018. }
  1019. }
  1020. }
  1021. }
  1022. return rst;
  1023. },
  1024. removeArchive: function() {
  1025. // 这个是从'归档报表'界面进来的
  1026. let me = rptArchiveObj;
  1027. const bkRefId = parseInt(me.currentNode.refId);
  1028. const bkUuid = me.currentArchiveUuid;
  1029. if (me.currentNode && me.currentArchiveUuid) {
  1030. const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${rptArchiveObj._getBusinessId()}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
  1031. CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
  1032. function(result){
  1033. // console.log(result.data);
  1034. let hasRemovedAll = false;
  1035. for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
  1036. if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
  1037. for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
  1038. if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
  1039. ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
  1040. break;
  1041. }
  1042. }
  1043. if (ARCHIVE_LIST[idx].items.length === 0) {
  1044. ARCHIVE_LIST.splice(idx, 0);
  1045. hasRemovedAll = true;
  1046. break;
  1047. }
  1048. }
  1049. }
  1050. //要刷新当前归档
  1051. if (hasRemovedAll) {
  1052. const validNode = me._getOneValidLeafNode(me.currentNode);
  1053. // me.iniPage();
  1054. me.treeObj.removeNode(me.currentNode);
  1055. if (validNode) {
  1056. me.currentNode = validNode;
  1057. me.onClick(null, null, me.currentNode);
  1058. me.treeObj.selectNode(me.currentNode, false);
  1059. me._iniArchiveItemForDeleteShow();
  1060. }
  1061. } else {
  1062. me.currentArchiveUuid = null;
  1063. me.currentArchiveDateStr = null;
  1064. me.currentArchivePdfPath = null;
  1065. me.onClick(null, null, me.currentNode);
  1066. }
  1067. }
  1068. );
  1069. }
  1070. }
  1071. };
  1072. function getAdvanceType2() {
  1073. return current_advance_type !== -1 ? ('tplType_prePay' + (current_advance_type + 1)) : '';
  1074. }
  1075. /**
  1076. * 获取 blob
  1077. * @param {String} url 目标文件地址
  1078. * @return {Promise}
  1079. */
  1080. function getBlob(url) {
  1081. return new Promise(resolve => {
  1082. const xhr = new XMLHttpRequest();
  1083. // let fullUrl = url + '?x-oss-process=image/info';
  1084. xhr.open('GET', url, true);
  1085. xhr.responseType = 'blob';
  1086. xhr.onload = () => {
  1087. if (xhr.status === 200) {
  1088. resolve(xhr.response);
  1089. } else {
  1090. resolve('not found!');
  1091. }
  1092. };
  1093. xhr.send();
  1094. });
  1095. }
  1096. /**
  1097. * pdf base64 转 blob
  1098. * @param {String} dataUrl base64码
  1099. * @return {Promise}
  1100. */
  1101. function convertBase64UrlToBlob(dataUrl) {
  1102. //去掉url的头,并转换为byte
  1103. var bytes = window.atob(dataUrl);
  1104. //处理异常,将ascii码小于0的转换为大于0
  1105. var ab = new Uint8Array(bytes.length);
  1106. for (var i = 0; i < bytes.length; i++) {
  1107. ab[i] = bytes.charCodeAt(i);
  1108. }
  1109. return new Blob([ab], { type: 'application/pdf' });
  1110. }
  1111. /**
  1112. * 保存
  1113. * @param {Blob} blob
  1114. * @param {String} filename 想要保存的文件名称
  1115. */
  1116. function saveAs(blob, filename) {
  1117. if (window.navigator.msSaveOrOpenBlob) {
  1118. navigator.msSaveBlob(blob, filename);
  1119. } else {
  1120. const link = document.createElement('a');
  1121. const body = document.querySelector('body');
  1122. link.href = window.URL.createObjectURL(blob);
  1123. link.download = filename;
  1124. // fix Firefox
  1125. link.style.display = 'none';
  1126. body.appendChild(link);
  1127. link.click();
  1128. body.removeChild(link);
  1129. window.URL.revokeObjectURL(link.href);
  1130. }
  1131. }
  1132. /**
  1133. * 下载
  1134. * @param {String} url 目标文件地址
  1135. * @param {String} filename 想要保存的文件名称
  1136. */
  1137. function download(url, filename) {
  1138. getBlob(url).then(blob => {
  1139. saveAs(blob, filename);
  1140. });
  1141. }
  1142. $(function () {
  1143. $('#download_file').click(function () {
  1144. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1145. console.log(rptArchiveObj.currentArchivePdfPath);
  1146. download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
  1147. } else {
  1148. alert('请选择打开一个报表!');
  1149. }
  1150. });
  1151. $('#print_file').click(function () {
  1152. if (rptArchiveObj.currentArchiveUuid) {
  1153. $('#iframe_made iframe')[0].contentWindow.print();
  1154. } else {
  1155. alert('请选择打开一个报表!');
  1156. }
  1157. });
  1158. $('#delete_file').click(function () {
  1159. if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
  1160. console.log(rptArchiveObj.currentArchivePdfPath);
  1161. rptArchiveObj.removeArchive();
  1162. } else {
  1163. alert('请选择打开一个报表!');
  1164. }
  1165. });
  1166. })