李金换
2023-04-21 cc7487a59bd4b0fa5bed1dd59f6d0565ace81b8b
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<apex:page id="Page" showHeader="false" sidebar="false" controller="BatchSelectRepairPageController" applyBodyTag="false" applyHtmlTag="false" action="{!init}">
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.CommonUtilJs)}"/>
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
<apex:includeScript value="{!URLFOR($Resource.xlsxCoreMinJs)}"/>
    <title>批量选择修理功能</title>
    <style type="text/css">
        .pure-table {
            /* border-collapse: collapse; */
            /* border-spacing: 0; */
            empty-cells: show;
            border: 1px solid #cbcbcb;
            width: 100%;
        }
 
        .pure-table caption {
            color: #000;
            font: italic 85%/1 arial,sans-serif;
        /* padding: 1em 0;*/
            text-align: center;
        }
        
        .pure-table td,.pure-table th {
            border-left: 1px solid #cbcbcb;
            border-width: 0 0 0 1px;
            font-size: inherit;
            margin: 0;
            overflow: visible;
            padding: .5em 1em;
        }
        
        .pure-table thead {
            background-color: #c3bfbf;
            color: #000;
            text-align: center;
            vertical-align: bottom;
        }
 
        .bPageBlock{
            border-top: 3px solid #3044b5;
        }
        
        .pure-table td {
            background-color: transparent; 
        }
 
        .pure-table-horizontal th,.pure-table-horizontal td {
            border-width: 0 0 1px 0;
            border-bottom: 1px solid #cbcbcb;
        }
 
        .pure-table-horizontal tbody>tr:last-child>td {
            border-bottom-width: 0;
        }
    </style>
    <script type="text/javascript">
        //全选功能
        function checkAll() {
            var cnt = j$(escapeVfId('raCnt')).val();
            // alert(jQuery('input[id$=checklist]').length);
            if (jQuery('input[id$=checkAll]').attr('checked') === 'checked') {
                 // alert(j$('input[id$=checklist]')[0].checked);
                for (var i = 0; i < cnt; i++) {
                    j$('input[id$=checklist]')[i].checked = true;
                }
            } else {
                for (var i = 0; i < cnt; i++) {
                     j$('input[id$=checklist]')[i].checked = false;
                }
            }
        }
 
        //跳转到pdf页面
        function skipPage() {
            var pdfURL = j$(escapeVfId('pdfURL')).val();
            window.open(pdfURL, "维修委托书PDF", "");
        }
     
        // table转Excel文件
        function exportExcel() {
            var csv = table2csv(j$(escapeVfId('theTable table'))[0]);
            // console.log(csv)
            var sheet = csv2sheet(csv);
            var blob = sheet2blob(sheet);
            openDownloadDialog(blob,'修理明细表.xlsx');
        }
 
        function table2csv(table) {
            var csv = [];
            var trSize = j$(j$(escapeVfId('theTable table'))[0]).find('tr').length;
            var spanSize = j$(j$(escapeVfId('theTable table'))[0]).find('tr td span').length;
            var aSize = j$(j$(escapeVfId('theTable table'))[0]).find('tr td span a').length;
            var fixSize = 0;
            var g = 0;
            var nbsp = '&nb' + 'sp;';
            for(var i = 0; i < trSize; i++){
                var temp = [];
                // 标题列用td
                if(i == 0){
                    for(var j = 0; j < 15; j++){
                        temp.push(j$(table).find('tr td')[j].innerHTML);
                    }
                    temp.shift(); // 移除第一个全选按钮
                } else{
                    for(var k = fixSize; k < fixSize + 14; k++){
                        var htmlText = j$(table).find('tr td span')[k].innerHTML;
                        if(htmlText.slice(1,2) == 'a' && htmlText.slice(htmlText.length-2,htmlText.length-1) == 'a'){
                            temp.push(j$(table).find('tr td span a')[g].innerHTML);
                            g++;
                        } else{
                            if(j$(table).find('tr td span')[k].innerHTML == nbsp){
                                temp.push('');
                            }else{
                                temp.push(j$(table).find('tr td span')[k].innerHTML);
                            }
                        }
                    }
                    if(fixSize < spanSize){
                        fixSize += 14;
                    }
                }      
                csv.push(temp.join(';'));
            }
            temp.push('');
            csv.push(temp.join(';'));
            // csv.shift();
            return csv.join('\n');
        }
 
        function csv2sheet(csv) {
            var sheet = {}; // 将要生成的sheet
            csv = csv.split('\n');
            csv.forEach(function(row, i) {
                row = row.split(';');
                if(i == 0) sheet['!ref'] = 'A1:'+String.fromCharCode(65+row.length-1)+(csv.length-1);
                row.forEach(function(col, j) {
                    sheet[String.fromCharCode(65+j)+(i+1)] = {v: col};
                });
            });
            return sheet;
        }
 
        function sheet2blob(sheet, sheetName) {
            sheetName = sheetName || 'sheet1';
            var workbook = {
                SheetNames: [sheetName],
                Sheets: {}
            };
            workbook.Sheets[sheetName] = sheet;
            // 生成excel的配置项
            var wopts = {
                bookType: 'xlsx', // 要生成的文件类型
                bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
                type: 'binary'
            };
            var wbout = XLSX.write(workbook, wopts);
            var blob = new Blob([s2ab(wbout)], {type:"application/octet-stream"});
            // 字符串转ArrayBuffer
            function s2ab(s) {
                var buf = new ArrayBuffer(s.length*2); // 每个字符占⽤2个字节
                var view = new Uint8Array(buf);
                for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
                return buf;
            }
            return blob;
        }
 
        /**
         * 通用的打开下载对话框方法,没有测试过具体兼容性
         * @param url 下载地址,也可以是一个blob对象,必选
         * @param saveName 保存文件名,可选
         */
         function openDownloadDialog(url, saveName) {
            if(typeof url == 'object' && url instanceof Blob) {
                url = URL.createObjectURL(url); // 创建blob地址
            }
            var aLink = document.createElement('a');
            aLink.href = url;
            aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
            var event;
            if(window.MouseEvent) event = new MouseEvent('click');
            else {
                event = document.createEvent('MouseEvents');
                event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            }
            aLink.dispatchEvent(event);
        }
    </script>
    <apex:form id="allForm" style="margin: 10px 10px;">
        <!-- <apex:actionFunction name="RetrievalBtn" action="{!RetrievalBtn}" rerender="allForm, message" onComplete="unblockUI();"/> -->
        <!-- <apex:actionFunction name="showPDF" action="{!showPDF}" rerender="allForm, message" onComplete="skipPage();unblockUI();"/> -->
        <!-- 后台报错信息显示的关键 -->
        <apex:outputPanel id="message">
            <apex:pageMessages ></apex:pageMessages>
        </apex:outputPanel>
        <apex:outputPanel id="allPanel">
            <input type="hidden" id="pdfURL" value="{!pdfURL}" />
            <apex:pageBlock mode="maindetail" Id="allBlock">
                <div style="position: relative; width:100%; ">
                    <apex:pageBlock title="检索列" id="Editable">
                        <table>
                            <!--<tr><td>&nbsp;</td></tr>-->
                            <tr>
                                <td style="text-align: left; position: relative; top: 7px; padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 25px;" value="状态1"/>
                                    <apex:selectList value="{!RevalInfo.Status1}" size="1" style="width: 150px; height: 24px;">
                                        <apex:selectOptions value="{!StatusItems1}"/>
                                    </apex:selectList><p/>
                                </td>
                                <td style="text-align: left; position: relative; top: 7px; padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 25px;" value="状态2"/>
                                    <apex:selectList value="{!RevalInfo.Status2}" size="1" style="width: 150px; height: 24px;">
                                        <apex:selectOptions value="{!StatusItems}"/>
                                    </apex:selectList><p/>
                                </td>
                                <td style="text-align: left;padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 5px;" value="RS修理单号"/>
                                    <apex:inputText id="RepairName" value="{!RevalInfo.RepairName}"/>
                                </td>
                                <td style="text-align: left;padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 6px;" value="SAP修理单号"/>
                                    <apex:inputText id="SAPRepairNo" value="{!RevalInfo.SAPRepairNo}"/>
                                </td>   
                            </tr>
                            <!--<tr><td>&nbsp;</td></tr>-->
                            <tr>
                                <td style="text-align: left; padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 5px;" value="机身编码"/>
                                    <apex:inputText id="SerialNumber" value="{!RevalInfo.SerialNumber}"/>
                                </td>
                                <td style="text-align: left; padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 50px;" value="省份"/>
                                    <apex:inputText id="State_Hospital" value="{!RevalInfo.State_Hospital}"/>
                                </td>
                                <td style="text-align: left; padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 50px;" value="医院名称"/>
                                    <apex:inputText id="HP_Name" value="{!RevalInfo.HospitalName}"/>
                                </td>
                                <td style="text-align: left; padding-left: 50px;" >
                                    <apex:outputLabel style="font-weight: bold; padding-right: 22px;" value="FSE申请日"/>
                                    <apex:inputField id="FSE_ApplyForRepair_Day" value="{!RevalInfo.repair.Aware_date__c}"/>-<apex:inputField value="{!RevalInfo.repair.Aware_date2__c}"/>
                                </td>
                            </tr>
                            <!--<tr><td>&nbsp;</td></tr>-->
                            <tr>
                                <td style="text-align: left; position: relative; top: 7px;padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 5px;" value="服务方式"/>
                                    <apex:selectList value="{!RevalInfo.onSiteRepair}" size="1" style="width: 150px; height: 24px;">
                                        <apex:selectOptions value="{!SiteRepairItems}"/>
                                    </apex:selectList><p/>
                                </td>
                                <td style="text-align: left; padding-left: 50px;">
                                    <apex:outputLabel style="font-weight: bold; padding-right: 22px;" value="维修中心"/>
                                    <apex:inputText id="workLocationSelect" value="{!RevalInfo.workLocationSelect}"/>
                                    <!-- <apex:selectList value="{!RevalInfo.workLocationSelect}" size="1" style="width: 150px; height: 24px;">
                                        <apex:selectOptions value="{!workLocationSelect}"/>
                                    </apex:selectList><p/> -->
                                </td>
                                <td style="text-align: left;padding-left: 50px;">
                                    <div style="float:left;padding-right: 22px;"><apex:outputLabel style="font-weight: bold; " value="修理委托者"/></div>
                                    <div style="float:left"><apex:inputField id="InchargeStaffName" value="{!RevalInfo.repair.Incharge_Staff__c}"/></div>
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: center;" colspan="6">
                                    <apex:commandButton style="width:80px;" value="检索" action="{!RetrievalBtn}" onclick="blockme();" reRender="allForm,message" onComplete="unblockUI();"/>
                                </td>
                            </tr>
                        </table>
                    </apex:pageBlock>  
                    <apex:pageBlock title="详细信息" >
                        <input type="hidden" id="raCnt" value="{!RACount}" />
                        <apex:commandButton style="width:80px;" value="打印PDF" action="{!showPDF}" onclick="blockme();" reRender="allForm,message" onComplete="unblockUI();skipPage();"/>&nbsp;&nbsp;
                        <apex:commandButton style="width:80px;" value="导出Excel" onclick="exportExcel();"/>
                        <div id="theTable" style="width:100%;height:385px;overflow:auto;">
                        <!-- <table class="pure-table pure-table-horizontal" id="theTable_header" style="width:99%; margin-top:10px;border-collapse: collapse;table-layout:fixed;font-weight:bold;word-break:break-all;word-break:break-all;">
                        </table> -->
                        <table class="pure-table pure-table-horizontal" id="theTable_header" style="margin-top:10px; width:99%; border-collapse: collapse;table-layout:fixed;">
                            <tr style="background-color:#f2f3f3;font-weight:bold;">
                                <td style="align:left; width:2%"><apex:inputCheckbox id="checkAll" onclick="checkAll();" style="text-align:left;"/></td>
                                <td style="text-align:center; width:6%">状态1</td>
                                <td style="text-align:center; width:6%">状态2</td>
                                <td style="text-align:center; width:8%">RS修理单号</td>
                                <td style="text-align:center; width:9%">SAP修理单号</td>
                                <td style="text-align:center; width:10%">型号</td>
                                <td style="text-align:center; width:6%">机身编号</td>
                                <td style="text-align:center; width:8%">医院名称</td>
                                <td style="text-align:center; width:5%">省份</td>
                                <td style="text-align:center; width:5%">修理委托者</td>
                                <td style="text-align:center; width:7%">FSE申请日期</td>
                                <td style="text-align:center; width:6%">维修中心</td>
                                <td style="text-align:center; width:6%">服务方式</td>
                                <td style="text-align:center; width:8%;">有无维修合同对象</td>
                                <td style="text-align:center; width:6%">无偿区别标志</td>
                            </tr>
                            <apex:repeat value="{!RAInfoList}" var="ra" id="records">
                            <tr>
                                <td align="center" width="2%">
                                    <apex:inputCheckbox style="text-align:left;" id="checklist" value="{!ra.IFCheck}" />
                                </td>
                                <td align="center" width="6%">
                                    <apex:outputField id="Status1" value="{!ra.repair.Status1__c}"/>
                                </td>
                                <td align="center" width="6%">
                                    <apex:outputField id="Status2" value="{!ra.repair.Status2__c}"/>
                                </td>
                                <td align="center" width="8%">
                                    <apex:outputField id="OTCode" value="{!ra.repair.Name}"/>
                                </td>
                                <td align="center" width="9%">
                                    <apex:outputField id="SAP_Service_Repair_No" value="{!ra.repair.SAP_Service_Repair_No__c}"/>
                                </td>
                                <td align="center" width="10%">
                                    <apex:outputField id="Delivered_Product" value="{!ra.repair.Delivered_Product__c}"/>
                                </td>
                                <td align="center" width="6%" style="word-wrap:break-word;word-break:break-all;">
                                    <apex:outputField id="SerialNumber" value="{!ra.repair.SerialNumber__c}"/>
                                </td>
                                <td align="center" width="8%">
                                    <apex:outputField id="HP_Name" value="{!ra.repair.HP_Name__c}"/>
                                </td>
                                <td align="center" width="5%">
                                    <apex:outputField id="State_Hospital" value="{!ra.repair.State_Hospital__c}"/>
                                </td>
                                <td align="center" width="5%">
                                    <apex:outputField id="Incharge_Staff" value="{!ra.repair.Incharge_Staff__c}"/>
                                </td>
                                <td align="center" width="7%">
                                    <apex:outputField id="FSE_ApplyForRepair_Day" value="{!ra.repair.FSE_ApplyForRepair_Day__c}"/>
                                </td>
                                <td align="center" width="6%">
                                    <apex:outputField id="work_location_select" value="{!ra.repair.work_location_select__c}"/>
                                </td>
                                <td align="center" width="6%">
                                    <apex:outputField id="On_site_repair" value="{!ra.repair.On_site_repair__c}"/>
                                </td>
                                <td align="center" width="8%">
                                    <apex:outputField id="Number_of_EffectiveContract" value="{!ra.repair.Number_of_EffectiveContract__c}"/>
                                </td>
                                <td align="center" width="6%">
                                    <apex:outputField id="NewProductGuaranteeObject" value="{!ra.repair.NewProductGuaranteeObject__c}"/>
                                </td>
                            </tr>
                            </apex:repeat>
                        </table>
                        </div>
                    </apex:pageBlock>
                </div>
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>
</apex:page>