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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
import {
    LightningElement,
    wire,
    api
} from 'lwc';
import {
    CurrentPageReference
} from "lightning/navigation";
import {
    CloseActionScreenEvent
} from 'lightning/actions';
import init from '@salesforce/apex/buttonAssetCtl.init';
import initUserName from '@salesforce/apex/buttonAssetCtl.initUserName';
import selecctAccountByAccountId from '@salesforce/apex/buttonAssetCtl.selecctAccountByAccountId';
import selecctProduct2ById from '@salesforce/apex/buttonAssetCtl.selecctProduct2ById';
import selecctRepairByFomatToday from '@salesforce/apex/buttonAssetCtl.selecctRepairByFomatToday';
import selecctQISReportByFomatToday from '@salesforce/apex/buttonAssetCtl.selecctQISReportByFomatToday';
import {
    NavigationMixin
} from 'lightning/navigation';
import {
    encodeDefaultFieldValues
} from 'lightning/pageReferenceUtils';
import LightningConfirm from 'lightning/confirm';
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';        
import {loadStyle} from 'lightning/platformResourceLoader'    
export default class LexCreateRepairFromAsset extends NavigationMixin(LightningElement) {
    @api recordId;
    str;
    IsLoading = true;
    Id;
    userID;
    EmployeeNoC;
    day;
    day1;
    day2;
    Name;
    NoPartRiskDateFC;
    ProductIDC;
    AccountId;
    HPIdC;
    HospitalC;
    DepartmentClassC;
    HospitalId;
    DepartmentClassId;
    RepairSalesPointProvinceChinaC;
    partSupplyFinishDate;
    notCreateRepairFromAssetButton;
    notCreateRepairFromAssetButton02;
    msg;
    flag = false;
    fomatToday;
    QIS_Name = '';
    QIS_Id = '';
    Old_Repair_Name = '';
    Work_Location = '';
    FSE_GI_Main_Leader__id = '';
    FSE_GI_Main_Leader__name = '';
    FSE_SP_Main_Leader__id = '';
    FSE_SP_Main_Leader__name = '';
    Incharge_Staff = '';
    Incharge_Staff_id = '';
 
 
    @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.Id = result.Id;
                this.userID = result.userID;
                this.day = result.day;
                this.day1 = result.day1;
                this.day2 = result.day2;
                this.Name = result.Name;
                this.NoPartRiskDateFC = result.NoPartRiskDateFC == undefined ? "" : result.NoPartRiskDateFC;
                this.ProductIDC = result.ProductIDC == undefined ? "" : result.ProductIDC;
                this.AccountId = result.AccountId == undefined ? "" : result.AccountId;
                this.HPIdC = result.HPIdC == undefined ? "" : result.HPIdC;
                this.HospitalC = result.HospitalC == undefined ? "" : result.HospitalC;
                this.DepartmentClassC = result.DepartmentClassC == undefined ? "" : result.DepartmentClassC;
                this.HospitalId = result.HospitalId == undefined ? "" : result.HospitalId;
                this.DepartmentClassId = result.DepartmentClassId == undefined ? "" : result.DepartmentClassId;
                this.notCreateRepairFromAssetButton = result.notCreateRepairFromAssetButton;
                this.notCreateRepairFromAssetButton02 = result.notCreateRepairFromAssetButton02;
                console.log('result.partSupplyFinishDate-------->>>>'+result.partSupplyFinishDate);
                this.partSupplyFinishDate = result.partSupplyFinishDate == undefined ? "" :result.partSupplyFinishDate;
 
