| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892 | /** * Created by Tony on 2021/4/2. */let rptArchiveObj = {    treeObj: null,    currentNode: null,    currentArchiveUuid: null,    currentArchiveDateStr: null,    currentEncryptionList: null,    currentArchivePdfPath: null,    iniPage: function() {        //初始化页面的归档信息        let me = rptArchiveObj;        me.currentNode = null;        me.currentArchiveUuid = 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.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.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 += '<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="750px" 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="750px" 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="750px" 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());            }        }    },    _changeArchiveDateSelect: function (dom) {        let me = rptArchiveObj;        // me.currentArchiveUuid = dom.uuid; //在dom的onclick时已经设置过了        me.currentArchiveDateStr = dom.innerHTML;        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="750px" 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="750px" 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="750px" 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="750px" 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.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('<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, 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'); //上传单个文件的添加方式                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);                            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.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;                            }                        }                        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.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('请选择打开一个报表!');        }    });})
 |