LiJinHuan
2024-01-05 462188a2c982b0a8750dfe01692dfd898216bb0c
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*
 * @Date: 2023-05-16 13:32:13
 * @Author: @zyh
 * @LastEditTime: 2023-11-13 18:30:31
 * @Descripttion: 
 */
import { LightningElement, wire, track, api } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import init from '@salesforce/apex/lexRentalApply_FromRepCtl.init';
import userInfo from '@salesforce/apex/lexRentalApply_FromRepCtl.UserInfo_Owner';
import rentalApp from '@salesforce/apex/lexRentalApply_FromRepCtl.rentalApp';
import qureySoql from '@salesforce/apex/ControllerUtil.qureySoql';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import { loadStyle } from 'lightning/platformResourceLoader'
 
export default class LexEquipmentRentalApply_FromRepair2 extends NavigationMixin(LightningElement) {
    @api recordId; //OpportunityId
    stauts1;
    repairId;
    repairName;
    hospital;
    repairDepartment;
    repairAccount;
    inspectionDate;
    shippedDate;
    assetModelNo;
    qisRepairId;
    qisId;
    qisRepairName;
    repairSource;
    maintenanceContract;
    purpose2;
    newProductGuaranteeObject;
    ifCheckFixture;
    IsLoading = true;
    isFormalStuff;
    userId;
    firstName;
    lastName;
    rtnJSON;
    records;
    dataFields;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        console.log(111);
        console.log(currentPageReference);
 
