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
import { LightningElement,wire,track,api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import LeadNewDailyReportId from '@salesforce/label/c.LeadNewDailyReportId';
import selectinfrastructureById from '@salesforce/apex/LexinfrastructureProjectController.selectInfrastructureProject';
 
export default class LexCreateLead extends NavigationMixin(LightningElement) {
    @api recordId;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        console.log(currentPageReference);
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.warn("str");
            console.warn(str);
            this.recordId = str;
          }
        }
    }
    connectedCallback(){
        debugger
        selectinfrastructureById({recordId:this.recordId}).then(item=>{
            // var url = '/00Q/e?' + 'Infrastructure_Project__c=' + '{!Infrastructure_Project__c.Id}'
            // + '&LeadSource=基建项目' + '&RecordTypeId=01210000000QiRf' + '&retURL=%2F' + '{!Infrastructure_Project__c.Id}' ;
            // window.open(url);
            const defaultValues = encodeDefaultFieldValues({
                Infrastructure_Project__c: this.recordId,
                LeadSource: '基建项目',
                Hospital_Name__c:item.OCSM_Hospital__c,
                RecordTypeId:LeadNewDailyReportId
            });
            console.log('defaultValues = ' + defaultValues);
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'Lead',
                    actionName: 'new'
                },
                state: {
                    // nooverride: '1',
                    defaultFieldValues: defaultValues
                }
            });
            this.dispatchEvent(new CloseActionScreenEvent());
        });
    }
}