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
<apex:page controller="SearchContactForAgencyOppController" docType="html-5.0" showHeader="false" id="page" lightningStylesheets="true">
    <apex:slds />     
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}" />
    <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}" />
    <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 searchKeyWord = '{!searchKeyWord}';
            var accountId = '{!accountId}';
            searchAWSContact(searchKeyWord,accountId);
 
            function searchAWSContactFromPop(){
                // var inputword = '{!searchKeyWord}';
                var inputword = document.getElementById('lksrch').value;
                var hosId = '{!accountId}';
                if(inputword == null || inputword == ''){
                    window.alert("请输入搜索关键字!");
                }
                searchAWSContact(inputword,hosId);
            }
        
            function searchAWSContact(searchKeyWord,hosId){
                console.log(searchKeyWord+hosId);
                let queryResult = document.getElementById('QueryResult');
                let table = document.getElementById('table');
                if(table){
                    queryResult.removeChild(table);
                }  
                var staticResourceContact = JSON.parse('{!staticResource}');
                let searchPayload = new Object();
                var contactAWSIds = JSON.parse('{!contactAWSIds}');
                searchPayload.dataIds = [];
                searchPayload.name = searchKeyWord;
                let resBody = JSON.stringify(searchPayload);
                AWSService.search(staticResourceContact.searchUrl, resBody , function(data){
                    if(data && data.object){
                        console.log(data.object.length);
                        if(data.object.length > 15000){
                            let newObj = [];
                            for(var i = 0; i < 15000; i++){
                                newObj.push(data.object[i]);
                            }
                            data.object = newObj;
                        }
                        console.log('object:'+JSON.stringify(data.object));
                        Visualforce.remoting.Manager.invokeAction(
                            '{!$RemoteAction.SearchContactForAgencyOppController.searchContacts}',
                            JSON.stringify(data.object),searchKeyWord,hosId,
                            function (result, event) {
                                if(event.status){
                                    console.log("result:"+JSON.stringify(result));
                                    refreshTable(result);                                  
                                }
                            },
                            { escape: true }
                        );
                    }
                }, staticResourceContact.token);
            }
        
            function refreshTable(contactInfoList){
                let cols = ['Name','Hospital_Name__c', 'Type__c', 'Doctor_Division1__c'];
                let myTableDiv = document.getElementById("QueryResult");
                let table = document.createElement('TABLE');
                table.border = '1';
                table.id = 'table'
                let tableBody = document.createElement('TBODY');
                table.appendChild(tableBody);
                let headerTR = document.createElement('TR');
                headerTR.setAttribute("class","headerRow");
                let colsHeader = ['姓名','医院名称','分类', '职务'];
                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 = contactInfoList[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;';
                        td.awsId = contactInfoTemp.AWS_Data_Id__c;      
                        td.recordId = contactInfoTemp.Id;      
                        td.conName = contactInfoTemp.Name;      
                        td.appendChild(document.createTextNode(contactInfoTemp[cols[j]]!=null?contactInfoTemp[cols[j]]:''));
                        if (cols[j] == 'Name') {
                            td.width = '120';
                        }
                        if (cols[j] == 'Name') {
                            td.addEventListener("click", function (obj) {
                                let awsId = obj.currentTarget.awsId;
                                let recordId = obj.currentTarget.recordId;
                                let conName = obj.currentTarget.conName;
                                let domId = "{!domId}";
                                console.log('obj:'+awsId+conName+recordId+domId);
                                // var dom = document.getElementById('')
                                var winMain = window.opener;
                                if (null == winMain) {
                                    winMain = window.parent.opener;
                                }
                                var domArr = winMain.document.querySelectorAll("input[field-api='Agency_Contact__c']");
                                var domArr1 = winMain.document.querySelectorAll("[field-api='AwsId']");
                                var domArr2 = winMain.document.querySelectorAll("[field-api='RecordId']");
                                console.log(domArr.length);
                                console.log(domArr1.length);
                                console.log(domArr2.length);
                                for(var j = 0; j < domArr.length; j++){
                                    var domname = domArr[j].parentNode.parentNode.id;
                                    if(domname == domId){
                                        console.log('domId:'+domId);
                                        domArr[j].value = conName;
                                        domArr1[j].value = awsId;
                                        domArr2[j].value = recordId;
                                    }
                                }
                                winMain.closePopupWindow();
                                window.close();
                            });
                            td.setAttribute("style","color:rgba(1, 118, 211, 1);text-align: left;cursor: pointer;");
                        }
                        tr.appendChild(td);
                    }
                }
                myTableDiv.appendChild(table);
            }
        </script>
        <apex:form id="form">
            <!-- Search Filter-->
            <div style="padding-left: 10px;padding-right: 10px;height:200px;max-height:200px;">
                <apex:inputHidden value="{!searchKeyWord}" id="searchKeyWord" />
                <div class="lookup">
                    <div class="content" style="text-align: center;font-size:18px;">
                        <h1>{!ObjectTypeLabel}</h1>
                    </div>
                    <div>
                        <apex:outputText value="{!ObjectTypeLabel}" style="width: 500px;" />
                    </div>
                    <div class="pBody">
                        <label class="assistiveText" for="lksrch">Search</label>
                        <apex:inputText styleClass="slds-input" id="lksrch" html-placeholder="请输入..." value="{!searchKeyWord}" style="width: 500px;height:32px;" />
                        <apex:commandButton styleClass="slds-button slds-button_neutral" value=" 检索 " style="margin-left:10px;height:32px;" onclick="searchAWSContactFromPop();" oncomplete="unblockUI();" />
                    </div>
                </div>
                <div><br/></div>
                <div id="QueryResult" style="height:480px;overflow:scroll;">
                </div>
            </div>
        </apex:form>
    </body>
</apex:page>