Li Jun
2022-03-28 f5a94e721ae5a26f817f0df75065b64f1f192eb3
force-app/main/default/pages/ConsumTrialPDF.page
@@ -44,33 +44,33 @@
                body {
                    font-family: Arial Unicode MS;
                    page-break-inside: auto;
                    font-size: 14px;
                    font-size: 14pt;
                }
                table {
                    border-collapse: collapse;
                    width: 100%;
                }
                table, th, td {
                    border: 1px solid black;
                    border: 1pt solid black;
                    text-align: left;
                }
                table.headTable tr td {
                    font-size: 13px;
                    font-size: 13pt;
                }
                table.deliInfoTable tr td {
                    font-size: 13px;
                    font-size: 12pt;
                }
                table.detailListTable tr td {
                    font-size: 8px;
                    font-size: 8pt;
                    text-align: left;
                    box-sizing:border-box;
                    padding: 1px;
                    padding: 1pt;
                }
                table.tailTable tr td {
                    font-size: 12px;
                    font-size: 12pt;
                }
                body{margin: 0 auto;width: 920px;font-size: 14px;}
                #title1{height: 30px;}
                body{margin: 0 auto;width: 920px;font-size: 14pt;}
                #title1{height: 50pt;}
                #title2{height: 80px;}
                #pdf-wrapper {position: relative;}
                #pdf-wrapper table{width: 100%;border-spacing: 0px;border-collapse: collapse;    border: none;}
@@ -80,6 +80,8 @@
            <!-- 20220221 PI改造 by 徐亮 start  -->
        <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
        <script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script>
        <!-- <script src="https://cdn.bootcss.com/es6-promise/4.1.1/es6-promise.auto.min.js" type="text/javascript"></script> -->
        <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
        <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
        <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
@@ -97,7 +99,9 @@
            <!-- 序号 -->
            <apex:variable value="{!1}" var="lineCnt" />
            <apex:repeat value="{!pdfPageList}" var="eachPdfPage">
                <img style="width:79px;height:79px;padding:0px;margin-top:1px;z-index:999;position:absolute;"
                <div class="pdf-page">
                    <div id="title1"></div>
                    <img style="width:72pt;height:72pt;padding:0px;margin-top:1pt;z-index:999;position:absolute;"
                        src="{!QRSrc}" />
                <!-- 表头 -->
                <table class="headTable" style="position:relative;">
@@ -105,7 +109,7 @@
                        <col width="100%"/>
                    </colgroup>
                    <tr>
                        <th style="box-sizing:border-box; text-align:center; font-size:24px; font-weight:900;" height="35">奥林巴斯医疗手术附件(器械)临床试用表</th>
                            <th style="box-sizing:border-box; text-align:center; font-size:24pt; font-weight:900;" height="35">奥林巴斯医疗手术附件(器械)临床试用表</th>
                    </tr>
                    <tr>
                        <td style="text-align:right;">
@@ -171,7 +175,7 @@
                    </tr>
                    <tr>
                        <td rowspan="3" >发货地址</td>
                        <td colspan="2" rowspan="3">
                            <td colspan="2" rowspan="3" id="shippmentAddress">
                            <apex:outputText value="{!shippmentAddress}" />
                        </td>
                        <td colspan="1">邮编</td>
@@ -202,7 +206,7 @@
                            <th style="text-align:center;" colspan="5" height="25">※奥林巴斯耗材备品借用须知</th>
                        </tr>
                        <tr>
                            <td style="font-size:12px;">
                                <td style="font-size:12pt;">
                                1、严格遵循医疗产品的合规使用原则,为评价该产品在临床使用的有效性、安全性无偿提供给医疗从业者进行试用。<br />
                                2、一次性医疗产品和重复性使用产品用于临床后由试用者按该院对医疗废弃物的处置规定进行废弃。<br />
                                3、未经奥林巴斯公司书面同意,借用方不得以任何理由对耗材进行临床用途以外的处理,包括但不限于向第三方转借、出租、出售、抵押等。<br />
@@ -247,10 +251,10 @@
                    </colgroup>
                    <apex:outputPanel layout="none" rendered="{!eachPdfPage.equipSetDetailList.size > 0}">
                        <tr>
                            <th style="text-align:center;" colspan="12" height="25">借用耗材备品发货清单</th>
                                <th style="text-align:center;" colspan="14" height="25">借用耗材备品发货清单</th>
                        </tr>
                        <tr>
                            <th style="text-align:center; font-size:10px;" colspan="12" height="25">共计耗材备品({!consumApplySetDetailListSize})件</th>
                                <th style="text-align:center; font-size:10pt;" colspan="14" height="25">共计耗材备品({!consumApplySetDetailListSize})件</th>
                        </tr>
                        <tr>
                            <td style="text-align: center;"><c:PDFWbr targetStr="序号"/></td>
