| | |
| | | ({ |
| | | CallBackAction: function (component, action_name, para, callback) { |
| | | var action = component.get( |
| | | "c." + action_name.trimStart().replace("c.", "") |
| | | ); |
| | | if (para) { |
| | | action.setParams(para); |
| | | } |
| | | if (callback) { |
| | | action.setCallback(this, function (data) { |
| | | callback(data); |
| | | }); |
| | | } |
| | | |
| | | $A.enqueueAction(action); |
| | | }, |
| | | ShowToast: function (paras) { |
| | | var toastEvent = $A.get("e.force:showToast"); |
| | | toastEvent.setParams(paras); |
| | | toastEvent.fire(); |
| | | }, |
| | | AwsPost: function (postURL, data, callback, token) { |
| | | let payloadForNewPI = ""; |
| | | if (typeof data == "string") { |
| | | payloadForNewPI = data; |
| | | } else { |
| | | payloadForNewPI = JSON.stringify(data); |
| | | } |
| | | |
| | | AWSService.post( |
| | | postURL, |
| | | payloadForNewPI, |
| | | function (result) { |
| | | //this.insertCalloutLog(this.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(result),this.successStatus); |
| | | if (callback) callback(result); |
| | | }, |
| | | token |
| | | ); |
| | | }, |
| | | AwsGet: function (url, data, callback, token) { |
| | | if (typeof data == "string") { |
| | | url += data; |
| | | } else { |
| | | let i = 0; |
| | | for (let p in data) { |
| | | url += i++ ? "&" : "?"; |
| | | url += p + "=" + data[p]; |
| | | } |
| | | } |
| | | |
| | | AWSService.get( |
| | | url, |
| | | function (result) { |
| | | //this.insertCalloutLog(this.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(result),this.successStatus); |
| | | if (callback) callback(result); |
| | | }, |
| | | token |
| | | ); |
| | | }, |
| | | refreshTable: function ( |
| | | component, |
| | | event, |
| | | helper, |
| | | cols, |
| | | contactInfoList, |
| | | contactsInfo |
| | | ) { |
| | | let that = this; |
| | | let myTableDiv = document.getElementById("QueryResult"); |
| | | let table = document.createElement("TABLE"); |
| | | table.border = "1"; |
| | | table.id = "table"; |
| | | table.setAttribute( |
| | | "class", |
| | | "slds-table slds-table_cell-buffer slds-table_bordered" |
| | | ); |
| | | let tableBody = document.createElement("TBODY"); |
| | | table.appendChild(tableBody); |
| | | let headerTR = document.createElement("TR"); |
| | | headerTR.setAttribute("class", "slds-line-height_reset"); |
| | | let colsHeader = ["姓名", "医院", "医生区分(职务)", "分类"]; |
| | | tableBody.appendChild(headerTR); |
| | | for (let i = 0; i < colsHeader.length; i++) { |
| | | let td = document.createElement("TH"); |
| | | td.width = "75"; |
| | | td.setAttribute("class", "slds-truncate"); |
| | | td.appendChild(document.createTextNode(colsHeader[i])); |
| | | headerTR.appendChild(td); |
| | | } |
| | | //3. Init the AWS data |
| | | for (let i = 0; i < contactInfoList.length; i++) { |
| | | let tr = document.createElement("TR"); |
| | | tableBody.appendChild(tr); |
| | | let contactInfoTemp = contactInfoList[i]; |
| | | for (let j = 0; j < cols.length; j++) { |
| | | let td = document.createElement("TD"); |
| | | td.width = "75"; |
| | | if (contactInfoTemp.pi) { |
| | | if (!contactsInfo.hasOwnProperty(contactInfoTemp.AWSDataId)) { |
| | | continue; |
| | | } |
| | | if (j == 0 && contactsInfo[contactInfoTemp.AWSDataId]) { |
| | | td.id = contactsInfo[contactInfoTemp.AWSDataId].Id; |
| | | } |
| | | } else { |
| | | td.id = contactInfoTemp.sfRecordId; |
| | | CallBackAction : function(component,action_name,para,callback) { |
| | | var action = component.get("c." + action_name.trimStart().replace("c.","")); |
| | | if(para){ |
| | | action.setParams(para); |
| | | } |
| | | td.appendChild( |
| | | document.createTextNode( |
| | | contactInfoTemp[cols[j]] != null ? contactInfoTemp[cols[j]] : "" |
| | | ) |
| | | ); |
| | | if (cols[j] == "Name") { |
| | | td.addEventListener("click", function (obj) { |
| | | that.redirectToParentPage(component, event, helper, obj); |
| | | }); |
| | | if(callback){ |
| | | action.setCallback(this,function(data){ |
| | | callback(data); |
| | | }); |
| | | } |
| | | tr.appendChild(td); |
| | | } |
| | | } |
| | | myTableDiv.appendChild(table); |
| | | component.find("button").set("v.disabled", false); |
| | | }, |
| | | redirectToParentPage: function (component, event, helper, obj) { |
| | | let agencyContactName = obj.currentTarget.innerText; |
| | | let id = obj.currentTarget.id; |
| | | component.set("v.ac_name", agencyContactName); |
| | | let layout = component.get("v.layout"); |
| | | for (let s of layout) { |
| | | for (let c of s.layoutColumns) { |
| | | for (let item of c.layoutItems) { |
| | | if (item.field == "Agency_Contact__c") { |
| | | item.value = id; |
| | | } |
| | | |
| | | $A.enqueueAction(action); |
| | | }, |
| | | ShowToast : function(paras){ |
| | | var toastEvent = $A.get("e.force:showToast"); |
| | | toastEvent.setParams(paras); |
| | | toastEvent.fire(); |
| | | }, |
| | | AwsPost : function(postURL, data ,callback,token){ |
| | | let payloadForNewPI = ''; |
| | | if(typeof(data) == 'string'){ |
| | | payloadForNewPI = data; |
| | | }else{ |
| | | payloadForNewPI = JSON.stringify(data); |
| | | } |
| | | } |
| | | } |
| | | component.set("v.isModalOpen", false); |
| | | }, |
| | | resetTable: function () { |
| | | let queryResult = document.getElementById("QueryResult"); |
| | | let table = document.getElementsByTagName("table"); |
| | | if (table.length > 1) { |
| | | for (var i = 1; i < table.length; i++) { |
| | | queryResult.removeChild(table[i]); |
| | | } |
| | | } |
| | | }, |
| | | preparePayloadForSearchAgencyContact: function (component, event, helper) { |
| | | let that = this; |
| | | let agencyHospitalId = ""; |
| | | let accountId = ""; |
| | | let layout = component.get("v.layout"); |
| | | for (let s of layout) { |
| | | for (let c of s.layoutColumns) { |
| | | for (let item of c.layoutItems) { |
| | | if (item.field == "Agency_Hospital__c") { |
| | | agencyHospitalId = item.value; |
| | | } |
| | | if (item.field == "Account_Opp__c") { |
| | | accountId = item.value; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | var action = component.get("c.getAWSDataIds"); |
| | | action.setParams({ |
| | | agencyHospitalId: agencyHospitalId, |
| | | accountId: accountId |
| | | }); |
| | | action.setCallback(this, function (response) { |
| | | var state = response.getState(); |
| | | if (state == "SUCCESS") { |
| | | var rv = response.getReturnValue(); |
| | | if (rv.Data.length == 0) { |
| | | component.find("button").set("v.disabled", false); |
| | | helper.ShowToast({ |
| | | message: "该经销商医院下面没有客户人员", |
| | | type: "warning" |
| | | }); |
| | | return; |
| | | } |
| | | let searchPayload = new Object(); |
| | | let searchAgencyContactName = component.get("v.searchKeyWord"); |
| | | searchPayload.dataIds = rv.Data; |
| | | searchPayload.name = searchAgencyContactName; |
| | | component.set("v.contactAWSIds", rv.Data); |
| | | let staticResource = component.get("v.staticResource"); |
| | | let url = staticResource.searchUrl; |
| | | let token = staticResource.token; |
| | | this.AwsPost( |
| | | url, |
| | | searchPayload, |
| | | function (data) { |
| | | if (data.success) { |
| | | let cols = ["Name", "AgencyHospital", "DoctorDivision1", "Type"]; |
| | | let contactInfoList = []; |
| | | let awsDataIds = []; |
| | | if (data.object.length == 0) { |
| | | component.find("button").set("v.disabled", false); |
| | | that.ShowToast({ |
| | | message: "没有查询到该客户人员", |
| | | type: "warning" |
| | | }); |
| | | return; |
| | | } |
| | | for (var i = 0; i < data.object.length; i++) { |
| | | if (data.object[i].dataId) { |
| | | let contactInfo = new Object(); |
| | | //需要修改 |
| | | contactInfo.Name = data.object[i].name; |
| | | contactInfo.AgencyHospital = ""; |
| | | contactInfo.DoctorDivision1 = data.object[i].doctorDivision1; |
| | | contactInfo.AWSDataId = data.object[i].dataId; |
| | | contactInfo.Type = data.object[i].type; |
| | | contactInfo.pi = true; |
| | | awsDataIds.push(contactInfo.AWSDataId); |
| | | contactInfo.sfRecordId = ""; |
| | | contactInfoList.push(contactInfo); |
| | | } |
| | | } |
| | | //let AWSIdToSFIdMapValue = {}; |
| | | var searchAgencyContacts = component.get( |
| | | "c.searchAgencyContacts" |
| | | ); |
| | | searchAgencyContacts.setParams({ |
| | | awsAgencyContactIds: JSON.stringify(awsDataIds), |
| | | agencyHospitalId: agencyHospitalId, |
| | | accountId: accountId |
| | | }); |
| | | searchAgencyContacts.setCallback(this, function (response) { |
| | | var state = response.getState(); |
| | | if (state == "SUCCESS") { |
| | | var rv = response.getReturnValue(); |
| | | if (rv.IsSuccess) { |
| | | let contactsInfo = ""; |
| | | if (rv.Data) { |
| | | contactsInfo = JSON.parse( |
| | | rv.Data.replace(/("\;)/g, '"') |
| | | ); |
| | | if (Object.keys(contactsInfo).length > 0) { |
| | | for (let i = 0; i < contactInfoList.length; i++) { |
| | | let contactFromSF = |
| | | contactsInfo[contactInfoList[i]["AWSDataId"]]; |
| | | if (contactFromSF) { |
| | | contactInfoList[i].sfRecordId = contactFromSF["Id"]; |
| | | if (contactFromSF["Agency_Hospital__r"]) { |
| | | contactInfoList[i].AgencyHospital = |
| | | contactFromSF["Agency_Hospital__r"]["Name"]; |
| | | } |
| | | if (contactFromSF["Department_Class__r"]) { |
| | | contactInfoList[i].AgencyHospital = |
| | | contactFromSF["Department_Class__r"]["Parent"][ |
| | | "Name" |
| | | ]; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | that.refreshTable( |
| | | component, |
| | | event, |
| | | helper, |
| | | cols, |
| | | contactInfoList, |
| | | contactsInfo |
| | | ); |
| | | } |
| | | } |
| | | }); |
| | | $A.enqueueAction(searchAgencyContacts); |
| | | |
| | | AWSService.post(postURL,payloadForNewPI,function(result) { |
| | | //this.insertCalloutLog(this.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(result),this.successStatus); |
| | | if(callback) callback(result); |
| | | },token); |
| | | }, |
| | | AwsGet : function(url, data ,callback,token){ |
| | | |
| | | if(typeof(data) == 'string'){ |
| | | url += data; |
| | | }else{ |
| | | let i = 0; |
| | | for(let p in data){ |
| | | url += (i++) ? '&' : '?'; |
| | | url += p + '=' + data[p]; |
| | | } |
| | | }, |
| | | token |
| | | ); |
| | | } |
| | | }); |
| | | $A.enqueueAction(action); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | AWSService.get(url,function(result){ |
| | | //this.insertCalloutLog(this.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(result),this.successStatus); |
| | | if(callback) callback(result); |
| | | },token); |
| | | }, |
| | | refreshTable : function(component, event, helper,cols,contactInfoList,contactsInfo){ |
| | | let that = this; |
| | | let myTableDiv = document.getElementById("QueryResult"); |
| | | let table = document.createElement('TABLE'); |
| | | table.border = '1'; |
| | | table.id = 'table'; |
| | | table.setAttribute('class','slds-table slds-table_cell-buffer slds-table_bordered'); |
| | | let tableBody = document.createElement('TBODY'); |
| | | table.appendChild(tableBody); |
| | | let headerTR = document.createElement('TR'); |
| | | headerTR.setAttribute('class','slds-line-height_reset'); |
| | | let colsHeader = ['姓名','医院', '医生区分(职务)','分类']; |
| | | tableBody.appendChild(headerTR); |
| | | for (let i = 0; i < colsHeader.length; i++) { |
| | | let td = document.createElement('TH'); |
| | | td.width = '75'; |
| | | td.setAttribute('class','slds-truncate slds-border_right'); |
| | | td.appendChild(document.createTextNode(colsHeader[i])); |
| | | headerTR.appendChild(td); |
| | | } |
| | | //3. Init the AWS data |
| | | for (let i = 0; i < contactInfoList.length; i++) { |
| | | let tr = document.createElement('TR'); |
| | | tableBody.appendChild(tr); |
| | | let contactInfoTemp = contactInfoList[i] |
| | | for (let j = 0; j < cols.length; j++) { |
| | | let td = document.createElement('TD'); |
| | | td.width = '75'; |
| | | if(contactInfoTemp.pi){ |
| | | if (!contactsInfo.hasOwnProperty(contactInfoTemp.AWSDataId)) { |
| | | continue; |
| | | } |
| | | if(j == 0 && contactsInfo[contactInfoTemp.AWSDataId] ){ |
| | | td.id = contactsInfo[contactInfoTemp.AWSDataId].Id; |
| | | } |
| | | }else{ |
| | | td.id = contactInfoTemp.sfRecordId; |
| | | } |
| | | td.appendChild(document.createTextNode(contactInfoTemp[cols[j]]!=null?contactInfoTemp[cols[j]]:'')); |
| | | if (cols[j] == 'Name') { |
| | | td.addEventListener("click", function (obj) { |
| | | that.redirectToParentPage(component, event, helper,obj); |
| | | }); |
| | | } |
| | | tr.appendChild(td); |
| | | } |
| | | } |
| | | myTableDiv.appendChild(table); |
| | | component.find('button').set('v.disabled', false); |
| | | }, |
| | | redirectToParentPage : function(component, event, helper,obj){ |
| | | let agencyContactName = obj.currentTarget.innerText; |
| | | let id = obj.currentTarget.id; |
| | | component.set('v.ac_name',agencyContactName); |
| | | let layout = component.get('v.layout'); |
| | | for(let s of layout){ |
| | | for(let c of s.layoutColumns){ |
| | | for(let item of c.layoutItems){ |
| | | if(item.field == 'Agency_Contact__c'){ |
| | | item.value = id; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | component.set("v.isModalOpen", false); |
| | | }, |
| | | resetTable : function(){ |
| | | let queryResult = document.getElementById('QueryResult'); |
| | | let table = document.getElementsByTagName('table'); |
| | | debugger; |
| | | console.log('table:' + table); |
| | | debugger; |
| | | if(table.length > 1){ |
| | | for(var i=1;i<table.length;i++){ |
| | | queryResult.removeChild(table[i]) |
| | | } |
| | | } |
| | | }, |
| | | preparePayloadForSearchAgencyContact : function(component, event, helper){ |
| | | let that = this; |
| | | let agencyHospitalId = ''; |
| | | let accountId = ''; |
| | | let layout = component.get('v.layout'); |
| | | for(let s of layout){ |
| | | for(let c of s.layoutColumns){ |
| | | for(let item of c.layoutItems){ |
| | | if(item.field == 'Agency_Hospital__c'){ |
| | | agencyHospitalId = item.value; |
| | | } |
| | | if(item.field == 'Account_Opp__c'){ |
| | | accountId = item.value; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | var action = component.get('c.getAWSDataIds'); |
| | | action.setParams({ |
| | | "agencyHospitalId" : agencyHospitalId, |
| | | "accountId" : accountId |
| | | }); |
| | | action.setCallback(this,function(response){ |
| | | var state = response.getState(); |
| | | if(state == 'SUCCESS'){ |
| | | var rv = response.getReturnValue(); |
| | | if(rv.Data.length == 0){ |
| | | component.find('button').set('v.disabled', false); |
| | | helper.ShowToast({ |
| | | "message" : "该经销商医院下面没有客户人员", |
| | | "type" : "warning" |
| | | }); |
| | | return |
| | | } |
| | | let searchPayload = new Object(); |
| | | let searchAgencyContactName = component.get('v.searchKeyWord'); |
| | | searchPayload.dataIds = rv.Data; |
| | | searchPayload.name = searchAgencyContactName; |
| | | component.set('v.contactAWSIds',rv.Data); |
| | | let staticResource = component.get('v.staticResource'); |
| | | let url = staticResource.searchUrl; |
| | | let token = staticResource.token; |
| | | this.AwsPost(url,searchPayload,function(data){ |
| | | if(data.success){ |
| | | let cols = ['Name','AgencyHospital', 'DoctorDivision1','Type']; |
| | | let contactInfoList = []; |
| | | let awsDataIds = []; |
| | | if(data.object.length == 0){ |
| | | component.find('button').set('v.disabled', false); |
| | | that.ShowToast({ |
| | | "message" : '没有查询到该客户人员', |
| | | "type" : "warning" |
| | | }); |
| | | return |
| | | } |
| | | for(var i=0;i<data.object.length;i++){ |
| | | if(data.object[i].dataId){ |
| | | let contactInfo = new Object(); |
| | | //需要修改 |
| | | contactInfo.Name = data.object[i].name; |
| | | contactInfo.AgencyHospital = ''; |
| | | contactInfo.DoctorDivision1 = data.object[i].doctorDivision1; |
| | | contactInfo.AWSDataId = data.object[i].dataId; |
| | | contactInfo.Type = data.object[i].type; |
| | | contactInfo.pi = true; |
| | | awsDataIds.push(contactInfo.AWSDataId); |
| | | contactInfo.sfRecordId = ''; |
| | | contactInfoList.push(contactInfo); |
| | | } |
| | | } |
| | | //let AWSIdToSFIdMapValue = {}; |
| | | var searchAgencyContacts = component.get('c.searchAgencyContacts'); |
| | | searchAgencyContacts.setParams({ |
| | | "awsAgencyContactIds" : JSON.stringify(awsDataIds), |
| | | "agencyHospitalId" : agencyHospitalId, |
| | | "accountId" : accountId |
| | | }); |
| | | searchAgencyContacts.setCallback(this,function(response){ |
| | | var state = response.getState(); |
| | | if(state == 'SUCCESS'){ |
| | | var rv = response.getReturnValue(); |
| | | if(rv.IsSuccess){ |
| | | let contactsInfo = ''; |
| | | if(rv.Data){ |
| | | contactsInfo = JSON.parse(rv.Data.replace(/("\;)/g,"\"")); |
| | | if(Object.keys(contactsInfo).length>0){ |
| | | for(let i=0;i<contactInfoList.length;i++){ |
| | | let contactFromSF = contactsInfo[contactInfoList[i]['AWSDataId']]; |
| | | if(contactFromSF){ |
| | | contactInfoList[i].sfRecordId = contactFromSF['Id']; |
| | | if(contactFromSF['Agency_Hospital__r']){ |
| | | contactInfoList[i].AgencyHospital = contactFromSF['Agency_Hospital__r']['Name']; |
| | | } |
| | | if(contactFromSF['Department_Class__r']){ |
| | | contactInfoList[i].AgencyHospital = contactFromSF['Department_Class__r']['Parent']['Name']; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | that.refreshTable(component, event, helper,cols,contactInfoList,contactsInfo); |
| | | } |
| | | } |
| | | }); |
| | | $A.enqueueAction(searchAgencyContacts); |
| | | } |
| | | },token); |
| | | } |
| | | }); |
| | | $A.enqueueAction(action); |
| | | } |
| | | }) |