1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156 |
- /**
- * Created by Tony on 2021/4/2.
- */
- const A4_PIXEL_HEIGHT = 1122;
- const A4_PIXEL_WIDTH = 793;
- const A3_PIXEL_HEIGHT = 1586;
- const A3_PIXEL_WIDTH = A4_PIXEL_HEIGHT;
- let rptArchiveObj = {
- treeObj: null,
- currentNode: null,
- currentArchiveUuid: null,
- currentChildArchiveUuids: null,
- currentArchiveDateStr: null,
- currentEncryptionList: null,
- currentArchivePdfPath: null,
- iniPage: function() {
- //初始化页面的归档信息
- let me = rptArchiveObj;
- me.currentNode = null;
- me.currentArchiveUuid = null;
- me.currentChildArchiveUuids = null;
- me.currentArchiveDateStr = null;
- me.currentEncryptionList = null;
- me.currentArchivePdfPath = null;
- const archivedRptIds = [];
- for (let aItem of ARCHIVE_LIST) {
- archivedRptIds.push(parseInt(aItem.rpt_id));
- }
- const _chkIfShouldFilter = function(rptItem, currentRptType = 'normal') {
- let rst = (!(rptItem.released) && rptItem.nodeType === 2 || rptItem.hidden); //未发布判断 或 故意隐藏
- if (!rst) {
- // 根据当前业务类型判断及检测其他非同类报表,如动态决算类型、支付审批类型
- switch(currentRptType) {
- case 'normal':
- // 检测:预付款
- if (CURRENT_SELECTED_BIZ_TYPE && CURRENT_SELECTED_BIZ_TYPE === 'change_prepay' && rptItem.nodeType === 2) {
- rst = true;
- if (rptItem.flags && rptItem.flags.rptTplType) {
- if (current_advance_id > 0) {
- rst = !((rptItem.flags.rptTplType || '') === getAdvanceType2());
- }
- }
- }
- break;
- case 'juesuan':
- break;
- case 'zhifushenpi':
- break;
- default:
- break;
- }
- }
- return rst;
- };
- let private_remove_hide_item = function (items, nlv) {
- if (items && items.length > 0) {
- for (let i = items.length - 1; i >= 0; i--) {
- // if (!(items[i].released) && items[i].nodeType === 2) {
- // if (archivedRptIds.indexOf(items[i].refId) < 0) {
- // // 备注:这里还要再判断是否存在已经归档的报表,如果有,需要保留。否则才真正剔除
- // items.splice(i, 1);
- // }
- // } else {
- if (_chkIfShouldFilter(items[i])) {
- if (archivedRptIds.indexOf(items[i].refId) < 0) {
- // 备注:这里还要再判断是否存在已经归档的报表,如果有,需要保留。否则才真正剔除
- items.splice(i, 1);
- }
- } else {
- if (items[i].items && items[i].items.length > 0) {
- private_remove_hide_item(items[i].items, nlv + 1);
- if (items[i].items.length === 0 && nlv > 0) {
- items.splice(i, 1);
- }
- }
- }
- }
- }
- };
- const private_remove_un_archive_item = function(items, nlv) {
- if (items && items.length > 0) {
- for (let i = items.length - 1; i >= 0; i--) {
- if (items[i].nodeType === 2) {
- if (archivedRptIds.indexOf(items[i].refId) < 0) {
- items.splice(i, 1);
- }
- } else {
- if (items[i].items && items[i].items.length > 0) {
- private_remove_un_archive_item(items[i].items, nlv + 1);
- if (items[i].items.length === 0 && nlv > 0) {
- items.splice(i, 1);
- }
- } else {
- //items[i]是目录,但又没有items子项,
- items.splice(i, 1);
- }
- }
- }
- }
- };
- let nodeLv = 0;
- private_remove_hide_item(TOP_TREE_NODES, nodeLv);
- private_remove_un_archive_item(TOP_TREE_NODES, nodeLv);
- zTreeHelper.createTreeDirectly(TOP_TREE_NODES, rpt_prj_folder_setting, "rptTplTree", me);
- me.treeObj.expandAll(true);
- me.refreshNodes();
- $('#iframe_made').html('<iframe src="/archive/pdf/show" class="border-0" height="100%" width="100%"></iframe>');
- rptArchiveObj._countChkedRptTpl();
- rptArchiveObj._buildeArchiveDateSelect();
- rptArchiveObj._iniArchiveItemForDeleteShow();
- rptArchiveObj._iniArchiveItemForDeleteShow();
- },
- toggleBtn: function (enabled) {
- if (getStageStatus() === 3 && enabled) {
- $('#btnArchiveRpt').removeAttr('disabled');
- $('#btnArchiveList').removeAttr('disabled');
- $('#btnBatchArchiveRpt').removeAttr('disabled');
- } else {
- $('#btnArchiveRpt').attr('disabled', '');
- $('#btnArchiveList').attr('disabled', '');
- $('#btnBatchArchiveRpt').attr('disabled', '');
- }
- },
- refreshNodes: function() {
- let me = this;
- let private_setupIsParent = function(node){
- node.isParent = (node.nodeType === RT.NodeType.NODE || node.level === 0);
- if (node.items && node.items.length) {
- for (let i = 0; i < node.items.length; i++) {
- private_setupIsParent(node.items[i]);
- }
- }
- };
- let topNodes = me.treeObj.getNodes();
- for (let i = 0; i < topNodes.length; i++) {
- private_setupIsParent(topNodes[i]);
- }
- me.treeObj.refresh();
- },
- onCheck: function(event, treeId, treeNode) {
- rptArchiveObj._countChkedRptTpl();
- if (treeNode.isParent) {
- rptArchiveObj.treeObj.expandNode(treeNode, true, true, false);
- }
- },
- onClick: function(event,treeId,treeNode) {
- let me = rptArchiveObj;
- if (treeNode && treeNode.nodeType === TPL_TYPE_TEMPLATE && treeNode.refId > 0) {
- me.currentNode = treeNode;
- for (let aItem of ARCHIVE_LIST) {
- if (treeNode.refId === parseInt(aItem.rpt_id)) {
- me.currentArchiveUuid = null;
- me.currentArchiveDateStr = null;
- me.currentArchivePdfPath = null;
- if (aItem.items && aItem.items.length > 0) {
- // me.currentArchiveUuid = aItem.items[0].uuid;
- // me.currentArchiveDateStr = aItem.items[0].updateDate_time;
- const newItems = _.orderBy(aItem.items, ['updateDate_time'], ['desc']);
- me.currentArchiveUuid = newItems[0].uuid;
- me.currentChildArchiveUuids = newItems[0].childUuids;
- me.currentArchiveDateStr = '#' + (_.findIndex(aItem.items, { updateDate_time: newItems[0].updateDate_time})+1) + ' ' + newItems[0].updateDate_time;
- if (can_netcasign) {
- for (const [i,item] of aItem.items.entries()) {
- if (_.find(signLogList, { uuid: item.uuid })) {
- me.currentArchiveUuid = item.uuid;
- me.currentChildArchiveUuids = item.childUuids;
- me.currentArchiveDateStr = '#' + (i+1) + ' ' + item.updateDate_time;
- break;
- }
- }
- }
- }
- break;
- }
- }
- me._countChkedRptTpl();
- me._buildeArchiveDateSelect();
- me._requestArchiveReport();
- rptArchiveObj._iniArchiveItemForDeleteShow();
- }
- },
- batchArchive: function() {
- if (zTreeOprObj.checkedRptTplNodes && zTreeOprObj.checkedRptTplNodes.length > 0) {
- if (zTreeOprObj.checkedRptTplNodes.length <= 10) {
- indexDbOprObj.storeReportRequest(current_stage_id, zTreeOprObj.checkedRptTplNodes, true, indexDbOprObj.startRequestReport);
- } else {
- alert('批量归档上限为10,请勾选10张以内');
- }
- }
- },
- _requestArchiveReport: function () {
- let me = rptArchiveObj;
- if (me.currentNode && me.currentArchiveUuid) {
- try {
- if (can_netcasign) {
- let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
- if (!msgSign) {
- msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
- }
- console.log(current_stage_id, msgSign, me.currentArchiveUuid);
- me.currentEncryptionList = msgSign;
- const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
- let html = '';
- let pagetr = '';
- if (msgSign) {
- const rows = 12/msgSign.encryption.length < 3 ? 'col-3' : 'col-' + 12/msgSign.encryption.length;
- for (const [index,role] of msgSign.encryption.entries()) {
- const disablehtml = _.find(uSignLogList, { role: role.name }) ? ' disabled' : '';
- html += '<div class="'+ rows +'">\n' +
- ' <div class="custom-control custom-radio custom-control-inline">\n' +
- ' <input type="radio" value="'+ index +'" id="sign_role_'+ index +'"'+ disablehtml +' name="sign_role" class="custom-control-input">\n' +
- ' <label class="custom-control-label" for="sign_role_'+ index +'">'+ role.name +'</label>\n' +
- ' </div>\n' +
- ' </div>';
- }
- let uhtml = '';
- for (const us of uSignLogList) {
- uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
- }
- for (let i = 1; i <= msgSign.total_page; i++) {
- pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
- }
- }
- $('#dateStr').html(me.currentArchiveDateStr);
- $('#role-list').html(html);
- $('#page-list').html(pagetr);
- $('#sign_num').text(uSignLogList.length);
- const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
- // 是否显示撤销按钮
- if(uHadSign && uHadSign.length > 0) {
- $('#show-removesign-modal-btn').show();
- } else {
- $('#show-removesign-modal-btn').hide();
- }
- postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
- 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();
- $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
- }, function () {
- me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
- $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
- })
- } else {
- me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
- $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
- console.log(me.currentArchivePdfPath);
- }
- // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
- // console.log(uuIdUrl);
- // $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + oss_path + '/'+ me.currentArchiveUuid +'.PDF" height="750px" width="100%" style="border: none;"></iframe>');
- // NetcaPDFSeal.openPDFWithUrl(window.location.href);
- // window.location = uuIdUrl;
- } catch (ex) {
- console.log(ex.toString());
- }
- }
- },
- _setChildUuidsByCurUuid: () => {
- let me = rptArchiveObj;
- me.currentChildArchiveUuids = null;
- if (me.currentNode && me.currentArchiveUuid) {
- for (let aItem of ARCHIVE_LIST) {
- if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
- for (let [index,item] of aItem.items.entries()) {
- if (item.uuid === me.currentArchiveUuid) {
- me.currentChildArchiveUuids = item.childUuids;
- break;
- }
- }
- break;
- }
- }
- }
- },
- _changeArchiveDateSelect: function (dom, archiveIdx) {
- let me = rptArchiveObj;
- // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
- me.currentArchiveDateStr = dom.innerHTML;
- me._setChildUuidsByCurUuid();
- if(can_netcasign) {
- postData('/tender/'+ TENDER_ID +'/signReport/post', {type: 'pdfIsExist', uuid: me.currentArchiveUuid}, function (result) {
- const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
- 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();
- $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
- me._buildeArchiveDateSelect();
- }, function () {
- me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
- $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
- me._buildeArchiveDateSelect();
- });
- // me._updateSignHtmlAndFrame();
- me._requestArchiveReport();
- me._iniArchiveItemForDeleteShow();
- } else {
- me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime();
- $('#iframe_made').html('<iframe src="/archive/pdf/show?file=' + me.currentArchivePdfPath + '" height="100%" width="100%" style="border: none;"></iframe>');
- me._buildeArchiveDateSelect();
- me._iniArchiveItemForDeleteShow();
- }
- },
- _buildeArchiveDateSelect: function () {
- let me = rptArchiveObj;
- let targetDom = document.getElementById("currentDrpArchiveSelect");
- targetDom.innerHTML = me.currentArchiveDateStr;
- let drpDom = $("#drpArchiveSelect");
- drpDom.empty();
- if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
- for (let aItem of ARCHIVE_LIST) {
- if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
- for (let [index,item] of aItem.items.entries()) {
- if (item.uuid !== me.currentArchiveUuid) {
- const str = `<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = '${item.uuid}'; rptArchiveObj._changeArchiveDateSelect(this)">#${index+1} ${item.updateDate_time}</a>`
- drpDom.append(str);
- }
- }
- }
- }
- }
- },
- _updateSignHtmlAndFrame: function (needFrame = false) {
- const me = rptArchiveObj;
- const uSignLogList = _.filter(signLogList, { uuid: me.currentArchiveUuid });
- for (let i = 0; i < $('#role-list div').length; i++) {
- if (_.find(uSignLogList, { role: $('#role-list div').eq(i).find('label').text() })) {
- $('#role-list div').eq(i).find('input').attr('disabled', true);
- } else {
- $('#role-list div').eq(i).find('input').removeAttr('disabled');
- }
- $('#role-list div').eq(i).find('input').prop('checked', false);
- }
- let uhtml = '';
- let pagetr = '';
- let msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID, uuid: me.currentArchiveUuid});
- if (!msgSign) {
- msgSign = _.find(ARCHIVE_ENCRYPTION_LIST, {rpt_id: me.currentNode.ID});
- }
- for (const us of uSignLogList) {
- uhtml += '<span class="text-success"><i class="fa fa-check"></i> '+ us.role +'('+ us.name +')</span>';
- }
- for (let i = 1; i <= msgSign.total_page; i++) {
- pagetr += '<tr><td>页'+ i +'</td><td>'+ me.currentNode.name +'</td><td>'+ uhtml +'</td></tr>';
- }
- $('#page-list').html(pagetr);
- if (needFrame) {
- 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();
- $('#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>');
- }
- $('#dateStr').html(me.currentArchiveDateStr);
- $('#sign_num').text(uSignLogList.length);
- const uHadSign = _.filter(uSignLogList, { uid: USER_ID});
- // 是否显示撤销按钮
- if(uHadSign && uHadSign.length > 0) {
- $('#show-removesign-modal-btn').show();
- } else {
- $('#show-removesign-modal-btn').hide();
- }
- },
- _countChkedRptTpl: function () {
- let me = rptArchiveObj;
- $('#delete_archive_btn').attr('disabled', '');
- if (me.treeObj) {
- me.checkedRptTplNodes = [];
- let chkNodes = me.treeObj.getCheckedNodes(true), cnt = 0, hasCurrentNode = false;
- for (let node of chkNodes) {
- if (node.nodeType === TPL_TYPE_TEMPLATE) {
- cnt++;
- me.checkedRptTplNodes.push(node);
- if (me.currentNode === node) hasCurrentNode = true;
- }
- }
- if (!hasCurrentNode && cnt === 0 && me.currentNode !== null) {
- //这里根据实际需求再做处理
- cnt++;
- me.checkedRptTplNodes.push(me.currentNode);
- }
- $("#print_div").find("span").each(function(cIdx,elementSpan){
- elementSpan.innerText = cnt;
- });
- $("#export_div").find("span").each(function(cIdx,elementSpan){
- elementSpan.innerText = cnt;
- });
- if (cnt) {
- $('#delete_archive_btn').removeAttr('disabled');
- }
- }
- },
- _iniArchiveItemForDeleteShow: function() {
- let me = rptArchiveObj;
- const dispArchInfoBody = $('#disp_archive_info_body');
- dispArchInfoBody.empty();
- let targetDom = document.getElementById("currentDrpArchiveSelect");
- let firstStr = `<h6>确认删除本张【${targetDom.innerText}】归档报表?</h6>`;
- let secondStr = `<h6>删除后,数据无法恢复,请谨慎操作。</h6>`;
- dispArchInfoBody.append(firstStr);
- dispArchInfoBody.append(secondStr);
- },
- showArchivedItem: function(currentNode) {
- //初始化当前报表已经归档的信息
- //ARCHIVE_LIST结构:[{rpt_id, items: [{uuid, update_time, is_common}...最多3个]}...] (当前项目、当前期的所有报表归档信息)
- if (currentNode) {
- //1. cardArchiveInfo
- let cardArchiveInfo = $('#cardArchiveInfo');
- cardArchiveInfo.empty();
- let auditDate = null;
- let achivedAmt = 0;
- let achivedItem = null;
- for (let item of ARCHIVE_LIST) {
- if (parseInt(item.rpt_id) === currentNode.refId) {
- if (LAST_AUDITOR) {
- if (LAST_AUDITOR.end_time) {
- auditDate = new Date(LAST_AUDITOR.end_time);
- } else {
- auditDate = new Date(LAST_AUDITOR.begin_time);
- }
- } else {
- // 其他情况(如变更令相关)
- }
- achivedAmt = item.items?item.items.length:0;
- achivedItem = item;
- break;
- }
- }
- if (-400 === current_stage_id) {
- cardArchiveInfo.append('<h6>预付款 第' + current_advance_order + '期');
- cardArchiveInfo.append('<h6>本张报表第' + current_advance_order + '期,已归档' + achivedAmt + '份文件。</h6>');
- } else if (-500 === current_stage_id) {
- cardArchiveInfo.append('<h6>材料调差 第' + current_material_order + '期');
- cardArchiveInfo.append('<h6>本张报表第' + current_material_order + '期,已归档' + achivedAmt + '份文件。</h6>');
- } else if (STAGE_ID <= -300 && STAGE_ID > -400) {
- if (auditDate) {
- cardArchiveInfo.append('<h6>审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
- }
- cardArchiveInfo.append('<h6>已归档' + achivedAmt + '份文件。</h6>');
- } else {
- if (auditDate) {
- cardArchiveInfo.append('<h6>计量期 第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。</h6>');
- } else {
- cardArchiveInfo.append('<h6>计量期 第' + current_stage_order + '期');
- }
- cardArchiveInfo.append('<h6>本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。</h6>');
- }
- if (achivedItem && achivedItem.items && achivedItem.items.length === 3) {
- cardArchiveInfo.append('<h6>本次归档将会覆盖最旧那次归档。</h6>');
- }
- cardArchiveInfo.append('<div class="form-group" id="archived_frm_grp">');
- if (achivedAmt > 0) {
- for (let idx = 0; idx < achivedItem.items.length; idx++) {
- cardArchiveInfo.append('<div class="form-check">');
- // if (achivedAmt === 3) {
- // cardArchiveInfo.append('<input class="form-check-input" type="radio" name="exampleRadios" id="exampleRadios' + idx + '" value="option' + idx + '" ' + ((idx === 0)?'checked':'') + '>');
- // }
- cardArchiveInfo.append('<label class="form-check-label" for="exampleRadios' + idx + '">');
- // let ad = new Date(achivedItem.items[idx].update_time);
- // cardArchiveInfo.append('#' + (idx + 1) + ' ' + ad.getFullYear() + '-' + (ad.getMonth() + 1) + '-' + ad.getDate() + ' 归档');
- cardArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ' 归档');
- cardArchiveInfo.append('</label>');
- cardArchiveInfo.append('</div>');
- }
- }
- cardArchiveInfo.append('</div>');
- //2. selectionArchiveInfo
- let selectionArchiveInfo = $('#selectionArchiveInfo');
- selectionArchiveInfo.empty();
- if (achivedAmt > 0) {
- for (let idx = 0; idx < achivedItem.items.length; idx++) {
- selectionArchiveInfo.append('<a class="dropdown-item" href="javascript: void(0);">#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + '</a>');
- }
- }
- }
- },
- _getCurrentArchives: function (currentNode) {
- let rst = null;
- if (ARCHIVE_LIST.length > 0 && currentNode) {
- for (let aItem of ARCHIVE_LIST) {
- if (parseInt(aItem.rpt_id) === currentNode.refId) {
- rst = aItem;
- break;
- }
- }
- }
- return rst;
- },
- _chkIfFullArchives: function(currentNode) {
- let aItem = this._getCurrentArchives(currentNode);
- let rst = (aItem && aItem.items && aItem.items.length === 3);
- return rst;
- },
- _getPageSignatureInfo: function(pageData, pageSize, rpt_id) {
- // 因接口方是这样的单位:A4(297*210 -> pt 814.68 * 595.44),那么需要把像素转换成pt的系数,经过测试发现这个系数就是PDF_SCALE,不用再设置了
- let psInfo = [], psInfoStr = [];
- let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化
- let controls = pageData[JV.NODE_CONTROL_COLLECTION];
- let ptChkHeight = pageSize === 'A4' ? A4_PIXEL_HEIGHT : A3_PIXEL_HEIGHT;
- const signatureOrderObj = {};
- pageData.items[0].signature_cells.forEach(sCell => {
- if (sCell.hasOwnProperty('Order')) {
- signatureOrderObj[sCell.signature_name] = sCell.Order + 1;
- }
- });
- const _getAreasProperty = (srcArea) => {
- const width = (srcArea[JV.IDX_RIGHT] - srcArea[JV.IDX_LEFT]);
- const height = (srcArea[JV.IDX_BOTTOM] - srcArea[JV.IDX_TOP]);
- let rst = {
- Left: srcArea[JV.IDX_LEFT] + offsetX, Top: srcArea[JV.IDX_TOP] + offsetY, width, height,
- PtCenterX: +((srcArea[JV.IDX_LEFT] + offsetX + width / 2) * PDF_SCALE).toFixed(2),
- PtCenterY: +((ptChkHeight - (srcArea[JV.IDX_TOP] + offsetX + height / 2)) * PDF_SCALE).toFixed(2),
- PtWidth: +(width * PDF_SCALE).toFixed(2), PtHeight: +(height * PDF_SCALE).toFixed(2),
- pages: []
- };
- return rst;
- };
- const _getProperSignatureArea = function(cell, control) {
- // 约定默认长宽比例是2:1,图片分辨率是600*300
- const rst = [0, 0, 0, 0]; // left, top, right, bottom
- if (cell && cell[JV.PROP_AREA]) {
- let width = cell[JV.PROP_AREA][JV.PROP_RIGHT] - cell[JV.PROP_AREA][JV.PROP_LEFT],
- height = cell[JV.PROP_AREA][JV.PROP_BOTTOM] - cell[JV.PROP_AREA][JV.PROP_TOP];
- if (width > height * 2) {
- width = height * 2;
- } else {
- height = width / 2;
- }
- switch (control[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
- case 'left':
- rst[0] = cell[JV.PROP_AREA][JV.PROP_LEFT];
- rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
- rst[2] = rst[0] + width;
- rst[3] = rst[1] + height;
- break;
- case 'right':
- rst[2] = cell[JV.PROP_AREA][JV.PROP_RIGHT];
- rst[3] = cell[JV.PROP_AREA][JV.PROP_BOTTOM];
- rst[0] = rst[2] - width;
- rst[1] = rst[3] - height;
- break;
- default:
- //center
- rst[0] = (cell[JV.PROP_AREA][JV.PROP_LEFT] + cell[JV.PROP_AREA][JV.PROP_RIGHT] - width) / 2;
- rst[1] = cell[JV.PROP_AREA][JV.PROP_TOP];
- rst[2] = rst[0] + width;
- rst[3] = rst[1] + height;
- break;
- }
- }
- rst[0] = rst[0] + offsetX;
- rst[2] = rst[2] + offsetX;
- rst[1] = rst[1] + offsetY;
- rst[3] = rst[3] + offsetY;
- return rst;
- };
- const _getStampArea = (stampCell) => {
- const rst = [0, 0, 0, 0];
- if (stampCell && stampCell[JV.PROP_AREA]) {
- const left = Math.round(stampCell[JV.PROP_AREA][JV.PROP_LEFT]);
- const right = Math.round(stampCell[JV.PROP_AREA][JV.PROP_RIGHT]);
- const top = Math.round(stampCell[JV.PROP_AREA][JV.PROP_TOP]);
- const bottom = Math.round(stampCell[JV.PROP_AREA][JV.PROP_BOTTOM]);
- let width = right - left,
- height = bottom - top;
- rst[0] = left;
- rst[1] = top;
- rst[2] = rst[0] + width;
- rst[3] = rst[1] + height;
- }
- rst[0] = rst[0] + offsetX;
- rst[2] = rst[2] + offsetX;
- rst[1] = rst[1] + offsetY;
- rst[3] = rst[3] + offsetY;
- return rst;
- };
- const _areaKeyCache = {
- normal: 'areas',
- company_stamp: 'company_stamp_areas',
- private_stamp: 'private_stamp_areas'
- };
- const _chkAndSetArea = (sCell, actSignArea, pageIdx, signNameKey) => {
- let idx = psInfoStr.indexOf(sCell[signNameKey]);
- const signType = sCell.signType || 'normal';
- const areaKey = _areaKeyCache[signType] || 'areas';
- if (idx < 0) {
- psInfoStr.push(sCell[signNameKey]);
- let newPsInfo = {'name': sCell[signNameKey], areas: [], company_stamp_areas: [], private_stamp_areas: [], order: signatureOrderObj[sCell[signNameKey]]};
- const area = _getAreasProperty(actSignArea);
- area.pages.push(pageIdx + 1);
- newPsInfo[areaKey].push(area);
- psInfo.push(newPsInfo);
- } else {
- let hasArea = false;
- for (let areaItem of psInfo[idx][areaKey]) {
- if (areaItem.Left === actSignArea[JV.IDX_LEFT] + offsetX && areaItem.Top === actSignArea[JV.IDX_TOP] + offsetX &&
- areaItem.width === actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT] && areaItem.height === actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]) {
- areaItem.pages.push(pageIdx + 1);
- hasArea = true;
- break;
- }
- }
- if (!hasArea) {
- const area = _getAreasProperty(actSignArea);
- area.pages.push(pageIdx + 1);
- psInfo[idx][areaKey].push(area);
- }
- }
- };
- for(let i = 0; i < pageData.items.length; i++) {
- let page = pageData.items[i];
- if (i === 0) {
- let maxX = 0;
- let maxY = 0;
- page.cells.forEach(cell => {
- if (cell.area.Right > maxX) maxX = cell.area.Right;
- if (cell.area.Bottom > maxY) maxY = cell.area.Bottom;
- });
- if (maxX > maxY) ptChkHeight = pageSize === 'A4' ? A4_PIXEL_WIDTH : A3_PIXEL_WIDTH;
- }
- for (let sCell of page.signature_cells) {
- // sCell.signature_name 草图不用加密
- if (sCell.signature_name.indexOf('dummy_pic') < 0) {
- let control = null;
- if (typeof sCell[JV.PROP_CONTROL] === "string") {
- control = controls[sCell[JV.PROP_CONTROL]];
- } else {
- control = sCell[JV.PROP_CONTROL];
- }
- let actSignArea = _getProperSignatureArea(sCell, control);
- _chkAndSetArea(sCell, actSignArea, i, 'signature_name');
- } else {
- let stampArea = _getStampArea(sCell);
- _chkAndSetArea(sCell, stampArea, i, 'signatureName'); // 注意:这里的判断不是signature_name(含dummy的),而是signatureName属性(之前的章信息设计导致)
- }
- }
- }
- return psInfo;
- },
- archiveCurrentReport: function (currentRptPageRst, currentNode, currentRolRel = ROLE_REL_LIST, cb) {
- let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = [];
- // 1. 找草图路径
- if (!PAGE_SHOW.closeArchiveSignature) {
- for (let pageIdx = 0; pageIdx < currentRptPageRst.items.length; pageIdx++) {
- // 每页
- for (let sCellIdx = 0; sCellIdx < currentRptPageRst.items[pageIdx].signature_cells.length; sCellIdx++) {
- let sCell = currentRptPageRst.items[pageIdx].signature_cells[sCellIdx];
- // if (sCell.signature_name === 'dummy_pic' && sCell.path.indexOf('/sign') < 0) {
- if (sCell.signature_name.indexOf('dummy_pic') >= 0) {
- //1. 草图就不考虑重复问题,重复就重复吧;
- //2. 如果是dummy_pic,也不用判断是否为签名了,因为有其他的逻辑直接选择审核人,不经过签名过程,就当草图一样放过去了
- let picIdx = picKeys.indexOf(sCell.path);
- if (picIdx < 0) {
- picKeys.push(sCell.path);
- picCells.push(sCell);
- } else {
- let dPicIdx = dupPicPath.indexOf(sCell.path);
- if (dPicIdx < 0) {
- dupPicPath.push(sCell.path);
- dupPicCell.push([]);
- dPicIdx = dupPicPath.length - 1;
- }
- dupPicCell[dPicIdx].push(sCell);
- }
- }
- }
- }
- }
- // 2. 下载草图,下载完毕后upload
- if (picCells.length > 0) {
- $.bootstrapLoading.start();
- let picAmt = picCells.length, picCnt = 0;
- let exceptionAmt = 0;
- for (let idx = 0; idx < picCells.length; idx++) {
- let dCell = picCells[idx];
- getBlob(picKeys[idx]).then(blob => {
- if (blob === 'not found!') {
- exceptionAmt++;
- if ((picCnt + exceptionAmt) === picAmt) {
- $.bootstrapLoading.end();
- rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, currentRolRel, cb);
- }
- } else {
- let oFileReader = new FileReader();
- oFileReader.onloadend = function (e) {
- picCnt++;
- let base64 = e.target.result;
- picCells[idx].pic = base64;
- let pPathIdx = dupPicPath.indexOf(dCell.path);
- if (pPathIdx >= 0) {
- for (let dupCell of dupPicCell[pPathIdx]) {
- dupCell.pic = base64;
- }
- }
- if ((picCnt + exceptionAmt) === picAmt) {
- $.bootstrapLoading.end();
- rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, currentRolRel, cb);
- }
- };
- oFileReader.readAsDataURL(blob);
- }
- });
- }
- } else {
- rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, currentRolRel, cb);
- }
- },
- _getBusinessId: function() {
- let rst = '-1';
- switch (current_stage_id) {
- case -300: // 变更令
- rst = encodeURIComponent(CHANGE_ID);
- break;
- case -301: // 变更方案
- case -302: // 变更立项
- case -303: // 变更申请
- rst = BUSINESS_ID;
- break;
- case -400:
- rst = current_advance_id; // 预付款
- break;
- case -500:
- rst = current_material_id; // 材差
- break;
- default:
- break;
- }
- return rst;
- },
- _archiveCurrentReport: function(currentRptPageRst, currentNode, currentRolRel, cb) {
- // 归档当前报表
- const bzId = rptArchiveObj._getBusinessId();
- const _prepareEncryptionParam = function(result, pageEncryptInfo) {
- const params = {};
- params.prjId = PROJECT_ID;
- params.stgId = current_stage_id;
- params.tenderId = TENDER_ID;
- params.businessId = bzId;
- params.rptId = currentNode.refId;
- params.ttlPgs = currentRptPageRst.items.length;
- params.content = pageEncryptInfo;
- params.uuid = result.uuid; //正确返回时,带着uuid回来
- params.childUuids = result.childUuids; //还有子uuid
- params.splitArcPages = currentRptPageRst.splitArcPages ? currentRptPageRst.splitArcPages : [];
- // params.splitArcPagesInfo = currentRptPageRst.splitArcPagesInfo ? currentRptPageRst.splitArcPagesInfo : {};
- params.reportName = currentNode.name;
- return params;
- };
- const _prepareArchiveUrl = function(archiveOprStr, suffix) {
- let rst = `/tender/report_api/${archiveOprStr}/${PROJECT_ID}/${current_stage_id}/${bzId}/${TENDER_ID}/${currentNode.refId}${suffix}`;
- if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) {
- 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}`;
- }
- return rst;
- }
- if (currentRptPageRst !== null) {
- try {
- let signCells = [];
- let txtSignCells = [];
- let dummyTxtSignCells = [];
- const restoreCells = (srcCells, targetCellsStr) => {
- if (srcCells.length > 0) {
- currentRptPageRst.items.forEach((pageItem, pageIdx) => {
- srcCells[pageIdx].forEach((srcCell) => {
- pageItem[targetCellsStr].push(srcCell);
- });
- srcCells[pageIdx] = null;
- });
- }
- };
- if (PAGE_SHOW.isTextSignature) {
- // 如果是显示文本签名,需要把相关签名移除(草图不动),等创建完后再加回来
- // 批量归档的数据后台会处理(已经移除相关签名)
- currentRptPageRst.items.forEach((pageItem, pageIdx) => {
- const dtlSignCells = [];
- signCells.push(dtlSignCells);
- for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
- let sCell = pageItem.signature_cells[sCellIdx];
- if (sCell.signature_name.indexOf('dummy_pic') < 0) {
- dtlSignCells.push(sCell);
- pageItem.signature_cells.splice(sCellIdx, 1);
- if (PAGE_SHOW.closeArchiveSignature) {
- // 如果还有closeArchiveSignature标记,那么不显示文本文档(只是清除匹配cell的Value,后续需要恢复)
- const cCell = pageItem.cells.find(cell => cell.area.Left === sCell.area.Left && cell.area.Top === sCell.area.Top && cell.Value === sCell.Value);
- if (cCell) {
- txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
- cCell.Value = '';
- }
- }
- } else if (PAGE_SHOW.closeArchiveSignature) {
- // 这个跟上面的判断属性不同,是orgArea(签章的)
- for (let cIdx = pageItem.cells.length - 1; cIdx >= 0; cIdx--) {
- const cCell = pageItem.cells[cIdx];
- if (cCell.area.Left === sCell.orgArea.Left && cCell.area.Right === sCell.orgArea.Right &&
- cCell.area.Top === sCell.orgArea.Top && cCell.area.Bottom === sCell.orgArea.Bottom &&
- cCell.Value !== '') {
- txtSignCells.push({bkCell: cCell, bkValue: cCell.Value});
- cCell.Value = '';
- break;
- }
- }
- }
- }
- });
- } else if (PAGE_SHOW.closeArchiveSignature) {
- // 这里还有一个场景需要考虑:签名是图片且选择了签名,又不归档输出,
- const rrSigns = [];
- currentRolRel.forEach(role_rel => {
- if (role_rel.sign_output && role_rel.sign_output.includes(NORMAL_SIGN_STR)) {
- rrSigns.push(role_rel.signature_name);
- }
- });
- if (rrSigns.length > 0) {
- currentRptPageRst.items.forEach((pageItem, pageIdx) => {
- const dtlSignCells = [];
- const dtlDummyCells = [];
- signCells.push(dtlSignCells);
- dummyTxtSignCells.push(dtlDummyCells);
- for (let sCellIdx = pageItem.signature_cells.length - 1; sCellIdx >= 0; sCellIdx--) {
- let sCell = pageItem.signature_cells[sCellIdx];
- if (rrSigns.includes(sCell.signature_name)) {
- dtlSignCells.push(sCell);
- pageItem.signature_cells.splice(sCellIdx, 1);
- // 还得加一个dummy cell,处理边框用的
- const newCell = {
- font: 'Footer',
- control: sCell.control,
- style: sCell.style,
- Value: '',
- area: { Left: sCell.area.Left, Right: sCell.area.Right, Top: sCell.area.Top, Bottom: sCell.area.Bottom },
- };
- dtlDummyCells.push(newCell);
- pageItem.cells.push(newCell);
- }
- }
- });
- }
- }
- const pageSize = rptControlObj.getCurrentPageSize();
- const relForArchive = PAGE_SHOW.closeArchiveSignature ? [] : currentRolRel;
- let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, pageSize, relForArchive, STAGE_AUDIT);
- restoreCells(signCells, 'signature_cells');
- signCells = null;
- txtSignCells.forEach(txtCellBkObj => {
- txtCellBkObj.bkCell.Value = txtCellBkObj.bkValue;
- });
- txtSignCells = null;
- if (dummyTxtSignCells.length === currentRptPageRst.items.length) {
- currentRptPageRst.items.forEach((pageItem, pageIdx) => {
- dummyTxtSignCells[pageIdx].forEach((dummyCell) => {
- const idx = pageItem.cells.indexOf(dummyCell);
- if (idx >= 0) pageItem.cells.splice(idx, 1);
- });
- dummyTxtSignCells[pageIdx] = null;
- });
- dummyTxtSignCells = null;
- }
- let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, pageSize, currentNode.refId);
- // console.log(pageEncryptInfo);
- let formData = new FormData();
- formData.append('file', doc.output('blob'), 'upload.pdf');
- // formData.append('size', pFile.size);
- if (currentRptPageRst.splitArcPages) {
- let docs = JpcJsPDFHelper.getChildrenDocs(currentRptPageRst, rptControlObj.getCurrentPageSize(), currentRolRel, STAGE_AUDIT);
- for (let docIdx = 0; docIdx < docs.length; docIdx++) {
- let file = docs[docIdx].output('blob');
- formData.append('file', file, `upload_child_${docIdx}.pdf`);
- }
- }
- if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
- const archiveUrl = _prepareArchiveUrl('addArchive', '');
- postDataWithFile(archiveUrl, formData, function (result) {
- // 成功后,更新当前页面
- //*
- if (result.updatedRst) {
- // console.log(result);
- ARCHIVE_LIST = result.updatedRst;
- rptArchiveObj.showArchivedItem(currentNode);
- zTreeOprObj.refreshNodes();
- //第二步:增加加密信息
- let params = _prepareEncryptionParam(result, pageEncryptInfo);
- CommonAjax.postXsrfEx("/tender/report_api/addArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
- function(rst){
- if (cb) {
- cb(null, 'add archive encryption succeed!', params.uuid);
- }
- }, function(err){
- if (cb) {
- cb('err', 'add archive encryption err!', params.uuid);
- }
- }, function(ex){
- if (cb) {
- cb('err', 'add archive encryption err!', params.uuid);
- }
- }
- );
- } else {
- // 有冲突,需要删除
- CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken_j'),
- function(result){
- if (cb) {
- cb('err', 'add archive conflict!', null);
- }
- }
- );
- }
- //*/
- }, function (error){
- if (cb) {
- cb('err', 'add archive err!', null);
- }
- });
- } else {
- let aItem = this._getCurrentArchives(currentNode);
- if (aItem && aItem.items && aItem.items.length > 0) {
- let orgName = aItem.items[0].uuid;
- let compStr = aItem.items[0].updateDate_time;
- for (let idx = 1; idx < aItem.items.length; idx++) {
- if (aItem.items[idx].updateDate_time < compStr) {
- compStr = aItem.items[idx].updateDate_time;
- orgName = aItem.items[idx].uuid;
- }
- }
- const archiveUrl = _prepareArchiveUrl('updateArchive', `/${orgName}`);
- postDataWithFile(archiveUrl, formData, function (result) {
- // 成功后,更新当前页面
- if (result.updatedRst) {
- // console.log(result);
- ARCHIVE_LIST = result.updatedRst;
- rptArchiveObj.showArchivedItem(currentNode);
- zTreeOprObj.refreshNodes();
- //第二步:更新加密信息
- // let params = {};
- let params = _prepareEncryptionParam(result, pageEncryptInfo);
- CommonAjax.postXsrfEx("/tender/report_api/updateArchiveEncryption", params, 10000, true, getCookie('csrfToken_j'),
- function(result){
- if (cb) {
- cb(null, 'update archive succeed!', params.uuid);
- }
- }, function(err){
- if (cb) {
- cb('err', 'update archive err!', params.uuid);
- }
- }, function(ex){
- if (cb) {
- cb('err', 'update archive err!', params.uuid);
- }
- }
- );
- } else {
- // 有冲突,需要删除
- CommonAjax.postXsrfEx(`/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${bzId}/${currentNode.refId}/${result.fileName}`, '', 3000, true, getCookie('csrfToken'),
- function(result){
- if (cb) {
- cb('err', 'update archive conflict!', null);
- }
- }
- );
- }
- }, function (error){
- // alert(error);
- if (cb) {
- cb('err', 'update archive conflict!', null);
- }
- });
- }
- }
- } catch (ex) {
- console.log(ex);
- console.log(ex.toString());
- if (cb) {
- cb('err', 'has exception!', null);
- }
- }
- } else {
- alert('请选择打开一个报表!');
- }
- },
- _getOneValidLeafNode: function(node) {
- let rst = null;
- let me = rptArchiveObj;
- if (node) {
- const preNode = node.getPreNode();
- if (preNode) {
- rst = preNode;
- } else {
- const nodes = me.treeObj.getNodes();
- for (let dtlNode of nodes) {
- if (dtlNode !== node && dtlNode.nodeType === 2) {
- rst = dtlNode;
- break;
- }
- }
- }
- }
- return rst;
- },
- removeArchive: function() {
- // 这个是从'归档报表'界面进来的
- let me = rptArchiveObj;
- const bkRefId = parseInt(me.currentNode.refId);
- const bkUuid = me.currentArchiveUuid;
- if (me.currentNode && me.currentArchiveUuid) {
- const url = `/tender/report_api/removeArchive/${PROJECT_ID}/${current_stage_id}/${rptArchiveObj._getBusinessId()}/${me.currentNode.refId}/${me.currentArchiveUuid}`;
- CommonAjax.postXsrfEx(url, '', 3000, true, getCookie('csrfToken_j'),
- function(result){
- // console.log(result.data);
- let hasRemovedAll = false;
- for (let idx = ARCHIVE_LIST.length - 1; idx >= 0; idx--) {
- if (bkRefId === parseInt(ARCHIVE_LIST[idx].rpt_id)) {
- for (let dtIdx = ARCHIVE_LIST[idx].items.length - 1; dtIdx >= 0; dtIdx--) {
- if (ARCHIVE_LIST[idx].items[dtIdx].uuid === bkUuid) {
- ARCHIVE_LIST[idx].items.splice(dtIdx, 1);
- break;
- }
- }
- if (ARCHIVE_LIST[idx].items.length === 0) {
- ARCHIVE_LIST.splice(idx, 0);
- hasRemovedAll = true;
- break;
- }
- }
- }
- //要刷新当前归档
- if (hasRemovedAll) {
- const validNode = me._getOneValidLeafNode(me.currentNode);
- // me.iniPage();
- me.treeObj.removeNode(me.currentNode);
- if (validNode) {
- me.currentNode = validNode;
- me.onClick(null, null, me.currentNode);
- me.treeObj.selectNode(me.currentNode, false);
- me._iniArchiveItemForDeleteShow();
- }
- } else {
- me.currentArchiveUuid = null;
- me.currentArchiveDateStr = null;
- me.currentArchivePdfPath = null;
- me.onClick(null, null, me.currentNode);
- }
- }
- );
- }
- }
- };
- function getAdvanceType2() {
- return current_advance_type !== -1 ? ('tplType_prePay' + (current_advance_type + 1)) : '';
- }
- /**
- * 获取 blob
- * @param {String} url 目标文件地址
- * @return {Promise}
- */
- function getBlob(url) {
- return new Promise(resolve => {
- const xhr = new XMLHttpRequest();
- // let fullUrl = url + '?x-oss-process=image/info';
- xhr.open('GET', url, true);
- xhr.responseType = 'blob';
- xhr.onload = () => {
- if (xhr.status === 200) {
- resolve(xhr.response);
- } else {
- resolve('not found!');
- }
- };
- xhr.send();
- });
- }
- /**
- * pdf base64 转 blob
- * @param {String} dataUrl base64码
- * @return {Promise}
- */
- function convertBase64UrlToBlob(dataUrl) {
- //去掉url的头,并转换为byte
- var bytes = window.atob(dataUrl);
- //处理异常,将ascii码小于0的转换为大于0
- var ab = new Uint8Array(bytes.length);
- for (var i = 0; i < bytes.length; i++) {
- ab[i] = bytes.charCodeAt(i);
- }
- return new Blob([ab], { type: 'application/pdf' });
- }
- /**
- * 保存
- * @param {Blob} blob
- * @param {String} filename 想要保存的文件名称
- */
- function saveAs(blob, filename) {
- if (window.navigator.msSaveOrOpenBlob) {
- navigator.msSaveBlob(blob, filename);
- } else {
- const link = document.createElement('a');
- const body = document.querySelector('body');
- link.href = window.URL.createObjectURL(blob);
- link.download = filename;
- // fix Firefox
- link.style.display = 'none';
- body.appendChild(link);
- link.click();
- body.removeChild(link);
- window.URL.revokeObjectURL(link.href);
- }
- }
- /**
- * 下载
- * @param {String} url 目标文件地址
- * @param {String} filename 想要保存的文件名称
- */
- function download(url, filename) {
- getBlob(url).then(blob => {
- saveAs(blob, filename);
- });
- }
- $(function () {
- $('#download_file').click(function () {
- if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
- console.log(rptArchiveObj.currentArchivePdfPath);
- download(`${rptArchiveObj.currentArchivePdfPath}`, `${rptArchiveObj.currentNode.name} ${rptArchiveObj.currentArchiveDateStr}.pdf`);
- } else {
- alert('请选择打开一个报表!');
- }
- });
- $('#print_file').click(function () {
- if (rptArchiveObj.currentArchiveUuid) {
- $('#iframe_made iframe')[0].contentWindow.print();
- } else {
- alert('请选择打开一个报表!');
- }
- });
- $('#delete_file').click(function () {
- if (rptArchiveObj.currentArchiveUuid && rptArchiveObj.currentArchivePdfPath) {
- console.log(rptArchiveObj.currentArchivePdfPath);
- rptArchiveObj.removeArchive();
- } else {
- alert('请选择打开一个报表!');
- }
- });
- })
|