@@ -272,7 +276,7 @@
                    <apex:repeat value="{!eachPdfPage.equipSetDetailList}" var="eachEquipSetDetail">
                        <tr style="vertical-align:center;">
                            <!-- 序号 -->
                            <td style="text-align:center;height:30px;">
                                <td style="text-align:center;height:25pt;">
                                <apex:outputPanel rendered="{!lineCnt  <= consumApplySetDetailListSize}" layout="none">
                                    <c:PDFWbr targetStr="{!lineCnt}"/>
                                </apex:outputPanel>
@@ -342,6 +346,7 @@
                    <div style="page-break-after:always;"/>
                </apex:outputPanel>
                <apex:variable value="{!pageCnt + 1}" var="pageCnt" />
                </div>
            </apex:repeat>
        </div>
        </body>
@@ -349,68 +354,114 @@
<script>
    AWSService.sfSessionId = '{!GETSESSIONID()}';
    var staticResource = JSON.parse('{!staticResource}');
        var staticResourceCon = JSON.parse('{!staticResourceCon}');
    var staticResourceFile = JSON.parse('{!staticResourceFile}');
    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';
            }
        }
        var form = jQuery("<form method='post'></form>");
        jQuery(document.body).append(form);
        form.attr({"action":staticResourceFile.viewUnifiedContactUrl+"?from="+encodeURIComponent(window.location.href)});
        // 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, {
        let jtargets = jQuery("#pdf-wrapper .pdf-page");
        let j_arr = new Array(jtargets.length+1).join(0).split('').map(function(){return false});
        let landscape = false;
        let pw = 595.28;
        let ph = 841.89;
        const marginw = 40;
        let orientation = '';
        if (landscape) {
            pw += ph;ph = pw - ph;pw = pw - ph;
            orientation = 'l';
        }
        var pdf = new jsPDF(orientation, 'pt', 'a4');// 第一个参数填字母l,注意不是数字1,为横向pdf
        jtargets.each(function(i,e){
            e.style.background = "#FFFFFF";
        })
        let rei = 0;
        let recursion = null;
        recursion = function(i){
            if(i>= jtargets.length){
                Fun(pdf);
                return;
            }
            e = jtargets[i];
            html2canvas(e, {
            scale: 2,
            onrendered:function(canvas) {
                    let canvas_max_page_num = 1;
                    let canvas_current_page_num = 0;
                var contentWidth = canvas.width;
                var contentHeight = canvas.height;
                //一页pdf显示html页面生成的canvas高度;
                var pageHeight = contentWidth / 592.28 * 841.89;
                    var pageHeight = contentWidth / pw * ph;
                //未生成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 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('', 'pt', 'a4');
                //有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
                //当内容未超过pdf一页显示的范围,无需分页
                if (leftHeight < pageHeight) {
                    pdf.addImage(pageData, 'JPEG', 40, 0, imgWidth, imgHeight );//左右边距20
                        pdf.addImage(pageData, 'JPEG', marginw, 0, imgWidth, imgHeight );//左右边距20
                } else {
                    while(leftHeight > 0) {
                        pdf.addImage(pageData, 'JPEG', 40, position, imgWidth, imgHeight)//左右边距20
                            if(i){
                                pdf.addPage();
                            }
                            canvas_current_page_num++;
                            pdf.addImage(pageData, 'JPEG', marginw, position, imgWidth, imgHeight)//左右边距20
                        leftHeight -= pageHeight;
                        position -= 841.89;
                            position -= ph;
                            if (canvas_max_page_num > 0 && canvas_current_page_num>=canvas_max_page_num) {
                                break;
                            }
                        //避免添加空白页
                        if(leftHeight > 0) {
                            pdf.addPage();
                        }
                    }
                }
                Fun(pdf);
                    recursion(i+1);
            }
        })
        };
        recursion(rei);
    }
    
    blockme();
    //blockme();
    document.body.onload = function(){
        let aws_ids = [];
        j$("[aws-data-id]").each(function(i,e){
@@ -421,24 +472,44 @@
            
        })
      let a1 = false;
        let a2 = false;
        var Foo = function(){
           if(a1 && a2){
               setTimeout(function() {
                    jsPdfDownload();
                }, 1500);
            }
        }
        AWSService.search(staticResource.searchUrl, JSON.stringify({
            dataIds:aws_ids
        }), function(data){
            unblockUI();
            //unblockUI();
            if (data && data.object && data.object.length > 0) {
                for (const d of data.object) {
                for(let di in data.object){let d=data.object[di];
                    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);
            a1= true;
            Foo();
        }, staticResource.token);
        
        if('{!targetConsumApply.Shippment_adress_detail__c}'){
           a2 = true;
            Foo();
        }else{
           AWSService.query(staticResourceCon.queryUrl, '{!targetConsumApply.AWS_Data_Id__c}', function(data){
                //unblockUI();
                if (data && data.object  ) {
                    j$("#shippmentAddress").html(data.object.directShippmentAddress);
                }
                a2 = true;
                Foo();
            }, staticResource.token);
        }
    }
    document.body.onclick = function(){
        //jsPdfDownload();