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
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
import { LightningElement, api, track, wire } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import initData from '@salesforce/apex/LexNewAndEditContactPIPLController.initData';
import searchContactByAccountId from '@salesforce/apex/LexNewAndEditContactPIPLController.searchContactByAccountId';
import { NavigationMixin } from 'lightning/navigation';
import { AWSService } from 'c/piUtils';
import lexPIPLCustomStyle from '@salesforce/resourceUrl/lexPIPLCustomStyle'
import { loadStyle } from 'lightning/platformResourceLoader';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { decodeDefaultFieldValues } from "lightning/pageReferenceUtils";
import { conmentCancel } from "c/lexPIPLConmentMethods";
import Contact from '@salesforce/schema/Contact';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
// Add By Li Jun 20231025 Start
import LexRecordNotCreateable  from '@salesforce/label/c.LexRecordNotCreateable';
import LexNotCreateNote  from '@salesforce/label/c.LexNotCreateNote';
const customLabel = {
    LexRecordNotCreateable,
    LexNotCreateNote
}
// Add By Li Jun 20231025 End
 
export default class LexNewAndEditContactPIPL extends NavigationMixin(LightningElement) {
    sobjectType = 'Contact';
 
    @track customLabel = customLabel;
    @api recordId;
    @track recordCloneId;
    @track recordTypeId;
    @wire(CurrentPageReference) pageRef;
    @track recordData = {};
    @track title = '';
    @track isLoading = false;
    @track layout = [];
    @track isDoctor = true;
 
 
    @track staticResource;
    @track staticResourceV2;
    @track staticResourceContact;
    @track piFieldsMap;
    @track abstractData = '';
    @track data = {};
    @track piplData = {};
    @track isNewMode = false;
    @track isCloneMode = false;
    @track isEditMode = false;
    @track sectionName = [];
    @track AWSToSobjectMap = {};
    @track AWSDataId = '';
    @track txId = '';
    @track isShowSearchAccount = false;
    @track accountId = '';
    @track contactId = '';
    @track accountName = '';
    @track dataIdManageCodeMap = {};
    @track saveAndNew = false;
    AWSService;
    @track customDivRef;
    @track accid;
 
    @track modifyObj = {};
    modifyArray = ['LastName'];
    @track isInitSuccess = false;
 
    defaultValues = {};
    fieldLabel = {};
 
    @track mobilePhone = '';  //deloitte-zhj 20231106
    @track hasMobilePhoneField = false;  //deloitte-zhj 20231106
 
    @wire(getObjectInfo, { objectApiName: Contact })
    getReportInfo({ data, error }) {
        if (data) {
            this.fieldLabel = data.fields;
            console.log('this.fieldLabel = ' + JSON.stringify(this.fieldLabel));
        }
    }
 
