buli
2022-04-06 2d4a8d2dcad5a17127d2c73c48ddc4b67ec79448
force-app/main/default/pages/QISPDF.page
@@ -1,31 +1,51 @@
<apex:page controller="QISPDFController" showHeader="false" sidebar="false" renderAs="pdf" action="{!init}" applyHtmlTag="false">
<!-- <apex:page controller="QISPDFController" showHeader="false" sidebar="false" action="{!init}" applyHtmlTag="false"> -->
<!-- <apex:page controller="QISPDFController" showHeader="false" sidebar="false" renderAs="pdf" action="{!init}" applyHtmlTag="false"> -->
<apex:page controller="QISPDFController" showHeader="false" sidebar="false" action="{!init}" applyHtmlTag="false">
<html>
    <head>
        <style>
        @page {
            size: A4 portrait;
            margin: 5mm 12mm 5mm 12mm;
            @page {
                size: A4 portrait;
                margin: 5mm 12mm 5mm 12mm;
    /*             @bottom-center { */
    /*                 content: counter(page) " / " counter(pages); */
    /*             } */
            }
            
/*             @bottom-center { */
/*                 content: counter(page) " / " counter(pages); */
/*             } */
        }
        table {border-collapse: collapse;}
/*         td {padding: 0px 0px 0px 0px;} */
        td.title {text-align: center; font-weight: bold; background-color: #BDBDBD;}
        td.middle {text-align: center; font-size:120%; font-weight: bold;}
        td.label {padding-left: 10px;}
            table {border-collapse: collapse;}
    /*         td {padding: 0px 0px 0px 0px;} */
            td.title {text-align: center; font-weight: bold; background-color: #BDBDBD;}
            td.middle {text-align: center; font-size:120%; font-weight: bold;}
            td.label {padding-left: 10px;}
            /* 20220221 PI改造 by 徐亮 start */
            body{margin: 0 auto;
            width: 780px;}
            #title1{height: 30px;}
            #title2{height: 110px;}
            /* 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 style="font-family: Arial Unicode MS;">
<body style="font-family: MS Gothic;">
    <div id="pdf-wrapper">
        <div id="title1"></div>
        <table width="100%" border="0">
            <tr>
                <td width="15%">
                <td width="25%">
                    <!-- <apex:image value="{!$Resource.swmLOGO}" /> -->
                    <table width="100%" border="1" cellspacing="0" style="border-color: red;">
                        <tr><td colspan="2" style="font-size: 6px; font-weight: bold; color: red; text-align: center; padding: 0px 0px 0px 0px;">OLYMPUS</td></tr>
@@ -47,7 +67,7 @@
            </tr>
        </table>
        <div style="height:3px;"></div>
        <table width="100%" border="1" cellspacing="2" style="font-size: 8pt;">
        <table width="100%" border="0" cellspacing="2" style="font-size: 8pt;">
            <tr>
                <td>
                    <table width="100%" border="1" cellspacing="0">
@@ -60,8 +80,8 @@
                        <tr>
                            <td class="label" height="23px">机器号/批号</td>
                            <td class="middle">{!qr.lot_or_serial__c}</td>
<!--                             <td class="label">OCM管理号码</td> -->
<!--                             <td class="middle">{!qr.OCM_control_no__c}</td> -->
    <!--                             <td class="label">OCM管理号码</td> -->
    <!--                             <td class="middle">{!qr.OCM_control_no__c}</td> -->
                        </tr>
                        <tr >
                            <td class="label" height="23px">问题现象</td>
@@ -102,13 +122,13 @@
                            <td width="25%" class="label" height="23px">提交者上司</td>
                            <td width="25%" class="middle">{!usr.Manager.Name}</td>
                            <td width="10%" class="label">电话号码</td>
                            <td colspan="2" class="middle">{!qr.Caller_phone__c}</td>
                            <td colspan="2" class="middle" id="Caller_phone__c">{!qr.Caller_phone__c}</td>
                        </tr>
                        <tr>
                            <td width="25%" class="label" height="23px">提交日期</td>
                            <td width="25%" class="middle"><apex:outputField value="{!qr.QIS_Submit_day__c}" /></td>
                            <td width="10%" class="label">联系人</td>
                            <td colspan="2" class="middle">{!qr.Responsible_Person_HP__c}</td>
                            <td colspan="2" class="middle" id="Responsible_Person_HP__c">{!qr.Responsible_Person_HP__c}</td>
                        </tr>
                    </table>
                </td>
@@ -161,10 +181,10 @@
                            </apex:outputPanel>内
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <apex:outputPanel layout="none"
                                 rendered="{!if(Not(inGuarantee) && Not(outOfGuarantee) , 'true', 'false')}"
                                 >&#10004;</apex:outputPanel>
                                    rendered="{!if(Not(inGuarantee) && Not(outOfGuarantee) , 'true', 'false')}"
                                    >&#10004;</apex:outputPanel>
                                <apex:outputPanel layout="none" 
                                rendered="{!if(inGuarantee || outOfGuarantee , 'true', 'false')}"
                                >&#9633;</apex:outputPanel>外
                            </td>
@@ -203,7 +223,7 @@
                            <td colspan="3" class="middle">{!qr.Set_usage_product__c}</td>
                        </tr>
                        <tr>
                            <td colspan="4" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;">问题内容描述</td>
                            <td colspan="4" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;border-bottom: none;border-bottom: none;">问题内容描述</td>
                        </tr>
                        <tr>
                            <td colspan="4" style="height:40px; border-top-color: white; font-size:120%; font-weight: bold; vertical-align: top;"><c:PDFWbr targetStr="{!qr.problem_detail__c}" /></td>
@@ -240,13 +260,13 @@
                            <td colspan="13" class="title">OCSM服务本部</td>
                        </tr>
                        <tr>
                            <td colspan="13" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;">检测/分析情况详述</td>
                            <td colspan="13" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;border-bottom: none;">检测/分析情况详述</td>
                        </tr>
                        <tr>
                            <td colspan="13" style="height:42px; border-top-color: white; font-size:120%; font-weight: bold; vertical-align: top;"><c:PDFWbr targetStr="{!qr.QIS_Reply_Comment__c}" /></td>
                        </tr>
                        <tr>
                            <td colspan="13" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;">原因</td>
                            <td colspan="13" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;border-bottom: none;">原因</td>
                        </tr>
                        <tr>
                            <td colspan="13" style="height:42px; border-top-color: white; font-size:120%; font-weight: bold; vertical-align: top;"><c:PDFWbr targetStr="{!qr.Reason_bloken__c}" /></td>
@@ -279,28 +299,28 @@
                            </td>
                        </tr>
                        <tr>
<!--                             <td colspan="4" style="text-align: center;" height="23px">现品收到日</td> -->
<!--                             <td colspan="4" style="text-align: center;">确认日</td> -->
    <!--                             <td colspan="4" style="text-align: center;" height="23px">现品收到日</td> -->
    <!--                             <td colspan="4" style="text-align: center;">确认日</td> -->
                            <td colspan="3" style="text-align: center;" height="23px">现品收到日</td>
                            <td colspan="3" style="text-align: center;">CDS日</td>
                            <td colspan="3" style="text-align: center;">检查日</td>
                            <td colspan="4" style="text-align: center;">确认日</td>
                        </tr>
                        <tr>
<!--                             <td colspan="4" class="middle" style="height:30px;"><apex:outputField value="{!qr.OCM_RC_RecievedDate__c}" /></td> -->
<!--                             <td colspan="4" class="middle"><apex:outputField value="{!qr.QIS_Reply_day__c}" /></td> -->
    <!--                             <td colspan="4" class="middle" style="height:30px;"><apex:outputField value="{!qr.OCM_RC_RecievedDate__c}" /></td> -->
    <!--                             <td colspan="4" class="middle"><apex:outputField value="{!qr.QIS_Reply_day__c}" /></td> -->
                            <td colspan="3" class="middle" style="height:30px;"><apex:outputField value="{!qr.OCM_RC_RecievedDate__c}" /></td>
                            <td colspan="3" class="middle"><apex:outputField value="{!qr.CDS_date__c}" /></td>
                            <td colspan="3" class="middle"><apex:outputField value="{!qr.RC_inspection_date__c}" /></td>
                            <td colspan="4" class="middle"><apex:outputField value="{!qr.QIS_Reply_day__c}" /></td>
                        </tr>
                        <tr>
<!--                             <td style="text-align: center; height:40px;">确认者</td> -->
<!--                             <td colspan="2" width="24%" class="middle">{!qr.RC__r.Alias__c}</td> -->
<!--                             <td style="text-align: center; color: #D8D8D8">盖章</td> -->
<!--                             <td style="text-align: center;">确认者</td> -->
<!--                             <td colspan="2" width="24%" class="middle">{!qr.RC_manager__r.Alias__c}</td> -->
<!--                             <td style="text-align: center; color: #D8D8D8">盖章</td> -->
    <!--                             <td style="text-align: center; height:40px;">确认者</td> -->
    <!--                             <td colspan="2" width="24%" class="middle">{!qr.RC__r.Alias__c}</td> -->
    <!--                             <td style="text-align: center; color: #D8D8D8">盖章</td> -->
    <!--                             <td style="text-align: center;">确认者</td> -->
    <!--                             <td colspan="2" width="24%" class="middle">{!qr.RC_manager__r.Alias__c}</td> -->
    <!--                             <td style="text-align: center; color: #D8D8D8">盖章</td> -->
                            <td width="6%" style="height:40px;">确认者</td>
                            <td width="13%" class="middle">{!qr.RC__r.Alias__c}</td>
                            <td width="6%" style="text-align: center; color: #D8D8D8">盖章</td>
@@ -324,7 +344,7 @@
                            <td colspan="10" class="title">OSH 医疗品质保障部</td>
                        </tr>
                        <tr>
                            <td colspan="9" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;">检测/分析情况详述<br/></td>
                            <td colspan="9" style="height:18px; padding-top: 0px; padding-bottom: 0px; padding-left: 10px;border-bottom: none;">检测/分析情况详述<br/></td>
                            <td style="text-align: center;">质量判定</td>
                        </tr>
                        <tr>
@@ -368,7 +388,7 @@
                            <td width="6%" style="text-align: center; color: #D8D8D8">盖章</td>
                            <td width="6%">负责人</td>
                            <td width="13%" class="middle">{!qr.OSH_Manager__r.Alias__c}
<!--                                 {!IF(Isblank(qr.OSH_Manager__r.BuchangApprovalManager__c), qr.OSH_Manager__r.Alias__c, qr.OSH_Manager__r.BuchangApprovalManager__r.Alias__c)} -->
    <!--                                 {!IF(Isblank(qr.OSH_Manager__r.BuchangApprovalManager__c), qr.OSH_Manager__r.Alias__c, qr.OSH_Manager__r.BuchangApprovalManager__r.Alias__c)} -->
                            </td>
                            <td width="6%" style="text-align: center; color: #D8D8D8">盖章</td>
                            <td width="25%" class="middle">{!qr.QIS_no_for_m_BC__c}</td>
@@ -380,9 +400,10 @@
        
        <div style="page-break-after: always;"></div>
        
        <div id="title2"></div>
        <table width="100%" border="0">
            <tr>
                <td width="15%">
                <td width="25%">
                    <table width="100%" border="1" cellspacing="0" style="border-color: red;">
                        <tr><td colspan="2" style="font-size: 6px; font-weight: bold; color: red; text-align: center; padding: 0px 0px 0px 0px;">OLYMPUS</td></tr>
                        <tr>
@@ -403,7 +424,7 @@
            </tr>
        </table>
        <div style="height:3px;"></div>
        <table width="100%" border="1" cellspacing="2" style="font-size: 8pt;">
        <table width="100%" border="0" cellspacing="2" style="font-size: 8pt;">
            <tr>
                <td>
                    <table width="100%" border="1" cellspacing="0">
@@ -416,8 +437,8 @@
                        <tr>
                            <td class="label" height="23px">机器号/批号</td>
                            <td class="middle">{!qr.lot_or_serial__c}</td>
<!--                             <td class="label">OCM管理号码</td> -->
<!--                             <td class="middle">{!qr.OCM_control_no__c}</td> -->
    <!--                             <td class="label">OCM管理号码</td> -->
    <!--                             <td class="middle">{!qr.OCM_control_no__c}</td> -->
                        </tr>
                        <tr >
                            <td class="label" height="23px">问题现象</td>
@@ -460,6 +481,97 @@
                </td>
            </tr>
        </table>
    </body>
    </div>
</body>
<!-- 20220221 PI改造 by 徐亮 start  -->
<script>
    AWSService.sfSessionId = '{!GETSESSIONID()}';
    var staticResources = JSON.parse('{!staticResource}');
    var staticResourceFile = JSON.parse('{!staticResourceFile}');
    function Fun(pdf){
        var form = jQuery("<form method='post'></form>");
        jQuery(document.body).append(form);
        let href = window.location.href
        let arr = href.split('/')
        form.attr({"action":staticResourceFile.viewUnifiedContactUrl+"?from="+encodeURIComponent(href)+"&fileName="+encodeURIComponent(arr[arr.length-1].split('?')[0])});
        // form.attr({"action":"http://127.0.0.1:8080/a/d?from="+encodeURIComponent(window.location.href)});
        let input = jQuery("<input type='hidden'/>");
        input.attr({"name":"base64Str"});
        input.val(pdf.output('datauristring').substr(28));
        form.append(input);
        form.submit();
        // jQuery("body > *").each(function(){
        //    jQuery(this).css('display','none');
        // })
        // jQuery("body").append('<embed style="position:absolute; left: 0; top: 0;" width="100%" height="100%" src="'+pdf.output('datauristring')+'" type="application/pdf"/>')
    }
    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(){
        AWSService.query(staticResources.queryUrl, '{!qr.AWS_Data_Id__c}', function(data){
            //unblockUI();
            document.getElementById("Responsible_Person_HP__c").innerHTML = data.object.responsiblePersonHP;
            document.getElementById("Caller_phone__c").innerHTML = data.object.callerPhone;
            jsPdfDownload();
        }, staticResources.token);
    }
</script>
<!-- 20220221 PI改造 by 徐亮 end  -->
</html>
</apex:page>