From f230c720655620fccb5cc5fd8d1991ffbf10c982 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 30 五月 2023 14:13:04 +0800
Subject: [PATCH] bakcupclass
---
force-app/main/default/aura/NewAgencyContact/NewAgencyContactController.js | 2
force-app/main/default/classes/LayoutDescriberHelper.cls | 11
force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js-meta.xml | 12
force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls | 222 +++++++++++++
force-app/main/default/classes/TestUserExample.cls-meta.xml | 5
force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls-meta.xml | 5
force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js | 525 ++++++++++++++++++++++++++++++++
force-app/main/default/classes/NewAgencyContactController.cls | 3
force-app/main/default/classes/TestUserExample.cls | 49 +++
force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.html | 75 ++++
force-app/main/default/pages/NewAndEditLead.page | 3
11 files changed, 904 insertions(+), 8 deletions(-)
diff --git a/force-app/main/default/aura/NewAgencyContact/NewAgencyContactController.js b/force-app/main/default/aura/NewAgencyContact/NewAgencyContactController.js
index 5c76bf6..fcb2080 100644
--- a/force-app/main/default/aura/NewAgencyContact/NewAgencyContactController.js
+++ b/force-app/main/default/aura/NewAgencyContact/NewAgencyContactController.js
@@ -18,7 +18,7 @@
record_type_id = pageref.state.recordTypeId
}
component.set("v.showSpinner", true);
- helper.CallBackAction(component,'Init',{
+ helper.CallBackAction(component,'init',{
rid : rid,
pid : pid,
//rid : component.get('v.recordId'),
diff --git a/force-app/main/default/classes/LayoutDescriberHelper.cls b/force-app/main/default/classes/LayoutDescriberHelper.cls
index 8041efd..9df6681 100644
--- a/force-app/main/default/classes/LayoutDescriberHelper.cls
+++ b/force-app/main/default/classes/LayoutDescriberHelper.cls
@@ -228,7 +228,8 @@
req.setEndpoint(urlForClassic);
req.setHeader('Authorization', 'Bearer ' + UserInfo.getsessionid());
}
- Http client = new Http();
+ Http client = new Http();
+ System.debug('req = ' + req);
resp = client.send(req);
system.debug('Schema Body:'+JSON.serialize(resp.getBody()));
return resp.getBody();
@@ -268,9 +269,9 @@
@AuraEnabled public boolean isPlaceHolder {get;set;}
@AuraEnabled public String defaultValue{set;get;}
}
-public static Integer ControllerUtil() {
-Integer i = 0;
-return i;
-}
+ public static Integer ControllerUtil() {
+ Integer i = 0;
+ return i;
+ }
}
\ No newline at end of file
diff --git a/force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls b/force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls
new file mode 100644
index 0000000..3cc2329
--- /dev/null
+++ b/force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls
@@ -0,0 +1,222 @@
+public with sharing class LexNewAndEditLeadPIPLController {
+ public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
+ // 瀛楁淇℃伅
+ public static Map<string, SObjectField> fieldMap = new Map<string, SObjectField>();
+
+ @AuraEnabled
+ public static ResponseBodyLWC initData2(Id rid, String recordTypeId, String sobjectType) {
+ System.debug('娴嬭瘯 initData2');
+ return new ResponseBodyLWC('Error', 500, '娴嬭瘯', '');
+ }
+ @AuraEnabled
+ public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType) {
+ try {
+ System.debug('rid = ' + rid);
+ System.debug('recordTypeId = ' + recordTypeId);
+ System.debug('sobjectType = ' + sobjectType);
+ fieldMap = schemaMap.get(sobjectType).getDescribe().fields.getMap();
+ ResponseBodyLWC res = new ResponseBodyLWC();
+ Map<String, object> data = new Map<String, object>();
+ res.entity = data;
+ List<Metadata.LayoutSection> layout = null;
+ data.put('recordTypeId', '');
+ if (String.isEmpty(recordTypeId)) {
+ data.put('recordTypeId', LayoutDescriberHelper.getDefaultRecordType(sobjectType));
+ recordTypeId = LayoutDescriberHelper.getDefaultRecordType(sobjectType);
+ System.debug('recordTypeId = ' + recordTypeId);
+ } else {
+ data.put('recordTypeId', recordTypeId);
+ }
+ LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(recordTypeId,'Lead','lightning');
+ List<LayoutDescriberHelper.LayoutSection> layoutSections = LayoutWrapperValue.layoutSections;
+ data.put('layout', Json.serialize(layoutSections));
+ //缂栬緫
+ if(!String.isBlank(rid)){
+ //鑾峰彇瀵瑰簲瀵硅薄鐨勫瓧娈�
+ List<Sobject> lso = Database.query('select id from RecordType where SobjectType = :sobjectType');
+ string sql = 'select Contact_Name__r.LastName,Contact_Name__r.AWS_Data_Id__c,Hospital_Name__r.Id';
+ DescribeSObjectResult objectType = rid.getSobjectType().getDescribe();
+ List<String> objectFields = new List<String>(objectType.fields.getMap().keySet());
+ sql += ', ' + String.join(objectFields, ',') +' from '+sobjectType+' where id =\''+rid+'\' limit 1';
+ System.debug('sql = ' + sql);
+ Sobject leadData = Database.query(sql);
+ if(leadData == null){
+ return new ResponseBodyLWC('Error',500, 'id涓嶅瓨鍦�', '');
+ }
+ data.put('recordTypeId', (String)leadData.get('RecordTypeId'));
+ data.put('AWSDataId', (String)leadData.get('AWS_Data_Id__c'));
+ //鑾峰彇鍊�
+ System.debug('leadData = ' + JSON.serialize(leadData));
+ data.put('data', leadData);
+ }
+ //鑾峰彇PI瀛楁
+ PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo(sobjectType);
+ Map<String, String> AWSToSobjectNonEncryptedMap = new Map<String, String>();
+ List<String> AWSToSobjectNonEncryptedMapKeySet = new List<String>();
+ for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) {
+ AWSToSobjectNonEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c);
+ AWSToSobjectNonEncryptedMapKeySet.add(PIDetail.AWS_Field_API__c);
+ }
+ data.put('AWSToSobjectNonEncryptedMap', AWSToSobjectNonEncryptedMap);
+ data.put('AWSToSobjectNonEncryptedMapKeySet', AWSToSobjectNonEncryptedMapKeySet);
+ data.put('staticResource', Json.serialize(PIHelper.getPIIntegrationInfo(sobjectType)));
+ data.put('staticResourceContact', Json.serialize(PIHelper.getPIIntegrationInfo('Contact')));
+ res.status = 'Success';
+ res.code = 200;
+ res.msg = '';
+ return res;
+ } catch (Exception e) {
+ System.debug('error = ' + e.getMessage() + ' line = ' + e.getLineNumber());
+ return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+ }
+ }
+
+ @AuraEnabled
+ public static ResponseBodyLWC queryAccount(String accountTypes, String accountId) {
+ ResponseBodyLWC res = new ResponseBodyLWC();
+ Map<String, object> data = new Map<String, object>();
+ res.entity = data;
+ System.debug('accountType = ' + accountTypes);
+ System.debug('accountId = ' + accountId);
+ try {
+ List<Object> types = (List<Object>) JSON.deserializeUntyped(accountTypes);
+ System.debug('types=' + types);
+ String soql = 'select Id,Name,';
+ for (Object t : types) {
+ soql += (String) t + ',';
+ }
+ soql = soql.substring(0, soql.length() - 1);
+ soql += ' from Account where id=\'' + accountId + '\'';
+ System.debug('soql=' + soql);
+ Sobject account = new Account();
+ if (!Test.isRunningTest()) {
+ account = Database.query(soql);
+ } else {
+ account.put('Id', '000000000000000');
+ }
+ Map<String, Map<String, String>> m = new Map<String, Map<String, String>>();
+ System.debug('account=' + account);
+ for (Object ty : types) {
+ String t = (String) ty;
+ if (account.get(t) != null || Test.isRunningTest()) {
+ Sobject acc = new Account();
+ if (Test.isRunningTest()) {
+ acc.put('Id', '000000000000000');
+ acc.put('Name', 'Name');
+ } else {
+ acc = Database.query('select Id,Name from Account where id=\'' + account.get(t) + '\'');
+ }
+ Map<String, String> n = new Map<String, String>();
+ n.put('Id', (String) acc.get('Id'));
+ n.put('Name', (String) acc.get('Name'));
+ m.put(t, n);
+ }
+ }
+ System.debug('m=' + m);
+ data.put('m', m);
+ data.put('account', account);
+ res.status = 'Success';
+ res.code = 200;
+ res.msg = '';
+ return res;
+ } catch (Exception e) {
+ return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+ }
+ }
+
+ @AuraEnabled
+ public static ResponseBodyLWC searchContactInit(String accountId, String searchKeyWord) {
+ ResponseBodyLWC res = new ResponseBodyLWC();
+ Map<String, object> data = new Map<String, object>();
+ res.entity = data;
+ System.debug('accountId = ' + accountId);
+ System.debug('searchKeyWord = ' + searchKeyWord);
+ try {
+ List<Contact> conList = new List<Contact>();
+ List<Contact> noPIContactList = new List<Contact>();
+ if (checkNullString(accountId) && checkNullString(searchKeyWord)) {
+ conList = new List<Contact>();
+ } else {
+ if (checkNullString(accountId)) {
+ conList = new List<Contact>();
+ } else {
+ //2022-5-12 yjk 灏嗙瀹ゅ尮閰嶆敼涓哄尰闄㈠尮閰嶆煡璇㈣仈绯讳汉 statt
+ Account act = [SELECT id, Hospital__c FROM Account WHERE id = :accountId];
+ conList = new List<Contact>(
+ [
+ SELECT Id, AWS_Data_Id__c, Account.Name
+ FROM Contact
+ WHERE Account.Hospital__c = :act.Hospital__c AND AWS_Data_Id__c != ''
+ ]
+ );
+ noPIContactList = AWSServiceTool.getNoPIContact(searchKeyWord, accountId);
+ //2022-5-12 yjk 灏嗙瀹ゅ尮閰嶆敼涓哄尰闄㈠尮閰嶆煡璇㈣仈绯讳汉 end
+ }
+ }
+ Map<String, Contact> awsIdToContactMap = new Map<String, Contact>();
+ List<String> conAWSIds = new List<String>();
+ for (Contact con : conList) {
+ conAWSIds.add(con.AWS_Data_Id__c);
+ awsIdToContactMap.put(con.AWS_Data_Id__c, con);
+ }
+ data.put('awsIdToContactMap', awsIdToContactMap);
+ data.put('conAWSIds', conAWSIds);
+ data.put('noPIContactList', noPIContactList);
+ data.put('contactStaticResource', JSON.serialize(PIHelper.getPIIntegrationInfo('Contact')));
+ res.status = 'Success';
+ res.code = 200;
+ res.msg = '';
+ return res;
+ } catch (Exception e) {
+ return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+ }
+ }
+
+ public static Boolean checkNullString(String inputString) {
+ if (String.isEmpty(inputString) || String.isBlank(inputString)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *@description 杞崲layout
+ *@param sections 榛樿metalayout
+ *@return List<Metadata.LayoutSection> 鏍囧噯metalayout
+ */
+ public static List<Metadata.LayoutSection> reviseMetaLayouts(List<Metadata.LayoutSection> sections) {
+ List<Metadata.LayoutSection> result = new List<Metadata.LayoutSection>();
+ if (sections == null) {
+ return null;
+ }
+ for (Metadata.LayoutSection s : sections) {
+ Metadata.LayoutSection section = new Metadata.LayoutSection();
+ section.customLabel = s.customLabel;
+ section.detailHeading = s.detailHeading;
+ section.editHeading = s.editHeading;
+ section.label = s.label;
+ section.style = s.style;
+ result.add(section);
+ for (Metadata.LayoutColumn c : s.layoutColumns) {
+ if (c.layoutItems == null) {
+ break;
+ }
+ Metadata.LayoutColumn col = new Metadata.LayoutColumn();
+ col.reserved = col.reserved;
+ section.layoutColumns.add(col);
+ for (Metadata.layoutItem item : c.layoutItems) {
+ if (!fieldMap.containsKey(item.field) || !isUpdateable(fieldMap.get(item.field).getDescribe())) {
+ System.debug(item.field);
+ continue;
+ }
+ col.layoutItems.add(item);
+ }
+ }
+ }
+ return result;
+ }
+
+ private static Boolean isUpdateable(Schema.DescribeFieldResult dfr) {
+ return (new List<String>{ 'Id', 'Name' }).contains(dfr.getName()) || dfr.isUpdateable();
+ }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls-meta.xml b/force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls-meta.xml
new file mode 100644
index 0000000..754ecb1
--- /dev/null
+++ b/force-app/main/default/classes/LexNewAndEditLeadPIPLController.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+ <apiVersion>57.0</apiVersion>
+ <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/classes/NewAgencyContactController.cls b/force-app/main/default/classes/NewAgencyContactController.cls
index 8020002..2b49738 100644
--- a/force-app/main/default/classes/NewAgencyContactController.cls
+++ b/force-app/main/default/classes/NewAgencyContactController.cls
@@ -3,7 +3,8 @@
static string sobjectType = 'Agency_Contact__c';
@AuraEnabled
- public static ControllerResponse Init(string rid,Id pid, string record_type_id){
+ public static ControllerResponse init(string rid,Id pid, string record_type_id){
+ system.debug('Debug lighting');
system.debug('rid='+rid+',length='+(rid==null?'null':rid.length()+''));
system.debug('record_type_id='+record_type_id+',length='+(record_type_id==null?'null':record_type_id.length()+''));
diff --git a/force-app/main/default/classes/TestUserExample.cls b/force-app/main/default/classes/TestUserExample.cls
new file mode 100644
index 0000000..fbbbf4d
--- /dev/null
+++ b/force-app/main/default/classes/TestUserExample.cls
@@ -0,0 +1,49 @@
+@isTest
+public with sharing class TestUserExample {
+
+
+ @isTest static void itWorks() {
+ System.runAs(new User(Id = UserInfo.getUserId())){
+ createUser();
+ }
+ User user = [SELECT Id FROM User WHERE UserName LIKE 'admin%' LIMIT 1];
+ //query user
+ //
+ //createAccount();
+
+ }
+
+ private static void createAccount(){
+ String random = String.valueof(DateTime.now().getTime());
+
+ Account acc = new Account(Name = random);
+ acc.CurrencyIsoCode = 'USD';
+ acc.BillingCity = 'New York';
+ acc.BillingCountry = 'United States';
+ acc.BillingState = 'New York';
+ acc.BillingStreet = 'abc 1234';
+ acc.Website = 'www.google.com';
+
+ insert ACC;
+
+ }
+
+ private static void createUser(){
+ String random = String.valueof(DateTime.now().getTime());
+
+ Profile profile = [SELECT Id FROM Profile WHERE Name='绯荤粺绠$悊鍛�'];
+
+ User user = new User();
+ user.Email = 'random@random.com'+random;
+ user.UserName = 'admin@random.com'+random;
+ user.LastName = 'random'+random;
+ user.Alias = 'random';
+ user.ProfileId = profile.Id;
+ user.EmailEncodingKey='UTF-8';
+ user.LanguageLocaleKey='en_US';
+ user.LocaleSidKey='en_US';
+ user.TimeZoneSidKey = 'America/Los_Angeles';
+
+ insert user;
+ }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/TestUserExample.cls-meta.xml b/force-app/main/default/classes/TestUserExample.cls-meta.xml
new file mode 100644
index 0000000..45cccbd
--- /dev/null
+++ b/force-app/main/default/classes/TestUserExample.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+ <apiVersion>57.0</apiVersion>
+ <status>Active</status>
+</ApexClass>
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.html b/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.html
new file mode 100644
index 0000000..7a7eb78
--- /dev/null
+++ b/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.html
@@ -0,0 +1,75 @@
+<!-- sldsValidatorIgnore -->
+<!-- sldsValidatorIgnore -->
+<template>
+ <template if:true={isShowSpinner}>
+ <lightning-spinner size="large" alternative-text="Loading"></lightning-spinner>
+ </template>
+ <!-- 鏌ヨ瀹㈡埛鍚� -->
+ <template if:true={isShowSearchAccount}>
+ <c-lex-search-lookup-l-w-c title="瀹㈡埛鍚�" search-name-label="瀹㈡埛鍚�" onclose={closeHospitalNameModal}
+ onselectcontact={handleSelectContact} account-id={hospitalId}></c-lex-search-lookup-l-w-c>
+ </template>
+ <!-- 灞曠ず -->
+ 聽<lightning-quick-action-panel header={title}>
+ <lightning-record-edit-form object-api-name="Lead" record-type-id={recordTypeId} record-id={recordId}
+ onsubmit={handleSubmit} onsuccess={handleSuccess} onerror={handleError}>
+ <template for:each={layout} for:item="layoutSection">
+ <template if:true={layoutSection.useHeader}>
+ <lightning-accordion class="greyyyy" active-section-name={sectionName} allow-multiple-sections-open
+ key={layoutSection.name}>
+ <lightning-accordion-section name={layoutSection.name} label={layoutSection.name}>
+ <lightning-layout multiple-rows="true">
+ <template for:each={layoutSection.layoutFields} for:item="layoutField">
+ <lightning-layout-item class="hehe-layoutItem" size="6" key={layoutField.fieldAPI}>
+ <template if:false={layoutField.isModify}>
+ <lightning-input-field field-name={layoutField.fieldAPI}
+ value={layoutField.value} required={layoutField.isRequired}
+ data-field={layoutField.fieldAPI} disabled={layoutField.isDisable}
+ onchange={dataChange}>
+ </lightning-input-field>
+ </template>
+
+ <template if:true={layoutField.isModify}>
+ <template if:true={layoutField.isShowIcon}>
+ <div
+ class="slds-form-element__control slds-input-has-icon slds-input-has-icon_right">
+ <lightning-icon size="x-small"
+ class="iconMargin slds-icon slds-input__icon slds-input__icon_right slds-icon-text-default"
+ icon-name="utility:search"></lightning-icon>
+ <lightning-input label={layoutField.fieldLabel}
+ value={layoutField.value} required={layoutField.isRequired}
+ data-field={layoutField.fieldAPI}
+ disabled={layoutField.isDisable} variant="label-inline"
+ onchange={dataChange} onclick={searchHospitalNameModal}>
+ </lightning-input>
+ </div>
+
+ </template>
+
+ <template if:false={layoutField.isShowIcon}>
+ <lightning-input label={layoutField.fieldLabel}
+ value={layoutField.value} required={layoutField.isRequired}
+ data-field={layoutField.fieldAPI} disabled={layoutField.isDisable}
+ variant="label-inline" onchange={dataChange}
+ onclick={searchHospitalNameModal}>
+ </lightning-input>
+ </template>
+
+ </template>
+ </lightning-layout-item>
+ </template>
+ </lightning-layout>
+ </lightning-accordion-section>
+
+ </lightning-accordion>
+ </template>
+ </template>
+ <div class="slds-text-align_center">
+ <lightning-button label="淇濆瓨" type="submit" onsubmit={handleSubmit}
+ class="slds-m-right_x-small"></lightning-button>
+ <lightning-button label="鍙栨秷" onclick={cancel} class="slds-m-right_x-small"></lightning-button>
+ </div>
+ </lightning-record-edit-form>
+ </lightning-quick-action-panel>
+
+</template>
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js b/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js
new file mode 100644
index 0000000..1d01e83
--- /dev/null
+++ b/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js
@@ -0,0 +1,525 @@
+import { LightningElement, api, track, wire } from 'lwc';
+import { CurrentPageReference } from 'lightning/navigation';
+import initData from '@salesforce/apex/LexNewAndEditLeadPIPLController.initData';
+import queryAccount from '@salesforce/apex/LexNewAndEditLeadPIPLController.queryAccount';
+import { NavigationMixin } from 'lightning/navigation';
+import { AWSService } from 'c/piUtils';
+import { ShowToastEvent } from 'lightning/platformShowToastEvent';
+
+export default class LexNewAndEditLeadPIPL extends NavigationMixin(LightningElement) {
+ sobjectType = 'Lead';
+
+ @api recordId;
+ @wire(CurrentPageReference) pageRef;
+ @track recordData = {};
+ @track title;
+ @track recordTypeId = '';
+ @track isShowSpinner = true;
+ @track layout = [];
+ @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 contactAWSDataId = '';
+ @track txId = '';
+ @track isShowSearchAccount = false;
+ @track hospitalId = '';
+ @track contactId = '';
+ AWSService;
+
+ //濮撳悕
+ //@track lastName = '';
+
+ @track modifyObj = {};
+ modifyArray = ['LastName', 'Hospital_Name__c'];
+
+ 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 + ' pid = ' + this.pid + ' 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') {
+ let layout = JSON.parse(r.entity.layout);
+ console.log('layout = ' + JSON.stringify(layout));
+ this.layout = layout;
+ this.recordData = r.entity.data;
+ console.log('this.recordData = ' + JSON.stringify(this.recordData));
+ this.AWSDataId = r.entity.AWSDataId;
+ for (var s of layout) {
+ this.sectionName.push(s.name);
+ for (var c of s.layoutFields) {
+ c['isModify'] = false;
+ c['isDisable'] = !c.editableField;
+ //鍚嶅瓧锛屽彧鐣橪astName
+ if(c['fieldAPI'] == 'Name') {
+ c.fieldAPI = 'LastName';
+ c.fieldLabel = '濮撳悕'
+ c['isModify'] = true;
+ if(this.isEditMode){
+ c['value'] = this.recordData.LastName
+ }
+ }
+ //瀹㈡埛浜哄憳鍚嶏紝鍥犱负瑕佽繘琛岃仈鍔ㄥ拰瑙e瘑鎵�浠ュ彉涓烘櫘閫歩nput锛岃嚜宸辨帶鍒跺��
+ if(c['fieldAPI'] == 'Contact_Name__c'){
+ c['isModify'] = true;
+ c['isShowIcon'] = true;
+ if(this.isEditMode){
+ c['value'] = this.recordData.Contact_Name__r == null ? '' : this.recordData.Contact_Name__r.LastName;
+ this.contactId = this.recordData.Contact_Name__c == null ? '' : this.recordData.Contact_Name__c;
+ this.contactAWSDataId = this.recordData.Contact_Name__r == null ? '' : this.recordData.Contact_Name__r.AWS_Data_Id__c;
+ }
+ }
+ if(c['fieldAPI'] == 'Hospital_Name__c' && this.isEditMode){
+ this.hospitalId = this.recordData.Hospital_Name__r == null ? '' : this.recordData.Hospital_Name__r.Id;
+ }
+ }
+ }
+
+ this.AWSToSobjectMap = JSON.parse(JSON.stringify(r.entity.AWSToSobjectNonEncryptedMap));
+ this.staticResource = JSON.parse(r.entity.staticResource);
+ this.staticResourceContact = JSON.parse(r.entity.staticResourceContact);
+ this.recordTypeId = r.entity.recordTypeId;
+ //缂栬緫
+ if(this.isEditMode){
+ //瑙e瘑瀹㈡埛浜哄憳
+ this.queryContactName();
+ //瑙e瘑鎰忓悜鐨勫姞瀵嗗瓧娈�
+ this.queryLeadFromAWSIFS();
+ }
+ this.isShowSpinner = false;
+ } else {
+ this.isShowSpinner = false;
+ this.showToast('Error', r.Msg);
+ }
+ })
+ }
+
+ //瑙e瘑瀹㈡埛浜哄憳
+ queryContactName(){
+ var that = this;
+ this.AWSService.query(this.staticResourceContact.queryUrl,this.contactAWSDataId,function(data){
+ console.log('data = ' + JSON.stringify(data));
+ if (data.object) {
+ for (var s of that.layout) {
+ for (var c of s.layoutFields) {
+ if(c['fieldAPI'] == 'Contact_Name__c'){
+ c['value'] = data.object.lastName;
+ }
+ }
+ }
+ }
+ },this.staticResourceContact.token)
+ }
+
+ //瑙e瘑鎰忓悜鐨勫姞瀵嗗瓧娈�
+ queryLeadFromAWSIFS(){
+ var that = this;
+ debugger
+ this.AWSService.query(this.staticResource.queryUrl,this.AWSDataId,function(data){
+ console.log('queryLeadFromAWSIFS data = ' + JSON.stringify(data));
+ if (data.object) {
+ for (var s of that.layout) {
+ for (var c of s.layoutFields) {
+ for (let f in that.AWSToSobjectMap) {
+ debugger
+ 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];
+ }
+ }
+ }
+ // if(c['fieldAPI'] == 'LastName'){
+ // console.log('data.object.lastName = ' + data.object.lastName);
+ // c['value'] = data.object.lastName == null ? '' : data.object.lastName;
+ // that.modifyObj['LastName'] = data.object.lastName == null ? '' : data.object.lastName;
+ // console.log('this.modifyObj[LastName] = ' + that.modifyObj['LastName']);
+ // }
+ // if(c['fieldAPI'] == 'Phone'){
+ // console.log('data.object.phone = ' + data.object.phone);
+ // c['value'] = data.object.phone == null ? '' : data.object.phone;
+ // }
+ // if(c['fieldAPI'] == 'Email'){
+ // console.log('data.object.email = ' + data.object.email);
+ // c['value'] = data.object.email == null ? '' : data.object.email;
+ // }
+ }
+ }
+ }
+ },this.staticResource.token)
+ }
+
+ //鍙栨秷
+ cancel() {
+ console.log('cancel');
+ window.history.back();
+ }
+
+ //change浜嬩欢
+ dataChange(event) {
+ let fieldName = event.target.getAttribute("data-field");
+ let value = event.detail.value;
+ console.log("fieldName = " + fieldName + " value = " + event.detail.value);
+ for (var s of this.layout) {
+ for (var c of s.layoutFields) {
+ if(c.fieldAPI == fieldName){
+ console.log('c.fieldAPI = ' + c.fieldAPI);
+ c['value'] = value;
+ }
+ }
+ }
+ if(this.modifyArray.indexOf(fieldName) != -1){
+ switch(fieldName){
+ case "LastName":
+ this.modifyObj[fieldName] = value;
+ break;
+ case "Hospital_Name__c":
+ //闇�瑕佺粰鎴樼暐绉戝鍒嗙被鍜屽叕鍙歌祴鍊�
+ if(value != "000000000000000" && value != ''){
+ let ls = ['Department_Class__c'];
+ this.hospitalId = value;
+ this.setVlookup(ls,value+'');
+ }else{
+ //娓呯┖鎴樼暐绉戝鍒嗙被
+ this.clearVlookup();
+ }
+ break;
+ }
+
+ }
+ }
+
+ //鎴樼暐绉戝鍒嗙被鍜屽叕鍙歌祴鍊�
+ setVlookup(ls,hospitalId){
+ this.isShowSpinner = true;
+ console.log('ls = ' + JSON.stringify(ls));
+ console.log('hospitalId = ' + hospitalId);
+ queryAccount({
+ accountTypes : JSON.stringify(ls),
+ accountId : hospitalId
+ }).then((r) => {
+ r = JSON.parse(JSON.stringify(r));
+ console.log('r = ' + JSON.stringify(r));
+ if (r.status == 'Success') {
+ console.log('queryAccount success');
+
+ for (var s of this.layout) {
+ for (var c of s.layoutFields) {
+ if(c['fieldAPI'] == 'Department_Class__c'){
+ console.log('m = ' + JSON.stringify(r.entity.m))
+ if(JSON.stringify(r.entity.m) != '{}'){
+ c['value'] = r.entity.m.Department_Class__c.Id;
+ }
+ }
+ if(c['fieldAPI'] == 'Company'){
+ c['value'] = r.entity.account.Name;
+ }
+ }
+ }
+ //1.5绉掑悗灏嗕細璋冪敤鎵цremind()鍑芥暟
+ var that = this;
+ setTimeout(function() { that.isShowSpinner = false; }, 1500);
+ //this.isShowSpinner = false;
+ } else {
+ this.showToast('Error', r.Msg);
+ }
+ })
+ }
+
+ //娓呯┖鎴樼暐绉戝鍒嗙被
+ clearVlookup(){
+ console.log('clearVlookup')
+ for (var s of this.layout) {
+ for (var c of s.layoutFields) {
+ if(c['fieldAPI'] == 'Department_Class__c'){
+ c['value'] =''
+ }
+ }
+ }
+ //this.layout = [...this.layout];
+ }
+
+ //鎻愪氦淇濆瓨
+ 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);
+ fields['Contact_Name__c'] = this.contactId;
+ console.log('fields = ' + JSON.stringify(fields));
+
+ //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
+ //鏂板缓
+ debugger
+ if(this.isNewMode){
+ this.NewPIToAWS(payloadForNewPI,fields);
+ }
+ //缂栬緫
+ if(this.isEditMode){
+ this.UpdatePIToAWS(payloadForNewPI,fields);
+ }
+ }
+
+ //鎻愪氦淇濆瓨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]');
+ }
+ }
+ if (this.isNewMode) {
+ fields['AWS_Data_Id__c'] = result.object[0].dataId;
+ } else {
+ //鏇存柊
+ }
+ this.txId = result.txId;
+ console.log('this.txId = ' + this.txId);
+ console.log('PI After fields = ' + JSON.stringify(fields));
+ if(fields.RecordTypeId){
+ console.log('length = ' + JSON.stringify(fields.RecordTypeId.length));
+ fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1);
+ console.log('RecordTypeId = ' + JSON.stringify(fields['RecordTypeId']));
+ }
+ //淇濆瓨鍒板悗绔�
+ 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]');
+ }
+ }
+ if (this.isNewMode) {
+ fields['AWS_Data_Id__c'] = result.object[0].dataId;
+ } else {
+ //鏇存柊
+ 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) {
+ console.log('length = ' + JSON.stringify(fields.RecordTypeId.length));
+ fields['RecordTypeId'] = fields.RecordTypeId.substring(1, fields.RecordTypeId.length - 1);
+ console.log('RecordTypeId = ' + JSON.stringify(fields['RecordTypeId']));
+ }
+ //淇濆瓨鍒板悗绔�
+ 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))
+ });
+ }
+
+ //楠岃瘉瀛楁
+ validateFieldValueFormate() {
+ 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 = '';
+ for (var s of this.layout) {
+ for (var c of s.layoutFields) {
+ if(c.isRequired && c.editableField && (fields[c.fieldAPI] == null || fields[c.fieldAPI] == '')){
+ msg += ';' + c.fieldLabel;
+ }
+ }
+ }
+ 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);
+ }
+
+ //鏌ヨ瀹㈡埛浜哄憳鏍规嵁鍖婚櫌
+ searchHospitalNameModal(event){
+ let fieldName = event.target.getAttribute("data-field");
+ if(fieldName == 'Contact_Name__c'){
+ if(this.hospitalId == "000000000000000" || this.hospitalId == ''){
+ this.showToast('Error','璇峰厛閫夋嫨鍖婚櫌鍚�');
+ return
+ }
+ this.isShowSearchAccount = true;
+ }
+ }
+
+ //閫夋嫨瀹㈡埛浜哄憳鍚庤繘琛岃祴鍊�
+ handleSelectContact(event){
+ this.isShowSpinner = true;
+ console.log('enter handleSelectContact ');
+ const selectContact = event.detail;
+ console.log('selectContact = ' + JSON.stringify(selectContact))
+ for (var s of this.layout) {
+ for (var c of s.layoutFields) {
+ if(c['fieldAPI'] == 'Contact_Name__c'){
+ c['value'] = selectContact.data.medicalStaffFullName;
+ this.contactId = selectContact.data.sfRecordId;
+ console.log('this.contactId = ' + this.contactId);
+ console.log('selectContact.data.sfRecordId = ' + selectContact.data.sfRecordId);
+ console.log('c[value] = ' + c['value']);
+ }
+ if(c['fieldAPI'] == 'LastName'){
+ c['value'] = selectContact.data.medicalStaffFullName;
+ this.modifyObj['LastName'] = selectContact.data.medicalStaffFullName;
+ console.log('c[value] = ' + c['value']);
+ }
+ }
+ }
+ this.layout = [...this.layout];
+ this.isShowSpinner = false;
+ this.closeHospitalNameModal();
+ }
+
+ //鍏抽棴瀹㈡埛浜哄憳鏍规嵁鍖婚櫌妯℃�佹
+ closeHospitalNameModal(){
+ this.isShowSearchAccount = false;
+ }
+
+ //鏄剧ず淇℃伅
+ showToast(type, msg) {
+ this.isShowSpinner = false;
+ const event = new ShowToastEvent({
+ title: type,
+ variant: type,
+ message: msg
+ });
+ this.dispatchEvent(event);
+ }
+}
\ No newline at end of file
diff --git a/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js-meta.xml b/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js-meta.xml
new file mode 100644
index 0000000..915a434
--- /dev/null
+++ b/force-app/main/default/lwc/lexNewAndEditLeadPIPL/lexNewAndEditLeadPIPL.js-meta.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
+ <apiVersion>57.0</apiVersion>
+ <isExposed>true</isExposed>
+ <targets>
+ <target>lightning__AppPage</target>
+ <target>lightning__RecordPage</target>
+ <target>lightning__HomePage</target>
+ <target>lightning__RecordAction</target>
+ <target>lightningCommunity__Page_Layout</target>
+ </targets>
+</LightningComponentBundle>
\ No newline at end of file
diff --git a/force-app/main/default/pages/NewAndEditLead.page b/force-app/main/default/pages/NewAndEditLead.page
index 7737fed..6ed63ae 100644
--- a/force-app/main/default/pages/NewAndEditLead.page
+++ b/force-app/main/default/pages/NewAndEditLead.page
@@ -1,9 +1,10 @@
-<apex:page lightningStylesheets="true" standardController="Lead" extensions="NewAndEditLeadController" id="page">
+<apex:page standardController="Lead" extensions="NewAndEditLeadController" id="page" lightningStyleSheets="true">
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}" />
<apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}" />
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}" />
<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
+ <apex:slds />
<style>
.disabledbutton {
pointer-events: none;
--
Gitblit v1.9.1