这是整个代码
({
doInit : function(component, event, helper) {
helper.getLeadId(component);
},
/**
*This function is responsible for opening the lead page in read mode on click of Open Lead button
*/
newLeadClick : function(component, event, helper) {
const workspaceAPI = component.find("workspace");
workspaceAPI.getEnclosingTabId().then(function(tabId) {
const tabContext = {
parentTabId: tabId,
url: '/lightning/r/Lead/'+component.get("v.LeadId")+'/view',
focus: true
}
helper.openWorkspaceSubTab(component, workspaceAPI, tabContext);
});
},
/**
*This function is responsible for opening the opportunity page in subtab in readmode on click of Open Opportunity Button
*/
newOppClick : function(component, event, helper) {
const workspaceAPI = component.find("workspace");
workspaceAPI.getEnclosingTabId().then(function(tabId) {
const tabContext = {
parentTabId: tabId,
url: '/lightning/r/Opportunity/'+component.get("v.OppId")+'/view',
focus: true
}
helper.openWorkspaceSubTab(component, workspaceAPI, tabContext);
});
},
afterSaveOpp : function(component, event, helper) {
component.set("v.showRecord", true);
},
/**
* this function is responsible for creating a default lead and attach it to transcript,
* and then open the same lead inside a lightning component in a new sub tab for user
* to add/modify the fields and save
*/
afterSaveLead : function(component, event, helper) {
component.set("v.editmode", true);
const action = component.get("c.attachToTranscript");
action.setParams({ leadId : null, chatTranscriptId: component.get("v.recordId")});
action.setCallback(this, function(response) {
const state = response.getState();
const result = response.getReturnValue();
if (state === "SUCCESS"){
component.set("v.LeadId", result);
component.set("v.showRecord", false);
const workspaceAPI = component.find("workspace");
workspaceAPI.getEnclosingTabId().then(function(tabId) {
const tabContext = {
parentTabId: tabId,
pageReference: {
"type": "standard__component",
"attributes": {
"componentName": "c__ShowLeadEditMode" // c__<comp Name>
},
"state": {
"c__leadid": component.get("v.LeadId") // c__<comp attribute Name>
}
},
focus: true
}
helper.openWorkspaceSubTab(component, workspaceAPI, tabContext);
});
} else {
helper.showToast(component);
}
component.set("v.showSpinner", false);
});
$A.enqueueAction(action);
},
});