buli
2022-05-13 2f4492ee18f90274582fcc2bb06f5e9bf64136e8
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
<apex:page id="Page" standardController="Mail_Merge__c" extensions="SendEmailController" sidebar="false" showHeader="false" action="{!init}" title="SendEmail">
 
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
 
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
 
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no"/>
    <style type="text/css"> 
        .tableCss{
            width: 100%;
            border: 0;
        }
        .errorMessage{
            font-size: 15px;
            color:#FF0000;
        }
        .title{
            height: 30px;
            background-color: #DFE6F0;
        }
        .title font{
            font-size:15px;
            color:#607799;
        }
    </style>
    <script>
 
        function formSubmit(){
            testFile();
        }
        function openPDF(){
            //var typeId = "{!mail.RECORD__c}";
            var baseUrl = j$(escapeVfId("baseUrl")).value();
            window.open(baseUrl + '/apex/QuotesPDF?id={!mail.RECORD__c}');
        }
        function openSearchMemberPage(lineNum){
            var baseUrl = j$(escapeVfId("baseUrl")).value();
            //var repairId = j$(escapeVfId("repairId")).value();
            window.open(baseUrl + '/apex/SearchMemberPage?lineNum='+lineNum,'pselect', 'width=600,height=450,scrollbars=yes,toolbar=no,status=no,directories=no,menubar=no,resizable=1', true);
        }
        function refreshPage(lineNum,memberId,memberName,memberEmail){
            /*var memberNameId = "memberName"+lineNum;
            var memberEmailId = "memberEmail"+lineNum;
            j$(escapeVfId(memberNameId)).attr("value",memberName);
            j$(escapeVfId(memberEmailId)).attr("value",memberEmail);*/
            addMemberData(lineNum,memberId,memberName,memberEmail);
        }
        function statusChabge(linenumNum,type){
            var toId = "Page:messageForm:lineDataList:"+linenumNum+":"+"to";
            var ccId = "Page:messageForm:lineDataList:"+linenumNum+":"+"cc";
            var bccId = "Page:messageForm:lineDataList:"+linenumNum+":"+"bcc";
            var toValue = j$(escapeVfId(toId)).value();
            var ccValue = j$(escapeVfId(ccId)).value();
            var bccValue = j$(escapeVfId(bccId)).value();
            j$(escapeVfId(toId)).attr("checked",false);
            j$(escapeVfId(ccId)).attr("checked",false);
            j$(escapeVfId(bccId)).attr("checked",false);
            //这个if判断,保证三个收件人类型有一个时选中的,不可以三个都为不勾选
            //if(toValue == ""&&ccValue==""&&bccValue==""){
                if(type == "to"){
                    j$(escapeVfId(toId)).attr("checked",true);
                }
                if(type == "cc"){
                    j$(escapeVfId(ccId)).attr("checked",true);
                }
                if(type == "bcc"){
                    j$(escapeVfId(bccId)).attr("checked",true);
                }
            //}
            //下边三个if,三个勾选框互斥,只能勾选一个
            /*if(type == "to"){
                j$(escapeVfId(ccId)).attr("checked",false);
                j$(escapeVfId(bccId)).attr("checked",false);
            }
            if(type == "cc"){
                j$(escapeVfId(toId)).attr("checked",false);
                j$(escapeVfId(bccId)).attr("checked",false);
            }
            if(type == "bcc"){
                j$(escapeVfId(toId)).attr("checked",false);
                j$(escapeVfId(ccId)).attr("checked",false);
            }*/
        }
 
        //dialog 弹窗 start 
        var popupBox;
            popupBox = new SimpleDialog("SpeedDialogId", false);  // 不可拖动
            popupBox.createDialog();        
        function openFile(){
            // alert('111111111');
            // uploadFileS();
            popupBox.setTitle("请选择要上传的图片!");
            popupBox.importContentNode(document.getElementById("Page:messageForm:popupBox"));
            popupBox.show(document.getElementById("Page:messageForm:popupBox"));
            document.getElementById("Page:messageForm:popupBox").style.display = 'block';
           
 
        }
        //dialog 弹窗 end 
        
        //上传图片
            function saveAttachment(){
                 var maxFileSize = 4350000;      //Base64 编码以后最大的文件字节数
                 var attachmentBody;                //附件内容
                 var attachmentName;                //附件名称
                 var attachmentType;                //附件名称
                 var attachmentSize;                //附件大小
                 var parentId = j$(escapeVfId("parentId")).value();
                 // 获取上传图片的数量
                 var size = document.getElementById("file_input").files.length;
                 if (size > 0) {
                    var nameList = [];
                    var typeList = [];
                    var bodyList = [];
                    for(var i = 0;i < size;i++){
                        var fbody = document.getElementById("file_input").files[i];
                        attachmentName = fbody.name;
                        if(fbody.size <= maxFileSize) {
                            attachmentType = fbody.type;
                            nameList.push(attachmentName);
                            typeList.push(attachmentType);
                            var fileReader = new FileReader();
                            fileReader.readAsBinaryString(fbody);
                            fileReader.onload = function(e) {
                                bodyList.push(window.btoa(this.result));
                            }
                            fileReader.onerror = function(e) {
                                alert("上传失败,请重新尝试");
                            }
                            fileReader.onabort = function(e) {
                                alert("上传失败,请重新尝试");
                            }
                        } else {
                            alert("Base64 编码最大允许4.3M文件,"+attachmentName + '过大无法上传');
                        }
 
 
                    }
                    if (nameList.length > 0) {
                         //使用RemoteAction上传附件
                         Visualforce.remoting.Manager.invokeAction(
                           '{!$RemoteAction.SendEmailController.AddAttachment}',
                           nameList,
                           typeList,
                           bodyList,
                           parentId,
                           function(result,event) {
                               
                             if(result == '文件上传成功'){
                                alert(result); 
                                RefreshPage();
                             } else if (result == null){
                                result = '文件上传失败,请重新上传';
                                alert(result); 
                                RefreshPage();
                             } else {
                                alert(result); 
                             }
                             
                           });
 
                    }
                    
                 }
                 
                 
            }
    </script>
    <div style="width : 100%;">
    <div style="width : 70%; margin: auto;">
        <apex:form id="messageForm">
            <input type="hidden" id="baseUrl" value="{!baseUrl}"/>
            <input type="hidden" id="parentId" value="{!Id}"/>
            <input type="hidden" id="isOnClick" value="{!isOnClick}"/>
            <apex:actionFunction name="addMemberData" action="{!addMemberData}" reRender="messageForm">
                <apex:param name="lineNum" assignTo="{!lineNum}" value="" />
                <apex:param name="memberId" assignTo="{!memberId}" value="" />
                <apex:param name="memberName" assignTo="{!memberName}" value="" />
                <apex:param name="memberEmail" assignTo="{!memberEmail}" value="" />
            </apex:actionFunction>
            <!-- 图片批量上传 保存Email -->
             <apex:actionFunction name="uploadFileS" action="{!uploadFileS}" reRender="messageForm" oncomplete="openFile();"/>
             <!-- 图片批量上传 刷新页面 -->
              <apex:actionFunction name="RefreshPage"  action="{!RefreshPage}" reRender="messageForm"/>
            <apex:actionFunction name="deleteFile" reRender="fileForm">
                <!-- <apex:param name="lineNum" assignTo="{!lineNum}" value="" /> -->
            </apex:actionFunction>
 
            <div style="width: 100%">
                <div class="errorMessage" style="margin-left: 39%">
                    <span id="errorMessage">{!errorMessage}</span>
                </div>
            </div>
 
            <div style="width: 100%;">
                <table class="tableCss">
                    <tr class="title">
                        <th colspan="2"><font>Recipients</font></th>
                    </tr>
                    <tr>
                        <th style="width: 20%;text-align:center;">FROM:</th>
                        <td><apex:outputText value="{!mail.FROM__c}" style="width: 40%"/></td>
                    </tr>
                </table>
            </div>
            <div style="width: 50%;margin-left: 20%;">
                <!-- style="border:1px solid #000000;" -->
                <table class="tableCss">
                    <thead>
                        <tr>
                            <th style="width: 25%;text-align:center;">email</th>
                            <th style="width: 10%;text-align:center;">name</th>
                            <th style="width: 5%;text-align:center;">TO</th>
                            <th style="width: 5%;text-align:center;">CC</th>
                            <th style="width: 5%;text-align:center;">BCC</th>
                            <th style="width: 5%;text-align:center;"></th>
                        </tr>
                    </thead>
                    <tbody id="memberBody">
                        <apex:repeat id="lineDataList" value="{!memberLineDatas}" var="lineData">
                            <tr style="text-align:center;">
                                <td>
                                <input type="hidden" id="memberName{!lineData.lineNum}" value="{!lineData.name}" />
                                <apex:inputText value="{!lineData.emailAddress}" /></td>
                                <td><apex:inputText value="{!lineData.name}" /></td>
                                <td><apex:inputCheckbox onclick="statusChabge({!lineData.lineNum},'to')" id="to" value="{!lineData.to}"/></td>
                                <td><apex:inputCheckbox onclick="statusChabge({!lineData.lineNum},'cc')" id="cc" value="{!lineData.cc}"/></td>
                                <td><apex:inputCheckbox onclick="statusChabge({!lineData.lineNum},'bcc')" id="bcc" value="{!lineData.bcc}"/></td>
                                <td><apex:commandButton onclick="blockme();" action="{!deLine}" reRender="messageForm" value="delete"  oncomplete="unblockUI();" disabled="{!isOnClick}">
                                    <apex:param name="lineNum" assignTo="{!lineNum}" value="{!lineData.lineNum}" />
                                </apex:commandButton></td>
                                <td>
                                    <apex:commandButton onclick="openSearchMemberPage({!lineData.lineNum});" value="Search" disabled="{!isOnClick}">
                                        
                                    </apex:commandButton>
                                </td>
                            </tr>
                        </apex:repeat>
                    </tbody>
                    <thead>
                        <tr style="text-align:center;">
                            <td><apex:commandButton id="addLine" onclick="blockme();" action="{!addLine}" reRender="messageForm" value="ADD Member" oncomplete="unblockUI();" disabled="{!isOnClick}"></apex:commandButton></td>
                        </tr>
                    </thead>
                </table>
            </div>
            <div style="width: 100%">
                <table class="tableCss">    
                    <tr class="title">
                        <th colspan="2"><font>Message</font></th>
                    </tr>
                    <tr>
                        <th style="width: 20%;text-align:center;">Date Time:</th>
                        <td><apex:inputField value="{!mail.DATE__c}" style="width: 40%"/></td>
                    </tr>
                    <!-- <tr>
                        <th style="width: 20%;text-align:center;">RECORD:</th>
                        <td><apex:inputField value="{!mail.RECORD__c}" style="width: 40%"/></td>
                    </tr>
                    <tr>
                        <th style="width: 20%;text-align:center;">RECORD TYPE:</th>
                        <td><apex:inputField value="{!mail.RECORD_TYPE__c}" style="width: 40%"/></td>
                    </tr> -->
                    <tr>
                        <th style="text-align:center;width: 20%;">SUBJECT:</th>
                        <td><apex:inputField value="{!mail.SUBJECT__c}" style="width: 40%"/></td>
                    </tr>
                    <tr>
                        <th style="text-align:center;width: 20%;">MESSAGE:</th>
                        <td><apex:inputField style="height: 200px;width: 60%" value="{!mail.MESSAGE__c}"/></td>
                    </tr>
                </table>
            </div>
        <!-- </apex:form>
        <apex:form id="fileForm"> -->
            <div style="width: 100%">
                <table class="tableCss">
                    <tr class="title">
                        <th colspan="2"><font>Attachments</font></th>
                    </tr>
 
                    <tr>
                        <td>
                            <apex:commandButton value="Upload Attachment" action="{!uploadFile}" disabled="{!isOnClick}">
                            </apex:commandButton>
                             <apex:panelGroup >
                                 <apex:commandButton onclick="uploadFileS();return false;" value="图片批量上传" disabled="{!isOnClick}"/>
                            </apex:panelGroup>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="margin-left: 5px;"> 
                <!-- border:1px solid #000000; -->
                <table class="tableCss" style="width: 80%"> 
                    <tr style="text-align:center;">
                        <th style="text-align:center;width: 33%;">File Name</th>
                        <th style="text-align:center;width: 33%;">Upload Time</th>
                        <th style="text-align:center;width: 33%;">File Size</th>
                    </tr>
                    <apex:repeat id="attachmentList" value="{!attachmentList}" var="attachment">
                        <tr style="text-align:center; vertical-align: middle;">
                            <!-- <td><input value="{!attachment.Name}" readonly="readonly" style="border:none;"/></td> -->
                            <td><apex:outputLink value="/{!attachment.Id}">{!attachment.Name}</apex:outputLink></td>
                            <td><apex:inputField value="{!attachment.CreatedDate}"/></td>
                            <td><apex:inputField value="{!attachment.BodyLength}"/></td>
                            <td id="{!attachment.Id}">
                                <apex:commandButton id="deleteFile" value="delete" action="{!deleteFile}" reRender="messageForm" onclick="blockme();" oncomplete="unblockUI();" disabled="{!isOnClick}">
                                    <apex:param name="fileId" assignTo="{!fileId}" value="{!attachment.Id}" />
                                </apex:commandButton>
                            </td>
                        </tr>
                    </apex:repeat>
                </table>
            </div>
 
            <div style="width: 30%;height: 5%;margin-left: 30%;margin-top: middle;">
                 <apex:outputPanel rendered="{!IF(type == 'Quotes', true, false)}">
                    <apex:commandButton id="open" value="查看报价单" onclick="openPDF()" style="width: 49%;height: 5%" />
                    <apex:commandButton id="addPDf" value="添加报价单" action="{!addPDF}" onclick="blockme();"  oncomplete="unblockUI();" reRender="messageForm" style="width: 49%;height: 5%" disabled="{!isOnClick}"/>
                </apex:outputPanel>
                <apex:commandButton id="test" action="{!SendEmail}" value="Send   Mail" onclick="blockme();"  oncomplete="unblockUI();" reRender="messageForm" style="width: 99%;height: 5%" disabled="{!isOnClick}">
                    <apex:param name="handleType" assignTo="{!handleType}" value="send" />
                </apex:commandButton>
            </div>
            <apex:outputPanel id="popupBox" layout="block" style="display:none">
 
                <input type="file" id="file_input" name="attFile" multiple="true"/><br/>
                <center>
                    <apex:commandButton value="确认" onclick="saveAttachment(); return false;" style="width: 20%; margin: 20px 10px 0px 10px" />
                    <apex:commandButton value="取消" onclick="popupBox.hide();" style="width: 20%; margin: 20px 10px 0px 10px" />
                </center>
            </apex:outputPanel> 
        </apex:form>
    </div>
    </div>
</apex:page>