                initUserName({
                    userId: this.userID
                }).then(result => {
                    console.log(result);
                    if (result != null) {
                        this.EmployeeNoC = result[0].Employee_No__c;
                        this.RepairSalesPointProvinceChinaC = result[0].RepairSalesPoint_Province_China__c;
                    }
                    this.CreateRepairFromAsset();
                })
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    // 新建修理    
    CreateRepairFromAsset() {
        var nCRepairFromAssetBSting = this.notCreateRepairFromAssetButton;
        var nCRepairFromAssetB02Sting = this.notCreateRepairFromAssetButton02;
        nCRepairFromAssetBSting = nCRepairFromAssetBSting + nCRepairFromAssetB02Sting;
        var nCRepairFromAssetBList = nCRepairFromAssetBSting.split(',');
        var EmployeeNo = this.EmployeeNoC;
        console.log(nCRepairFromAssetBList.indexOf(EmployeeNo) != -1,'权限判断')
        if (nCRepairFromAssetBList.indexOf(EmployeeNo) != -1) {
            this.ShowToastEvent("对不起,您无权使用此按钮创建修理!", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
 
        this.fomatToday = this.day1;
 
 
        selecctQISReportByFomatToday({
            AssetId: this.Id,
            fomatToday: this.fomatToday
        }).then(records => {
            console.log(records,'records<<<<<<<<')
            if (records.length >= 1) {
                this.QIS_Name = records[0].Name;
                this.QIS_Id = records[0].Id;
            }
            if (records.length >= 1) {
                this.handleConfirmClick01('请确认此件是否属于10天内重复报告,如果是,请使用原QIS信息填写。');
            } else {
                this.Repair();
            }
 
        })
    }
 
    Repair() {
        selecctRepairByFomatToday({
            AssetId: this.Id,
            fomatToday: this.fomatToday
        }).then(records2 => {
            console.log(records2);
 
            //20231108 ymh 修改 satrt
            if (records2.length >= 1) {
                this.Old_Repair_Name = records2[0].Name;
            }
            if (records2.length >= 1) {
                this.handleConfirmClick02('此件设备如为10天内重复报告,建议回到原修理单使用复制功能提交。请确认是否继续新建修理? ');
            } else {
                this.ContactYesOrNo();
            }
 
            // var partSupplyFinishDate = this.NoPartRiskDateFC;
            // if (this.day < this.NoPartRiskDateFC && this.NoPartRiskDateFC <= this.day2) {
            //     this.ShowToastEvent('预计' + partSupplyFinishDate + '零件即将停产,请送修前与工厂及RC联络', "error");
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return;
            // }
            // console.log(this.NoPartRiskDateFC ,'this.NoPartRiskDateFC ')
            // if (this.NoPartRiskDateFC != "" && this.NoPartRiskDateFC != null && this.NoPartRiskDateFC != undefined && this.NoPartRiskDateFC <= this.day) {
            //     this.ShowToastEvent('该型号零件已经停产,有特殊需求,请送修前与工厂RC联络', "error");
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return;
            // }
            // if (records2.length >= 1) {
            //     this.Old_Repair_Name = records2[0].Name;
            // }
            // if (records2.length >= 1) {
            //     this.handleConfirmClick02('此件设备如为10天内重复报告,建议回到原修理单使用复制功能提交。请确认是否继续新建修理? ');
            // } else {
            //     this.Product2();
            // }
            // 20231108 ymh 修改  end
        })
    }
    //20231108  ymh  add start
    async ContactYesOrNo(){
        var partSupplyFinish = this.partSupplyFinishDate;
        console.log(this.partSupplyFinishDate ,'this.partSupplyFinishDate ')
        if (this.day < this.partSupplyFinishDate && this.partSupplyFinishDate <= this.day2) {
            if (!this.handleConfirmClickYesOrNo('预计' + partSupplyFinish + '零件即将停产,请送修前与工厂及RC联络')) {
                return;
            }
        }else if (this.partSupplyFinishDate != "" && this.partSupplyFinishDate != null && this.partSupplyFinishDate != undefined && this.partSupplyFinishDate <= this.day) {
            if (!this.handleConfirmClickYesOrNo('该型号零件已经停产,有特殊需求,请送修前与工厂RC联络')) {
                return;
            }
        }else{
            this.Product2();
        }
    }
    //20231108  ymh  add end
 
 
    async handleConfirmClickYesOrNo(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.Product2();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    Product2() {
 
        selecctProduct2ById({
            Id: this.ProductIDC
        }).then(recordP => {
            console.log(recordP);
 
            if (recordP != null && recordP.length > 0) {
                var canRepair = recordP[0].Can_Repair__c;
                if (canRepair == '第三方') {
                    this.ShowToastEvent('非我司修理对象,无法新建修理,如有不明请咨询CIC', "error");
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                if (canRepair == '不' || canRepair == null) {
                    this.ShowToastEvent('本设备无法新建修理', "error");
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                if (canRepair == 'RC送修') {
                    this.flag = true;
                }
            }
            selecctAccountByAccountId({
                AccountId: this.AccountId
            }).then(List => {
                console.log(List);
                if (List != null) {
                    var RecordTypeId = List[0]['Parent']['RecordType_DeveloperName__c'];
                    console.log(RecordTypeId);
                    if (RecordTypeId != 'Agency') {
                        if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
                            this.FSE_GI_Main_Leader__id = List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'];
                            this.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) {
                            this.FSE_SP_Main_Leader__id = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__c'];
                            this.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'];
                            if (recordId == 'Department_Class_GI' || recordId == 'Department_Class_BF' || recordId == 'Department_Class_ET') {
                                if (List[0]['Parent']['Parent']['FSE_GI_Main_Leader__c'] != null) {
                                    this.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) {
                                    this.Work_Location = List[0]['Parent']['Parent']['FSE_SP_Main_Leader__r']['Work_Location__c'];
                                }
 
                            }
                            console.log(this.Work_Location,List[0],'xxxx')
                        }
                        if (RecordTypeId == 'Department_Class_GI') {
                            this.Incharge_Staff = this.FSE_GI_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_GI_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_BF') {
                            this.Incharge_Staff = this.FSE_GI_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_GI_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_ET') {
                            this.Incharge_Staff = this.FSE_GI_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_GI_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_GS') {
                            this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_URO') {
                            this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_ENT') {
                            this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_GYN') {
                            this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
                        }
                        if (RecordTypeId == 'Department_Class_OTH') {
                            this.Incharge_Staff = this.FSE_SP_Main_Leader__name;
                            this.Incharge_Staff_id = this.FSE_SP_Main_Leader__id;
                        }
                    }
                }
                const url = encodeDefaultFieldValues({
                    Hospital__c: this.HospitalId,
                    Department_Class__c: this.DepartmentClassId,
                    Account__c: this.AccountId,
                    Delivered_Product__c: this.Id,
                    Incharge_Staff__c: this.Incharge_Staff_id,
                    Work_Location_select__c: this.RepairSalesPointProvinceChinaC,
                    SalesOfficeCode_selection__c: this.Work_Location,
                    Source_QIS__c: this.QIS_Id,
                    Old_Name__c: this.Old_Repair_Name,
                    Exc_Work_Location__c: this.flag,
                    Repair_Source__c:'只修理',
                    //2023 08 22 张赫阳 PIPL相关按钮改造 start
                    AssetName: this.Name
                    //2023 08 22 张赫阳 PIPL相关按钮改造 end
                });
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: 'Repair__c',
                        actionName: 'new'
                    },
                    state: {
                        //2023 08 22 张赫阳 PIPL相关按钮改造 start
                        //nooverride: '1',
                        //2023 08 22 张赫阳 PIPL相关按钮改造 end
                        defaultFieldValues: url
                    }
                });
                this.dispatchEvent(new CloseActionScreenEvent());
            })
        })
    }
 
    async handleConfirmClick01(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.Repair();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    async handleConfirmClick02(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.ContactYesOrNo();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    ShowToastEvent(msg, type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode:'Sticky'
            });
            this.dispatchEvent(event);
        }
    }
 
    closeAction() {
        location.reload();
    }
}