From ac719375874fd50fad5a11f8e04ac3329081bd0b Mon Sep 17 00:00:00 2001
From: Li Jun <buli@deloitte.com.cn>
Date: 星期五, 08 四月 2022 22:58:44 +0800
Subject: [PATCH] Fix Weekly Report

---
 force-app/main/default/pages/InsReportPDF.page |  133 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 128 insertions(+), 5 deletions(-)

diff --git a/force-app/main/default/pages/InsReportPDF.page b/force-app/main/default/pages/InsReportPDF.page
index 3dd8854..f811b6e 100644
--- a/force-app/main/default/pages/InsReportPDF.page
+++ b/force-app/main/default/pages/InsReportPDF.page
@@ -1,4 +1,4 @@
-<apex:page controller="InsReportPDFController" showHeader="false" sidebar="false" renderAs="PDF" action="{!init}" applyHtmlTag="false">
+<apex:page controller="InsReportPDFController" showHeader="false" sidebar="false" action="{!init}" applyHtmlTag="false">
 <html>
 <apex:stylesheet value="{!URLFOR($Resource.BeforeOPDPDF)}"/>
 
@@ -14,18 +14,38 @@
             }
         }
         
-        table {border-collapse: collapse;}
+        table {border-collapse: collapse;border: 0px;}
         
         th {text-align: center;}
         th.border-thick-title { border-width: 1pt 0pt 1pt 0pt; border-style: solid; border-color: black; text-align: center;}
         td.middle {text-align: center;}
         td.topClear {border-top-color: white;}
+
+        /* 20220221 PI鏀归�� by 寰愪寒 start */
+        body{margin: 0 auto;
+        width: 780px;}
+        #title1{height: 30px;}
+        #title2{height: 80px;}
+        .dianjian td{border: 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  -->
         <script>
         </script>
     </head>
     
     <body style="font-family: Arial Unicode MS;">
+        <div id="pdf-wrapper">
+            <div id="title1"></div>
         <table border="0" style="width:100%;">
             <tr>
                 <!-- update by rentx 20210707 start -->
@@ -52,7 +72,7 @@
                     <td>鐐规浜�</td>
                 </tr>
                 <tr>
-                    <td width="70%">闄㈡柟璐熻矗浜� &nbsp;&nbsp;&nbsp;&nbsp;{!ir.Responsible_Person__c}</td>
+                    <td width="70%">闄㈡柟璐熻矗浜� &nbsp;&nbsp;&nbsp;&nbsp;<span id="Responsible_Person__c">{!ir.Responsible_Person__c}</span></td>
                     <td width="15%"><apex:outputField value="{!ir.Inspection_Date__c}" /></td>
                     <td width="15%">{!usr.Alias__c}</td>
                 </tr>
@@ -72,7 +92,7 @@
                     <td> 鏈鐐规瀵硅薄鏁� &nbsp;&nbsp;&nbsp;&nbsp; {!ir.Inspection_asset_number__c}</td>
                 </tr>
                 <tr>
-                    <td width="70%"> 闄㈡柟璐熻矗浜� &nbsp;&nbsp;&nbsp;&nbsp;{!ir.Responsible_Person__c}</td>
+                    <td width="70%"> 闄㈡柟璐熻矗浜� &nbsp;&nbsp;&nbsp;&nbsp;<span id="Responsible_Person__c">{!ir.Responsible_Person__c}</span></td>
                     <td > 鏈鐐规鏃ユ湡 &nbsp;&nbsp;&nbsp;&nbsp; <apex:outputField value="{!ir.Inspection_Date__c}" /></td>
                 </tr>
                 <tr>
@@ -82,7 +102,7 @@
             </apex:outputText>
         </table>
         <br/>
-        <table border="1" style="width:100%;">
+        <table class="dianjian" border="0" style="width:100%;border-collapse: collapse;border: 0px;">
             <!-- update by rentx 20210707 start -->
             <apex:outputText rendered="{!ir.Contract__c = null}">
                 <tr>
@@ -199,6 +219,109 @@
         <table border="0" width="100%">
             <tr><td style="text-align: right"><apex:image value="{!ir.SignUrl__c}" width="300px" height="150px" rendered="{!NOT(ISBLANK(ir.SignUrl__c))}" /></td></tr>
         </table>
+    </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) {
+                let landscape = true;
+                let pw = 595.28;
+                let ph = 841.89;
+                const marginw = 40;
+
+                let orientation = '';
+                if (landscape) {
+                    let temp =ph;
+                    ph = pw;
+                    pw = temp;
+                    orientation = 'l';
+                }
+                
+                
+                var contentWidth = canvas.width;
+                var contentHeight = canvas.height;
+
+                //涓�椤祊df鏄剧ずhtml椤甸潰鐢熸垚鐨刢anvas楂樺害;
+                var pageHeight = contentWidth / pw * ph;
+                //鏈敓鎴恜df鐨刪tml椤甸潰楂樺害
+                var leftHeight = contentHeight;
+                //椤甸潰鍋忕Щ
+                var position = 0;
+                //a4绾哥殑灏哄[595.28,841.89]锛宧tml椤甸潰鐢熸垚鐨刢anvas鍦╬df涓浘鐗囩殑瀹介珮
+                var imgWidth = pw-2*marginw;//595.28//宸﹀彸杈硅窛20
+                var imgHeight = imgWidth/contentWidth * contentHeight;//宸﹀彸杈硅窛20
+
+                var pageData = canvas.toDataURL('image/jpeg', 1.0);
+
+                var pdf = new jsPDF(orientation, 'pt', 'a4');// 绗竴涓弬鏁板~瀛楁瘝l锛屾敞鎰忎笉鏄暟瀛�1锛屼负妯悜pdf
+
+                //鏈変袱涓珮搴﹂渶瑕佸尯鍒嗭紝涓�涓槸html椤甸潰鐨勫疄闄呴珮搴︼紝鍜岀敓鎴恜df鐨勯〉闈㈤珮搴�(841.89)
+                //褰撳唴瀹规湭瓒呰繃pdf涓�椤垫樉绀虹殑鑼冨洿锛屾棤闇�鍒嗛〉
+                if (leftHeight < pageHeight) {
+                    pdf.addImage(pageData, 'JPEG', marginw, 0, imgWidth, imgHeight );//宸﹀彸杈硅窛20
+                } else {
+                    while(leftHeight > 0) {
+                        pdf.addImage(pageData, 'JPEG', marginw, position, imgWidth, imgHeight)//宸﹀彸杈硅窛20
+                        leftHeight -= pageHeight;
+                        position -= ph;
+                        //閬垮厤娣诲姞绌虹櫧椤�
+                        if(leftHeight > 0) {
+                            pdf.addPage();
+                        }
+                    }
+                }
+                Fun(pdf);
+            }
+        })
+    }
+    
+    //blockme();
+    document.body.onload = function(){
+        
+        AWSService.query(staticResources.queryUrl, '{!ir.AWS_Data_Id__c}', function(data){
+            //unblockUI();
+            document.getElementById("Responsible_Person__c").innerHTML = data.object.responsiblePerson;
+            
+            jsPdfDownload(); 
+        }, staticResources.token);
+        
+    }
+</script>
+<!-- 20220221 PI鏀归�� by 寰愪寒 end  -->
 </html>
 </apex:page>
\ No newline at end of file

--
Gitblit v1.9.1