import { LightningElement, api , track, wire } from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
|
import init from '@salesforce/apex/LexNewIntentionController.init';
|
import getRecordIdByName from '@salesforce/apex/LexSubmitCampaignController.getRecordIdByName';
|
import getRecordTypeId from '@salesforce/apex/LexSubmitCampaignController.getRecordTypeId';
|
import getAccountByLongName from '@salesforce/apex/LexNewIntentionController.getAccountByLongName';
|
import Agency_Opportunity from '@salesforce/label/c.Agency_Opportunity';
|
import Opportunity_stage from '@salesforce/label/c.Opportunity_stage';
|
import Opp_Name from '@salesforce/label/c.Opp_Name';
|
import Purchase_Reason from '@salesforce/label/c.Purchase_Reason';
|
import Fund_Basis from '@salesforce/label/c.Fund_Basis';
|
import Purchase_Type from '@salesforce/label/c.Purchase_Type';
|
import Sales_Method from '@salesforce/label/c.Sales_Method';
|
import Request from '@salesforce/label/c.Request';
|
import Request_Detail from '@salesforce/label/c.Request_Detail';
|
|
|
const event1 = new ShowToastEvent({
|
message:
|
'请从询价画面新建报价委托',
|
variant : 'error',
|
mode : 'sticky'
|
});
|
export default class lexNewIntention extends NavigationMixin(LightningElement) {
|
|
@api recordId;
|
AgencyOpportunity;
|
IsLoading=true;
|
|
|
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
|
|
|
connectedCallback(){
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
console.log(this.recordId);
|
init({
|
recordId: this.recordId
|
}).then(result => {
|
if (result != null) {
|
this.AgencyOpportunity = result;
|
console.log(result);
|
this.newIntention().then(result=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}).catch(error=>{
|
alert(error.message);
|
console.log(error.message);
|
});
|
}
|
});
|
|
}
|
|
|
|
async newIntention(){
|
if(this.AgencyOpportunity.Is_Transformed__c == true){
|
this.dispatchEvent(event1);
|
return;
|
}
|
var accountName = this.AgencyOpportunity.Department_Class_Opp_Name__c + ' '
|
+ this.AgencyOpportunity.Department_Name_Text__c;
|
var accountrecords = await getAccountByLongName({Name: accountName});
|
var accountID = '';
|
if(accountrecords.length > 0){
|
accountID = accountrecords[0].Id;
|
}
|
if (accountID == '') {
|
accountName = this.AgencyOpportunity.Department_Class_Opp_Name__c;
|
accountrecords = await getAccountByLongName({Name : accountName});
|
console.log('accountrecords');
|
console.log(accountrecords);
|
if(accountrecords.length > 0){
|
accountID = accountrecords[0].Id;
|
}
|
}
|
console.log('医院='+this.AgencyOpportunity.Account_Opp__c);
|
console.log('战略科室='+accountID);
|
//如果要说传参的问题,那就是页面的问题。该传的都传了。那个页面的默认值他没带,还有没做。
|
// var recordTypeId= await getRecordIdByName({Name : '拜访获取的意向'})
|
var recordTypeId= await getRecordTypeId()//梁 注:要换成“其他途径获取的意向”的记录类型
|
const defaultValues = encodeDefaultFieldValues({
|
Agency_Opportunity__c: this.AgencyOpportunity.Id,
|
LeadSource: '经销商',
|
Opportunity_stage__c : this.AgencyOpportunity.StageName__c ,
|
Close_Forecasted_Date__c : this.AgencyOpportunity.Close_Forecasted_Date__c ,
|
Opp_Name__c : this.AgencyOpportunity.Name ,
|
Purchase_Reason__c : this.AgencyOpportunity.Purchase_Reason__c ,
|
Fund_Basis__c :this.AgencyOpportunity.Fund_Basis__c ,
|
Purchase_Type__c : this.AgencyOpportunity.Purchase_Type__c ,
|
Sales_Method__c : this.AgencyOpportunity.Sales_Method__c ,
|
Request__c : this.AgencyOpportunity.Request__c ,
|
Request_Detail__c : this.AgencyOpportunity.Request_Detail__c ,
|
Department_Class__c:this.AgencyOpportunity.Department_Class_Opp__c,
|
Hospital_Name__c : accountID,
|
RecordTypeId:recordTypeId,
|
Company:this.AgencyOpportunity.Department_Class_Opp_Name__c +' '+this.AgencyOpportunity.Department_Name_Text__c
|
});
|
console.log(this.AgencyOpportunity.StageName__c);
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'Lead',
|
actionName: 'new'
|
},
|
state: {
|
// nooverride: '1', //deloitte-zhj 20230829
|
defaultFieldValues: defaultValues,
|
}
|
});
|
|
|
|
}
|
|
}
|