force-app/main/default/aura/lexNewRepairAura/lexNewRepairAura.cmp
New file @@ -0,0 +1,78 @@ <!-- 2023/04/14 新建(修理) --> <aura:component implements="flexipage:availableForRecordHome,force:lightningQuickActionWithoutHeader,force:hasRecordId,lightning:actionOverride,lightning:isUrlAddressable" access="global" controller="lexNewRepairAuraController"> <aura:attribute name="urlStr" type="String"/> <aura:attribute name="recordId" type="String"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <lightning:notificationsLibrary aura:id="notifLib"/> <!-- <aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" > <aura:attribute name="fields" type="String[]" default="['Name','AnnualRevenue','Industry']" /> <aura:attribute name="recordId" type="String"/> <lightning:notificationsLibrary aura:id="notifLib"/> <lightning:recordForm objectApiName="Account" fields="{!v.fields}" onsuccess="{!c.handleSuccess}" /> </aura:component> --> <!-- <aura:attribute name = "recordId" type = "Id" default = ""/> <aura:attribute name="title" type="string"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <aura:attribute name="layout" type="LayoutDescriberHelper.LayoutWrapper"/> <aura:attribute name="record_data" type="Map"/> <aura:attribute name="section_names" type="List"/> <aura:attribute name="showSpinner" type="Boolean" default = "False"/> <aura:attribute name="staticResource" type="Map"/> <aura:attribute name="pi_fields_map" type="Map"/> <aura:attribute name="isClone" type="Boolean" default = "False"/> <ltng:require scripts="{! $Resource.AWSService+'/AWSService.js' }" /> <ltng:require scripts="{! $Resource.jquery183minjs }" /> <aura:registerEvent name="NewAgencyContactEvent" type="c:NewAgencyContactEvent"/> --> <div class="{! v.container_class}"> <!-- header --> <header class="slds-modal__header"> <!-- <h2 id="modal-heading-01" class="slds-modal__title slds-hyphenate"> --> <div class="ptBody"> <div class="content" style="font-size: 18px;font-weight: bold;"> <img src="/img/s.gif" alt="修理" class="pageTitleIcon" title="修理" /> <span class="pageType">修理编辑 <span class="titleSeparatingColon">:</span> </span> <span class="pageDescription">新建修理</span> <div class="blank"> </div> </div> <!-- <div class="links"> <a href="javascript:openPopupFocusEscapePounds(%27https://help.salesforce.com/apex/htdoor?loc=help&target=repairs_edit.htm&section=repairs&language=zh_CN&release=234.18.8&instance=CS117&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> <!-- </h2> --> </header> <div class="slds-modal__content slds-p-around_medium"> <!-- <aura:iteration items="1,2,3,4,5" var="item"> {!item} </aura:iteration> --> <!-- <lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Repair__c"> <lightning:messages /> <div class="slds-col slds-size_1-of-2"> Your lightning:inputField components here <lightning:inputField fieldName="Source_QIS__c" /> </div> <lightning:button class="slds-m-top_small" type="submit" label="Create new" /> </lightning:recordEditForm> --> <c:lexNewRepairLWC recordId="{!v.recordId}" urlStr="{!v.urlStr}" /> </div> </div> <!-- <div class="exampleHolder"> <c:newRepairLWC recordId="{!v.recordId}"/> </div> --> </aura:component> force-app/main/default/aura/lexNewRepairAura/lexNewRepairAura.cmp-meta.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>54.0</apiVersion> <description>A Lightning Component Bundle</description> </AuraDefinitionBundle> force-app/main/default/aura/lexNewRepairAura/lexNewRepairAuraController.js
New file @@ -0,0 +1,106 @@ ({ doInit1 : function(component, event, helper) { let rid = component.get('v.recordId'); console.log(rid); let pid = window.location.href.replace("https://","").split("/"); pid = pid[pid.length-1].replace("new?",""); let jsonobj = {}; console.log(pid); pid.split("&").forEach(function(v){ console.log(v); let param = v.split("="); jsonobj[param[0]] = param[1]; }); let urlStr = JSON.stringify(jsonobj); console.log(urlStr); // if (rid) {} /*let pid = null; if(!rid){ pid = window.location.href.replace("https://","").split("/")[4]; } let isClone = component.get('v.isClone'); if(!rid || isClone){ component.set('v.title',$A.get("$Label.c.New")+'.客户人员'); }else{ component.set('v.title',$A.get("$Label.c.Edit")+'.客户人员'); } let record_type_id = null; let pageref = component.get("v.pageReference") if(!record_type_id && pageref){ record_type_id = pageref.state.recordTypeId } component.set("v.showSpinner", true);*/ helper.CallBackAction(component,'init',{ recordId : rid, urlStr : urlStr },function(data){ console.log("data"); console.log(data); }); }, doInit : function(component, event, helper) { let rid = component.get('v.recordId'); // console.log(rid); let pid = window.location.href.replace("https://","").split("/"); pid = pid[pid.length-1].replace("new?",""); let jsonobj = {}; // console.log(pid); pid.split("&").forEach(function(v){ // console.log(v); let param = v.split("="); jsonobj[param[0]] = param[1]; }); let urlStr = JSON.stringify(jsonobj); // console.log(urlStr); component.set('v.urlStr',urlStr); // create a one-time use instance of the serverEcho action // in the server-side controller /*var action = component.get("c.init"); action.setParams({ recordId : rid, urlStr : urlStr }); // Create a callback that is executed after // the server-side action returns action.setCallback(this, function(response) { console.log("response"); console.log(response); // var state = response.getState(); if (state === "SUCCESS") { // Alert the user with the value returned // from the server alert("From server: " + response.getReturnValue()); // You would typically fire a event here to trigger // client-side notification that the server-side // action is complete } else if (state === "INCOMPLETE") { // do something } else if (state === "ERROR") { var errors = response.getError(); if (errors) { if (errors[0] && errors[0].message) { console.log("Error message: " + errors[0].message); } } else { console.log("Unknown error"); } } }); // optionally set storable, abortable, background flag here // A client-side action could cause multiple events, // which could trigger other events and // other server-side action calls. // $A.enqueueAction adds the server-side action to the queue. $A.enqueueAction(action);*/ } }) force-app/main/default/aura/lexNewRepairAura/lexNewRepairAuraHelper.js
New file @@ -0,0 +1,20 @@ ({ CallBackAction : function(component,action_name,para,callback) { var action = component.get("c." + action_name.trimStart().replace("c.","")); if(para){ action.setParams(para); } if(callback){ action.setCallback(this,function(data){ callback(data); }); } $A.enqueueAction(action); }, ShowToast : function(paras){ var toastEvent = $A.get("e.force:showToast"); toastEvent.setParams(paras); toastEvent.fire(); } }) force-app/main/default/classes/lexNewRepairAuraController.cls
New file @@ -0,0 +1,438 @@ /** * 2023-04-14 * Lightning new Repair */ public with sharing class lexNewRepairAuraController { public static String sobjectTypeValue = 'Repair__c'; //查询Repair数据 修理对象的new和update @AuraEnabled public static ReturnData init(String recordId,String urlStr) { ReturnData res = new ReturnData(); String sobjectId = [SELECT CustomObjectId,CustomObjectName FROM CustomObjectUserLicenseMetrics where CustomObjectName ='Repair' limit 1].CustomObjectId; String Input_Required_Field_Msg = Label.Input_Required_Field_Msg; String PIPL_Name_Label = Label.PIPL_Name_Label; String PIPL_Input_Account_Error_Msg = label.PIPL_Input_Account_Error_Msg; Map<string,string> mso = (Map<string,string>)JSON.deserialize(urlStr, Map<string,string>.class); system.debug('mso='+mso); if (recordId != null) { res.recordTypeId = [SELECT Id,RecordTypeId FROM Repair__c WHERE Id = :recordId].RecordTypeId; res.status = true; } String RepairSubOrderAWSDataId; // AssignValueFromUrl(mso,controller.getRecord()); //通过id查 问题 //PIPL zhj 2022-11-11 start //从报修子单过来00N10000009H1rR if (mso.containsKey('CF00N10000009H1rR_lkid')) { String repairSubOrderId = mso.get('CF00N10000009H1rR_lkid'); System.debug('repairSubOrderId = ' + repairSubOrderId); //查询AWSDataId List<RepairSubOrder__c> rso = [select AWS_Data_Id__c from RepairSubOrder__c where Id=:repairSubOrderId]; if(rso.size() > 0){ //todo 从报修子单过来,需要解密报修人 lwc是否需要进行解密处理? RepairSubOrderAWSDataId = rso[0].AWS_Data_Id__c; res.AWS_Data_Id = rso[0].AWS_Data_Id__c; res.status = true; } } //PIPL zhj 2022-11-11 end List<Repair__c> rc = new List<Repair__c>(); system.debug('retURL=' + mso.containsKey('retURL')); if (mso.containsKey('retURL')) { String RepairId = mso.get('retURL').substring(1); System.debug('RepairId = ' + RepairId); rc = [select Hospital__c,Department_Class__c,Account__c,Dealer__c,Incharge_Staff_Contact__c,Incharge_Staff__c, RepairSubOrder__c,On_Call_ID__c,QIS_ID__c, InsReport__c,Rental_Apply_Equipment_Set_Detail__c from Repair__c where id =:RepairId ]; System.debug('rc = ' + rc); if(rc.size() > 0){ //已有数据赋值 //医院 res.Hospital = rc[0].Hospital__c; //战略科室分类 res.Department_Class = rc[0].Department_Class__c; //科室 res.Account = rc[0].Account__c; //经销商名 res.Dealer = rc[0].Dealer__c; //修理委托者(员工) res.Incharge_Staff_Contact = rc[0].Incharge_Staff_Contact__c; //修理委托者(FSE) res.Incharge_Staff = rc[0].Incharge_Staff__c; //报修子单RepairSubOrder__c res.RepairSubOrder = rc[0].RepairSubOrder__c; //查询AWSDataId List<RepairSubOrder__c> rso = [select AWS_Data_Id__c from RepairSubOrder__c where Id=:rc[0].RepairSubOrder__c]; if(rso.size() > 0){ RepairSubOrderAWSDataId = rso[0].AWS_Data_Id__c; res.AWS_Data_Id = rso[0].AWS_Data_Id__c; } //On-Call号码On_Call_ID__c res.On_Call_ID = rc[0].On_Call_ID__c; //QIS号码QIS_ID__c res.QIS_ID = rc[0].QIS_ID__c; //点检报告书InsReport__c res.InsReport = rc[0].InsReport__c; //借出备品配套一览明细Rental_Apply_Equipment_Set_Detail__c res.Rental_Apply_Equipment_Set_Detail = rc[0].Rental_Apply_Equipment_Set_Detail__c; res.status = true; } } //2023/04/23 lwc的保存并新建 保存后刷新页面 // PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo('Repair__c'); // PIHelper.PIIntegration piIntegrationAddress = PIHelper.getPIIntegrationInfo('Address__c'); // PIHelper.PIIntegration piIntegrationContact = PIHelper.getPIIntegrationInfo('Contact'); // PIHelper.PIIntegration piIntegrationRepairSubOrder = PIHelper.getPIIntegrationInfo('RepairSubOrder__c'); // String staticResource = JSON.serialize(piIntegration); // //zhj MEBG新方案改造 2022-11-29 start // String staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('Repair__cV2')); // //zhj MEBG新方案改造 2022-11-29 end // String staticResourceAddress = JSON.serialize(piIntegrationAddress); // String staticResourceContact = JSON.serialize(piIntegrationContact); // String staticResourceRepairSubOrder = JSON.serialize(piIntegrationRepairSubOrder); // List<String> encryptedAPIList = piIntegration.PIFields; // String sobjectPrefix = piIntegration.sobjectPrefix; //save and new url page处保存并新建跳转地址:new?recordTypeId=01210000000QmS9&additionalParams=retURL%3D%252Fa0J%252Fo%26&count=1 // String newUrl = '/setup/ui/recordtypeselect.jsp?ent=' + sobjectId + '&retURL=/' + sobjectPrefix + '/o&save_new_url=/' + sobjectPrefix + '/e?retURL=%2F' + sobjectPrefix + '%2Fo'; // res.newUrl = newUrl; return res; } public static String getAllFieldNames(String objName){ Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); List<Schema.sObjectField> fields = schemaMap.get(objName).getDescribe().fields.getMap().values(); String fieldString = ''; for( Schema.sObjectField field : fields ){ fieldString += field + ','; } fieldString = fieldString.removeEnd(','); return fieldString; } // @AuraEnabled public static List <LayoutDescriberHelper.LayoutSection > init1(String recordId,String urlStr) { String sobjectId = [SELECT CustomObjectId,CustomObjectName FROM CustomObjectUserLicenseMetrics where CustomObjectName ='Repair' limit 1].CustomObjectId; Boolean isNewMode = true; String Input_Required_Field_Msg = Label.Input_Required_Field_Msg; String PIPL_Name_Label = Label.PIPL_Name_Label; String PIPL_Input_Account_Error_Msg = label.PIPL_Input_Account_Error_Msg; String rtTypeId; // String sobjecttypeForFrontEnd = sobjectTypeValue; //获取所有字段 // List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Repair__c').getDescribe().fields.getMap().keyset()); // Add fields to controller. This is to avoid the SOQL error in visualforce page // if(!Test.isRunningTest()){ // controller.addFields(fieldList); // } // SObject obj = controller.getRecord(); if(recordId == ''){ //更新 页面判断 // isNewMode = false; Repair__c repairData = [select Id,RecordTypeId,AWS_Data_Id__c,Address_AWS_Data_Id__c,Contact_AWS_Data_Id__c,Address_Contacts_Encrypt__c,Address_Contacts_Name_Encrypt__c,Address_Telephone_Encrypt__c,Address_ZipCode_Encrypt__c,Detailed_Address_Encrypt__c from Repair__c where id =: recordId]; rtTypeId = repairData.RecordTypeId; String AWSDataId = repairData.AWS_Data_Id__c; String DecryptAWSDataId = String.valueOf(repairData.Address_AWS_Data_Id__c); String ContactAWSDataId = String.valueOf(repairData.Contact_AWS_Data_Id__c); }else{ //get url 参数 // Map<string,string> mso = ApexPages.currentPage().getParameters(); Map<string,string> mso = (Map<string,string>)JSON.deserialize(urlStr, Map<string,string>.class); system.debug('mso='+mso); // AssignValueFromUrl(mso,controller.getRecord()); //通过id查 问题 //PIPL zhj 2022-11-11 start //从报修子单过来00N10000009H1rR if (mso.containsKey('CF00N10000009H1rR_lkid')) { String repairSubOrderId = mso.get('CF00N10000009H1rR_lkid'); System.debug('repairSubOrderId = ' + repairSubOrderId); //查询AWSDataId List<RepairSubOrder__c> rso = [select AWS_Data_Id__c from RepairSubOrder__c where Id=:repairSubOrderId]; if(rso.size() > 0){ String RepairSubOrderAWSDataId = rso[0].AWS_Data_Id__c; } } //PIPL zhj 2022-11-11 end List<Repair__c> rc = new List<Repair__c>(); system.debug('retURL=' + mso.containsKey('retURL')); if (mso.containsKey('retURL')) { String RepairId = mso.get('retURL').substring(1); System.debug('RepairId = ' + RepairId); rc = [select Hospital__c,Department_Class__c,Account__c,Dealer__c,Incharge_Staff_Contact__c,Incharge_Staff__c, RepairSubOrder__c,On_Call_ID__c,QIS_ID__c, InsReport__c,Rental_Apply_Equipment_Set_Detail__c from Repair__c where id =:RepairId ]; System.debug('rc = ' + rc); if(rc.size() > 0){ //已有数据赋值 defaultValue /*//医院 controller.getRecord().put('Hospital__c',rc[0].Hospital__c); //战略科室分类 controller.getRecord().put('Department_Class__c',rc[0].Department_Class__c); //科室 controller.getRecord().put('Account__c',rc[0].Account__c); //经销商名 controller.getRecord().put('Dealer__c',rc[0].Dealer__c); //修理委托者(员工) controller.getRecord().put('Incharge_Staff_Contact__c',rc[0].Incharge_Staff_Contact__c); //修理委托者(FSE) controller.getRecord().put('Incharge_Staff__c',rc[0].Incharge_Staff__c); //报修子单RepairSubOrder__c controller.getRecord().put('RepairSubOrder__c',rc[0].RepairSubOrder__c); //查询AWSDataId List<RepairSubOrder__c> rso = [select AWS_Data_Id__c from RepairSubOrder__c where Id=:rc[0].RepairSubOrder__c]; if(rso.size() > 0){ RepairSubOrderAWSDataId = rso[0].AWS_Data_Id__c; } //On-Call号码On_Call_ID__c controller.getRecord().put('On_Call_ID__c',rc[0].On_Call_ID__c); //QIS号码QIS_ID__c controller.getRecord().put('QIS_ID__c',rc[0].QIS_ID__c); //点检报告书InsReport__c controller.getRecord().put('InsReport__c',rc[0].InsReport__c); //借出备品配套一览明细Rental_Apply_Equipment_Set_Detail__c controller.getRecord().put('Rental_Apply_Equipment_Set_Detail__c',rc[0].Rental_Apply_Equipment_Set_Detail__c);*/ } } // rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); rtTypeId = mso.get('RecordType'); if(String.isBlank(rtTypeId)||String.isEmpty(rtTypeId)){ List<RecordType> rtList = new List<RecordType>([select Id,DeveloperName from RecordType where SobjectType ='Repair__c' and DeveloperName ='Repair']); rtTypeId = rtList[0].Id; } } LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Repair__c','classic'); List <LayoutDescriberHelper.LayoutSection > layoutSections = LayoutWrapperValue.layoutSections; String layoutSectionsStr = JSON.serialize(layoutSections); //for dynamic add readonly attribute List<String> requiredFieldAPIList = LayoutWrapperValue.requiredFieldAPIList; Map<String,String> fieldAPIToLabelMap = LayoutWrapperValue.fieldAPIToLabelMap; String requiredFieldAPIListStr = JSON.serialize(requiredFieldAPIList); String fieldAPIToLabelMapStr = JSON.serialize(fieldAPIToLabelMap); PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo('Repair__c'); PIHelper.PIIntegration piIntegrationAddress = PIHelper.getPIIntegrationInfo('Address__c'); PIHelper.PIIntegration piIntegrationContact = PIHelper.getPIIntegrationInfo('Contact'); PIHelper.PIIntegration piIntegrationRepairSubOrder = PIHelper.getPIIntegrationInfo('RepairSubOrder__c'); String staticResource = JSON.serialize(piIntegration); //zhj MEBG新方案改造 2022-11-29 start String staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('Repair__cV2')); //zhj MEBG新方案改造 2022-11-29 end String staticResourceAddress = JSON.serialize(piIntegrationAddress); String staticResourceContact = JSON.serialize(piIntegrationContact); String staticResourceRepairSubOrder = JSON.serialize(piIntegrationRepairSubOrder); List<String> encryptedAPIList = piIntegration.PIFields; String sobjectPrefix = piIntegration.sobjectPrefix; //获取lookup字段 List<String> VLookUpFields = new List<String>(); for (LayoutDescriberHelper.LayoutSection ls : layoutSections) { for (LayoutDescriberHelper.LayoutField lf : ls.layoutFields) { if (lf.fieldAPI != '' && lf.fieldType == 'reference') { VLookUpFields.add(lf.fieldAPI); } } } String VLookUpFieldsJson = Json.serialize(VLookUpFields); System.debug(LoggingLevel.INFO, '*** layoutSectionsLWC: ' + layoutSections); return layoutSections; } // 从url参数赋值到当前页面 public static void AssignValueFromUrl(Map<string,string> mso, sobject sobj){ String sobject_name = sobj.getSObjectType().getDescribe().getName(); Map<string,object> temp = new Map<string,object>(); Map<string,FieldDefinition> fdm = new Map<string,FieldDefinition>(); List<FieldDefinition> fds = [SELECT Id, DurableId, QualifiedApiName,ValueTypeId , EntityDefinitionId, NamespacePrefix,EntityDefinition.NamespacePrefix, DeveloperName, MasterLabel, Label FROM FieldDefinition where EntityDefinition.QualifiedApiName = :sobject_name]; for(FieldDefinition fd : fds){ //system.debug(fd.DurableId); fdm.put(fd.DurableId.split('\\.')[1],fd); } for(string key : mso.keySet()){ if (key.toLowerCase() == 'id') { System.debug('skip id assign'); continue; } string new_key = key; system.debug('new_key='+new_key); if(new_key.contains('_lkid')){ new_key = new_key.replace('_lkid', ''); new_key = new_key.substring(2); }else{ if(temp.containsKey(new_key)){ continue; } } system.debug('now new_key='+new_key); if(fdm.containsKey(new_key)){ system.debug('fdm.get(new_key)='+fdm.get(new_key)); string val_str = mso.get(key); system.debug('val_str='+val_str); /*无需做decode,sf内部已经做好 try{ val_str = EncodingUtil.urlDecode(mso.get(key),'UTF-8'); }catch(Exception e){ continue; system.debug('Exception from get Key:'+e.getMessage()); system.debug(e.getStackTraceString()); } */ object val = null; string type_id = fdm.get(new_key).ValueTypeId; // address, boolean, date, datetime, double, id, location, string, time if(string.isBlank(val_str)){ val = null; }else if(type_id == 'boolean'){ if(val_str == '1'){ val = true; }else{ val = boolean.valueOf(val_str); } }else if(type_id == 'date'){ // try{ val = date.parse(val_str); }catch(Exception e){ system.debug('val_str='+val_str); system.debug(e.getMessage()); system.debug(e.getStackTraceString()); try{ val = date.valueOf(val_str); }catch(Exception ee){ system.debug('val_str='+val_str); system.debug(ee.getMessage()); system.debug(ee.getStackTraceString()); continue; } } }else if(type_id == 'datetime'){ // try{ val = datetime.parse(val_str); }catch(Exception e){ system.debug('val_str='+val_str); system.debug(e.getMessage()); system.debug(e.getStackTraceString()); try{ val = datetime.valueOf(val_str); }catch(Exception ee){ system.debug('val_str='+val_str); system.debug(ee.getMessage()); system.debug(ee.getStackTraceString()); continue; } } }else if(type_id == 'double' || type_id == 'number'){ try{ val = decimal.valueOf(val_str.replace(',', '')); }catch(Exception ee){ system.debug('val_str='+val_str); system.debug(ee.getMessage()); system.debug(ee.getStackTraceString()); continue; } }else if(type_id == 'id' || type_id == 'string'){ val = val_str; }else{ system.debug('type_id='+type_id+' is not support to convert'); continue; } temp.put(fdm.get(new_key).QualifiedApiName,val); }else{ system.debug(key+' is not in fdm'); } } for(string key : temp.keySet()){ system.debug('assign '+key+'='+temp.get(key)); try{ sobj.put(key, temp.get(key)); }catch(Exception e){ system.debug(e.getMessage()); system.debug(e.getStackTraceString()); } } } public class RetrievalData { @AuraEnabled public String Status1; @AuraEnabled public String Status2; @AuraEnabled public String RepairName; @AuraEnabled public String SAPRepairNo; @AuraEnabled public String SerialNumber; @AuraEnabled public String onSiteRepair; @AuraEnabled public String workLocationSelect; @AuraEnabled public String State_Hospital; @AuraEnabled public String HospitalName; @AuraEnabled public Repair__c repair; public RetrievalData(){ repair = new Repair__c(); } } public class RepairData { @AuraEnabled public Boolean IFCheck; @AuraEnabled public Repair__c repair; public RepairData(Repair__c RepairInfo){ IFCheck = null; repair = RepairInfo; } } //2023/04/18 返回查询结果和状态 public class ReturnData { //判断是否有Repair的默认值 @AuraEnabled public Boolean status; // @AuraEnabled // public Repair__c repair; //todo 报修人 @AuraEnabled public String AWS_Data_Id; //医院 @AuraEnabled public String Hospital; @AuraEnabled public String Department_Class; @AuraEnabled public String Account; @AuraEnabled public String Dealer; @AuraEnabled public String Incharge_Staff_Contact; @AuraEnabled public String Incharge_Staff; @AuraEnabled public String RepairSubOrder; @AuraEnabled public String On_Call_ID; @AuraEnabled public String QIS_ID; @AuraEnabled public String InsReport; @AuraEnabled public String Rental_Apply_Equipment_Set_Detail; @AuraEnabled public String recordTypeId; // @AuraEnabled // public String newUrl; public ReturnData(){ this.status = false; } } } force-app/main/default/classes/lexNewRepairAuraController.cls-meta.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>54.0</apiVersion> <status>Active</status> </ApexClass> force-app/main/default/lwc/lexNewRepairLWC/lexNewRepairLWC.css
New file @@ -0,0 +1,12 @@ .exampleHolder{ position: relative; top: 0; width: 0; left: 0; right: 0; margin: 0 auto; } .repairTitle{ --slds-c-accordion-heading-font-size: 1.05rem; --slds-c-accordion-summary-color-background:#f3f3f3; } force-app/main/default/lwc/lexNewRepairLWC/lexNewRepairLWC.html
New file @@ -0,0 +1,93 @@ <template> <div class="exampleHolder" if:true={isLoading}> <lightning-spinner alternative-text="Loading" size="small"></lightning-spinner> </div> <div class="newRepair"> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-2"> <!-- onsectiontoggle={handleSectionToggle} --> <lightning-accordion allow-multiple-sections-open="true" active-section-name={activeSections}> <!-- Repair__c --> <lightning-record-edit-form onload={handleRecordEditFormLoad} onsubmit={handleSubmit} onsuccess={handleSucess} onerror={handleError} object-api-name='{objectName}' record-type-id={recordTypeId} record-id={recordIdStr}> <lightning-messages></lightning-messages> <template if:true={uiPageLayoutView}> <lightning-layout multiple-rows="true"> <lightning-layout-item size="12"> <!-- active-section-name={activeSections} --> <template for:each={uiPageLayoutView.sections} for:item="section"> <lightning-accordion-section name={section.id} key={section.id} label={section.heading} class="repairTitle"> <lightning-layout multiple-rows="true" style="margin-top: 10px;"> <template for:each={section.layoutRows} for:item="layoutRow"> <template for:each={layoutRow.layoutItems} for:item="layoutItem"> <template for:each={layoutItem.layoutComponents} for:item="layoutComponent"> <lightning-layout-item key={layoutComponent.apiName} size="6" padding="horizontal-small"> <template if:true={layoutItem.editableForNew}> <lightning-input-field data-fieldname={layoutComponent.apiName} field-name={layoutComponent.apiName} name={layoutComponent.apiName} required={layoutItem.required}> </lightning-input-field> </template> <!-- <template if:false={layoutItem.editableForNew}> --> <!-- 修理受付番号 --> <!-- <template if:true={layoutComponent.apiName}> <lightning-output-field field-name={layoutComponent.apiName}> </lightning-output-field> </template> --> <!-- </template> --> </lightning-layout-item> </template> </template> </template> </lightning-layout> </lightning-accordion-section> </template> </lightning-layout-item> </lightning-layout> </template> <lightning-messages></lightning-messages> <div class="" style="text-align: center;"> <lightning-button label="取消" onclick={handleCancel} ></lightning-button> <lightning-button type="submit" name="save" label="保存" style="margin-left: 10px;" ></lightning-button> <lightning-button if:true={hasRecordId} name="saveAndNew" type="submit" label="保存并新建" onclick={handleSubmitAndNew} style="margin-left: 10px;" ></lightning-button> </div> </lightning-record-edit-form> </lightning-accordion> </div> <!-- <div class="footer-background-class"> <div class="slds-align_absolute-center slds-p-around_xx-small"> <lightning-button class="slds-m-around_xx-small" title="Cancel" label="Cancel" onclick={closeNewObjectModal}> </lightning-button> <lightning-button variant="brand" title="Save" onclick={submitRecordForm} name="Save" label="Save"> </lightning-button> </div> </div> --> </div> <!-- a0J0l00000Ep9XHEAZ --> <!-- <lightning-record-edit-form record-id="" object-api-name='{objectName}'> <lightning-input-field field-name="Delivered_Product__c"> </lightning-input-field> <lightning-button class="slds-m-top_small" variant="brand" type="submit" label="Update" > </lightning-button> </lightning-record-edit-form> --> </template> force-app/main/default/lwc/lexNewRepairLWC/lexNewRepairLWC.js
New file @@ -0,0 +1,171 @@ import { LightningElement,wire,track,api} from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import { NavigationMixin } from 'lightning/navigation'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import init from '@salesforce/apex/lexNewRepairAuraController.init'; export default class lexNewRepairLWC extends NavigationMixin(LightningElement) { // Flexipage provides recordId @api recordId; // @api recordId; @api urlStr; @api objectApiName; /* @wire(CurrentPageReference) getStateParameters(currentPageReference) { console.log(111); console.log(currentPageReference); if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; console.log("str"); console.log(str); this.recordId = str; } } }*/ objectName = 'Repair__c'; uiPageLayoutView; isNewMode; //属性默认值 defaultValue = {}; isLoading = true; activeSections; isSaveAndNew = false; //更新操作时 不显示保存新建 hasRecordId = false; recordIdStr; recordTypeId = ''; connectedCallback(){ console.log(this.recordId); console.log(JSON.parse(this.urlStr)); if (!this.recordId) { this.hasRecordId = true; // urlStr 传参处理 let urlObj = JSON.parse(this.urlStr); if (urlObj.hasOwnProperty("CF00N10000009H1rR_lkid") || urlObj.hasOwnProperty("retURL") ) { console.log('urlObj.hasOwnProperty:',urlObj); // init 向Controller发送请求获取数据 init({ recordId : this.recordId,urlStr : this.urlStr }).then(result => { console.log("result"); console.log(result); this.defaultValue = result; //返回结果赋值 if (result.status) { this.recordTypeId = result.recordTypeId; } }).catch(error => { console.log("error"); console.log(error); }).finally(() => { }); } } } //获取Layout字段 handleRecordEditFormLoad(event) { if (event.detail.layout == undefined) { return; } console.log('Layout => ', JSON.stringify(event.detail.layout)); this.uiPageLayoutView = event.detail.layout; console.log('Layout1 => ',this.uiPageLayoutView); //页面内容初始化 del //to del ! err: Delivered_Product 02i10000004tNXIAA2 Hospital 0011000001g11rDAAQ // this.defaultValue['Delivered_Product'] = '02i10000004tMKgAAM'; // // this.defaultValue['Delivered_Product'] = '02i10000004tNXIAA2'; // this.defaultValue['Account'] = '0011000001g11rDAAQ'; // this.defaultValue['SalesOfficeCode_selection'] = '北京'; // this.defaultValue['On_site_repair'] = 'RC修理'; // this.defaultValue['Repair_Detail'] = 'testLwcSaveAndNew'; // this.defaultValue['Hospital'] = '0011000001g0R8vAAE'; // // this.defaultValue['Hospital'] = '0011000001g11rDAAQ'; // // 0011000000V9SG5AAN // this.defaultValue['work_location_select'] = '北京办事处'; const inputFields = this.template.querySelectorAll('lightning-input-field'); if (inputFields) { inputFields.forEach(field => { let fieldName = field.name.replace("__c",""); if (this.defaultValue.hasOwnProperty(fieldName)) { field.value= this.defaultValue[fieldName]; } }); } let checkedSections = new Set(); if (this.uiPageLayoutView.sections.length > 0) { for(const tabs of this.uiPageLayoutView.sections){ checkedSections.add(tabs.id); } this.activeSections = Array.from(checkedSections); } this.isLoading = false; this.recordIdStr = this.recordId; } //保存 保存新建提交事件 handleSubmit(event){ this.isLoading = true; console.log("handleSubmit"); event.preventDefault(); // stop the form from submitting const fields = event.detail.fields; /*console.log("fields"); console.log(fields);*/ this.template.querySelector('lightning-record-edit-form').submit(fields); // console.log("success"); } handleSubmitAndNew(event){ this.isSaveAndNew = true; } //成功后跳转 handleSucess(event){ // console.log("handleSucess"); const updatedRecord = event.detail.id; console.log('onsuccess: ', updatedRecord); if (this.isSaveAndNew) { // console.log("isSaveAndNew"); window.location.reload(); }else if (event.detail.id) { // console.log("NavigationMixin"); this[NavigationMixin.Navigate]({ type:'standard__recordPage', attributes:{ recordId:updatedRecord, objectApiName:this.objectName, actionName:'view' } }); } this.isLoading = false; } //对象验证,属性验证 handleError(event) { console.log("handleError event"); console.log(JSON.stringify(event.detail)); } handleCancel(event) { window.location.href = "https://ocsm--partial.sandbox.lightning.force.com/lightning/o/Repair__c/list?filterName=Recent&0.source=alohaHeader"; } showToast(theTitle, theMessage, theVariant) { const event = new ShowToastEvent({ title: theTitle, message: theMessage, variant: theVariant }); this.dispatchEvent(event); } } force-app/main/default/lwc/lexNewRepairLWC/lexNewRepairLWC.js-meta.xml
New file @@ -0,0 +1,11 @@ <?xml version="1.0"?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>54.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__RecordPage</target> <target>lightning__AppPage</target> <target>lightning__HomePage</target> <target>lightning__RecordAction</target> </targets> </LightningComponentBundle>