unknown
2023-07-19 f3ff606d272bf6427d4d2c1ef6e0ccb47ce74038
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import {
    LightningElement,
    wire,
    api
} from 'lwc';
import {
    CurrentPageReference
} from "lightning/navigation";
import {
    CloseActionScreenEvent
} from 'lightning/actions';
import init from '@salesforce/apex/buttonQISReportCtl.init';
import initUserName from '@salesforce/apex/buttonQISReportCtl.initUserName';
import selecctAccountByAccountId from '@salesforce/apex/buttonQISReportCtl.selecctAccountByAccountId';
import {
    NavigationMixin
} from 'lightning/navigation';
import {
    encodeDefaultFieldValues
} from 'lightning/pageReferenceUtils';
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
 
export default class LexCreateRepairFromQIS extends NavigationMixin(LightningElement) {
    @api recordId;
    str;
    IsLoading = true;
    Id;
    Name;
    RepairSalesPointProvinceChinaC;
    Hospital;
    HospitalId;
    nextAction;
    SpecialFollow;
    HPID;
    SourceOnCall;
    DepartmentClassId;
    DepartmentClass;
    HospitalDepartment;
    nonyushohin;
    TrableOccurDaYCollect;
    sourceForRepair;
    OCMJudgementC
    HospitalDepartmentId;
    userId;
    SourceOnCallId;
    nonyushohinId;
 
