高章伟
2022-03-18 4bfe21c4b5ddc089ae5a95f4b10f6cff148b690d
force-app/main/default/pages/ConsumTrialPDF.page
@@ -1,5 +1,5 @@
<apex:page applyHtmlTag="false" Controller="ConsumTrialPDFController" showHeader="false" sidebar="false" id="allPage" action="{!init}" renderAs="pdf">
<!-- renderAs="pdf" -->
<apex:page applyHtmlTag="false" Controller="ConsumTrialPDFController" showHeader="false" sidebar="false" id="allPage" action="{!init}">
<!-- renderAs="pdf" -->
    <html>
        <head>
            <style type="text/css" media="print">
@@ -39,16 +39,66 @@
                }
            </style>
            <style>
                /* 20220221 PI改造 by 徐亮 start */
                body {
                    font-family: Arial Unicode MS;
                    page-break-inside: auto;
                    font-size: 14px;
                }
                table {
                    border-collapse: collapse;
                    width: 100%;
                }
                table, th, td {
                    border: 1px solid black;
                    text-align: left;
                }
                table.headTable tr td {
                    font-size: 13px;
                }
                table.deliInfoTable tr td {
                    font-size: 13px;
                }
                table.detailListTable tr td {
                    font-size: 8px;
                    text-align: left;
                    box-sizing:border-box;
                    padding: 1px;
                }
                table.tailTable tr td {
                    font-size: 12px;
                }
                body{margin: 0 auto;width: 920px;font-size: 14px;}
                #title1{height: 30px;}
                #title2{height: 80px;}
                #pdf-wrapper {position: relative;}
                #pdf-wrapper table{width: 100%;border-spacing: 0px;border-collapse: collapse;    border: none;}
                #pdf-wrapper table th,td{border-bottom: 1px #000 solid;}
                /* 20220221 PI改造 by 徐亮 end */
            </style>
            <!-- 20220221 PI改造 by 徐亮 start  -->
        <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
        <script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script>
        <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
        <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
        <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
        <apex:includeScript value="{!URLFOR($Resource.jspdf)}"/>
        <apex:includeScript value="{!URLFOR($Resource.html2canvas)}"/>
        <!-- 20220221 PI改造 by 徐亮 end  -->
        </head>
        <body>
            <div id="pdf-wrapper">
                <div id="title1"></div>
            <!-- 页码 -->
            <apex:variable value="{!1}" var="pageCnt" />
            <!-- 借用耗材备品发货清单 -->
            <!-- 序号 -->
            <apex:variable value="{!1}" var="lineCnt" />
            <apex:repeat value="{!pdfPageList}" var="eachPdfPage">
                <img style="float:left;width:79px;height:79px;padding:0px;margin-top:1px;z-index:999;position:relative;"
                        src="{!'/servlet/servlet.FileDownload?file=' + targetConsumApply.QRId__c}" />
                <img style="width:79px;height:79px;padding:0px;margin-top:1px;z-index:999;position:absolute;"
                        src="{!QRSrc}" />
                <!-- 表头 -->
                <table class="headTable" style="position:relative;">
                    <colgroup>
@@ -197,10 +247,10 @@
                    </colgroup>
                    <apex:outputPanel layout="none" rendered="{!eachPdfPage.equipSetDetailList.size > 0}">
                        <tr>
                            <th style="text-align:center;" colspan="14" height="25">借用耗材备品发货清单</th>
                            <th style="text-align:center;" colspan="12" height="25">借用耗材备品发货清单</th>
                        </tr>
                        <tr>
                            <th style="text-align:center; font-size:10px;" colspan="14" height="25">共计耗材备品({!consumApplySetDetailListSize})件</th>
                            <th style="text-align:center; font-size:10px;" colspan="12" height="25">共计耗材备品({!consumApplySetDetailListSize})件</th>
                        </tr>
                        <tr>
                            <td style="text-align: center;"><c:PDFWbr targetStr="序号"/></td>
@@ -254,7 +304,7 @@
                            <!-- 病例/动物脏器 -->
                            <td><c:PDFWbr targetStr="{!eachEquipSetDetail.Case_OR_animal_organ__c}"/></td>
                            <!-- 试用者盖章 -->
                            <td><c:PDFWbr targetStr="{!eachEquipSetDetail.Trial_User__c}"/></td>
                            <td aws-data-id="{!eachEquipSetDetail.AWS_Data_Id__c}"><c:PDFWbr targetStr="{!eachEquipSetDetail.Trial_User__c}"/></td>
                            <!-- 跟台者盖章 -->
                            <td><c:PDFWbr targetStr="{!eachEquipSetDetail.Follower_User__r.Name}"/></td>
                            <!-- 备用 -->
