liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
<apex:page controller="SearchContactLWCController" showHeader="false" id="page" lightningStylesheets="true">
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}" />
    <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}" />
    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}" />
    <apex:stylesheet value="{!URLFOR($Resource.StyleUtilCss)}"/>
    <head>
    </head>
    <style>
        /* 1. 定义表单样式 To Do Later*/
        table {
            border-collapse: collapse;
            border-spacing: 0;
            width: 98%;
            margin-left: 5px;
            font-family: sans-serif;
            left;
            white-space: nowrap;
        }
        th {
            height: 25px;
            text-align: left;
            background: rgb(240 238 238);
            border-width: 1px 1px 1px 1px;
            border-color: #e0e3e5;
            font-size:0.75rem;
            font-weight: 700;
            color: black;
            white-space: nowrap;
        }
        td {
            /* background: #f2f3f3; */
            height: 29px;
            border-width: 1px 1px 1px 1px;
            border-color: #e0e3e5;
            font-size: inherit;
            /*font-weight: bold;*/
            color: black;
            text-align: center;
            left;
            white-space: nowrap;
            /* font-size: 13px; */
        }
        /* div{
            padding-left: 10px;
            padding-right: 10px;
        } */
        tr.dataRow:hover {
            background-color: #e3f3ff;
        }
    </style>
 
    <body id="body" class="lookupTab">
        <script type="text/javascript">
            var staticResources = JSON.parse('{!staticResource}');
            var contactAWSIds = JSON.parse('{!contactAWSIds}');
            var contactsInfo = JSON.parse('{!contactsInfo}');
            var searchKeyWord = '{!searchKeyWord}';
 
            let inputHiddenId='{!inputHiddenId}';
            let inputFieldId ='{!inputFieldId}';
            //2023 08 30 张赫阳 PIPL页面改造 start
            var OFSType = '{!OFSType}';
            //2023 08 30 张赫阳 PIPL页面改造 end
            var searchContactName = searchKeyWord;
 
            queryLeadFromAWS();
            function searchAWSContact(){
                console.log('===============================================================');
                console.log('{!ObjectType}');
                console.log('{!FieldNameList}');
                console.log('{!FieldApiNameList}');
                console.log('{!QueryFieldName}');
                console.log('{!QueryFieldApiName}');
                //1. reset table;
                blockme();
                resetTable();
                //2. get contact name value 
                searchContactName = document.getElementById('page:form:lksrch').value;
                queryLeadFromAWS();
            }
            function initSearchAWSContact(){
                console.log('===============================================================');
                console.log('{!ObjectType}');
                console.log('{!FieldNameList}');
                console.log('{!FieldApiNameList}');
                console.log('{!QueryFieldName}');
                console.log('{!QueryFieldApiName}');
                //1. reset table;
                resetTable();
                //2. get contact name value 
                searchContactName = document.getElementById('page:form:lksrch').value;
                queryLeadFromAWS();
            }
            function resetTable(){
                let queryResult = document.getElementById('QueryResult');
                let table = document.getElementById('table');
                if(table){
                    queryResult.removeChild(table);
                }
                // resetTablecss();               
            }
 
            // function resetTablecss(){
            //     var obj = document.getElementById('table');
            //     // obj.setAttribute('class','list');
            //     for (var i = 0; i < obj.length; i++) {
            //         obj[i].setAttribute('class','list' );
            //     }
            // }
            function preparePayloadForSearchContact(){
                let searchPayload = new Object();
                searchPayload.dataIds = contactAWSIds;
                searchPayload.contactName = searchContactName;
                return JSON.stringify(searchPayload);
            }
            function queryLeadFromAWS() {
                let requestSearchPayload = preparePayloadForSearchContact();
                let queryBackContactName = function queryBackContactName(result){
                    // if(result.object){
                    //     initContactTable(result);
                    // }
                    console.log('result!');
                    console.log(result);
                    initContactTable(result);
                };
                // console.log(staticResources);
                initContactTable('');
                // AWSService.search('staticResources.searchUrl',requestSearchPayload,queryBackContactName,'staticResources.token');
            }
            
            function redirectToParentPage(obj) {
                console.log('redirectToParentPage obj = ' + obj.currentTarget.AWSDataId)
                var winMain = window.opener;
                if (null == winMain) {
                    winMain = window.parent.opener;
                }
                console.log(obj.currentTarget.innerHTML,'20231027001>>>');
                
                let value = obj.currentTarget.innerHTML;
                let contactInfo = new Object();
                contactInfo.Name = obj.currentTarget.innerHTML;
                contactInfo.Id = obj.currentTarget.AWSDataId.substring(0,15);
                //2022-5-7 yjk 增加邮箱、手机号 
                var tdNodes = obj.currentTarget.parentNode.childNodes;
                contactInfo.AWSDataId = obj.currentTarget.AWSDataId.substring(0,15);
                //2023 08 30 张赫阳 PIPL页面改造 start
                // var selectedContactNode = winMain.document.getElementById(inputHiddenId);
                // console.log(winMain.document.getElementById(inputHiddenId));
                let inputFieldIdT ='{!inputFieldId}';
                console.log(inputFieldIdT,'20231027002>>>');
                console.log(document.getElementById(inputFieldIdT),'20231027003>>>');
                console.log(winMain.document.getElementById(inputFieldIdT),'20231027003>>>');
                // winMain.document.getElementById(inputHiddenId).value = contactInfo.Id;
                // j$(escapeVfId(inputFieldId)).val(contactInfo.Name);
                winMain.document.getElementById(inputFieldIdT + '_lkold').value = contactInfo.Name;
                winMain.document.getElementById(inputFieldIdT + '_lkid').value = contactInfo.Id;
                winMain.document.getElementById(inputFieldIdT).value = contactInfo.Name;
                // selectedContactNode.value = JSON.stringify(contactInfo);
                try{
 
                }catch(e){
                    console.log(e);
                }
 
                closeWindow();
            }
 
            function closeWindow() {
                var winMain = window.opener;
                if (null == winMain) {
                    winMain = window.parent.opener;
                }
                // winMain.closePopupWindow();
                window.close();
            }
            function refreshTable(cols,contactInfoList){
                let myTableDiv = document.getElementById("QueryResult");
                let table = document.createElement('TABLE');
                table.border = '1';
                // table.setAttribute("class","list");
                // table.class = 'list';
                table.id = 'table'
                let tableBody = document.createElement('TBODY');
                table.appendChild(tableBody);
                let headerTR = document.createElement('TR');
                headerTR.setAttribute("class","headerRow");
                // let colsHeader = ['姓名','客户名称','邮箱', '电话','手机号'];
                let colsHeader = '{!FieldNameList}';
                colsHeader=colsHeader.split(',');
                tableBody.appendChild(headerTR);
                for (let i = 0; i < colsHeader.length; i++) {
                    let td = document.createElement('TH');
                    td.width = '75';
                    td.style = 'text-align: left;';
                    td.appendChild(document.createTextNode(colsHeader[i]));
                    headerTR.appendChild(td);
                }
                //3. Init the AWS data
                for (let i = 0; i < contactInfoList.length; i++) {
                    let tr = document.createElement('TR');
                    tr.setAttribute("class","dataRow");
                    tableBody.appendChild(tr);
                    let contactInfoTemp = contactsInfo[Object.keys(contactsInfo)[i]];
                    for (let j = 0; j < cols.length; j++) {
                        let td = document.createElement('TD');
                        td.setAttribute("class","dataCell");
                        td.width = '75';
                        td.style = 'text-align: left;';
                        try{
                            if(j == 0 && contactsInfo[Object.keys(contactsInfo)[i]] ){
                                td.id = contactInfoTemp.Id;
                                td.AWSDataId = contactInfoTemp.Id;
                                td.setAttribute("style","color:rgba(1, 118, 211, 1);text-align: left;");
                                
                            }
                            if(j == 1 && contactsInfo[Object.keys(contactsInfo)[i]] ){
                                td.id = contactInfoTemp.Id;
                            }
                            if(cols[j] == 'AccountName'){
                                let accountName = contactInfoTemp['Account']['Name'] != null ? contactInfoTemp['Account']['Name'] : '';
                                td.appendChild(document.createTextNode(accountName));
                            }else{
                                td.appendChild(document.createTextNode(contactInfoTemp[cols[j]]!=null?contactInfoTemp[cols[j]]:''));
                            }
                            
                            
                        }catch(e){
                                       
                            
                        }
                        if (cols[j] == 'Name') {
                            td.width = '120';
                        }
                        if (cols[j] == 'Name') {
                            td.addEventListener("click", function (obj) {
                                redirectToParentPage(obj);
                            });
                            td.setAttribute("style","color:rgba(1, 118, 211, 1);text-align: left;cursor: pointer;");
                        }
                        tr.appendChild(td);
                    }
                }
                myTableDiv.appendChild(table);
                // unblockUI();
            }
            function initContactTable(data) {            
                let cols = '{!FieldApiNameList}';
                cols=cols.split(',');
                let contactInfoList = [];
                let awsDataIds = [];
                let AWSIdToSFIdMapValue = {};
                //Invoke SF BackEnd
                let searchWord=document.getElementById('page:form:lksrch').value;
                console.log('searchWord:'+searchWord);
 
                Visualforce.remoting.Manager.invokeAction(
                    '{!$RemoteAction.SearchContactLWCController.searchContacts}',
                    JSON.stringify(awsDataIds),searchWord,'{!FieldApiNameList}','{!ObjectType}','{!QueryFieldApiName}','{!SelectObj}','{!SelectFld}','{!setVal}','{!FilterSql}',
                    function (result, event) {
                        debugger
                        console.log('data=');
                        console.log(data);
                        console.log('res=');
                        console.log(result);
                        console.log(contactInfoList);
                        if(event.status){
                            if(result.status = 'success'){
                                if(result.message){
                                    contactsInfo = JSON.parse(result.message.replace(/(&quot\;)/g,"\""));
                                    console.log('contactsInfo=');
                                    console.log(contactsInfo);
                                    console.log(Object.keys(contactsInfo).length);
                                    if(Object.keys(contactsInfo).length>0){
                                        for(let i=0;i<Object.keys(contactsInfo).length;i++){
                                            let contactInfo = new Object();
                                            let contactInfoTemp=contactsInfo[Object.keys(contactsInfo)[i]];
                                            for(let j=0;j<cols.length;j++){
                                                try{
                                                    if(cols[j] == 'Account.Name'){
                                                        contactInfo['AccountName']=contactInfoTemp['Account']['Name'];
                                                    }else{
                                                        contactInfo[cols[j]]=contactInfoTemp[cols[j]];
                                                    }
                                                }catch(e){
                                                    contactInfo[cols[j]]='';
                                                }
                                            }
                                            contactInfoList.push(contactInfo);
                                        }
                                    }
                                }
                                for(let i = 0; i < cols.length; i++){
                                    if(cols[i] == 'Account.Name'){
                                        cols[i] = 'AccountName';
                                    }
                                }
                                refreshTable(cols,contactInfoList);
                            }else{
                                console.log('No result');
                            }                                               
                        }
                    },
                    { escape: true }
                );
            }
        </script>
        <apex:form id="form">
            <div style="padding-left: 10px;padding-right: 10px;height:200px;max-height:200px;">
    <!--             <apex:actionFunction name="searchContacts" action="{!searchContacts}" rerender="form" onComplete="">
                </apex:actionFunction> -->
                <apex:inputHidden value="{!searchKeyWord}" id="searchKeyWord" />
                <!-- Search Filter-->
                <div class="lookup">
                    <div class="content" style="text-align: center;">
                        <!-- <img src="/img/s.gif" alt="" class="pageTitleIcon" title="" /> -->
                        <h1>{!ObjectTypeLabel}</h1>
                        <!-- <h1>{!$ObjectType.DiscountProductApplication__c.fields.RawAccount__c.label}</h1> -->
                        <!-- <h1>查找</h1> -->
                    </div>
                    <div>
                        <apex:outputText value="{!ObjectTypeLabel}" style="width: 500px;" />
                    </div>
                    <div class="pBody">
                        <label class="assistiveText" for="lksrch">Search</label>
                        <apex:inputText id="lksrch" html-placeholder="请输入..." value="{!searchKeyWord}" style="width: 500px;" />
                        <apex:commandButton value=" 检索 "   onclick="searchAWSContact();" oncomplete="unblockUI();" />
                        <!-- <div class="bDescription">You can use "*" as a wildcard next to other characters to improve your search results.
                        </div> -->
                    </div>
                </div>
                <div><br/></div>
                <div id="QueryResult" style="height:350px;overflow:scroll;">
                </div>
            </div>
        </apex:form>
    </body>
    <!-- <script type="text/javascript">
        // var obj = document.getElementById('table');
        // // obj.setAttribute('class','list');
        // for (var i = 0; i < obj.length; i++) {
        //     obj[i].setAttribute('class','list' );
        // }
        // var obj = document.getElementsByTagName('th');
        // for (var i = 0; i < inputs.length; i++) {
        //     inputs[i].setAttribute('class','initialSortAsc sortable' );
    </script> -->
    <script type="text/javascript">
        initSearchAWSContact();
    </script>
</apex:page>