<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(/("\;)/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>
|