|  |  | 
 |  |  |   @last modified on  : 03-30-2022 | 
 |  |  |   @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc | 
 |  |  | --> | 
 |  |  | <apex:page standardController="Consum_Apply__c" extensions="NewConsumApplyController" id="page"> | 
 |  |  |  <apex:page standardController="Consum_Apply__c" extensions="NewConsumApplyController" id="page"> | 
 |  |  |     <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" /> | 
 |  |  |     <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/> | 
 |  |  |     <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/> | 
 |  |  |     <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/> | 
 |  |  |     <script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script> | 
 |  |  |     <apex:includeScript value="{!URLFOR($Resource.connection20)}"/> | 
 |  |  |     <style> | 
 |  |  |         .disabledbutton { | 
 |  |  |             pointer-events: none; | 
 |  |  | 
 |  |  |     <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 = ''; | 
 |  |  |         console.log('isEdit = ' + isEdit); | 
 |  |  |         //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(['Loaner_medical_Staff__c', 'Hospital__c', 'Strategic_dept__c', 'Account__c', 'QIS_number__c', 'OPDPlan__c', 'Campaign__c', 'Rental_Apply__c', 'Shipment_address__c', 'Dealer__c', 'Old_Consum_Apply__c', 'DeliverySlip__c', 'OwnerId', 'OPD__c']); | 
 |  |  |         var userVLookUpFields = ['Person_In_Charge__c', 'applyUser__c', 'CC_EmailUser__c', 'Assign_Person__c', 'Consum_Assistant__c', 'Consum_Assistant2__c', 'Consum_Assistant3__c', 'SalesManager__c', 'ZongjianApprovalManager__c', 'BuchangApprovalManagerSales__c', 'TongkuoZongjian__c']; | 
 |  |  |         //var VLookUpFields = new Set(['Loaner_medical_Staff__c', 'Hospital__c', 'Strategic_dept__c', 'Account__c', 'QIS_number__c', 'OPDPlan__c', 'Campaign__c', 'Rental_Apply__c', 'Shipment_address__c', 'Dealer__c', 'Old_Consum_Apply__c', 'DeliverySlip__c', 'OwnerId', 'OPD__c']); | 
 |  |  |         var VLookUpFields = {! VLookUpFieldsJson}; | 
 |  |  |         // var userVLookUpFields = ['Person_In_Charge__c', 'applyUser__c', 'CC_EmailUser__c', 'Assign_Person__c', 'Consum_Assistant__c', 'Consum_Assistant2__c', 'Consum_Assistant3__c', 'SalesManager__c', 'ZongjianApprovalManager__c', 'BuchangApprovalManagerSales__c', 'TongkuoZongjian__c']; | 
 |  |  |         var redirectMode = 'Save'; | 
 |  |  |  | 
 |  |  |         function EditButton(isDisabled){ | 
 |  |  | 
 |  |  |         //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 == null ? '': 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 == null ? '' : data.object.directShippmentAddress; | 
 |  |  |             } | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |             unblockUI(); | 
 |  |  |         }; | 
 |  |  |  | 
 |  |  | 
 |  |  |             console.log('payloadJson=' + JSON.stringify(payloadJson)); | 
 |  |  |             payloadJson.Phone_number__c = r.object[0].phoneNumber; | 
 |  |  |             payloadJson.direct_shippment_address__c = r.object[0].directShippmentAddress; | 
 |  |  |             payloadJson.Phone_Number_Encrypt__c = r.object[0].phoneNumberEncrypt; | 
 |  |  |             payloadJson.Direct_Shippment_Address_Encrypt__c = r.object[0].directShippmentAddressEncrypt; | 
 |  |  |             //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 (isNewMode || {!isCloneMode}) { | 
 |  |  |                 payloadJson.AWS_Data_Id__c = r.object[0].dataId; | 
 |  |  | 
 |  |  |                 result.HP_received_sign_rich__c = document.querySelector("[aria-describedby = 'cke_34']").contentWindow.document.getElementsByTagName('body')[0].innerHTML | 
 |  |  |             }  | 
 |  |  |             for (let index = 0; index < nodelist.length; index++) { | 
 |  |  |                 if (VLookUpFields.has(nodelist[index].getAttribute("data-id"))) { | 
 |  |  |                 let tag_name = nodelist[index].tagName.toLowerCase(); | 
 |  |  |                 if(tag_name == 'div'){ | 
 |  |  |                     console.log(nodelist[index]) | 
 |  |  |                 } | 
 |  |  |                 if (VLookUpFields.indexOf(nodelist[index].getAttribute("data-id")) >= 0) { | 
 |  |  |                     console.log(nodelist[index].id.indexOf('lkwgt')); | 
 |  |  |                     if (nodelist[index].id.indexOf('lkwgt') == -1) { | 
 |  |  |                         let vlookUpNodeId = nodelist[index].id + '_lkid'; | 
 |  |  |                         let vlookUpNodeValue = document.getElementById(vlookUpNodeId).value; | 
 |  |  |                         result[nodelist[index].getAttribute("data-id")] = vlookUpNodeValue; | 
 |  |  |                         if (tag_name == 'div') { | 
 |  |  |                             vlookUpNodeId = nodelist[index].id.substring(0,nodelist[index].id.length-4) + '_lkid'; | 
 |  |  |                         } | 
 |  |  |                         let vlookUpNodeValue = document.getElementById(vlookUpNodeId); | 
 |  |  |                         let v = ''; | 
 |  |  |                         if(vlookUpNodeValue){ | 
 |  |  |                             v = vlookUpNodeValue.value; | 
 |  |  |                         }else{ | 
 |  |  |                             v = nodelist[index].value; | 
 |  |  |                         } | 
 |  |  |                         result[nodelist[index].getAttribute("data-id")] = v; | 
 |  |  |                     } | 
 |  |  |                 } else if (nodelist[index].type == 'checkbox') { | 
 |  |  |                     result[nodelist[index].getAttribute("data-id")] = nodelist[index].checked; | 
 |  |  | 
 |  |  |                     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; | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             // 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(result.pickup_time__c){ | 
 |  |  |                 result.pickup_time__c = result.pickup_time__c.replace(/\//g, '-')+':00'; | 
 |  |  | 
 |  |  |             let obj = JSON.parse(payloadForNewPI); | 
 |  |  |             obj[0].dataId = '{!AWSDataId}'; | 
 |  |  |             let payloadForNewPIJson = JSON.stringify(obj); | 
 |  |  |             AWSService.update(staticResources.updateUrl, consumApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             //AWSService.update(staticResources.updateUrl, consumApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             AWSService.update(staticResourcesV2.updateUrl, consumApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //Insert Sensitive Information to AWS | 
 |  |  |         function NewPIToAWS(consumApplyJson, payloadForNewPI) { | 
 |  |  |             let controllerSaveMethod = '{!$RemoteAction.NewConsumApplyController.saveConsumApply}'; | 
 |  |  |             AWSService.insert(staticResources.newUrl, consumApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             //AWSService.insert(staticResources.newUrl, consumApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             AWSService.insert(staticResourcesV2.newUrl, consumApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.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]]) { | 
 |  |  |                 if (formData[requiredFieldAPIList[i]] && (VLookUpFields.indexOf(requiredFieldAPIList[i]) == -1)) { | 
 |  |  |                     continue; | 
 |  |  |                 }else if((VLookUpFields.indexOf(requiredFieldAPIList[i]) != -1) && formData[requiredFieldAPIList[i]] != '000000000000000'&&formData[requiredFieldAPIList[i]] != ''){ | 
 |  |  |                     continue; | 
 |  |  |                 } else { | 
 |  |  |                     if (blankRequiredFields == '') { | 
 |  |  | 
 |  |  |             //3. Prepare the payload for New PI API To AWS - To Do | 
 |  |  |             let payloadForNewPI = getPIPayload(consumApplyJson); | 
 |  |  |  | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             if(isEdit == true && (consumApplyJson.Phone_number__c != phoneNumber || consumApplyJson.direct_shippment_address__c != directShippmentAddress)){ | 
 |  |  |                 alertErrorMessage('申请单批准后,不能编辑耗材备品借用信息'); | 
 |  |  |                 return | 
 |  |  |             } | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |              | 
 |  |  |             //4. consumApply to AWS  | 
 |  |  |             ProcessPI(consumApplyJson, payloadForNewPI); | 
 |  |  |         } | 
 |  |  | 
 |  |  |             let dataId = contactsInfo[sfId]; | 
 |  |  |             let url = staticResourcesContact.queryUrl + '?dataId=' + dataId; | 
 |  |  |             let queryBackContactName = function queryBackContactName(result){ | 
 |  |  |                 document.querySelector("[data-id='Loaner_medical_Staff__c']").value = result.object.lastName; | 
 |  |  |                 if(document.querySelector("[data-id='Loaner_medical_Staff__c']")) | 
 |  |  |                     document.querySelector("[data-id='Loaner_medical_Staff__c']").value = result.object.lastName; | 
 |  |  |                 //document.querySelector("[data-id='LastName']").value = result.object.lastName; | 
 |  |  |             }; | 
 |  |  |             debugger | 
 |  |  |             AWSService.query(staticResourcesContact.queryUrl, dataId, queryBackContactName, staticResourcesContact.token); | 
 |  |  |             // fetch(url, { | 
 |  |  |             //     method: 'GET', | 
 |  |  | 
 |  |  |                             } | 
 |  |  |                         }) | 
 |  |  |                     }); | 
 |  |  |  | 
 |  |  |                      | 
 |  |  |                     unblockUI(); //zhj 2022/12/02  | 
 |  |  |                     // jQuery(".lookupInput").each(function(i,e){ | 
 |  |  |                     //     let je =jQuery(e).find('input'); | 
 |  |  |                     //     je.attr("readonly",""); |