    @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 => {
            console.log(result);
            if (result != null) {
                this.Id = result.Id;
                this.Name = result.Name;
                this.SourceOnCallId = result.SourceOnCallId == undefined ? "" : result.SourceOnCallId;
                this.nonyushohinId = result.nonyushohinId == undefined ? "" : result.nonyushohinId;
                this.Hospital = result.Hospital == undefined ? "" : result.Hospital;
                this.HospitalId = result.HospitalId == undefined ? "" : result.HospitalId;
                this.nextAction = result.nextAction == undefined ? "" : result.nextAction;
                this.SpecialFollow = result.SpecialFollow == undefined ? "" : result.SpecialFollow;
                this.HPID = result.HPID == undefined ? "" : result.HPID;
                this.SourceOnCall = result.SourceOnCall == undefined ? "" : result.SourceOnCall;
                this.DepartmentClassId = result.DepartmentClassId == undefined ? "" : result.DepartmentClassId;
                this.DepartmentClass = result.DepartmentClass == undefined ? "" : result.DepartmentClass;
                this.HospitalDepartment = result.HospitalDepartment == undefined ? "" : result.HospitalDepartment;
                this.nonyushohin = result.nonyushohin == undefined ? "" : result.nonyushohin;
                this.TrableOccurDaYCollect = result.TrableOccurDaYCollect == undefined ? "" : result.TrableOccurDaYCollect;
                this.sourceForRepair = result.sourceForRepair == undefined ? "" : result.sourceForRepair;
                this.OCMJudgementC = result.OCMJudgementC == undefined ? "" : result.OCMJudgementC;
                this.HospitalDepartmentId = result.HospitalDepartmentId == undefined ? "" : result.HospitalDepartmentId;
                this.userId = result.userId;
 
                initUserName({
                    userId: this.userId
                }).then(result => {
                    console.log(result);
                    if (result != null) {
                        this.RepairSalesPointProvinceChinaC = result[0].RepairSalesPoint_Province_China__c;
                    }
                    this.CreateRepairFromQIS();
                })
 
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    //新建修理QIS    
    CreateRepairFromQIS() {
        var newflag = false;
        if ((this.OCMJudgementC == '质量问题' && this.nextAction == '无偿维修' && this.SpecialFollow == '0') || (this.OCMJudgementC == '非质量问题' && this.nextAction == '无偿维修' && this.SpecialFollow == '1') || (this.OCMJudgementC == '非质量问题' && this.nextAction == '有偿维修' && this.SpecialFollow == '0') || (this.OCMJudgementC == '质量问题+非质量问题' && this.nextAction == '无偿维修' && this.SpecialFollow == '1') || (this.OCMJudgementC == '质量问题+非质量问题' && this.nextAction == '有偿维修+无偿维修' && this.SpecialFollow == '0')) {
            newflag = true;
        }
        console.log(newflag);
        if (newflag) {
            selecctAccountByAccountId({
                HospitalDepartmentId: this.HospitalDepartmentId
            }).then(List => {
                console.log(List);
                var RecordTypeId;
                var Incharge_Staff = '';
                var Incharge_Staff_id = '';
                var Work_Location = '';
                if (List.length > 0) {
                    if (List[0]['ParentId'] != null) {
                        RecordTypeId = List[0]['Parent']['RecordType_DeveloperName__c'].substring(0, 15);
                        console.log(RecordTypeId);
                        var FSE_GI_Main_Leader__id = '';
                        var FSE_GI_Main_Leader__name = '';
                        var FSE_SP_Main_Leader__id = '';
                        var FSE_SP_Main_Leader__name = '';
                        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 (List[0]['Parent']['RecordType_DeveloperName__c'] != null || List[0]['Parent']['RecordType_DeveloperName__c'] != undefined) {
                            var recordId = List[0]['Parent']['RecordType_DeveloperName__c'].substring(0, 15);
                            if (recordId == 'Department_Class_GI' || recordId == 'Department_Class_BF' || recordId == 'Department_Class_ET') {
                                if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
                                    Work_Location = List[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 (List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'] != null) {
                                    Work_Location = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c'];
                                }
 
                            }
                        }
                        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 url = encodeDefaultFieldValues({
                    On_Call_ID__c: this.SourceOnCall,
                    QIS_ID__c: this.Id,
                    Hospital__c: this.Hospital,
                    Department_Class__c: this.DepartmentClass,
                    Account__c: this.HospitalDepartment,
                    Delivered_Product__c: this.nonyushohin,
                    Incharge_Staff__c: Incharge_Staff_id,
                    Failure_Occurrence_Date__c: this.TrableOccurDaYCollect,
                    SalesOfficeCode_selection__c: encodeURI(Work_Location),
                    Repair_Source__c: this.sourceForRepair,
                    work_location_select__c: this.RepairSalesPointProvinceChinaC
                });
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: 'Repair__c',
                        actionName: 'new'
                    },
                    state: {
                        nooverride: '1',
                        defaultFieldValues: url
                    }
                });
                this.dispatchEvent(new CloseActionScreenEvent());
 
                // window.open("/a0J/e?CF00N10000002FIJU_lkid=" + this.SourceOnCallId + "&CF00N10000002FIJU=" + this.SourceOnCall + 
                // "&CF00N10000002FIJZ_lkid=" + this.Id + "&CF00N10000002FIJZ=" + this.Name + 
                // "&CF00N10000002Dx66_lkid=" + this.HospitalId + "&CF00N10000002Dx66=" + this.Hospital + 
                // "&CF00N10000002Dx5t_lkid=" + this.DepartmentClassId + "&CF00N10000002Dx5t=" + this.DepartmentClass + 
                // "&CF00N10000002Dx5n_lkid=" + this.HospitalDepartmentId + "&CF00N10000002Dx5n=" + this.HospitalDepartment + 
                // "&CF00N10000002Dx1X_lkid=" + this.nonyushohinId + "&CF00N10000002Dx1X=" + this.nonyushohin + 
                // "&CF00N10000002EMHw_lkid=" + Incharge_Staff_id + "&CF00N10000002EMHw=" + Incharge_Staff + 
                // "&00N10000002Dx5y=" + this.TrableOccurDaYCollect + "&00N10000006P6SM=" + encodeURI(Work_Location) + 
                // "&00N10000002FH86=" + this.sourceForRepair + "&00N10000006P6Rn=" + this.RepairSalesPointProvinceChinaC + 
                // "&retURL=%2F" + this.Id);
 
            })
        } else {
            this.ShowToastEvent("不能新建修理", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    ShowToastEvent(msg, type) {
        const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
    }
}