/** * Created by Tony on 2021/4/2. */ 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)); } 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) { 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(); rptArchiveObj._countChkedRptTpl(); rptArchiveObj._buildeArchiveDateSelect(); rptArchiveObj._iniArchiveItemForDeleteShow(); rptArchiveObj._iniArchiveItemForDeleteShow(); }, toggleBtn: function (enabled) { if (current_stage_status === 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, 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 += '
\n' + '
\n' + ' \n' + ' \n' + '
\n' + '
'; } let uhtml = ''; for (const us of uSignLogList) { uhtml += ' '+ us.role +'('+ us.name +')'; } for (let i = 1; i <= msgSign.total_page; i++) { pagetr += '页'+ i +''+ me.currentNode.name +''+ uhtml +''; } } $('#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(''); }, function () { me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime(); $('#iframe_made').html(''); }) } else { me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime(); $('#iframe_made').html(''); console.log(me.currentArchivePdfPath); } // let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_"); // console.log(uuIdUrl); // $('#iframe_made').html(''); // 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(''); me._buildeArchiveDateSelect(); }, function () { me.currentArchivePdfPath = oss_path + '/'+ me.currentArchiveUuid +'.PDF?' + new Date(me.currentArchiveDateStr.slice(3).replace(/-/g, '/')).getTime(); $('#iframe_made').html(''); 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(''); 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 = `#${index+1} ${item.updateDate_time}` 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 += ' '+ us.role +'('+ us.name +')'; } for (let i = 1; i <= msgSign.total_page; i++) { pagetr += '页'+ i +''+ me.currentNode.name +''+ uhtml +''; } $('#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(''); } $('#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 = `
确认删除本张【${targetDom.innerText}】归档报表?
`; let secondStr = `
删除后,数据无法恢复,请谨慎操作。
`; 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.end_time) { auditDate = new Date(LAST_AUDITOR.end_time); } else { auditDate = new Date(LAST_AUDITOR.begin_time); } achivedAmt = item.items?item.items.length:0; achivedItem = item; break; } } if (auditDate) { cardArchiveInfo.append('
第' + current_stage_order + '期,审批通过时间:' + auditDate.getFullYear() + '-' + (auditDate.getMonth() + 1) + '-' + auditDate.getDate() + '。
'); } else { cardArchiveInfo.append('
第' + current_stage_order + '期'); } cardArchiveInfo.append('
本张报表第' + current_stage_order + '期,已归档' + achivedAmt + '份文件。
'); if (achivedItem && achivedItem.items && achivedItem.items.length === 3) { cardArchiveInfo.append('
本次归档将会覆盖最旧那次归档。
'); } cardArchiveInfo.append('
'); if (achivedAmt > 0) { for (let idx = 0; idx < achivedItem.items.length; idx++) { cardArchiveInfo.append('
'); // if (achivedAmt === 3) { // cardArchiveInfo.append(''); // } cardArchiveInfo.append(''); cardArchiveInfo.append('
'); } } cardArchiveInfo.append('
'); //2. selectionArchiveInfo let selectionArchiveInfo = $('#selectionArchiveInfo'); selectionArchiveInfo.empty(); if (achivedAmt > 0) { for (let idx = 0; idx < achivedItem.items.length; idx++) { selectionArchiveInfo.append('#' + (idx + 1) + ' ' + achivedItem.items[idx].updateDate_time + ''); } } } }, _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, rpt_id) { let psInfo = [], psInfoStr = []; let offsetX = 0, offsetY = 0; //这个跟导出pdf一致,以防万一有变化 let controls = pageData[JV.NODE_CONTROL_COLLECTION]; 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; } for(let i = 0; i < pageData.items.length; i++) { let page = pageData.items[i]; for (let sCell of page.signature_cells) { // sCell.signature_name 草图不用加密 if (sCell.signature_name.indexOf('dummy_pic') < 0) { // if (sCell.signature_name !== 'dummy_pic') { let control = null; if (typeof sCell[JV.PROP_CONTROL] === "string") { control = controls[sCell[JV.PROP_CONTROL]]; } else { control = sCell[JV.PROP_CONTROL]; } let idx = psInfoStr.indexOf(sCell.signature_name); let actSignArea = _getProperSignatureArea(sCell, control); if (idx < 0) { psInfoStr.push(sCell.signature_name); let newPsInfo = {'name': sCell.signature_name, areas: []}; let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []}; area.pages.push(i + 1); newPsInfo.areas.push(area); psInfo.push(newPsInfo); } else { let hasArea = false; for (let areaItem of psInfo[idx].areas) { 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(i + 1); hasArea = true; break; } } if (!hasArea) { let area = {Left: actSignArea[JV.IDX_LEFT] + offsetX, Top: actSignArea[JV.IDX_TOP] + offsetY, width: (actSignArea[JV.IDX_RIGHT] - actSignArea[JV.IDX_LEFT]), height: (actSignArea[JV.IDX_BOTTOM] - actSignArea[JV.IDX_TOP]), pages: []}; area.pages.push(i + 1); psInfo[idx].areas.push(area); } } } } } return psInfo; }, archiveCurrentReport: function (currentRptPageRst, currentNode, cb) { let picKeys = [], picCells = [], dupPicPath = [], dupPicCell = []; // 1. 找草图路径 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) { // if (sCell.signature_name === 'dummy_pic') { //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, 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, cb); } }; oFileReader.readAsDataURL(blob); } }); } } else { rptArchiveObj._archiveCurrentReport(currentRptPageRst, currentNode, cb); } }, _archiveCurrentReport: function(currentRptPageRst, currentNode, cb) { // 归档当前报表 if (currentRptPageRst !== null) { try { let signCells = []; 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) { // if (sCell.signature_name !== 'dummy_pic') { dtlSignCells.push(sCell); pageItem.signature_cells.splice(sCellIdx, 1); } } }); } let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT); if (PAGE_SHOW.isTextSignature) { currentRptPageRst.items.forEach((pageItem, pageIdx) => { signCells[pageIdx].forEach((signCell) => { pageItem.signature_cells.push(signCell); }); signCells[pageIdx] = null; }); signCells = null; } let pageEncryptInfo = rptArchiveObj._getPageSignatureInfo(currentRptPageRst, 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(), ROLE_REL_LIST, 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)) { let archiveUrl = `/tender/report_api/addArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}`; if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) { archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`; } postDataWithFile(archiveUrl, formData, function (result) { // postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) { // postDataWithFile('/tender/report_api/addParentChildrenArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) { // 测试 // 成功后,更新当前页面 //* if (result.updatedRst) { // console.log(result); ARCHIVE_LIST = result.updatedRst; rptArchiveObj.showArchivedItem(currentNode); zTreeOprObj.refreshNodes(); //第二步:增加加密信息 let params = {}; params.prjId = PROJECT_ID; params.stgId = current_stage_id; 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; 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 + '/' + 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; } } let archiveUrl = `/tender/report_api/updateArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${orgName}`; if (currentRptPageRst.splitArcPages && currentRptPageRst.splitArcPages.length > 0) { // archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${orgName}`; archiveUrl = `/tender/report_api/addParentChildrenArchive/${PROJECT_ID}/${current_stage_id}/${currentNode.refId}/${JSON.stringify(currentRptPageRst.splitArcPages)};${JSON.stringify(currentRptPageRst.splitArcPagesInfo)};${currentRptPageRst.items.length}`; // 分页方式不需要 orgName } postDataWithFile(archiveUrl, formData, function (result) { // postDataWithFile('/tender/report_api/updateArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + '/' + orgName, formData, function (result) { // 成功后,更新当前页面 if (result.updatedRst) { // console.log(result); ARCHIVE_LIST = result.updatedRst; rptArchiveObj.showArchivedItem(currentNode); zTreeOprObj.refreshNodes(); //第二步:更新加密信息 let params = {}; params.prjId = PROJECT_ID; params.stgId = current_stage_id; params.rptId = currentNode.refId; params.ttlPgs = currentRptPageRst.items.length; params.content = pageEncryptInfo; params.childUuids = result.updatedRst.childUuids; params.splitArcPages = (currentRptPageRst.splitArcPages) ? currentRptPageRst.splitArcPages : []; params.uuid = orgName; 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 + '/' + 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}/${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); } } ); } } }; /** * 获取 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('请选择打开一个报表!'); } }); })