        if (currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if (urlValue) {
                let str = `${urlValue}`;
                console.log("str");
                console.log(str);
                this.recordId = str;
            }
        }
    }
 
    connectedCallback() {
        console.log(this.recordId);
 
        this.IsLoading = false;
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        this.initRepairToApply();
    }
    async initRepairToApply(){
        await rentalApp({
            recordId: this.recordId
        }).then(result => {
            console.log('rentalApp============', result);
            if (result.length > 0) {
                const evt = new ShowToastEvent({
                    // title : 'Error',
                    message: '同一个型号的修理记录不能重复申请备品',
                    variant: 'error',
                    mode: 'sticky'
                });
                this.dispatchEvent(evt);
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
            // init({
            //     recordId: this.recordId
            // }).then(result => {
            //     console.log('init============' + result);
            //     console.log(result);
            //     if (result != null) {
            //         userInfo({}).then(result => {
            //             this.userId = result.id;
            //             this.isFormalStuff = result.isFormalStuff;
            //             this.firstName = result.firstName;
            //             this.lastName = result.lastName;
            //         })
            //         this.stauts1 = result.stauts1;
            //         this.repairId = result.repairId;
            //         this.repairName = result.repairName;
            //         this.hospital = result.hospital;
            //         this.inspectionDate = result.inspectionDate;
            //         this.shippedDate = result.shippedDate;
            //         this.qisId = result.qisId;
            //         this.newProductGuaranteeObject = result.newProductGuaranteeObject;
            //         this.maintenanceContract = result.maintenanceContract;
            //         this.repairSource = result.repairSource;
            //         this.ifCheckFixture = result.ifCheckFixture;
            //         this.repairDepartment = result.repairDepartment;
            //         this.repairAccount = result.repairAccount;
 
            //         if (this.qisId != '' && this.qisId != null) {
            //             console.log('qureySoql1===row');
            //             qureySoql({
            //                 soql: "select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id ='" + this.recordId + "'"
            //             }).then(result => {
            //                 console.log('qureySoql============' + result);
            //                 this.rtnJSON = result;
            //                 this.records = JSON.parse(this.rtnJSON);
            //                 this.repairToApply();
 
            //             }).catch(error => {
            //                 console.log("error");
            //                 console.log(error);
            //             }).finally(() => {
 
            //             });
            //         } else {
            //             console.log('qureySoql2===row');
            //             console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'");
            //             qureySoql({
            //                 soql: "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'"
            //             }).then(result => {
            //                 console.log('qureySoql============' + result);
            //                 this.rtnJSON = result;
            //                 console.log('rtnJSON111111===row' + this.rtnJSON);
            //                 this.records = JSON.parse(this.rtnJSON);
            //                 this.repairToApply();
 
            //             }).catch(error => {
            //                 console.log("error");
            //                 console.log(error);
            //             }).finally(() => {
 
            //             });
            //         }
            //         // this.repairToApply();
            //         this.dispatchEvent(new CloseActionScreenEvent());
            //         // window.location.reload();
            //     }
            // }).catch(error => {
            //     console.log("error");
            //     console.log(error);
            // }).finally(() => {
 
            // });
        }).catch(error => {
            console.log("error11");
            console.log(error);
        }).finally(() => {
 
        });
        await userInfo({}).then(result => {
            this.userId = result.id;
            this.isFormalStuff = result.isFormalStuff;
            // this.firstName = result.firstName;
            this.lastName = result.lastName;
        })
        await init({
            recordId: this.recordId
        }).then(result => {
            console.log('init============' + result);
            console.log(result);
            if (result != null) {
                // userInfo({}).then(result => {
                //     this.userId = result.id;
                //     this.isFormalStuff = result.isFormalStuff;
                //     // this.firstName = result.firstName;
                //     this.lastName = result.lastName;
                // })
                this.stauts1 = result.stauts1;
                this.repairId = result.repairId;
                this.repairName = result.repairName;
                this.hospital = result.hospital;
                this.inspectionDate = result.inspectionDate;
                this.shippedDate = result.shippedDate;
                this.qisId = result.qisId;
                this.newProductGuaranteeObject = result.newProductGuaranteeObject;
                this.maintenanceContract = result.maintenanceContract;
                this.repairSource = result.repairSource;
                this.ifCheckFixture = result.ifCheckFixture;
                this.repairDepartment = result.repairDepartment;
                this.repairAccount = result.repairAccount;
 
                if (this.qisId != '' && this.qisId != null) {
                    console.log('qureySoql1===row');
                    qureySoql({
                        soql: "select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id ='" + this.recordId + "'"
                    }).then(result => {
                        console.log('qureySoql============' + result);
                        this.rtnJSON = result;
                        this.records = JSON.parse(this.rtnJSON);
                        this.repairToApply();
 
                    }).catch(error => {
                        console.log("error");
                        console.log(error);
                    }).finally(() => {
 
                    });
                } else {
                    console.log('qureySoql2===row');
                    console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'");
                    qureySoql({
                        soql: "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'"
                    }).then(result => {
                        console.log('qureySoql============' + result);
                        this.rtnJSON = result;
                        console.log('rtnJSON111111===row' + this.rtnJSON);
                        this.records = JSON.parse(this.rtnJSON);
                        this.repairToApply();
 
                    }).catch(error => {
                        console.log("error");
                        console.log(error);
                    }).finally(() => {
 
                    });
                }
                // this.repairToApply();
                this.dispatchEvent(new CloseActionScreenEvent());
                // window.location.reload();
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
 
        });
    }
    repairToApply() {
        console.log('草案中============' + this.stauts1);
        if (this.inspectionDate != null) {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '从修理做备品借出申请时,修理的[最终检测日]必须为空',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中1============' + this.stauts1);
            return;
        }
 
        if (this.isFormalStuff == true) {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '试用期内,不能申请',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中2============' + this.stauts1);
            return;
        }
        if (this.shippedDate != null) {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '从修理做备品借出申请时,修理的[RC修理品返送日]必须为空',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中3============' + this.stauts1);
            return;
        }
        if (this.isFormalStuff == true) {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '试用期内,不能申请',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中4============' + this.stauts1);
            return;
        } else if (this.stauts1 == '0.删除') {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '修理的状态为删除,不可借用备品',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中5============' + this.stauts1);
            return;
        } else if (this.stauts1 == '0.取消') {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '修理的状态为取消,不可借用备品',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中6============' + this.stauts1);
            return;
        } else if (this.stauts1 == '5.完毕') {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '修理的状态为完毕,不可借用备品',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            console.log('草案中7============' + this.stauts1);
            return;
        } else if (this.stauts1 != '草案中') {
            console.log('草案中============' + this.stauts1 + this.qisId);
            // var rtnJSON;
            // if(this.qisId != '' && this.qisId != null){
            //     console.log('qureySoql1===row');
            //     qureySoql({
            //         soql: 'select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id =' + this.recordId
            //     }).then(result => {
            //         console.log('qureySoql============' + result);
            //         rtnJSON = result;
            //     }).catch(error => {
            //         console.log("error");
            //         console.log(error);
            //     }).finally(() => {
 
            //     });
            // }else{
            //     console.log('qureySoql2===row');
            //     console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='"  + this.recordId +"'");
            //     qureySoql({
            //         soql: "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='"  + this.recordId +"'"
            //     }).then(result => {
            //         console.log('qureySoql============' + result);
            //         this.rtnJSON = result;
            //         console.log('rtnJSON111111===row'+ this.rtnJSON);
            //         this.records = JSON.parse(this.rtnJSON);
            //     }).catch(error => {
            //         console.log("error");
            //         console.log(error);
            //     }).finally(() => {
 
            //     });
            // }
            console.log('rtnJSON===row' , this.records);
            console.log('202===row');
            console.log('202===row'+this.records.length);
            // var records = JSON.parse(this.rtnJSON);
            var AssetModelNo = '';
            // var qisRepairId = '';
            // var qisRepairName = '';
            if (this.records.length > 0) {
                console.log('records.lenth===row');
                AssetModelNo = this.records[0].Delivered_Product__r.Product2.Asset_Model_No__c;
                console.log('records.lenth===qisId' + this.qisId);
                console.log('records.lenth===qisIdtest' + this.qisId != '' && this.qisId != null);
                // console.log('records.lenth===records' + this.records[0].QIS_ID__c);
                // console.log('records.lenth===records' + this.records[0].QIS_ID__r.Repair__r.Name);
 
                if (this.qisId != '' && this.qisId != null) {
                    this.qisRepairId = this.records[0].QIS_ID__r.Repair__c;
                    this.qisRepairName = this.records[0].QIS_ID__r.Repair__r.Name;
                }
            }
            var isKeepRepair = false;
            if (this.newProductGuaranteeObject == '2: 服务多年保修' && (AssetModelNo == 'LTF-190-10-3D' || AssetModelNo == 'LTF-S190-5' || AssetModelNo == 'CYF-VHA' || AssetModelNo == 'CYF-VA2' || AssetModelNo == 'CYF-5A' || AssetModelNo == 'LTF-S190-10' || AssetModelNo == 'OER-AW' || AssetModelNo == 'URF-V' || AssetModelNo == 'URF-V2' || AssetModelNo == 'URF-P6')) {
                isKeepRepair = true;
            }
            var purpose2 = '';
            if (this.repairSource != 'QIS转修理') {
                if (this.newProductGuaranteeObject == '8: 市场多年保修') {
                    purpose2 = '市场多年保修';
                } else if (this.maintenanceContract != null && this.maintenanceContract != '') {
                    purpose2 = "保修用户";
                } else if (this.ifCheckFixture) {
                    purpose2 = "故障排查";
                } else {
                    if (isKeepRepair) {
                        purpose2 = '保修用户';
                    } else {
                        purpose2 = '一般用户';
                    }
                }
            } else {
                purpose2 = '索赔QIS';
            }
            console.log('236===row' + purpose2);
            console.log('236===row');
            console.log('236===row' + this.repairName);
            // const defaultValues = encodeDefaultFieldValues({
            //     // RecordTypeId : '',
            //     Name : '*',
            //     Hospital__c : this.hospital,
            //     Strategic_dept__c : this.repairDepartment,
            //     Account__c : this.repairAccount,
            //     Demo_purpose1__c : '维修代用',
            //     demo_purpose2__c : purpose2,
            //     Person_In_Charge__c : this.lastName + ' ' + this.firstName,//备品出街担当
            //     applyUser__c : this.lastName + ' ' + this.firstName,//操作者
            //     // Repair__c : this.repairId,
            //     Loaner_received_staff__c : this.lastName + ' ' + this.firstName// 收件者姓名 (销售或FSE)
            // });
            let defaultValues = {
                // RecordTypeId : '',
                Name: '*',
                //2023 7 11 update by 张赫阳 PIPL Start
                RepairName: this.repairName,
                //2023 7 11 update by 张赫阳 PIPL End
                Hospital__c: this.hospital,
                Strategic_dept__c: this.repairDepartment,
                Account__c: this.repairAccount,
                Demo_purpose1__c: '维修代用',
                demo_purpose2__c: purpose2,
                // Person_In_Charge__c : this.lastName + ' ' + this.firstName,//备品出街担当
                Person_In_Charge__c: this.userId, //备品出街担当
                // applyUser__c : this.lastName + ' ' + this.firstName,//操作者
                applyUser__c: this.userId, //操作者
                Repair__c: this.repairId,
                // Loaner_received_staff__c: this.lastName + ' ' + this.firstName // 收件者姓名 (销售或FSE)
                Loaner_received_staff__c: this.lastName // 收件者姓名 (销售或FSE)
                    // Loaner_received_staff__c : this.lastName// 收件者姓名 (销售或FSE)
            }
            console.log('236===row' + this.lastName + '==收件者姓名');
            console.log('236===rowUserId' + this.userId);
            console.log('236===rowRepairId' + this.repairId);
 
            this.dataFields = defaultValues;
            console.log('236===row' + this.dataFields);
            if (purpose2 == '索赔QIS' && this.qisId != null && this.qisId != '') {
                // const defaultValues = encodeDefaultFieldValues({
                //     RecordTypeId : '',
                //     Repair__c : this.repairName,
                //     Name : '*',
                //     Hospital__c : this.hospital,
                //     Strategic_dept__c : this.repairDepartment,
                //     Account__c : this.repairAccount,
                //     Demo_purpose1__c : '维修代用',
                //     demo_purpose2__c : purpose2,
                //     Person_In_Charge__c : this.lastName + ' ' + this.firstName,//备品出街担当
                //     applyUser__c : this.lastName + ' ' + this.firstName,//操作者
                //     Loaner_received_staff__c : this.lastName + ' ' + this.firstName,// 收件者姓名 (销售或FSE)
                //     QISRepair__c : this.qisRepairName,
                //     QIS_number__c : this.qisId
                // });
                let defaultValues = {
                    // RecordTypeId : '',
                    Repair__c: this.repairId,
                    //2023 7 11 update by 张赫阳 PIPL Start
                    RepairName: this.repairName,
                    //2023 7 11 update by 张赫阳 PIPL End
                    Name: '*',
                    Hospital__c: this.hospital,
                    Strategic_dept__c: this.repairDepartment,
                    Account__c: this.repairAccount,
                    Demo_purpose1__c: '维修代用',
                    demo_purpose2__c: purpose2,
                    Person_In_Charge__c: this.userId, //备品出街担当
                    applyUser__c: this.userId, //操作者
                    // Loaner_received_staff__c: this.lastName + ' ' + this.firstName, // 收件者姓名 (销售或FSE)
                    Loaner_received_staff__c: this.lastName, // 收件者姓名 (销售或FSE)
                    // Loaner_received_staff__c : this.lastName,// 收件者姓名 (销售或FSE)
                    // QISRepair__c: this.qisRepairName,
                    QISRepair__c: this.qisRepairId,
                    QIS_number__c: this.qisId
                }
 
                this.dataFields = defaultValues;
                console.log('testzyh==='+this.qisRepairName);
            }
            // this[NavigationMixin.Navigate]({
            //     type: 'standard__objectPage',
            //     attributes: {
            //         objectApiName: 'Rental_Apply__c',
            //         actionName: 'new'
            //     },
            //     state:{
            //         defaultFieldValues: this.dataFields
            //     }
            // });
            //2023 7 11 update by 张赫阳 PIPL Start
            debugger;
            //2023 7 11 update by 张赫阳 PIPL End
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'Rental_Apply__c', // 要新建的对象API
                    actionName: 'new'
                },
                state: {
                    // defaultFieldValues:'Repair__c='+this.repairName// 要复制的字段API
                    // defaultFieldValues:this.dataFields// 要复制的字段API
                    defaultFieldValues: encodeDefaultFieldValues(this.dataFields) // 要复制的字段API
 
                }
            });
            console.log('236===row' + this.dataFields);
 
        } else {
            const evt = new ShowToastEvent({
                // 刘川 titl横展 start 2023年10月11日
                // title : '',
                // 刘川 title横展 end 2023年10月11日
                message: '申请修理后,才可以新建备品借出申请',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(evt);
            // console.log('草案中6============' + this.stauts1);
            return;
        }
    }
}