From 7157f000748f7d8ff1b77d8a21a1a77f521b69af Mon Sep 17 00:00:00 2001
From: unknown <sunxia@prec-tech.com>
Date: 星期二, 25 四月 2023 14:14:43 +0800
Subject: [PATCH] 新建备品借出申请

---
 force-app/main/default/pages/NewRentalApply.page-meta.xml |    7 
 force-app/main/default/pages/NewRentalApply.page          |  661 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 668 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/pages/NewRentalApply.page b/force-app/main/default/pages/NewRentalApply.page
new file mode 100644
index 0000000..597ecc3
--- /dev/null
+++ b/force-app/main/default/pages/NewRentalApply.page
@@ -0,0 +1,661 @@
+<apex:page standardController="Rental_Apply__c" extensions="RentalApplyController" id="page"
+lightningStylesheets="true">
+    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
+    <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
+    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
+    <!-- <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/> -->
+    <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
+    <style>
+        .disabledbutton {
+            pointer-events: none;
+            opacity: 0.4;
+        }
+    </style>
+    <script>
+        //Initial Required Information
+        var staticResources = JSON.parse('{!staticResource}');
+        //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+        var staticResourcesV2 = JSON.parse('{!staticResourceV2}');
+        var isEdit = JSON.parse('{!isEdit}');
+        var phoneNumber = '';
+        var directShippmentAddress = '';
+        //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+        var staticResourcesContact = JSON.parse('{!staticResourceContact}');
+        var requiredFieldAPIList = JSON.parse('{!requiredFieldAPIListStr}');
+        var fieldAPIToLabelMap = JSON.parse('{!fieldAPIToLabelMapStr}');
+        var VLookUpFields = new Set(['OwnerId','OPDPlan__c','Zsq_Rental_Apply__c','Loaner_medical_Staff__c','Hospital__c','Strategic_dept__c','Account__c','Repair__c','Campaign__c','QIS_number__c','QISRepair__c','NewRepair__c','Follow_UP_Opp__c','Statu_Achievements__c','Shipment_address__c','Dealer__c','Old_Rental_Apply__c','OPD__c']);
+        var userVLookUpFields = ['Person_In_Charge__c','Return_Trake_Staff__c','applyUser__c','Rental_Assistant__c','Assign_Person__c','ZongjianApprovalManager__c','BuchangApprovalManager__c','JingliApprovalManager__c','BuchangApprovalManagerSales__c','SalesManager__c'];
+        var redirectMode = 'Save';
+
+        //Redirect Required Parameter
+        var redirectCallBack = function redirectCallBack(sfId,errorMessage) {
+            if(sfId){
+                if (redirectMode == 'Save') {
+                window.open('/' + sfId, '_self');
+            } else if (redirectMode == 'SaveAndNew') {
+                window.open('/a3i/e', '_self');
+            }
+            }else{
+                // alert(errorMessage);
+                alertErrorMessage(errorMessage);
+            }
+        }
+        
+        
+
+        //Query Required Parameter
+        var queryBack = function queryBack(data) {
+            console.log('data = ' + data);
+            // document.querySelector("[data-id='Phone_number__c']").value = data.object.phoneNumber;
+            // document.querySelector("[data-id='direct_shippment_address__c']").value = data.object.directShippmentAddress;
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+            if(document.querySelector("[data-id='Phone_number__c']")){
+                document.querySelector("[data-id='Phone_number__c']").value = data.object.phoneNumber;
+                phoneNumber = data.object.phoneNumber;
+            }
+                
+            if(document.querySelector("[data-id='direct_shippment_address__c']")){
+                document.querySelector("[data-id='direct_shippment_address__c']").value = data.object.directShippmentAddress;
+                directShippmentAddress = data.object.directShippmentAddress;
+            }
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+            unblockUI();
+            enableButtonStatus();//Add by Li Jun 20220418
+        };
+
+        //Check If Insert Or Update
+        var insertOrUpdateBack = function insertOrUpdateBack(payloadJson, result, isNewMode) {
+            debugger
+            console.log(result);
+            let r = result;
+            console.log('Result from AWS' + JSON.stringify(r));
+            console.log('payloadJson=' + JSON.stringify(payloadJson));
+            payloadJson.Phone_number__c = r.object[0].phoneNumber;
+            payloadJson.direct_shippment_address__c = r.object[0].directShippmentAddress;
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+            // payloadJson.Phone_Number_Encrypt__c = r.object[0].phoneNumberEncrypt;
+            // payloadJson.Direct_Shippment_Address_Encrypt__c = r.object[0].directShippmentAddressEncrypt;
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+            payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
+            if('{!rtTypeId}'){
+                payloadJson.RecordTypeId = '{!rtTypeId}';//Add by Li Jun for Record Type Issue 20220419
+            }
+           
+            if (isNewMode || {!isCloneMode}) {
+                payloadJson.AWS_Data_Id__c = r.object[0].dataId;
+                delete payloadJson.OwnerId;
+            } else {
+                payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
+            }
+            if('{!rtTypeId}'){
+                payloadJson.RecordTypeId = '{!rtTypeId}';//Add by zhj for Record Type Issue 20220421
+            }
+            return payloadJson;
+        }
+        //Add Button status start 20220418
+        function enableButton(obj) {
+            obj.classList.remove("btnDisabled");
+        }
+
+        function disableButton(obj) {
+            obj.classList.add("btnDisabled");
+        }
+
+        function disableButtonStatus() {
+            let btnList = document.getElementsByClassName('btn');
+            for (let i = 0; i < btnList.length; i++) {
+                disableButton(btnList[i]);
+            }
+        }
+
+        function enableButtonStatus() {
+            let btnList = document.getElementsByClassName('btn');
+            for (let i = 0; i < btnList.length; i++) {
+                enableButton(btnList[i]);
+            }
+        }
+        disableButtonStatus();
+        //Add Button status end 20220418 
+        // New Or Edit
+
+        function EditButton(isDisabled){
+            var topele = document.getElementById('topButtonRow');
+            var bottomele = document.getElementById('bottomButtonRow');
+
+            if (isDisabled) {
+                topele.classList.add("disabledbutton");
+                bottomele.classList.add("disabledbutton");
+            }else {
+                topele.classList.remove("disabledbutton");
+                bottomele.classList.remove("disabledbutton");
+            }
+        }
+        function ProcessPI(rentalApplyJson, payloadForNewPI) {
+            blockme();
+            if ({!isNewMode} || {!isCloneMode}) {
+                NewPIToAWS(rentalApplyJson, payloadForNewPI)
+            }else {
+                UpdatePIToAWS(rentalApplyJson, payloadForNewPI)
+            }
+        }
+
+        var GetEleByClass = function(class_name){
+            let eles = document.getElementsByClassName(class_name);
+            if(eles.length > 0) return eles[0];
+            return null;
+        }
+
+        function GetEleApiName(ele){
+            for(let ci in ele.classList){
+                let c = ele.classList[ci];
+                if(c.indexOf('PIBackApi_')>-1){
+                    return c.replace('PIBackApi_','');
+                }
+            }
+            return '';
+        }
+
+        function IsFormTag(tag_name){
+            if (!tag_name) {
+                return false;
+            }
+            return ['input','select','textarea'].indexOf(tag_name.toLowerCase())>-1;
+        }
+        
+        function IsFormElement(e){
+            return IsFormTag(e.tagName);
+        }
+
+        //Get Sensitive Information
+        function getPIPayload(rentalApplyJson) {
+            let rentalApplyPayloadList = [];
+            let phoneNumber = rentalApplyJson.Phone_number__c;
+            let directShippmentAddress = rentalApplyJson.direct_shippment_address__c;
+            let rentalApplyPIData = new Object();
+            rentalApplyPIData.phoneNumber = phoneNumber;
+            rentalApplyPIData.directShippmentAddress = directShippmentAddress;
+            rentalApplyPIData.sfRecordId = '';
+            console.log('rentalApply PI Data:' + JSON.stringify(rentalApplyPIData));
+            rentalApplyPayloadList.push(rentalApplyPIData);
+            console.log(JSON.stringify(rentalApplyPayloadList));
+            return JSON.stringify(rentalApplyPayloadList);
+        }
+
+        //Check Validate Field Value
+        function validateFieldValueFormate() {
+            return true;
+        }
+
+        function getCKEinstance(api_name){
+            let t = jQuery("label[for$='textAreaDelegate_"+api_name+"']").closest("tr").find("textarea")[0];
+            if(t && t.id){
+                return CKEDITOR.instances[t.id]
+                
+            }
+            return null;
+        }
+
+        //Get Page Information
+        function getRentalApplyInformation() {
+            let nodelist = document.querySelectorAll("[data-id]");
+            let result = {}
+            //瀵屾枃鏈�
+            // if(document.querySelector("[aria-describedby = 'cke_38']")){
+            //     result.HP_received_sign_rich__c = document.querySelector("[aria-describedby = 'cke_38']").contentWindow.document.getElementsByTagName('body')[0].innerHTML
+            // }
+            // result.HP_received_sign_rich__c = CKEDITOR.instances["page:form:block:j_id34:12:j_id35:j_id36:1:j_id37:textAreaDelegate_HP_received_sign_rich__c"].getData();
+            // if(document.querySelector("[aria-describedby = 'cke_71']")){
+            //     result.  Extension_List_RentalApply__c = document.querySelector("[aria-describedby = 'cke_71']").contentWindow.document.getElementsByTagName('body')[0].innerHTML
+            // }
+            for (let index = 0; index < nodelist.length; index++) {
+                if (VLookUpFields.has(nodelist[index].getAttribute("data-id"))) {
+                    console.log(nodelist[index].id.indexOf('lkwgt'));
+                    if (nodelist[index].id.indexOf('lkwgt') == -1) {
+                        let vlookUpNodeId = nodelist[index].id + '_lkid';
+                        if(document.getElementById(vlookUpNodeId)){
+                            let vlookUpNodeValue = document.getElementById(vlookUpNodeId).value;
+                            result[nodelist[index].getAttribute("data-id")] = vlookUpNodeValue;
+                        }
+                    }
+                } else if (nodelist[index].type == 'checkbox') {
+                    result[nodelist[index].getAttribute("data-id")] = nodelist[index].checked;
+                } else if (nodelist[index].type == 'select-multiple') {
+                    //nodelist[index].getAttribute("data-id")
+                    let multiple = nodelist[index].getAttribute("data-id");
+                    let targets = document.querySelector("[data-id=" + multiple + "]").parentNode.children[1].children[0].children[1].children[2].children[0].innerText;
+                    targets = targets.replace(/\n/g, ";");
+                    console.log('targets = ' + targets);
+                    result[nodelist[index].getAttribute("data-id")] = targets;
+                } else {
+                    result[nodelist[index].getAttribute("data-id")] = nodelist[index].value;
+                }
+                let x = index + 1;
+                if (x <= nodelist.length - 1 && (nodelist[x].getAttribute("data-id") == nodelist[index].getAttribute("data-id"))) {
+                    index++;
+                }
+            }
+            for (let i = 0; i < userVLookUpFields.length; i++) {
+                if(document.querySelector("[data-id='" + userVLookUpFields[i] + "']")!=null){
+                    let userVlookUpNodeValue = document.querySelector("[data-id='" + userVLookUpFields[i] + "']").children[1].value;
+                    console.log('userVlookUpNodeValue:'+userVlookUpNodeValue);
+                    if(userVlookUpNodeValue!='000000000000000'){
+                        result[userVLookUpFields[i]] = userVlookUpNodeValue;
+                    }
+                }             
+            }
+            if(api_id_map['demo_purpose2__c']){
+                result.demo_purpose2__c = document.getElementById(api_id_map['demo_purpose2__c']).value!='_\x01_'?document.getElementById(api_id_map['demo_purpose2__c']).value:'';
+            }            
+            if(api_id_map['ToAgency__c']){
+                result.ToAgency__c = document.getElementById(api_id_map['ToAgency__c']).value!='_\x01_'?document.getElementById(api_id_map['ToAgency__c']).value:'';
+            }            
+            //document.querySelector("[id='page:form:block:j_id34:0:j_id35:j_id36:18:j_id37']").disabled =true; // Commented By Li Jun 20220304
+            if(api_id_map['Loaner_cancel_reason__c']){
+                result.Loaner_cancel_reason__c = document.getElementById(api_id_map['Loaner_cancel_reason__c']).value!='_\x01_'?document.getElementById(api_id_map['Loaner_cancel_reason__c']).value:'';
+            }
+            // else{
+            //     if(document.querySelector("[id='page:form:block:j_id34:11:j_id35:j_id36:1:j_id37']")!=null){
+            //         result.Loaner_cancel_reason__c = document.querySelector("[id='page:form:block:j_id34:11:j_id35:j_id36:1:j_id37']").value;
+            //     }               
+            // }
+            // //鏍煎紡鍖栨椂闂�
+            // if(result.HP_received_sign_day__c){
+            //     result.HP_received_sign_day__c = result.HP_received_sign_day__c.replace(/\//g, '-')+':00';
+            // }
+            let e = getCKEinstance('HP_received_sign_rich__c');
+            if(e){
+                    result.HP_received_sign_rich__c = e.getData();
+                }
+                e = getCKEinstance('Extension_List_RentalApply__c');
+            if(e){
+                    result.Extension_List_RentalApply__c = e.getData();
+                }
+            if(document.getElementById(api_id_map['Office_Assistant1__c'] + '_lkid')!=null){
+                // result.ToAgency__c = document.getElementById('page:form:block:j_id34:0:j_id35:j_id36:18:j_id37').value;
+                result.Office_Assistant1__c = document.getElementById(api_id_map['Office_Assistant1__c'] + '_lkid').value;
+            }
+            if(document.getElementById(api_id_map['Office_Assistant2__c'] + '_lkid')!=null){
+                // result.ToAgency__c = document.getElementById('page:form:block:j_id34:0:j_id35:j_id36:18:j_id37').value;
+                result.Office_Assistant2__c = document.getElementById(api_id_map['Office_Assistant2__c'] + '_lkid').value;
+            }
+            console.log(JSON.stringify(result));
+            return result;
+        }
+
+        //Query from AWS
+        function QueryRentalApplyFromAWS() {
+            AWSService.query(staticResources.queryUrl, '{!AWSDataId}', queryBack, staticResources.token);
+        }
+
+        //Update Sensitive Information to AWS
+        function UpdatePIToAWS(rentalApplyJson, payloadForNewPI) {
+            let controllerSaveMethod = '{!$RemoteAction.RentalApplyController.saveRentalApply}';
+            let obj = JSON.parse(payloadForNewPI);
+            obj[0].dataId = '{!AWSDataId}';
+            let payloadForNewPIJson = JSON.stringify(obj);
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+            //AWSService.update(staticResources.updateUrl, rentalApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack);
+            AWSService.update(staticResourcesV2.updateUrl, rentalApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResourcesV2.transactionUrl, false, insertOrUpdateBack, redirectCallBack);
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+        }
+
+        //Insert Sensitive Information to AWS
+        function NewPIToAWS(rentalApplyJson, payloadForNewPI) {
+            let controllerSaveMethod = '{!$RemoteAction.RentalApplyController.saveRentalApply}';
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+            //AWSService.insert(staticResources.newUrl, rentalApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack);
+            debugger
+            console.log('staticResourcesV2.newUrl = ' + staticResourcesV2.newUrl);
+            AWSService.insert(staticResourcesV2.newUrl, rentalApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResourcesV2.transactionUrl, true, insertOrUpdateBack, redirectCallBack);
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+        }
+
+        //Check Required Fields
+        function checkRequiredFieldMsg(formData) {
+            let blankRequiredFields = '';
+            for (i = 0; i < requiredFieldAPIList.length; i++) {
+                if (formData[requiredFieldAPIList[i]] && !VLookUpFields.has(requiredFieldAPIList[i])) {
+                    continue;
+                }else if(VLookUpFields.has(requiredFieldAPIList[i]) && formData[requiredFieldAPIList[i]] != '000000000000000'){
+                    continue;
+                } else {
+                    if (blankRequiredFields == '') {
+                        blankRequiredFields = blankRequiredFields + fieldAPIToLabelMap[requiredFieldAPIList[i]];
+                    } else {
+                        blankRequiredFields = blankRequiredFields + ',' + fieldAPIToLabelMap[requiredFieldAPIList[i]];
+                    }
+
+                }
+            }
+            return blankRequiredFields;
+        }
+
+        //Base Process
+        function saveRentalApplyProcess(saveMode) {
+            EditButton(true);
+            redirectMode = saveMode;
+            console.log('redirectMode' + redirectMode);
+            hiddenErrorMsgNode();
+            //1. Get rentalApply Information from Form
+            let rentalApplyJson = getRentalApplyInformation();
+            //2. Validate the rentalApply field value formate, for example the email formate or phone formate
+            let validationResultMessage = validateFieldValueFormate();
+            console.log(validationResultMessage);
+            if (!validationResultMessage) {
+                //Popup error message.  - To Do After POC
+                alertErrorMessage('閭鏍煎紡杈撳叆鏈夎锛岃閲嶆柊杈撳叆锛�');
+                return
+            }
+            // Check Required Field
+            let checkRequiredFieldMsgResult = checkRequiredFieldMsg(rentalApplyJson);
+            if (checkRequiredFieldMsgResult) {
+                alertErrorMessage('{!Input_Required_Field_Msg}' + checkRequiredFieldMsgResult);
+                return
+            }
+            //3. Prepare the payload for New PI API To AWS - To Do
+            let payloadForNewPI = getPIPayload(rentalApplyJson);
+
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+            debugger
+            if(isEdit == true && (rentalApplyJson.Phone_number__c != phoneNumber || rentalApplyJson.direct_shippment_address__c != directShippmentAddress)){
+                alertErrorMessage('鐢宠鍗曟壒鍑嗗悗锛屼笉鑳界紪杈戝鍝佸�熺敤淇℃伅');
+                return
+            }
+            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+
+            //4. rentalApply to AWS 
+            ProcessPI(rentalApplyJson, payloadForNewPI);
+        }
+
+        //Alert Error Message
+        function alertErrorMessage(errorMsg) {
+            let errorMsgNode = document.getElementById("page:form:block:msgContent");
+            errorMsg = '閿欒锛氭棤鏁堟暟鎹��' + '\n' + errorMsg;
+            errorMsgNode.innerText = errorMsg;
+            errorMsgNode.className = 'pbError';
+            unblockUI();
+            EditButton(false);
+        }
+
+        //Hide Error Message
+        function hiddenErrorMsgNode() {
+            let errorMsgNode = document.getElementById("page:form:block:msgContent");
+            errorMsgNode.innerText = '';
+            errorMsgNode.className = '';
+        }
+        //鏇挎崲vlookup
+        function replaceSearchContactLookup() {
+            let lookUpNode = htmlToElement(contactHtmlString);
+            console.log(lookUpNode);
+            if (!{!isNewMode}) {
+                queryContactName();
+            }           
+            let parentNode = document.querySelector("[data-id='Loaner_medical_Staff__c']").parentNode;
+            document.querySelector("[data-id='Loaner_medical_Staff__c']").removeAttribute("onchange");
+            parentNode.replaceChild(lookUpNode, document.querySelector("[data-id='Loaner_medical_Staff__c']").parentNode.children[2]);
+        }
+        var newSearchContactWindow = null;  
+        var contactHtmlString = '<img src="/img/s.gif" onclick="searchContact(\'page:form:contactId\')" alt="Reference Document Number Lookup" class="lookupIcon"  title="Reference Document Number Lookup (New Window)"/>';
+        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 queryContactName() {
+            let sfId = document.getElementById(document.querySelector("[data-id='Loaner_medical_Staff__c']").id + '_lkid').value;
+            let dataId = '';
+            if ('{!contactsInfo}' != '') {
+                let contactsInfo = JSON.parse('{!contactsInfo}');
+                dataId = contactsInfo[sfId];
+            } else if ('{!AWSDataId}' != '') {
+                dataId = '{!AWSDataId}';
+            }
+            let queryBackContactName = function queryBackContactName(result){
+                document.querySelector("[data-id='Loaner_medical_Staff__c']").value = result.object.lastName;
+            };
+            AWSService.query(staticResourcesContact.queryUrl, dataId, queryBackContactName, staticResourcesContact.token);
+        }
+        //鑷畾涔塴ookup鏌ヨ
+        function searchContact(contactNodeId){
+            let accountValue = "";
+            if (document.querySelector("[data-id='Account__c']")) {
+                let accountNodeId = document.querySelector("[data-id='Account__c']").id + '_lkid';
+                accountValue = document.getElementById(accountNodeId).value;   
+            } 
+            let searchContactKeyWord = document.querySelector("[data-id='Loaner_medical_Staff__c']").value;
+            console.log(accountValue);
+            if(accountValue !='000000000000000'){
+                let baseUrl = "/apex/SearchContactPage";
+                let suffixUrl = "?contactId="+contactNodeId+"&accountId="+accountValue+"&searchContactKeyWord=" + searchContactKeyWord;
+                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{
+                alertErrorMessage('{!PIPL_Input_Account_Error_Msg}');
+            }
+        }
+        //绐楀彛鍏抽棴鏃跺彂鐢�
+        function closePopupWindow() {
+            if (null != newSearchContactWindow) {
+                newSearchContactWindow.close();
+            }
+            let contactInfoStr = document.getElementById('page:form:contactId').value;
+            console.log('closePopup:'+contactInfoStr);
+            let contactInfo = JSON.parse(contactInfoStr);
+            let contactNodeId = document.querySelector("[data-id='Loaner_medical_Staff__c']").id + '_lkid';
+            document.getElementById(contactNodeId).value = contactInfo.ContactId;
+            document.querySelector("[data-id='Loaner_medical_Staff__c']").value = contactInfo.Name;
+        }
+    </script>
+    <div class="bPageTitle">
+        <div class="ptBody">
+            <div class="content">
+                <img src="/img/s.gif" alt="澶囧搧鍊熷嚭鐢宠" class="pageTitleIcon" title="澶囧搧鍊熷嚭鐢宠" />
+                <h1 class="pageType">澶囧搧鍊熷嚭鐢宠缂栬緫
+                    <span class="titleSeparatingColon">:</span>
+                </h1>
+                <h2 class="pageDescription"> 鏂板缓澶囧搧鍊熷嚭鐢宠</h2>
+                <div class="blank">&nbsp;</div>
+            </div>
+            <div class="links">
+                <a href="javascript:openPopupFocusEscapePounds(%27https://help.salesforce.com/apex/htdoor?loc=help&amp;target=rentalApplys_edit.htm&amp;section=rentalApplys&amp;language=zh_CN&amp;release=234.18.8&amp;instance=CS117&amp;showSplash=true%27, %27Help%27, 700, 600, %27width=700,height=600,resizable=yes,toolbar=yes,status=no,scrollbars=yes,menubar=yes,directories=no,location=no,dependant=no%27, false, false);"
+                    title="姝ら〉闈㈢殑甯姪 锛堟柊绐楀彛锛�">
+                    <span class="helpLink">姝ら〉闈㈢殑甯姪</span>
+                    <img src="/img/s.gif" alt="" class="helpIcon" />
+                </a>
+            </div>
+        </div>
+        <div class="ptBreadcrumb"></div>
+    </div>
+    <apex:form id="form">
+        <apex:inputHidden value="{!contactId}" id="contactId"/>
+        <apex:pageblock id="block">
+            <div class="pbHeader">
+                <table cellspacing="0" cellpadding="0" border="0">
+                    <tbody>
+                        <tr>
+                            <td class="pbTitle">
+                                <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" />
+                                <h2 class="mainTitle">澶囧搧鍊熷嚭鐢宠缂栬緫</h2>
+                            </td>
+                            <td class="pbButton" id="topButtonRow" style="pointer-events: none; opacity: 0.4;">
+                                <input class="btn" type="Button" value="淇濆瓨" onclick="saveRentalApplyProcess('Save')" />
+                                <input class="btn" type="Button" value="淇濆瓨骞舵柊寤�" onclick="saveRentalApplyProcess('SaveAndNew')" />
+                                <apex:commandButton action="{!cancel}" value="鍙栨秷" />
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+            </div>
+            <!-- Error Msg-->
+            <div style="text-align: center;">
+                <apex:outputPanel id="errorMsg">
+                    <apex:pageMessages id="msgContent" escape="false" />
+                </apex:outputPanel>
+            </div>
+            <!-- Iterate the layoutSections, which is a list of sections -->
+            <apex:repeat value="{!layoutSections}" var="layoutSection">
+                <apex:pageBlockSection title="{!layoutSection.name}" collapsible="{!layoutSection.allowCollapse}" columns="{!layoutSection.columns}">
+
+                    <!--Each section has layoutFields, let's iterate them as well-->
+                    <apex:repeat value="{!layoutSection.layoutFields}" var="layoutField">
+                        <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" style="width:50px" rendered="{!not(layoutField.isPlaceHOlder)&&isNewMode}"
+                            required="{!layoutField.isRequired}" />
+                        <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&not(isNewMode)&&layoutField.fieldAPI!='RecordTypeId'}"
+                            required="{!layoutField.isRequired}" />
+                        <apex:outputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&not(isNewMode)&&layoutField.fieldAPI=='RecordTypeId'}"
+                       />
+                        <apex:pageblocksectionitem rendered="{!layoutField.isPlaceHolder}">
+                        </apex:pageblocksectionitem>
+                    </apex:repeat>
+
+                </apex:pageBlockSection>
+            </apex:repeat>
+            <script>
+                blockme(); //zhj 2022-12-28 improve
+               var init_nodes = document.getElementsByClassName("PIBackApi");
+                var api_id_map={};
+                for(let ei in init_nodes){
+                    let e = init_nodes[ei];
+                    if(IsFormElement(e)){
+                        if(e.getAttribute("multiple") != 'multiple' || e.style.display == 'none' && e.id.indexOf('selected') < 0){
+                            api_id_map[GetEleApiName(e)] = e.id;
+                        }
+                    }else{
+                        let eid = jQuery(e).find(".lookupInput input").attr("id")
+                        if(eid){
+                            eid += '_lkid';
+                            if(document.getElementById(eid)){
+                                api_id_map[GetEleApiName(e)] = eid;
+                            }
+                        }
+                    }
+                }
+                console.log(api_id_map);
+                //Append Page
+                sfdcPage.appendToOnloadQueue(function () {
+                    var layoutSections = JSON.parse('{!layoutSectionsStr}');
+                    for (let m = 0; m < layoutSections.length; m++) {
+                        let layoutSection = layoutSections[m].layoutFields;
+                        for (let n = 0; n < layoutSection.length; n++) {
+                            let layoutField = layoutSection[n];
+                            if (layoutField.fieldAPI != '' && document.querySelector("[data-id='"+layoutField.fieldAPI+"']") != null) {
+                                let e = document.querySelector("[data-id='"+layoutField.fieldAPI+"']");
+                                console.log('layoutField.fieldAPI= ' + layoutField.fieldAPI);
+                                e.disabled = !(layoutField.editableField);
+                                if (!(layoutField.editableField)) {
+                                    if (e.getAttribute("multiple") && e.getAttribute("multiple") == 'multiple') {
+                                        e.parentNode.classList.add("disabledbutton");
+                                    }
+                                    if (e.tagName == 'DIV') {
+                                        e.classList.add("disabledbutton");
+                                    }
+                                    if(document.querySelector('[data-id=Old_Rental_Apply__c] .lookupIcon')){
+                                        document.querySelector('[data-id=Old_Rental_Apply__c] .lookupIcon').classList.add("disabledbutton");
+                                    }
+                                    
+
+                                }
+                            }
+                        }
+                    }
+                    var onlyReadFields = ['ExtensionStatus__c','ExtensionApplicationTime_Initial__c','ExtensionApprovalTime_Initial__c','ExtensionApplicationTime_Final__c','ExtensionApprovalTime_Final__c','ExtensionSuccessTimes__c','ZongjianApprovalManager__c','BuchangApprovalManager__c','JingliApprovalManager__c','BuchangApprovalManagerSales__c','SalesManager__c'];
+                    console.log(onlyReadFields);
+                    for(let i=0;i<onlyReadFields.length;i++){
+                        if(document.querySelector('[data-id='+onlyReadFields[i]+']')){
+                            document.querySelector('[data-id='+onlyReadFields[i]+']').parentNode.remove();
+                        }
+                    }
+                    
+                    //2. Query AWS Data by dataId 
+                    console.log('Mode for rentalApply Page:' + {!isNewMode});
+                    if (!{!isNewMode}) {
+                        QueryRentalApplyFromAWS();
+                    }else{
+                        enableButtonStatus();//Add by Li Jun 20220418
+                    };
+                    //Replace Vlookup Field
+                    replaceSearchContactLookup();
+                    document.querySelector("[data-id='OwnerId']").classList.add("disabledbutton");
+                    
+                    document.getElementById('topButtonRow').style = '';
+聽 聽 聽 聽 聽 聽 聽document.getElementById('bottomButtonRow').style = '';
+                    
+                    let previous_value = {};
+                    jQuery(".lookupInput input").each(function(i,e){
+                        let je =jQuery(e);
+
+                        let dataid = je.attr('data-id');
+                        if(['Loaner_medical_Staff__c'].indexOf(dataid) < 0) return;
+
+                        jQuery(e).focus(function(){
+                            previous_value[this.id] = this.value;
+                        })
+
+                        jQuery(e).change(function(){
+                            if (previous_value[this.id] != jQuery(this).val()) {
+                                document.getElementById(this.id+'_lkid').value = '';
+                            }
+                        })
+                    });
+
+                    unblockUI();
+                                        
+
+
+
+                    // jQuery(".lookupInput").each(function(i,e){
+                    //     let je =jQuery(e).find('input');
+                    //     je.attr("readonly","");
+                    //     je.css("background","unset");
+                        
+                    //     let dataid = je.attr('data-id');
+                    //     if(['Hospital_Name__c','Department_Class__c','OwnerId'].indexOf(dataid) > -1) return;
+                    //     jQuery(e).children(":last-child").before('<img class="closeIcon" data-id="'+dataid+'" generate="" alt="Clear" src="/s.gif" style="display: inline-block;">');
+                    // })
+                    
+                    // jQuery(".lookupInput").on("mouseenter","img[generate]",function(e){
+                    //     this.className = "closeIconOn";
+                    // });
+                    
+                    // jQuery(".lookupInput").on("mouseleave","img[generate]",function(e){
+                    //     this.className = "closeIcon"
+                    // });
+                    
+                    // jQuery(".lookupInput").on("click","img[generate]",function(e){
+                    //     let id = jQuery("input[data-id='"+jQuery(this).attr("data-id")+ "']").attr("id");
+                    //     let input = document.getElementById(id);
+                    //     if(input){
+                    //         input.value = '';
+                    //         let hidden = document.getElementById(id+'_lkid');
+                    //         if(hidden){
+                    //             hidden.value = '';
+                    //         }
+                    //     }
+                    // });
+
+                });
+            </script>
+            <div class="pbBottomButtons">
+                <table cellspacing="0" cellpadding="0" border="0">
+                    <tbody>
+                        <tr>
+                            <td class="pbTitle">
+                                <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" />&nbsp;</td>
+                            <td class="pbButtonb" id="bottomButtonRow" style="pointer-events: none; opacity: 0.4;">
+                                <input class="btn" type="Button" value="淇濆瓨" onclick="saveRentalApplyProcess('Save')" />
+                                <input class="btn" type="Button" value="淇濆瓨骞舵柊寤�" onclick="saveRentalApplyProcess('SaveAndNew')" />
+                                <apex:commandButton action="{!cancel}" value="鍙栨秷" />
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+            </div>
+        </apex:pageblock>
+
+    </apex:form>
+</apex:page>
\ No newline at end of file
diff --git a/force-app/main/default/pages/NewRentalApply.page-meta.xml b/force-app/main/default/pages/NewRentalApply.page-meta.xml
new file mode 100644
index 0000000..e5ffeb2
--- /dev/null
+++ b/force-app/main/default/pages/NewRentalApply.page-meta.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>54.0</apiVersion>
+    <availableInTouch>false</availableInTouch>
+    <confirmationTokenRequired>false</confirmationTokenRequired>
+    <label>NewRentalApply</label>
+</ApexPage>

--
Gitblit v1.9.1