@@ -283,8 +333,7 @@
                    <!-- 20211210 ljh SFDC-C923SR add -->
                    <tr>
                        <td colspan="2" style=" border: none;">
                            <img align="left" src="{!'/servlet/servlet.FileDownload?file=' + targetConsumApply.BRId__c}" />
                            <img align="left" src="{!BRSrc}" />
                        </td>
                    </tr>
                    <!-- 20211210 ljh SFDC-C923SR end -->
@@ -294,6 +343,107 @@
                </apex:outputPanel>
                <apex:variable value="{!pageCnt + 1}" var="pageCnt" />
            </apex:repeat>
        </div>
        </body>
        <!-- 20220221 PI改造 by 徐亮 start  -->
<script>
    AWSService.sfSessionId = '{!GETSESSIONID()}';
    var staticResource = JSON.parse('{!staticResource}');
    function Fun(pdf){
        var iframe = document.createElement('iframe');
        iframe.setAttribute('style', 'position:absolute;right:0; top:0; bottom:0; height:100%; width:100%');
        document.body.appendChild(iframe);
        iframe.src = pdf.output('datauristring');
        for(let e of document.body.childNodes){
            if( e != iframe && e.style){
                e.style.display = 'none';
            }
        }
    }
    let id = "pdf-wrapper";
    var target = document.getElementById(id);
    function jsPdfDownload(){
        let pdfName = "测试";
        let id = "pdf-wrapper";
        var target = document.getElementById(id);
        target.style.background = "#FFFFFF";
        if(pdfName==''||pdfName==undefined) pdfName= getNowFormatDate();
        html2canvas(target, {
            scale: 2,
            onrendered:function(canvas) {
                var contentWidth = canvas.width;
                var contentHeight = canvas.height;
                //一页pdf显示html页面生成的canvas高度;
                var pageHeight = contentWidth / 592.28 * 841.89;
                //未生成pdf的html页面高度
                var leftHeight = contentHeight;
                //页面偏移
                var position = 0;
                //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
                var imgWidth = 515.28;//595.28//左右边距20
                var imgHeight = 515.28/contentWidth * contentHeight;//左右边距20
                var pageData = canvas.toDataURL('image/jpeg', 1.0);
                var pdf = new jsPDF('', 'pt', 'a4');
                //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
                //当内容未超过pdf一页显示的范围,无需分页
                if (leftHeight < pageHeight) {
                    pdf.addImage(pageData, 'JPEG', 40, 0, imgWidth, imgHeight );//左右边距20
                } else {
                    while(leftHeight > 0) {
                        pdf.addImage(pageData, 'JPEG', 40, position, imgWidth, imgHeight)//左右边距20
                        leftHeight -= pageHeight;
                        position -= 841.89;
                        //避免添加空白页
                        if(leftHeight > 0) {
                            pdf.addPage();
                        }
                    }
                }
                Fun(pdf);
            }
        })
    }
    blockme();
    document.body.onload = function(){
        let aws_ids = [];
        j$("[aws-data-id]").each(function(i,e){
            let id = j$(e).attr('aws-data-id');
            if (id) {
                aws_ids.push(id);
            }
        })
        AWSService.search(staticResource.searchUrl, JSON.stringify({
            dataIds:aws_ids
        }), function(data){
            unblockUI();
            if (data && data.object && data.object.length > 0) {
                for (const d of data.object) {
                    j$("[aws-data-id='"+d.dataId +"']").html(d.trialUser);
                }
            }
            //document.getElementById("Responsible_Person_HP__c").innerHTML = data.object.responsiblePersonHP;
            //document.getElementById("Caller_phone__c").innerHTML = data.object.callerPhone;
            setTimeout(() => {
                jsPdfDownload();
            }, 1500);
        }, staticResource.token);
    }
    document.body.onclick = function(){
        //jsPdfDownload();
    }
</script>
<!-- 20220221 PI改造 by 徐亮 end  -->
    </html>
</apex:page>