KKbes
2023-08-07 890eafcf31f5f8d519bb9e6f9c15303be5328e2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { LightningElement, api , track, wire } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
 
import init  from '@salesforce/apex/LexNewIntentionController.init';
import getRecordIdByName  from '@salesforce/apex/LexSubmitCampaignController.getRecordIdByName';
import getAccountByLongName  from '@salesforce/apex/LexNewIntentionController.getAccountByLongName';
import getAccountByShortName  from '@salesforce/apex/LexNewIntentionController.getAccountByShortName';
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({
            title: '提示',
            message:
                '请从询价画面新建报价委托',
        });
export default class lexNewIntention extends 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(){
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            if (result != null) {
                this.AgencyOpportunity = result;
                this.newIntention().then(result=>{
                    IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });
                this.judageWhertherNull();
            }
        });
 
    }
 
 
 
    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 getAccountByShortName({Name : accountName});
                if(accountrecords.length > 0){
                    accountID = accountrecords[0].Id;
                }
        }
    //后端代码取参数数据,一一对应
    var recordTypeId= await getRecordIdByName({Name : '拜访获取的意向'})
    var url = '/apex/NewAndEditLead?' + Agency_Opportunity+'=' + this.AgencyOpportunity.Id
    + '&LeadSource=经销商' + '&'+Opportunity_stage+'=' + this.AgencyOpportunity.StageName__c 
    + '&00N10000006qOF0=' +     this.AgencyOpportunity.Close_Forecasted_Date__c 
    + '&'+Opp_Name+'=' +         this.AgencyOpportunity.Name 
    + '&'+Purchase_Reason+'=' + this.AgencyOpportunity.Purchase_Reason__c 
    + '&'+Fund_Basis+'=' +         this.AgencyOpportunity.Fund_Basis__c 
    + '&'+Purchase_Type+'=' +     this.AgencyOpportunity.Purchase_Type__c 
    +'&'+Sales_Method+'=' +     this.AgencyOpportunity.Sales_Method__c
    + '&'+Request+'=' +         this.AgencyOpportunity.Request__c
    + '&'+Request_Detail+'=' +  this.AgencyOpportunity.Request_Detail__c
    + '&CF00N10000002CvC5=' + accountName
    + '&CF00N10000002CvC5_lkid=' + accountID
    + '&RecordTypeId='+recordTypeId + '&retURL=%2F' + this.AgencyOpportunity.Id;
    window.open(url);
 
    
    }
 
}