buli
2022-04-15 60a9db0296617ffc71f928c46991aa3c6ddf0e83
force-app/main/default/pages/NewLoanerUser.page
@@ -1,26 +1,180 @@
<apex:page standardController="loaner_user__c" extensions="NewLoanerUserController" showHeader="true" sidebar="false" action="{!init}" title="新建样机借用客户">
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<script>
function saveJs() {
   if(confirm('联系人和客户为必填信息,如果为空将不保存此条记录,是否已确认所有需要保存的信息该字段都不为空?')){
      blockme();
      updateUser();
<apex:page standardController="loaner_user__c" extensions="NewLoanerUserController" id="allPage" showHeader="true" sidebar="false" action="{!init}" title="新建样机借用客户">
<!-- <apex:page standardController="loaner_user__c" extensions="NewLoanerUserController" showHeader="true" sidebar="false" action="{!init}" title="新建样机借用客户"> -->
   <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
   <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
   <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
   <!-- Update 20220317 By Yang Kaiyu Start -->
   <apex:includeScript value="{!URLFOR($Resource.CommonUtilJs)}"/>
   <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
   <apex:includeScript value="/soap/ajax/40.0/connection.js"/>
   <!-- Update 20220317 By Yang Kaiyu End -->
   <script>
      // Update 20220317 By Yang Kaiyu Start
      AWSService.sfSessionId = '{!GETSESSIONID()}';
        var staticResource = JSON.parse('{!staticResource}');
      var staticResourceContact = JSON.parse('{!staticResourceContact}');
      var aws_data = {};
      let conList = [];
      //替换vlookup
      var closeField = '';
        var newSearchContactWindow = null;
      var contactInfoStr = '';
      var conValue = ''
      //自定义lookup查询
        function searchContact(contactNodeId,field,conValue,conid){
            closeField = conid;
         this.conValue = conValue;
            let accountValue = "";
            if (document.getElementById(field)!=null) {
                accountValue = document.getElementById(field).value;
            }
            console.log(accountValue);
            if(accountValue !='000000000000000'){
                let baseUrl = "/apex/SearchContactPage";
                let suffixUrl = "?contactId="+contactNodeId+"&accountId="+accountValue;
                let newSearchContactParam = 'height=600,width=800,left=100,top=100,dialogHide=true,resizable=no,scrollbars=yes,toolbar=no,status=no';
                newSearchContactWindow = window.open(baseUrl+suffixUrl, 'Popup', newSearchContactParam);
                if (window.focus) {
                    newSearchContactWindow.focus();
                }
                return false;
            }else{
                alert('请先选择客户再选择联系人')
            }
        }
      var dataLinesJson;
      function replaceSearchContactLookup() {
         conList = JSON.parse('{!conListJson}');
         dataLinesJson = JSON.parse('{!dataLinesJson}');
         console.log('dataLinesJson = ' + dataLinesJson);
         for(var i = 0;i<dataLinesJson.length;i++){
            //if(document.getElementById('allpage:allForm:allBlock:lines:'+i+':customer') != null){
            let contactHtmlString = '<img src="/img/s.gif" onclick="searchContact(\'allPage:allForm:contactId\',\'allPage:allForm:allBlock:lines:'+i+':customer_lkid\',\'allPage:allForm:allBlock:lines:'+i+':contact_lkid\',\'allPage:allForm:allBlock:lines:'+i+':contact\')" alt="Reference Document Number Lookup" class="lookupIcon"  title="Reference Document Number Lookup (New Window)"/>';
            let lookUpNode = htmlToElement(contactHtmlString);
            console.log(lookUpNode);
            let parentNode = document.getElementById('allPage:allForm:allBlock:lines:'+i+':contact').parentNode;
            //parentNode.appendChild(lookUpNode);
            parentNode.replaceChild(lookUpNode, document.getElementById('allPage:allForm:allBlock:lines:'+i+':contact').parentNode.children[2]);
            //}
         }
        }
      function htmlToElement(html) {
            var template = document.createElement('template');
            html = html.trim(); // Never return a text node of whitespace as the result
            template.innerHTML = html;
            return template.content.firstChild;
        }
      function closePopupWindow() {
            if (null != newSearchContactWindow) {
                newSearchContactWindow.close();
            }
            contactInfoStr = document.getElementById('allPage:allForm:contactId').value;
            console.log('closePopup:'+contactInfoStr);
            let contactInfo = JSON.parse(contactInfoStr);
            let contactNodeId = conValue;
            document.getElementById(contactNodeId).value = contactInfo.ContactId;
            document.getElementById(closeField).value = contactInfo.Name;
        }
      function DecryptAll(){
            let dataIds = [];
            //"{!conList}".each((i,e)=>{
         //   console.log('------------------')
         //   console.log(e);
            //    let v = "{!conList}"[i].contactIdValue;
            //    if (v) {
            //        dataIds.push(v);
            //    }
            //});
         conList = JSON.parse('{!conListJson}');
         if(conList){
            for(var i=0 ;i<conList.length;i++){
               if(conList[i]!=null){
                  let v = conList[i].contactIdValue;
                  if (v) {
                     dataIds.push(v);
                  }
               }
            }
         }
            Decrypt(dataIds);
        }
      j$(function(){
            DecryptAll();
        })
      function Decrypt(dataIds){
            let Foo = function(){
                for (const id in dataIds) {
                    if (aws_data.hasOwnProperty(dataIds[id])) {
                        let d = aws_data[dataIds[id]];
                        let $e =j$("[aws-id='"+d.dataId+ "']");
                        //$e.html(d[$e.attr("aws-id")]);
                  $e.each(function(i,e){
                     j$(e).val(d.lastName);
                  })
                    }
                }
            }
            let ids = [];
            //for (const id in dataIds) {
            //    if (!aws_data.hasOwnProperty(id)) {
            //        ids.push(id);
            //    }
            //}
         for(var i =0 ;i<dataIds.length;i++){
            if (!aws_data.hasOwnProperty(dataIds[i])) {
               ids.push(dataIds[i]);
            }
         }
            if (ids.length > 0) {
                blockme();
                AWSService.search(staticResourceContact.searchUrl,
            JSON.stringify({
                    "dataIds":ids
                }),
            function(data){
                    unblockUI();
                    if(data.object && data.object.length > 0){
                        for(let d in data.object){
                     console.log('----------------')
                     console.log(d);
                            if(data.object[d].dataId){
                                aws_data[data.object[d].dataId] = data.object[d];
                            }
                        }
                        Foo();
                    }
                },
            staticResourceContact.token);
            }else{
                Foo();
            }
        }
      // Update 20220317 By Yang Kaiyu End
      function saveJs() {
      if(confirm('联系人和客户为必填信息,如果为空将不保存此条记录,是否已确认所有需要保存的信息该字段都不为空?')){
         blockme();
         updateUser();
      }
   }
}
</script>
   </script>
<style type="text/css">
   .dateFormat{
      display: none;
   }
</style>
   <style type="text/css">
      .dateFormat{
         display: none;
      }
   </style>
   <apex:form id="allForm">
      <!-- Update 20220317 By Yang Kaiyu Start -->
       <apex:inputHidden value="{!contactId}" id="contactId" />
       <!-- Update 20220317 By Yang Kaiyu End -->
       <apex:actionFunction name="updateUser" action="{!updateUser}" rerender="allForm,message,allPanel" onComplete="unblockUI();"></apex:actionFunction>
       <apex:outputPanel id="message">
            <apex:messages />
@@ -42,23 +196,37 @@
                   <div style="overflow: scroll;height: 300px;width: 1260px; ">
                     <apex:variable value="{!1}" var="cnt" />
                    <apex:repeat value="{!dataLines}" var="line" id="lines">
                           <div style="width: 1260px;">
                        {!$ObjectType.loaner_user__c.fields.Customer__c.label}:
                        <apex:inputField value="{!line.Customer__c}" />
                   <div style="width: 1260px;">
                           {!$ObjectType.loaner_user__c.fields.Customer__c.label}:
                     <!-- Update 20220317 By Yang Kaiyu Start -->
                           <apex:inputField id="customer" value="{!line.Customer__c}" />
                     <!-- Update 20220317 By Yang Kaiyu End -->
                            {!$ObjectType.loaner_user__c.fields.Contact__c.label}:
                            <apex:inputField value="{!line.Contact__c}" />
                     <!-- Update 20220317 By Yang Kaiyu Start -->
                            <apex:inputField id="contact"  value="{!line.Contact__c}" html-aws-id="{!line.Contact__r.AWS_Data_Id__c}" />
                     <!-- <apex:inputText id="contact" html-aws-id="{!line.Contact__r.AWS_Data_Id__c}" disabled="false" value="{!line.Contact__r.LastName}" ></apex:inputText>                       -->
                     <!-- Update 20220317 By Yang Kaiyu End -->
                            {!$ObjectType.loaner_user__c.fields.FromThePeriod__c.label}:
                            <apex:inputField value="{!line.FromThePeriod__c}"/>
                            {!$ObjectType.loaner_user__c.fields.EndThePeriod__c.label}:
                            <apex:inputField value="{!line.EndThePeriod__c}"/>
                        {!$ObjectType.loaner_user__c.fields.Follow_UP_Opp__c.label}:
                        <apex:inputField value="{!line.Follow_UP_Opp__c}"/>
                           {!$ObjectType.loaner_user__c.fields.Follow_UP_Opp__c.label}:
                           <apex:inputField value="{!line.Follow_UP_Opp__c}"/>
                            {!$ObjectType.loaner_user__c.fields.Remarks__c.label}:
                            <apex:inputField value="{!line.Remarks__c}"/>
                           <apex:variable value="{!cnt + 1}" var="cnt" />
                        </div>
                    </apex:repeat>
               <!-- Update 20220317 By Yang Kaiyu Start -->
               <script>
                  sfdcPage.appendToOnloadQueue(function () {
                     //Replace Vlookup Field
                     replaceSearchContactLookup();
                  })
               </script>
               <!-- Update 20220317 By Yang Kaiyu End -->
                </div>
            </apex:pageBlock>