    connectedCallback() {
        this.isLoading = true;
        loadStyle(this, lexPIPLCustomStyle);
        console.log('enter connectedCallback');
        this.AWSService = new AWSService();
        if (!this.recordId) {
            this.title = '新建客户人员';
            this.isNewMode = true;
        }
        if (this.recordId) {
            this.title = '编辑客户人员';
            this.isEditMode = true;
        }
        if (this.pageRef && this.pageRef.state) {
            this.accid = this.pageRef.state.accid;
            this.recordTypeId = this.pageRef.state.recordTypeId;
            console.log('this.recordTypeId = ' + this.recordTypeId);
            this.isCloneMode = Boolean(this.pageRef.state.c__isClone);
            //克隆
            if (this.isCloneMode) {
                this.isNewMode = false;
                this.isEditMode = false;
                this.recordCloneId = this.pageRef.state.c__recordId;
                console.log('recordCloneId = ' + this.recordCloneId);
                this.title = '克隆客户人员';
            }
            if (this.pageRef.state.defaultFieldValues) {
                this.defaultValues = decodeDefaultFieldValues(
                    this.pageRef.state.defaultFieldValues
                );
                console.log('this.contactAWSDataId = ' + this.contactAWSDataId);
            }
            console.log("defaultValues:", JSON.stringify(this.defaultValues));
        }
        console.log('recordId = ' + this.recordId + ' recordCloneId = ' + this.recordCloneId + ' recordTypeId = ' + this.recordTypeId + ' sobjectType = ' + this.sobjectType);
        let id = this.isCloneMode == true ? this.recordCloneId : this.recordId;
        debugger
        initData({
            rid: id,
            recordTypeId: this.recordTypeId,
            sobjectType: this.sobjectType,
            accid: this.accid
        }).then((r) => {
            r = JSON.parse(JSON.stringify(r));
            console.log('r = ' + JSON.stringify(r))
            if (r.status == 'Success') {
                this.isDoctor = r.entity.isDoctor;
                console.log('this.isDoctor = ' + this.isDoctor);
                if (this.recordTypeId == null)
                    this.recordTypeId = r.entity.recordTypeId;
                console.log('this.recordTypeId = ' + this.recordTypeId);
                this.recordData = r.entity.data;
                console.log('this.recordData = ' + JSON.stringify(this.recordData));
                let index = 1;
                //如果不是医院类型,使用标准页面
                if (!this.isDoctor) {
                    debugger
                    let layout = JSON.parse(r.entity.layout);
                    layout = this.sortMetaLayouts(layout);
                    console.log('this.layout = ' + JSON.stringify(layout));
                    for (let s of layout) {
                        s['showSection'] = false;
                        if (s['editHeading'] || s['detailHeading']) {
                            s['showSection'] = true;
                        }
                        s['showLabel'] = false;
                        for (let c of s.layoutColumns) {
                            c['index'] = index++;
                            if (c.layoutItems.length != 0 && s['showLabel'] == false) {
                                s['showLabel'] = true;
                            }
                            if (c.layoutItems) {
                                for (let item of c.layoutItems) {
                                    item['isDisable'] = item.behavior == 'Readonly' ? true : false;
                                    item['isRequired'] = item.behavior == 'Required' ? true : false;
                                    item['isModify'] = false;
                                    let fieldName = item['field'];
                                    if (fieldName == 'RecordTypeId') {
                                        item['isDisable'] = true;
                                    }
                                    if (this.isNewMode && this.defaultValues && Object.keys(this.defaultValues).length != 0) {
                                        if (this.defaultValues[item["field"]]) {
                                            item["value"] = this.defaultValues[item["field"]];
                                        }
                                        if (item['field'] == 'AccountId') {
                                            console.log('this.defaultValuesaccid = ' + this.defaultValues['AccountId']);
                                            this.accountId = this.defaultValues['AccountId'];
                                        }
                                    }
                                }
                            }
                        }
                    }
                    this.layout = layout;
                } else {
                    this.AWSDataId = r.entity.AWSDataId;
                    console.log('this.AWSDataId = ' + this.AWSDataId);
                    let layout = JSON.parse(r.entity.layout);
                    layout = this.sortMetaLayouts(layout);
                    console.log('this.layout = ' + JSON.stringify(layout));
                    this.sectionName = layout.map(s => s.label);
                    for (let s of layout) {
                        s['showSection'] = false;
                        if (s['editHeading'] || s['detailHeading']) {
                            s['showSection'] = true;
                        }
                        s['showLabel'] = false;
                        for (let c of s.layoutColumns) {
                            c['index'] = index++;
                            if (c.layoutItems.length != 0 && s['showLabel'] == false) {
                                s['showLabel'] = true;
                            }
                            if (c.layoutItems) {
                                for (let i = 0; i < c.layoutItems.length; i++) {
                                    c.layoutItems[i]['isDisable'] = c.layoutItems[i].behavior == 'Readonly' ? true : false;
                                    c.layoutItems[i]['isRequired'] = c.layoutItems[i].behavior == 'Required' ? true : false;
                                    c.layoutItems[i]['isModify'] = false;
                                    let fieldName = c.layoutItems[i]['field'];
                                    if (this.isCloneMode && fieldName != 'UnifiedI_Contact_ID__c' && fieldName != 'ServicePlatformCode__c') {
                                        c.layoutItems[i]['value'] = this.recordData[fieldName];
                                    }
                                    if (fieldName == 'RecordTypeId') {
                                        c.layoutItems[i]['isDisable'] = true;
                                    }
                                    if (c.layoutItems[i]['field'] == 'Name') {
                                        c.layoutItems[i].field = 'LastName';
                                        c.layoutItems[i].fieldLabel = '姓名'
                                        c.layoutItems[i]['isModify'] = true;
                                        if (this.isEditMode || this.isCloneMode) {
                                            c.layoutItems[i]['value'] = this.recordData.LastName
                                        }
                                        // 创建要插入的新元素
                                        let newItem = {
                                            field: "Salutation",
                                        };
                                        // 使用splice方法在满足条件的item后插入新元素
                                        c.layoutItems.splice(i + 1, 0, newItem);
                                    }
                                    if (c.layoutItems[i]['field'] == 'AccountId' && (this.isEditMode || this.isCloneMode)) {
                                        this.accountId = this.recordData.AccountId == null ? '' : this.recordData.AccountId;
                                    }
                                    if (this.isNewMode && this.defaultValues && Object.keys(this.defaultValues).length != 0) {
                                        if (this.defaultValues[c.layoutItems[i]["field"]]) {
                                            c.layoutItems[i]["value"] = this.defaultValues[c.layoutItems[i]["field"]];
                                        }
                                        if (c.layoutItems[i]['field'] == 'AccountId') {
                                            console.log('this.defaultValuesaccid = ' + this.defaultValues['AccountId']);
                                            this.accountId = this.defaultValues['AccountId'];
                                        }
                                    }
                                    //deloitte-zhj 20231106
                                    if(fieldName == 'MobilePhone'){
                                        this.hasMobilePhoneField = true;
                                    }
                                }
                            }
                        }
                    }
 
                    this.layout = layout;
                    console.log('this.accountId = ' + JSON.stringify(this.accountId));
                    console.log('this.layout = ' + JSON.stringify(this.layout));
                    this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap));
                    this.staticResource = JSON.parse(r.entity.staticResource);
                    this.staticResourceV2 = JSON.parse(r.entity.staticResourceV2);
                    console.log('this.staticResourceV2 = ' + JSON.stringify(this.staticResourceV2));
 
                    //编辑
                    if (this.isEditMode || this.isCloneMode) {
                        //解密客户的加密字段
                        this.querySobjectFromAWS();
                    }
                }
                this.isInitSuccess = true;
 
            } else {
                //this.showToast('Error', r.msg);
                this.showMyToast(r.msg, '', 'error')
            }
        })
    }
 
    sortMetaLayouts(layout) {
        layout.forEach(s => {
            let c1 = (s.layoutColumns[0].layoutItems != null) ? s.layoutColumns[0].layoutItems : [];
            let c2 = [];
            if (s.layoutColumns.length > 1) {
                c2 = (s.layoutColumns[1].layoutItems != null) ? s.layoutColumns[1].layoutItems : [];
            }
            else {
                s.layoutColumns.push({ "reserved": null, "layoutItems": [] });
            }
            let emptySpaceItem = {
                "width": null,
                "showScrollbars": null,
                "showLabel": null,
                "scontrol": null,
                "reportChartComponent": null,
                "page_x": null,
                "height": null,
                "field": null,
                "emptySpace": true,
                "customLink": null,
                "component": null,
                "canvas": null,
                "behavior": null,
                "analyticsCloudComponent": null
            }
            let maxSize = 0
            if (c1.length > c2.length) {
                maxSize = c1.length;
                for (let i = 0; i < maxSize; i++) {
                    if (c2.length == maxSize) {
                        break;
                    }
                    c2.push(emptySpaceItem);
                }
            } else {
                maxSize = c2.length;
                for (let i = 0; i < maxSize; i++) {
                    if (c1.length == maxSize) {
                        break;
                    }
                    c1.push(emptySpaceItem);
                }
            }
            let tempList = [];
            let index = 0;
            for (let i = 0; i < maxSize; i++) {
                tempList.push(c1[i]);
                if (tempList.length == maxSize) {
                    s.layoutColumns[index].layoutItems = tempList;
                    tempList = [];
                    tempList.push(c2[i]);
                    index++;
                } else {
                    tempList.push(c2[i]);
                    if (tempList.length == maxSize) {
                        s.layoutColumns[index].layoutItems = tempList;
                        tempList = [];
                        index++;
                    }
                }
            }
        })
        layout = [...layout];
        return layout;
    }
 
    handleLoad() {
        console.log('handleLoad')
        console.log('this.isInitSuccess = ' + this.isInitSuccess)
        if (this.isInitSuccess) {
            let time = 1000;
            if (!this.isNewMode) {
                time = 2000;
            }
 
            let that = this;
            setTimeout(() => {
                that.isLoading = false;
            }, time);
        }
    }
 
    querySobjectFromAWS() {
        debugger
        let that = this;
        this.AWSService.query(this.staticResource.queryUrl, this.AWSDataId, function (data) {
            console.log('queryLeadFromAWSIFS data = ' + JSON.stringify(data));
            if (data.object) {
                for (let s of that.layout) {
                    for (let lc of s.layoutColumns) {
                        if (lc.layoutItems) {
                            for (let c of lc.layoutItems) {
                                for (let f in that.AWSToSobjectMap) {
                                    if (data.object.hasOwnProperty(f) && c['field'] == that.AWSToSobjectMap[f]) {
                                        c['value'] = data.object[f] == null ? '' : data.object[f];
                                        if (c['field'] == 'LastName') {
                                            that.modifyObj['LastName'] = data.object[f] == null ? '' : data.object[f];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //deloitte-zhj 20231106
                if(!that.hasMobilePhoneField){
                    that.mobilePhone = data.object.mobilePhone;
                }
            }
        }, this.staticResource.token)
    }
 
 
    dataChange(event) {
        let fieldName = event.target.getAttribute("data-field");
        let value = event.detail.value;
        console.log("fieldName = " + fieldName + " value = " + event.detail.value);
        console.log(typeof event.detail.value);
        switch (fieldName) {
            case "LastName":
                this.modifyObj[fieldName] = value;
                break;
            case "AccountId":
                this.accountId = value[0];
                console.log('this.accountId = ' + this.accountId)
                break
        }
    }
 
    clickSubmit() {
        debugger
        console.log('clickSubmit');
        const btn = this.template.querySelector(".hidden");
        if (btn) {
            btn.click();
        }
    }
 
    clickSubmitAndNew() {
        console.log('clickSubmitAndNew');
        this.saveAndNew = true;
        const btn = this.template.querySelector(".hidden");
        if (btn) {
            btn.click();
        }
    }
    clickSection(event) {
        event.preventDefault();
    }
 
    handleSubmit(event) {
        this.isLoading = true;
        //1. Get Sobject Information from Form
        console.log('handleSubmit');
        event.preventDefault();
        const fields = event.detail.fields;
        //如果不是医生类型,直接保存即可无需加密
        if (!this.isDoctor) {
            //保存到后端
            this.template.querySelector('lightning-record-edit-form').submit(fields);
        } else {
            console.log('this.modifyObj = ' + JSON.stringify(this.modifyObj));
            Object.assign(fields, this.modifyObj);
            console.log('fields = ' + JSON.stringify(fields));
 
            debugger
            //2. select cannot actively select redaction option
            let validationResultMessage = this.validateFieldValueFormate(fields);
            console.log(validationResultMessage);
            if (validationResultMessage) {
                //this.showToast('Error', validationResultMessage);
                this.showMyToast(validationResultMessage, '', 'error')
                return
            }
 
            //3. Check Required Field
            let checkRequiredFieldMsgResult = this.checkRequiredFieldMsg(fields);
            console.log('checkRequiredFieldMsgResult = ' + checkRequiredFieldMsgResult);
            if (checkRequiredFieldMsgResult != '') {
                //this.showToast('Error', checkRequiredFieldMsgResult + '需要进行填写');
                this.showMyToast(checkRequiredFieldMsgResult + '需要进行填写', '', 'error')
                return
            }
 
            //4. Prepare the payload for New PI API To AWS - To Do
            let payloadForNewPI = this.getPIPayload(fields);
            console.log('payloadForNewPI = ' + payloadForNewPI);
            //5. PI To AWS
            //判断重复
            debugger
            searchContactByAccountId({
                accountId: this.accountId,
                RecordTypeId: this.recordTypeId,
                Isactive: fields['Isactive__c']
            }).then((result) => {
                result = JSON.parse(JSON.stringify(result));
                if (result.status == 'fail') {
                    //this.showToast('Error', result.message);
                    this.showMyToast(result.message, '', 'error')
                    return
                }
                this.accountName = result.accountName;
                this.dataIdManageCodeMap = result.dataIdManageCodeMap;
                let contactList = '';
                for (let i = 0; i < result.contactList.length; i++) {
                    if (result.contactList[i].AWS_Data_Id__c)
                        contactList += ',' + result.contactList[i].AWS_Data_Id__c;
                }
                contactList = contactList.substring(1);
                payloadForNewPI = JSON.parse(payloadForNewPI);
                payloadForNewPI[0].contactIds = contactList;
                payloadForNewPI[0].isMobileVerif = result.isMobileVerif;
                payloadForNewPI[0].isNameMobileVerif = result.isNameMobileVerif;
                //deloitte-zhj 20231106 start
                if(!this.hasMobilePhoneField){
                    payloadForNewPI[0].mobilePhone = this.mobilePhone;
                }
                //deloitte-zhj 20231106 end
                payloadForNewPI = JSON.stringify(payloadForNewPI);
                //新建
                if (this.isNewMode || this.isCloneMode || this.AWSDataId == '' || this.AWSDataId == null) {
                    this.NewPIToAWS(payloadForNewPI, fields);
                    return
                }
                //编辑
                if (this.isEditMode) {
                    this.UpdatePIToAWS(payloadForNewPI, fields);
                }
            });
        }
 
 
    }
 
    //验证字段
    validateFieldValueFormate(fields) {
        let error_msg = '';
        let b = false;
        for (let key in fields) {
            if (fields[key] == "*****")
                b = true;
        }
        if (b)
            error_msg = '下拉框不能主动选择密文选项';
        return error_msg;
    }
 
    //验证required字段需要进行填写
    checkRequiredFieldMsg(fields) {
        let msg = '';
        try {
            for (let s of this.layout) {
                for (let lc of s.layoutColumns) {
                    if (lc.layoutItems) {
                        for (let c of lc.layoutItems) {
                            if (!c.isDisable && c.isRequired && (fields[c.field] == null || fields[c.field] === '')) {
                                msg += ";" + this.fieldLabel[c.field].label;
                            }
                        }
                    }
                }
            }
        } catch (err) {
            //this.showToast('Error', err.message);
            this.showMyToast(err.message, '', 'error')
        }
        msg = msg.substring(1);
        return msg;
    }
 
    //获取PI字段
    getPIPayload(sobjJsonLwc) {
        console.log()
        let leadPayloadList = [];
        let leadPIData = {};
 
        for (let f in this.AWSToSobjectMap) {
            if (sobjJsonLwc.hasOwnProperty(this.AWSToSobjectMap[f])) {
                leadPIData[f] = sobjJsonLwc[this.AWSToSobjectMap[f]]
            }
            else {
                console.log(this.AWSToSobjectMap[f] + 'is not in sobjJsonLwc');
            }
        }
 
        leadPIData.medicalStaffFullName = leadPIData.lastName;
        leadPIData.sfRecordId = '';
        console.log('Sobject PI Data x :' + leadPIData);
        leadPayloadList.push(leadPIData);
        console.log('leadPayloadList = ' + JSON.stringify(leadPayloadList));
        return JSON.stringify(leadPayloadList);
    }
 
    //新建保存ToAWS
    NewPIToAWS(payloadForNewPI, fields) {
        debugger
        this.AWSService.post(this.staticResourceV2.newUrl, payloadForNewPI, (result) => {
            if (result && result.object) {
                //判断已存在相同名字的联系人
                let errorMsg = '';
                if (result.status == '129') {
                    errorMsg = '客户 [ ' + this.accountName + ' ],已存在相同名字的联系人 人员管理编码 [' + this.dataIdManageCodeMap[result.object[0].dataId] + ' ] ,不能重复创建,请了解';
                    //this.showToast('Error', errorMsg)
                    this.showMyToast(errorMsg, '', 'error')
                    return
                }
                if (result.status == '130') {
                    if (result.object[0] && result.object[0].sfRecordId != null && result.object[0].sfRecordId != '') {
                        errorMsg = '已找到重复值: UniqueNumber__c 与记录值重复,ID 为: ' + result.object[0].sfRecordId + '客户人员信息';
                    }
                    else {
                        errorMsg = '数据中存在重复的电话号码';
                    }
                    //this.showToast('Error', errorMsg)
                    this.showMyToast(errorMsg, '', 'error')
                    return
                }
                console.log('result = ' + JSON.stringify(result));
                for (let f in this.AWSToSobjectMap) {
                    if (result.object[0].hasOwnProperty(f)) {
                        fields[this.AWSToSobjectMap[f]] = result.object[0][f];
                        console.log('this.AWSToSobjectMap[f] = ' + this.AWSToSobjectMap[f]);
                        console.log('fields[this.AWSToSobjectMap[f]] = ' + fields[this.AWSToSobjectMap[f]]);
                    }
                    else {
                        console.log(f + 'is not in result.object[0]');
                    }
                }
                fields['AWS_Data_Id__c'] = result.object[0].dataId;
                this.txId = result.txId;
                //保存到后端
                this.template.querySelector('lightning-record-edit-form').submit(fields);
            } else {
                console.log('result = ' + JSON.stringify(result));
            }
        }, this.staticResource.token);
    }
 
    //编辑保存ToAWS
    UpdatePIToAWS(payloadForNewPI, fields) {
        let obj = JSON.parse(payloadForNewPI);
        if (this.AWSDataId) {
            obj[0].dataId = this.AWSDataId;
        } else {
            this.showMyToast("Error", '未找到该记录的AWS Id,请确认记录完整性', 'error');
            return;
        }
        obj[0].dataId = this.AWSDataId;
        let payloadForNewPIJson = JSON.stringify(obj);
        this.AWSService.post(this.staticResourceV2.updateUrl, payloadForNewPIJson, (result) => {
            if (result && result.object) {
                //判断已存在相同名字的联系人
                let errorMsg = '';
                if (result.status == '129') {
                    errorMsg = '客户 [ ' + this.accountName + ' ],已存在相同名字的联系人 人员管理编码 [' + this.dataIdManageCodeMap[result.object[0].dataId] + ' ] ,不能重复创建,请了解';
                    //this.showToast('Error', errorMsg)
                    this.showMyToast(errorMsg, '', 'error')
                    return
                }
                if (result.status == '130') {
                    if (result.object[0] && result.object[0].sfRecordId != null && result.object[0].sfRecordId != '') {
                        errorMsg = '已找到重复值: UniqueNumber__c 与记录值重复,ID 为: ' + result.object[0].sfRecordId + '客户人员信息';
                    }
                    else {
                        errorMsg = '数据中存在重复的电话号码';
                    }
                    //this.showToast('Error', errorMsg)
                    this.showMyToast(errorMsg, '', 'error')
                    return
                }
                console.log('result = ' + JSON.stringify(result));
                for (let f in this.AWSToSobjectMap) {
                    if (result.object[0].hasOwnProperty(f)) {
                        fields[this.AWSToSobjectMap[f]] = result.object[0][f];
                        console.log('this.AWSToSobjectMap[f] = ' + this.AWSToSobjectMap[f]);
                        console.log('fields[this.AWSToSobjectMap[f]] = ' + fields[this.AWSToSobjectMap[f]]);
                    }
                    else {
                        console.log(f + 'is not in result.object[0]');
                    }
                }
                fields['AWS_Data_Id__c'] = this.AWSDataId;
                this.txId = result.txId;
                console.log('this.txId = ' + this.txId);
                console.log('PI After fields = ' + JSON.stringify(fields));
                if (fields.RecordTypeId) {
                    fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1);
                }
                //保存到后端
                console.log('update submit = ' + JSON.stringify(fields));
                this.template.querySelector('lightning-record-edit-form').submit(fields);
            } else {
                console.log('result = ' + JSON.stringify(result));
            }
        }, this.staticResource.token);
    }
 
    //提交保存成功
    handleSuccess(event) {
        debugger
        let updatedRecord = event.detail.id;
        console.log('onsuccess: ', updatedRecord);
        console.log('confirmTrans');
        let that = this;
        if (!this.isDoctor) {
            this.showToast('Success', '保存成功');
            console.log('updatedRecord = ' + updatedRecord)
            if (this.saveAndNew) {
                console.log('this.recordTypeId = ' + this.recordTypeId);
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: this.sobjectType,
                        actionName: 'new',
                    },
                    state: {
                        recordTypeId: this.recordTypeId
                    }
                });
                setTimeout(function() {
                    location.reload();
                }, 1000); // 延迟一秒(1000毫秒)  
            } else {
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        actionName: "view",
                        recordId: updatedRecord,
                        objectApiName: this.sobjectType
                    }
                });
                setTimeout(function() {
                    location.reload();
                }, 1000); // 延迟一秒(1000毫秒)  
            }
        } else {
            this.AWSService.confirm(true, updatedRecord, this.txId, this.staticResource.token, this.staticResource.transactionUrl, function (result) {
                console.log('result = ' + JSON.stringify(result))
                that.showToast('Success', '保存成功');
                console.log('updatedRecord = ' + updatedRecord)
                if (that.saveAndNew) {
                    console.log('that.recordTypeId = ' + that.recordTypeId);
                    that[NavigationMixin.Navigate]({
                        type: 'standard__objectPage',
                        attributes: {
                            objectApiName: that.sobjectType,
                            actionName: 'new',
                        },
                        state: {
                            recordTypeId: that.recordTypeId
                        }
                    });
                    setTimeout(function() {
                        location.reload();
                    }, 1000); // 延迟一秒(1000毫秒)   
                } else {
                    that[NavigationMixin.Navigate]({
                        type: 'standard__recordPage',
                        attributes: {
                            actionName: "view",
                            recordId: updatedRecord,
                            objectApiName: that.sobjectType
                        }
                    });
                    setTimeout(function() {
                        location.reload();
                    }, 1000); // 延迟一秒(1000毫秒)   
                }
            });
        }
    }
 
    //提交保存失败
    handleError(event) {
        event.preventDefault();
        event.stopImmediatePropagation();
        //字段级别的报错
        if (event.detail.output && event.detail.output.fieldErrors && Object.keys(event.detail.output.fieldErrors).length != 0) {
            let msg = '';
            for (let key in event.detail.output.fieldErrors) {
                msg += ',' + event.detail.output.fieldErrors[key][0].message;
            }
            msg = msg.substring(1);
            this.showMyToast(event.detail.message + ' : ' + msg, '', 'error');
        } else {
            //add by Li Jun 20231025 Start 
            if(event.detail.message != '' &&  this.customLabel.LexRecordNotCreateable.indexOf(event.detail.message) != -1){
                this.showMyToast("Error", this.customLabel.LexNotCreateNote, 'error');
            }else{
                this.showMyToast("Error", event.detail.message + ' : ' + event.detail.detail, 'error');
            }
            //add by Li Jun 20231025 End
        }
        //add by Li Jun 20231025 Start 
        if(this.txId && this.staticResource){
            if (this.isDoctor) {
                this.AWSService.confirm(false,'',this.txId,this.staticResource.token,this.staticResource.transactionUrl,function(result){
                    console.log('result = ' + JSON.stringify(result))
                });
            }
        }
        //add by Li Jun 20231025 End
    }
 
 
    //取消
    cancel() {
        conmentCancel(this.defaultValues);
    }
 
    //标准新建页面跳转
    RedirectStandardNewPage() {
        // this[NavigationMixin.Navigate]({
        //     type: 'standard__objectPage',
        //     attributes: {
        //       objectApiName: this.sobjectType,
        //       actionName: 'list'
        //     }
        // }).then(() => {
        //     // 跳转成功后的逻辑
        //     debugger
        //     console.log('跳转成功');
        //     // this[NavigationMixin.Navigate]({
        //     //     type: 'standard__objectPage',
        //     //     attributes: {
        //     //         objectApiName: 'Contact',
        //     //         actionName: 'new'
        //     //     },
        //     //     state: {
        //     //         nooverride: '1',
        //     //         recordTypeId: this.recordTypeId
        //     //     }
        //     // });
        // })
        // .catch(error => {
        //     // 取消跳转的逻辑
        //     console.log('取消跳转');
        // });
 
        // 在取消操作的回调函数中执行页面跳转
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Contact',
                actionName: 'new'
            },
            state: {
                nooverride: '1',
                recordTypeId: this.recordTypeId
            }
        });
    }
 
    //标准编辑页面跳转
    RedirectStandardEditPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                objectApiName: 'Contact',
                recordId: this.recordId,
                actionName: 'edit',
            },
            state: {
                nooverride: '1',
            }
        });
    }
 
    //显示信息
    showToast(type, msg) {
        this.isLoading = false;
        const event = new ShowToastEvent({
            //title: msg,
            variant: type,
            message: msg
        });
        this.dispatchEvent(event);
    }
 
    //显示信息
    showMyToast(title, message, variant) {
        console.log('show custom message');
        let iconName = '';
        let content = '';
        if (variant == 'success') {
            iconName = 'utility:check';
        } else {
            iconName = 'utility:error';
        }
        if (message != '') {
            content =
                '<h2><strong>' +
                title +
                '<strong/></h2><h5>' +
                message +
                '</h5>';
        } else {
            content = '<h2><strong>' + title + '<strong/></h2>';
        }
        this.template
            .querySelector('c-common-toast')
            .showToast(variant, content, iconName, 10000);
        this.isLoading = false;
    }
}