123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- /**
- * Created by Tony on 2021/4/2.
- */
- let rptArchiveObj = {
- treeObj: null,
- currentNode: null,
- currentArchiveUuid: null,
- currentArchiveDateStr: null,
- iniPage: function() {
- //初始化页面的归档信息
- let me = rptArchiveObj;
- 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();
- },
- toggleBtn: function (enabled) {
- if (current_stage_status === 3 && enabled) {
- $('#btnArchiveRpt').removeAttr('disabled');
- $('#btnArchiveList').removeAttr('disabled');
- } else {
- $('#btnArchiveRpt').attr('disabled', '');
- $('#btnArchiveList').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;
- if (aItem.items && aItem.items.length > 0) {
- me.currentArchiveUuid = aItem.items[0].uuid;
- me.currentArchiveDateStr = aItem.items[0].updateDate_time;
- }
- break;
- }
- }
- me._countChkedRptTpl();
- me._buildeArchiveDateSelect();
- me._requestArchiveReport();
- }
- },
- _requestArchiveReport: function () {
- let me = rptArchiveObj;
- if (me.currentNode && me.currentArchiveUuid) {
- try {
- let uuIdUrl = "/getArchivedFileByUUID/" + me.currentArchiveUuid + "/" + stringUtil.replaceAll(me.currentNode.name, "#", "_");
- // window.location = uuIdUrl;
- } catch (ex) {
- console.log(ex.toString());
- }
- }
- },
- _changeArchiveDateSelect: function (dom) {
- let me = rptArchiveObj;
- // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了
- me.currentArchiveDateStr = dom.innerHTML;
- me._buildeArchiveDateSelect();
- },
- _buildeArchiveDateSelect: function () {
- let me = rptArchiveObj;
- if (me.currentNode && me.currentArchiveUuid && me.currentArchiveDateStr) {
- let targetDom = document.getElementById("currentDrpArchiveSelect");
- targetDom.innerHTML = me.currentArchiveDateStr;
- let drpDom = $("#drpArchiveSelect");
- drpDom.empty();
- for (let aItem of ARCHIVE_LIST) {
- if (me.currentNode.refId === parseInt(aItem.rpt_id)) {
- for (let item of aItem.items) {
- if (item.uuid !== me.currentArchiveUuid) {
- const str = '<a class="dropdown-item" href="javascript: void(0);" onclick="rptArchiveObj.currentArchiveUuid = \'' + item.uuid + '\'; rptArchiveObj._changeArchiveDateSelect(this)">' + item.updateDate_time + '</a>';
- drpDom.append(str);
- }
- }
- }
- }
- }
- },
- _countChkedRptTpl: function () {
- let me = rptArchiveObj;
- 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;
- });
- }
- },
- 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) {
- auditDate = new Date(LAST_AUDITOR.begin_time);
- achivedAmt = item.items?item.items.length:0;
- achivedItem = item;
- break;
- }
- }
- 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;
- },
- archiveCurrentReport: function(currentRptPageRst, currentNode) {
- // 归档当前报表
- if (currentRptPageRst !== null) {
- try {
- let doc = JpcJsPDFHelper._createPdf(currentRptPageRst, rptControlObj.getCurrentPageSize(), ROLE_REL_LIST, STAGE_AUDIT);
- let formData = new FormData();
- formData.append('file', doc.output('blob'), 'upload.pdf'); //上传单个文件的添加方式
- if (!rptArchiveObj._chkIfFullArchives(currentNode)) {
- postDataWithFile('/tender/report_api/addArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId, formData, function (result) {
- // 成功后,更新当前页面
- if (result.addedRst) {
- // console.log(result);
- ARCHIVE_LIST = result.addedRst;
- rptArchiveObj.showArchivedItem(currentNode);
- } else {
- // 有冲突,需要删除
- CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
- function(result){
- //
- }
- );
- }
- }, function (error){
- // alert(error);
- });
- } 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;
- }
- }
- 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();
- } else {
- // 有冲突,需要删除
- CommonAjax.postXsrfEx('/tender/report_api/removeArchive/' + PROJECT_ID + '/' + current_stage_id + '/' + currentNode.refId + result.fileName, '', 3000, true, getCookie('csrfToken'),
- function(result){
- //
- }
- );
- }
- }, function (error){
- // alert(error);
- });
- }
- }
- } catch (ex) {
- console.log(ex.toString());
- }
- } else {
- alert('请选择打开一个报表!');
- }
- }
- };
- function _dataURLtoFile(dataurl, filename) {
- var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
- bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
- while(n--){
- u8arr[n] = bstr.charCodeAt(n);
- }
- return new File([u8arr], filename, {type:mime});
- };
|