From 80a3f59e2d3df07805bc67e329300b8de90a5b3a Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 11 七月 2023 14:13:08 +0800
Subject: [PATCH] Merge branch 'LEXCommunityLiJun' into LEXUpgrade2023-Deloitte

---
 force-app/main/default/lwc/lexNewAndEditContactPIPL/lexNewAndEditContactPIPL.js |  505 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 505 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/lwc/lexNewAndEditContactPIPL/lexNewAndEditContactPIPL.js b/force-app/main/default/lwc/lexNewAndEditContactPIPL/lexNewAndEditContactPIPL.js
new file mode 100644
index 0000000..a9f5362
--- /dev/null
+++ b/force-app/main/default/lwc/lexNewAndEditContactPIPL/lexNewAndEditContactPIPL.js
@@ -0,0 +1,505 @@
+import { LightningElement, api, track, wire } from 'lwc';
+import { CurrentPageReference } from 'lightning/navigation';
+import initData from '@salesforce/apex/LexNewAndEditContactPIPLController.initData';
+import { NavigationMixin } from 'lightning/navigation';
+import { AWSService } from 'c/piUtils';
+import { ShowToastEvent } from 'lightning/platformShowToastEvent';
+
+export default class LexNewAndEditContactPIPL extends NavigationMixin(
+    LightningElement
+) {
+    sobjectType = 'Contact';
+
+    @api recordId;
+    @track recordTypeId = '';
+    @wire(CurrentPageReference) pageRef;
+    @track recordData = {};
+    @track title = '';
+    @track isShowSpinner = true;
+    @track layout = [];
+    @track isDoctor = true;
+
+    @track staticResource;
+    @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 hospitalId = '';
+    @track contactId = '';
+    AWSService;
+
+    @track modifyObj = {};
+    modifyArray = ['LastName'];
+
+    connectedCallback() {
+        console.log('enter connectedCallback');
+        this.AWSService = new AWSService();
+        if (!this.recordId || this.isCloneMode) {
+            this.title = '鏂板缓瀹㈡埛浜哄憳';
+            this.isNewMode = true;
+        }
+        if (this.recordId) {
+            this.title = '缂栬緫瀹㈡埛浜哄憳';
+            this.isEditMode = true;
+        }
+        if (this.pageRef && this.pageRef.state) {
+            this.recordTypeId = this.pageRef.state.recordTypeId;
+            console.log('this.recordTypeId = ' + this.recordTypeId);
+        }
+        console.log(
+            'recordId = ' +
+                this.recordId +
+                ' recordTypeId = ' +
+                this.recordTypeId +
+                ' sobjectType = ' +
+                this.sobjectType
+        );
+        initData({
+            rid: this.recordId,
+            recordTypeId: this.recordTypeId,
+            sobjectType: this.sobjectType
+        }).then((r) => {
+            r = JSON.parse(JSON.stringify(r));
+            if (r.status == 'Success') {
+                this.isDoctor = r.entity.isDoctor;
+                console.log('this.isDoctor = ' + this.isDoctor);
+                if (this.isEditMode) {
+                    this.recordTypeId = r.entity.recordTypeId;
+                }
+                console.log('this.recordTypeId = ' + this.recordTypeId);
+                debugger;
+                //濡傛灉涓嶆槸鍖婚櫌绫诲瀷锛屼娇鐢ㄦ爣鍑嗛〉闈�
+                if (!this.isDoctor) {
+                    if (this.isNewMode) this.RedirectStandardNewPage();
+                    if (this.isEditMode) this.RedirectStandardEditPage();
+                    return;
+                }
+                this.AWSDataId = r.entity.AWSDataId;
+                let layout = JSON.parse(r.entity.layout);
+                console.log('layout = ' + JSON.stringify(layout));
+                console.log('layout = ' + typeof layout);
+
+                let index = 1;
+                this.sectionName = layout.map((s) => s.label);
+                for (let s of layout) {
+                    for (let c of s.layoutColumns) {
+                        c['index'] = index++;
+                        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;
+                                if (item['field'] == 'Name') {
+                                    item.field = 'LastName';
+                                    item.fieldLabel = '濮撳悕';
+                                    item['isModify'] = true;
+                                    if (this.isEditMode) {
+                                        item['value'] =
+                                            this.recordData.LastName;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                this.layout = layout;
+                console.log('this.layout = ' + JSON.stringify(this.layout));
+                this.AWSToSobjectMap = JSON.parse(
+                    JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap)
+                );
+                this.staticResource = JSON.parse(r.entity.staticResource);
+
+                //缂栬緫
+                if (this.isEditMode) {
+                    //瑙e瘑瀹㈡埛鐨勫姞瀵嗗瓧娈�
+                    this.querySobjectFromAWS();
+                }
+                this.isShowSpinner = false;
+            } else {
+                this.showToast('Error', r.msg);
+            }
+        });
+    }
+
+    querySobjectFromAWS() {
+        debugger;
+        var 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];
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    // for (var s of that.layout) {
+                    //     for (var c of s.layoutFields) {
+                    //         for (let f in that.AWSToSobjectMap) {
+                    //             if (data.object.hasOwnProperty(f) && c['fieldAPI'] == that.AWSToSobjectMap[f]) {
+                    //                 c['value'] = data.object[f] == null ? '' : data.object[f];
+                    //                 if (c['fieldAPI'] == 'LastName') {
+                    //                     that.modifyObj['LastName'] = data.object[f] == null ? '' : data.object[f];
+                    //                 }
+                    //             }
+                    //         }
+                    //     }
+                    // }
+                }
+            },
+            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
+        );
+        switch (fieldName) {
+            case 'LastName':
+                this.modifyObj[fieldName] = value;
+                break;
+        }
+    }
+
+    handleSubmit(event) {
+        this.isShowSpinner = true;
+        //1. Get Sobject Information from Form
+        console.log('handleSubmit');
+        event.preventDefault();
+        const fields = event.detail.fields;
+        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);
+            return;
+        }
+
+        //3. Check Required Field
+        let checkRequiredFieldMsgResult = this.checkRequiredFieldMsg(fields);
+        console.log(
+            'checkRequiredFieldMsgResult = ' + checkRequiredFieldMsgResult
+        );
+        if (checkRequiredFieldMsgResult != '') {
+            this.showToast(
+                'Error',
+                checkRequiredFieldMsgResult + '闇�瑕佽繘琛屽~鍐�'
+            );
+            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
+        //鏂板缓
+        if (this.isNewMode) {
+            this.NewPIToAWS(payloadForNewPI, fields);
+        }
+        //缂栬緫
+        if (this.isEditMode) {
+            this.UpdatePIToAWS(payloadForNewPI, fields);
+        }
+    }
+
+    //楠岃瘉瀛楁
+    validateFieldValueFormate(fields) {
+        let error_msg = '';
+        let b = false;
+        for (var 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 += ';' + c.fieldLabel;
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (err) {
+            this.showToast('Error', err.message);
+        }
+        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) {
+        this.AWSService.post(
+            this.staticResource.newUrl,
+            payloadForNewPI,
+            (result) => {
+                if (result && result.object) {
+                    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);
+        obj[0].dataId = this.AWSDataId;
+        let payloadForNewPIJson = JSON.stringify(obj);
+        this.AWSService.post(
+            this.staticResource.updateUrl,
+            payloadForNewPIJson,
+            (result) => {
+                if (result && result.object) {
+                    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) {
+        let updatedRecord = event.detail.id;
+        console.log('onsuccess: ', updatedRecord);
+        console.log('confirmTrans');
+        let that = this;
+        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);
+                that[NavigationMixin.Navigate]({
+                    type: 'standard__recordPage',
+                    attributes: {
+                        actionName: 'view',
+                        recordId: updatedRecord,
+                        objectApiName: that.sobjectType
+                    }
+                });
+            }
+        );
+    }
+
+    //鎻愪氦淇濆瓨澶辫触
+    handleError(event) {
+        event.preventDefault();
+        event.stopImmediatePropagation();
+        this.showToast('Error', event.detail.detail);
+        this.AWSService.confirm(
+            false,
+            '',
+            this.txId,
+            this.staticResource.token,
+            this.staticResource.transactionUrl,
+            function (result) {
+                console.log('result = ' + JSON.stringify(result));
+            }
+        );
+    }
+
+    //change浜嬩欢
+    dataChange(event) {
+        let fieldName = event.target.getAttribute('data-field');
+        let value = event.detail.value;
+        console.log(
+            'fieldName = ' + fieldName + ' value = ' + event.detail.value
+        );
+        if (this.modifyArray.indexOf(fieldName) != -1) {
+            switch (fieldName) {
+                case 'LastName':
+                    this.modifyObj[fieldName] = value;
+                    break;
+            }
+        }
+    }
+
+    //鍙栨秷
+    cancel() {
+        console.log('cancel');
+        window.history.back();
+    }
+
+    //鏍囧噯鏂板缓椤甸潰璺宠浆
+    RedirectStandardNewPage() {
+        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.isShowSpinner = false;
+        const event = new ShowToastEvent({
+            title: type,
+            variant: type,
+            message: msg
+        });
+        this.dispatchEvent(event);
+    }
+}

--
Gitblit v1.9.1