liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import {
    LightningElement,
    wire,
    api
} from 'lwc';
import {
    CurrentPageReference
} from "lightning/navigation";
import {
    CloseActionScreenEvent
} from 'lightning/actions';
import init from '@salesforce/apex/buttonOnCallCtl.init';
import selecctAccountBySegmentId from '@salesforce/apex/buttonOnCallCtl.selecctAccountBySegmentId';
import selecctAccountBySegmentId02 from '@salesforce/apex/buttonOnCallCtl.selecctAccountBySegmentId02';
import initUserName from '@salesforce/apex/buttonOnCallCtl.initUserName';
import { NavigationMixin } from 'lightning/navigation';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';        
import {loadStyle} from 'lightning/platformResourceLoader'    
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
 
export default class LexCreateRepairFromOnCall extends NavigationMixin(LightningElement) {
    @api recordId;
    str;
    IsLoading = true;
    Id;
    RepairSalesPointProvinceChinaC;
    Name;
    SegmentC;
    HPC;
    HospitalIdC;
    SalesdepartmentHPIDC;
    SalesdepartmentHPC;
    OncallEquipmentC;
    TrableOccurdaYCollectC;
    userID;
    SegmentId;
    OncallEquipmentId;
 
    @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)            
        ]);    
        init({
            recordId: this.recordId
        }).then(result => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.Name = result.Name;
                this.SegmentC = result.SegmentC == undefined ? "" : result.SegmentC;
                this.HPC = result.HPC == undefined ? "" : result.HPC;
                this.HospitalIdC = result.HospitalIdC == undefined ? "" : result.HospitalIdC;
                this.SalesdepartmentHPIDC = result.SalesdepartmentHPIDC == undefined ? "" : result.SalesdepartmentHPIDC;
                this.SalesdepartmentHPC = result.SalesdepartmentHPC == undefined ? "" : result.SalesdepartmentHPC;
                this.OncallEquipmentC = result.OncallEquipmentC == undefined ? "" : result.OncallEquipmentC;
                this.TrableOccurdaYCollectC = result.TrableOccurdaYCollectC == undefined ? "" : result.TrableOccurdaYCollectC;
                this.userID = result.userID;
                this.SegmentId = result.SegmentId == undefined ? "" : result.SegmentId;
                this.OncallEquipmentId = result.OncallEquipmentId == undefined ? "" : result.OncallEquipmentId;
 
                initUserName({
                    userId: this.userID
                }).then(result => {
                    console.log(result);
                    if (result != null) {
                        this.RepairSalesPointProvinceChinaC = result[0].RepairSalesPoint_Province_China__c;
                    }
                    this.CreateRepairFromOnCall();
                })
 
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    //新建修理    
    CreateRepairFromOnCall() {
        var Work_Location = '';
        var Incharge_Staff = '';
        var Incharge_Staff_id = '';
        var FSE_GI_Main_Leader__id = '';
        var FSE_GI_Main_Leader__name = '';
        var FSE_SP_Main_Leader__id = '';
        var FSE_SP_Main_Leader__name = '';
        var RecordTypeId;
 
        selecctAccountBySegmentId({
            segmentId: this.SegmentId
        }).then(List => {
            console.log(List);
            if (List[0]['ParentId']) {
                RecordTypeId = List[0]['Parent']['RecordType_DeveloperName__c'];
                console.log(RecordTypeId);
            }
 
            selecctAccountBySegmentId02({
                segmentId: this.SegmentId
            }).then(account => {
                console.log(account);
                if (account[0].ParentId != null) {
                    if (account[0].Parent.RecordTypeId != null || account[0].Parent.RecordTypeId != undefined) {
                        var recordId = account[0].Parent.RecordType_DeveloperName__c;
                        console.log(recordId);
                        if (recordId == 'Department_Class_GI' || recordId == 'Department_Class_BF' || recordId == 'Department_Class_ET') {
                            if (account[0].Parent.Parent.FSE_GI_Main_Leader__c != null) {
                                Work_Location = account[0].Parent.Parent.FSE_GI_Main_Leader__r.Work_Location__c;
                            }
 
                        } else if (recordId == 'Department_Class_GS' || recordId == 'Department_Class_URO' || recordId == 'Department_Class_ENT' || recordId == 'Department_Class_GYN' || recordId == 'Department_Class_OTH') {
                            if (account[0].Parent.Parent.FSE_SP_Main_Leader__c != null) {
                                Work_Location = account[0].Parent.Parent.FSE_SP_Main_Leader__r.Work_Location__c;
                            }
                        }
                    }
 
                    if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
                        FSE_GI_Main_Leader__id = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'].substring(0, 15);
                        FSE_GI_Main_Leader__name = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__r']['Name'];
                    }
                    if (List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) {
                        FSE_SP_Main_Leader__id = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'].substring(0, 15);
                        FSE_SP_Main_Leader__name = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Name'];
                    }
                    if (RecordTypeId == 'Department_Class_GI') {
                        Incharge_Staff = FSE_GI_Main_Leader__name;
                        Incharge_Staff_id = FSE_GI_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_BF') {
                        Incharge_Staff = FSE_GI_Main_Leader__name;
                        Incharge_Staff_id = FSE_GI_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_ET') {
                        Incharge_Staff = FSE_GI_Main_Leader__name;
                        Incharge_Staff_id = FSE_GI_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_GS') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_URO') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_ENT') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_GYN') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                    if (RecordTypeId == 'Department_Class_OTH') {
                        Incharge_Staff = FSE_SP_Main_Leader__name;
                        Incharge_Staff_id = FSE_SP_Main_Leader__id;
                    }
                }
                const defaultValues = encodeDefaultFieldValues({
                    On_Call_ID__c: this.Id,
                    Hospital__c: this.HospitalIdC,
                    Department_Class__c: this.SalesdepartmentHPIDC,
                    Account__c:this.SegmentId,
                    Delivered_Product__c: this.OncallEquipmentId,
                    Incharge_Staff__c: Incharge_Staff_id,
                    Failure_Occurrence_Date__c: this.TrableOccurdaYCollectC,
                    Repair_Source__c:'从On-Call',
                    work_location_select__c:this.RepairSalesPointProvinceChinaC,
                    SalesOfficeCode_selection__c:Work_Location,
                    retURL:this.Id,
                });
                // var url = "/a0J/e?CF00N10000002FIJU_lkid=" + this.Id + "&CF00N10000002FIJU=" + this.Name + 
                // "&CF00N10000002Dx66_lkid=" + this.HospitalIdC + "&CF00N10000002Dx66=" + this.HPC + "&CF00N10000002Dx5t_lkid=" + 
                // this.SalesdepartmentHPIDC + "&CF00N10000002Dx5t=" + this.SalesdepartmentHPC +
                //  "&CF00N10000002Dx5n_lkid=" + this.SegmentId + "&CF00N10000002Dx5n=" + this.SegmentC +
                //   "&CF00N10000002Dx1X_lkid=" + this.OncallEquipmentId + "&CF00N10000002Dx1X=" + this.OncallEquipmentC + 
                //   "&CF00N10000002EMHw_lkid=" + Incharge_Staff_id + "&CF00N10000002EMHw=" + Incharge_Staff 
                //   + "&00N10000002Dx5y=" + this.TrableOccurdaYCollectC + "&00N10000002FH86=%e4%bb%8eOn-Call&00N10000006P6Rn=" + this.RepairSalesPointProvinceChinaC + "&00N10000006P6SM=" + encodeURI(Work_Location) + "&retURL=%2F" + this.Id;
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: 'Repair__c',
                        actionName: 'new'
                    },
                    state:{
                        defaultFieldValues: defaultValues,
                    }
                });
                // window.open(url);
            })
        })
    }
}