zhangqian
2023-08-10 af7f2ebba1ca53c05ad1c47361c889afd53a9765
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference,NavigationMixin } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import  init  from '@salesforce/apex/InquiryFormController.init';
import  sqlResult  from '@salesforce/apex/InquiryFormController.sqlResult';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
export default class lexInquiryFormCustomLink1 extends NavigationMixin(LightningElement) {
    @api recordId;//OwnerId
    IsLoading = true;
    Id= "";
    ServiceStatus= "";
    userId= "";
    Status= "";
    LeadLink= "";
    OppNameSearch= "";
    ContactName= "";
    ContactId = "";
    HospitalName= "";
    HospitalID= "";
    DepartmentClass= "";
    DepartmentID = "";
    OppNameSearchID= "";
    Campaign= "";
    CampaignID= "";
    Name= "";
    CancelReason= "";
    Phone= "";
    Email= "";
    LastName= "";
    LeadSource= "";
    OpportunityDivision= "";
    Request1= "";
    Urgent = false;
    FSEOwner= "";
    FamilyName= "";
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
          }
        }
    }
    connectedCallback(){
        init({
            recordId: this.recordId
        }).then(result => {
            this.IsLoading = false;
            this.Id = result.Id != undefined ? result.Id : "";
            this.ServiceStatus = result.ServiceStatus != undefined ? result.ServiceStatus : "";
            this.userId = result.userId != undefined ? result.userId : "";
            this.Status = result.Status != undefined ? result.Status : "";
            this.LeadLink = result.LeadLink != undefined ? result.LeadLink : "";
            this.OppNameSearch = result.OppNameSearch != undefined ? result.OppNameSearch : "";
            this.ContactName = result.ContactName != undefined ? result.ContactName : "";
            this.ContactId = result.ContactId != undefined ? result.ContactId : "";
            this.HospitalName = result.HospitalName != undefined ? result.HospitalName : "";
            this.HospitalID = result.HospitalID != undefined ? result.HospitalID : "";
            this.DepartmentClass = result.DepartmentClass != undefined ? result.DepartmentClass : "";
            this.DepartmentID = result.DepartmentID != undefined ? result.DepartmentID : "";
            this.OppNameSearchID = result.OppNameSearchID != undefined ? result.OppNameSearchID : "";
            this.Campaign = result.Campaign != undefined ? result.Campaign : "";
            this.CampaignID = result.CampaignID != undefined ? result.CampaignID : "";
            this.Name = result.Name != undefined ? result.Name : "";
            this.CancelReason = result.CancelReason != undefined ? result.CancelReason : "";
            this.Phone = result.Phone != undefined ? result.Phone : "";
            this.Email = result.Email != undefined ? result.Email : "";
            this.LastName = result.LastName != undefined ? result.LastName : "";
            this.LeadSource = result.LeadSource != undefined ? result.LeadSource : "";
            this.OpportunityDivision = result.OpportunityDivision != undefined ? result.OpportunityDivision : "";
            this.Request1 = result.Request1 != undefined ? result.Request1 : "";
            this.FSEOwner = result.FSEOwner != undefined ? result.FSEOwner : "";
            this.FamilyName = result.FamilyName != undefined ? result.FamilyName : "";
            this.Urgent = result.Urgent == 0 ? 0 :1;
            this.Standard = result.Standard != undefined ? result.Standard : "";
            this.CustomLink1();
        })       
    }
    // 产品咨询单 新建意向
    CustomLink1(){
        var lead = "";
        var search = "";
        sqlResult({id:this.recordId}).then(records=>{
            var Request = '';
            if(records[0].Request_Detail__c != null){
            Request = records[0].Request_Detail__c.toString();
            }
            var lead = this.LeadLink;
            var search = this.OppNameSearch;
            //zyh add-search
            var name = this.ContactName;
            name = name.replace(" ","");
            // this.CustomLink1();
            var defaultValues = null;
            if(lead){
                // alert('已经有意向了,不能再创建新的意向。');
                this.showToast("已经有意向了,不能再创建新的意向。","error");
                return;
            }else{
            if(search !=  "" && search != null){
                defaultValues = encodeDefaultFieldValues({
                    RecordTypeId:this.Standard,
                    Contact_Name__c:this.ContactId,
                    Hospital_Name__c:this.HospitalID,
                    Department_Class__c:this.DepartmentID,
                    Opp_Name_Search__c:this.OppNameSearchID,
                    Campaign__c:this.CampaignID,
                    // Contact_Name__c:this.ContactName,
                    // Contact_Id__c:this.ContactId,
                    // Hospital_Name__c:this.HospitalName, //
                    // Hospital_ID__c:this.HospitalID,
                    // Department_Class__c:this.DepartmentClass,
                    // Department_ID__c:this.DepartmentID,
                    // Opp_Name_Search__c:this.OppNameSearch,
                    // Opp_Name_Search_ID__c:this.OppNameSearchID,
                    // Campaign__c:this.Campaign,
                    // Campaign_ID__c:this.CampaignID,
                    Name:this.Name,
                    Lead_Inquiry_form__c:this.Id,
                    Cancel_Reason__c:this.CancelReason,
                    Request_Detail__c:Request,
                    lea13:'未跟进',
                    lea3:this.HospitalName,
                    lea8:this.Phone.trim(),
                    lea11:this.Email.trim(),
                    name_lastlea2:name,
                    name_firstlea2:this.LastName,
                    lea5:this.LeadSource,
                    Request1__c:this.Request1,
                    Opportunity_Division__c:this.OpportunityDivision,
                    Urgent__c:this.Urgent,
                    Opp_Name__c:this.OppNameSearch,
                });
            }else{
                 defaultValues = encodeDefaultFieldValues({
                    RecordTypeId:this.Standard,
                    Contact_Name__c:this.ContactId,
                    Hospital_Name__c:this.HospitalID,
                    Department_Class__c:this.DepartmentID,
                    Opp_Name_Search__c:this.OppNameSearchID,
                    Campaign__c:this.CampaignID,
                    Name:this.Name,
                    Lead_Inquiry_form__c:this.Id,
                    Cancel_Reason__c:this.CancelReason,
                    Request_Detail__c:Request,
                    lea13:'未跟进',
                    lea3:this.HospitalName,
                    lea8:this.Phone.trim(),
                    lea11:this.Email.trim(),
                    name_lastlea2:name,
                    name_firstlea2:this.LastName,
                    lea5:this.LeadSource,
                    Request1__c:this.Request1,
                    Opportunity_Division__c:this.OpportunityDivision,
                    Urgent__c:this.Urgent,
                });
            }
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'Lead',
                    actionName: 'new'
                },
                state:{
                    defaultFieldValues: defaultValues
                }
            }); 
            this.dispatchEvent(new CloseActionScreenEvent());
            }
        })
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}