liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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,
            }
        });    
 
 
    
    }
 
}