force-app/main/default/aura/lexExistingInquiryAura/lexExistingInquiryAura.cmp
New file @@ -0,0 +1,8 @@ <aura:component implements="flexipage:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasRecordId,lightning:actionOverride,lightning:isUrlAddressable" access="global"> <aura:attribute name="recordId" type="String" /> <aura:handler name="render" value="{!this}" action="{!c.closeModal}" /> <aura:attribute name="isDoneRendering" type="Boolean" default="false"/> <div class="exampleHolder"> <c:lexExistingInquiry recordId="{!v.recordId}" /> </div> </aura:component> force-app/main/default/aura/lexExistingInquiryAura/lexExistingInquiryAura.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/lexExistingInquiryAura/lexExistingInquiryAura.css
New file @@ -0,0 +1,2 @@ .THIS { } force-app/main/default/aura/lexExistingInquiryAura/lexExistingInquiryAuraController.js
New file @@ -0,0 +1,5 @@ ({ myAction : function(component, event, helper) { } }) force-app/main/default/aura/lexExistingInquiryAura/lexExistingInquiryAuraHelper.js
New file @@ -0,0 +1,5 @@ ({ helperMethod : function() { } }) force-app/main/default/classes/LexInquiryController.cls
New file @@ -0,0 +1,105 @@ //author : kkbes public with sharing class LexInquiryController { @AuraEnabled public static Task init(String recordId){ Task res = new Task(); try{ res=[SELECT Id,Related_Opportunity1__c,QuoteIraiId__c ,Status FROM Task WHERE Id = : recordId ]; } catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); } return res; } @AuraEnabled public static List<Opportunity> getOpportunityIds(String RelatedOpportunity1){ List<Opportunity> res = new List<Opportunity>(); try{ res=[SELECT id FROM Opportunity WHERE Opportunity_No__c = : RelatedOpportunity1]; } catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); } return res; } @AuraEnabled public static QuoteIrai__c getQuoteIrai(String QuoteIraiId){ QuoteIrai__c res = new QuoteIrai__c(); try{ res=[SELECT Id,Lead__c FROM QuoteIrai__c WHERE Id = : QuoteIraiId ]; } catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); } return res; } @AuraEnabled public static String makeAndUpdateLead(String leadId,String Id,String QuoteIraiId){ Lead res = new Lead(); try{ res.Id = leadId; res.Opp_Name_Search__c = Id; if(QuoteIraiId != ''){ res.LatestQuotationEntrustment__c=QuoteIraiId; } update res; return 'success'; } catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); String a = e.getMessage()+' And '+e.getCause(); return a; } } @AuraEnabled public static String makeAndUpdateTask(String Status,String Id){ Task res = new Task(); try{ res.Id = Id; res.Status = Status; res.Quotation_request_completed_time__c = System.now(); update res; return 'success'; } catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); return e.getMessage(); } } @AuraEnabled public static String makeAndUpdateQuoteIrai(String QuoteIraiStatus,String Id){ QuoteIrai__c res = new QuoteIrai__c(); try{ res.Id = Id; res.QuoteIrai_Status__c = QuoteIraiStatus; update res; return 'success'; } catch(Exception e){ System.debug(LoggingLevel.INFO, '*** e: ' + e); return e.getMessage(); } } } force-app/main/default/classes/LexInquiryController.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>51.0</apiVersion> <status>Active</status> </ApexClass> force-app/main/default/lwc/lexExistingInquiry/lexExistingInquiry.html
New file @@ -0,0 +1,5 @@ <template> <div class="Attachment" if:true={IsLoading}> <lightning-spinner alternative-text="Loading" size="medium"></lightning-spinner> </div> </template> force-app/main/default/lwc/lexExistingInquiry/lexExistingInquiry.js
New file @@ -0,0 +1,199 @@ //author : kk //self review 更新失败返回的错误信息没有之前class的好。给出的都是意义不明的报错 import { LightningElement, track, wire , api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import init from '@salesforce/apex/LexInquiryController.init'; import getOpportunityIds from '@salesforce/apex/LexInquiryController.getOpportunityIds'; import getQuoteIrai from '@salesforce/apex/LexInquiryController.getQuoteIrai'; import makeAndUpdateLead from '@salesforce/apex/LexInquiryController.makeAndUpdateLead'; import makeAndUpdateTask from '@salesforce/apex/LexInquiryController.makeAndUpdateTask'; import makeAndUpdateQuoteIrai from '@salesforce/apex/LexInquiryController.makeAndUpdateQuoteIrai'; const event1 = new ShowToastEvent({ message: '请填写询价的编码', variant : 'error' }); const event2 = new ShowToastEvent({ message: '更新已完成', variant : 'success' }); const event3 = new ShowToastEvent({ message: '报价委托未关联意向', variant : 'error' }); const event4 = new ShowToastEvent({ message: '编码有误!请确认正确的编码', variant : 'error' }); const event5 = new ShowToastEvent({ message: '任务已结束,如需修改请联系管理员', variant : 'error' }); export default class lexExistingInquiry extends LightningElement { @api recordId; Task; QuoteIrai; Opportunity; NewLead; NewTask; NewQuoteIrai; IsLoading=true; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback(){ console.log(this.recordId); init({ recordId: this.recordId }).then(result => { console.log(result); if (result != null) { this.Task = result; this.ExistingInquiry().then(result=>{ IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } }).catch(error => { console.log("error"); console.log(error); }); } async ExistingInquiry(){ var judage = 0; if( this.Task.Status == '未着手'|| this.Task.Status == '進行中'){ if(this.Task.Related_Opportunity1__c == undefined || this.Task.Related_Opportunity1__c ==''){ this.dispatchEvent(event1); } else{ await getOpportunityIds({ RelatedOpportunity1 : this.Task.Related_Opportunity1__c }).then(res =>{ this.Opportunity=res; }); if(this.Opportunity.length>0){ await getQuoteIrai({QuoteIraiId : this.Task.QuoteIraiId__c }).then(res=>{ this.NewTask=res; }).catch(err=>{ console.log("err:",err.message); }); if(this.NewTask.Lead__c){ // Lead作成并更 await makeAndUpdateLead({ Lead_c : this.Opportunity.Lead__c, Id : this.NewTask.Id, QuoteIraiId__c : this.Task.QuoteIraiId__c }).then(res=>{ if(res !='success'){ const event6 = new ShowToastEvent({ message: res+',Lead更新错误', variant : 'error' }); judage +=1; this.dispatchEvent(event6); } }); if(judage!=0){ return; } // 判断报价委托 if( this.Task.QuoteIraiId__c != '') { // 报价委托作成 await makeAndUpdateQuoteIrai({ QuoteIraiStatus : "已有询价", Id : this.Task.QuoteIraiId__c }).then(res=>{ if(res!= 'success'){ const event8 = new ShowToastEvent({ message: res+',QuoteIrai更新错误', variant : 'error' }); this.dispatchEvent(event8); judage +=1; } }); if(judage!=0){ return; } } // Task做成并更新 await makeAndUpdateTask({ Status : "已有询价", Id : this.Task.Id }).then(res=>{ if(res !='success'){ const event7 = new ShowToastEvent({ message: res+',Task更新错误', variant : 'error' }); this.dispatchEvent(event7); judage +=1; } else{ this.dispatchEvent(event2); //发送成功后,希望自动刷新画面。 location.reload(); } if(judage!=0){ return; } }); } else{ this.dispatchEvent(event3); } } else{ this.dispatchEvent(event4); } } } else{ this.dispatchEvent(event5); } } } force-app/main/default/lwc/lexExistingInquiry/lexExistingInquiry.js-meta.xml
New file @@ -0,0 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="lexExistingInquiry"> <apiVersion>51.0</apiVersion> <isExposed>true</isExposed> <targets> <target>lightning__AppPage</target> <target>lightning__RecordPage</target> <target>lightning__HomePage</target> <target>lightning__RecordAction</target> </targets> </LightningComponentBundle>