Li Jun
2022-04-06 fb04e7c01d119c60632b4298d18fd93f3ccb3d79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<apex:page controller="InsReportPDFController" showHeader="false" sidebar="false" action="{!init}" applyHtmlTag="false">
<html>
<apex:stylesheet value="{!URLFOR($Resource.BeforeOPDPDF)}"/>
 
    <head>
    <meta name="viewport" content="width=860,user-scalable=yes" />
        <style>
        @page {
            size: A4 landscape;
            margin: 5mm 12mm 5mm 12mm;
            
            @bottom-center {
                content: counter(page) " / " counter(pages);
            }
        }
        
        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 -->
                <!-- <td colspan="3" style="text-align: center; font-size: 16pt; font-weight: bold;">点检报告书</td> -->
                <apex:outputText rendered="{!ir.Contract__c = null}">
                    <td colspan="3" style="text-align: center; font-size: 16pt; font-weight: bold;">点检报告书</td>
                </apex:outputText>
                <apex:outputText rendered="{!ir.Contract__c != null}">
                    <td colspan="3" style="text-align: center; font-size: 16pt; font-weight: bold;">合同点检报告书</td>
                </apex:outputText>
                
                <!-- update by rentx 20210707 end -->
 
            </tr>
            <tr><td colspan="3" height="20px"></td></tr>
            <apex:outputText rendered="{!ir.Contract__c = null}">
                <tr>
                    <td>医院名&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Hospital__r.Name}</td>
                    <td colspan="2">点检报告书号码&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Name}</td>
                </tr>
                <tr>
                    <td>科室名&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Department_name_formula__c}</td>
                    <td>点检日期</td>
                    <td>点检人</td>
                </tr>
                <tr>
                    <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>
            </apex:outputText>
            <tr><td colspan="3" height="20px"></td></tr>
            <apex:outputText rendered="{!ir.Contract__c != null}">
                <tr>
                    <td />
                    <td colspan="2">合同号 &nbsp;&nbsp;&nbsp;&nbsp; {!ir.Contract__r.Maintenance_Contract_No__c} </td>
                </tr>
                <tr>
                    <td> 医院名 &nbsp;&nbsp;&nbsp;&nbsp; {!ir.Hospital__r.Name}</td>
                    <td> 预定点检对象总数 &nbsp;&nbsp;&nbsp;&nbsp; {!ir.Contract__r.dianjiansum__c}</td>
                </tr>
                <tr>
                    <td> 科室名 &nbsp;&nbsp;&nbsp;&nbsp;{!ir.Department_name_formula__c}</td>
                    <td> 本次点检对象数 &nbsp;&nbsp;&nbsp;&nbsp; {!ir.Inspection_asset_number__c}</td>
                </tr>
                <tr>
                    <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>
                    <td />
                    <td colspan="2"> 本次点检时间 &nbsp;&nbsp;&nbsp;&nbsp; {!ir.StartHour_Page__c}:{!startfen} - {!ir.EndHour_Page__c}:{!endfen}  </td>
                </tr>
            </apex:outputText>
        </table>
        <br/>
        <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>
                    <td width="50%">点检设备总数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Inspection_asset_number__c}</td>
                    <td width="50%">发现异常设备数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Failourassetnumber__c}</td>
                </tr>
                <tr>
                    <td>维修合同点检设备数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Contract_product_number__c}</td>
                    <td>OER点检设备数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.OER_inspection_number__c}</td>
                </tr>
                <tr>
                    <td>本次点检对象数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Inspection_asset_number__c}</td>
                    <td/>
                </tr>
            </apex:outputText>
            <apex:outputText rendered="{!ir.Contract__c != null}">
                <tr>
                    <td width="50%">点检人&nbsp;&nbsp;&nbsp;&nbsp;{!usr.Alias__c}</td>
                    <td width="50%">发现异常设备数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Failourassetnumber__c}</td>
                </tr>
                <tr>
                    <td>OER点检设备数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.OER_inspection_number__c}</td>
                    <td>本次点检对象数&nbsp;&nbsp;&nbsp;&nbsp;{!ir.Inspection_asset_number__c}</td>
                </tr>
            </apex:outputText>
            <!-- update by rentx 20210707 end -->
        </table>
        <br/>
        
        <apex:variable value="{!1}" var="cnt" />
        <apex:repeat value="{!itemList}" var="t">
            <table cellspacing="0" cellpadding="0" border="1" style="width:100%; table-layout: fixed;">
                <tr>
                    <th width="3%" >No</th>
                    <th >产品名</th>
                    <th width="8%" >机身号</th>
                    <th width="10%" >维修合同对象</th>
                    <th width="12%" >上次修理结束日</th>
                    <th width="8%" >点检结果</th>
                    <th width="25%" >故障描述</th>
                    <!-- add by rentx 20210831 start -->
                    <apex:outputText rendered="{!ir.Contract__c != null}">
                    <th>是否送修</th>
                    </apex:outputText>
                    <!-- add by rentx 20210831 end -->
                </tr>
                <apex:variable value="{!1}" var="cnt2" />
                <apex:repeat value="{!t.detailList}" var="d">
                    <tr>
                        <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.lineNo}</td>
                        <td class="{!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">
                            <table border="0" style="width:100%; table-layout: fixed;">
                                <tr>
                                    <td width="30%" style="text-align: right;">{!d.productNo}</td>
                                    <td width="1%">{!d.delimiter}</td>
                                    <td style="text-align: left;">{!d.productName}</td>
                                </tr>
                            </table>
                        </td>
                        <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.serialNo}</td>
                        <!-- update by rentx 20210903 start 点检报告书上'维修合同'不为空 显示'是' 否则显示 '否' -->
                        <!-- <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.rec.AssetId__r.Service_Agreement_formula__c}</td> -->
                        <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.isHTsb}</td>
                        
                        <!-- update by rentx 20210903 end 点检报告书上'维修合同'不为空 显示'是' 否则显示 '否' -->
                        <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}"><apex:outputText value="{0,date,yyyy/MM/dd}"><apex:param value="{!d.lastRepair}" /></apex:outputText></td>
                        <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.isNormal}</td>
                        <td class="{!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.diagnosis}</td>
                        <!-- add by rentx 20210831 start -->
                        <apex:outputText rendered="{!ir.Contract__c != null}">
                            <td class="middle {!IF(!d.isRecord && cnt2 != 1, 'topClear', '')}">{!d.isSongxiu}</td>
                        </apex:outputText>
                        <!-- add by rentx 20210831 end -->
                    </tr>
                    <apex:variable value="{!cnt2 + 1}" var="cnt2" />
                </apex:repeat>
            </table>
            
            <!-- 改ページ -->
            <apex:outputPanel layout="none" rendered="{!cnt < itemCount}">
                <div style="page-break-after: always;"></div>
                <br/>
            </apex:outputPanel>
 
            <apex:variable value="{!cnt + 1}" var="cnt" />
        </apex:repeat>
        
        <br/>
 
        <table style="font-family: Arial Unicode MS;" width="100%">
            <tr>
                <th style="text-align: right;" >清洗液</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.CleaningFluid__c}</th>
                <!-- add by rentx 20210927 start -->
                <th style="text-align: right;">方式</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.Mode__c}</th>
                <!-- add by rentx 20210927 end -->
                <th style="text-align: right;">灭菌方式</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.SterilizationMethod__c}</th>
                <th style="text-align: right;">其他备注</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.Remarks__c}</th>
            </tr>
            <tr>
                <th style="text-align: right;">消毒液</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.Disinfectant__c}</th>
                <th style="text-align: right;">使用机器</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.UsedMachine__c}</th>
                <th style="text-align: right;">使用ET</th>
                <th style="border:1px solid #000000; width: 15%;text-align: left;">{!ir.Used_ET__c}</th>
            </tr>
        </table>
        
        <!-- サイン -->
        <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;
 
                //一页pdf显示html页面生成的canvas高度;
                var pageHeight = contentWidth / pw * ph;
                //未生成pdf的html页面高度
                var leftHeight = contentHeight;
                //页面偏移
                var position = 0;
                //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
                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页面的实际高度,和生成pdf的页面高度(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>