From bdb1a98b64a2cf59bcfd575c579aa0742e0de954 Mon Sep 17 00:00:00 2001
From: chenjingwu <chenjingwu@prec-tech.com>
Date: 星期五, 24 五月 2024 17:21:32 +0800
Subject: [PATCH] 1
---
force-app/main/default/lwc/lexNewOpportunityAgency/lexNewOpportunityAgency.js | 161 ++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 120 insertions(+), 41 deletions(-)
diff --git a/force-app/main/default/lwc/lexNewOpportunityAgency/lexNewOpportunityAgency.js b/force-app/main/default/lwc/lexNewOpportunityAgency/lexNewOpportunityAgency.js
index 9b6cfc7..41650dc 100644
--- a/force-app/main/default/lwc/lexNewOpportunityAgency/lexNewOpportunityAgency.js
+++ b/force-app/main/default/lwc/lexNewOpportunityAgency/lexNewOpportunityAgency.js
@@ -7,7 +7,12 @@
import queryForRecords from '@salesforce/apex/OpportunityLightingButtonController.queryForNewOpportunityAgencyButtonToRecords';
import queryForRecTypeList from '@salesforce/apex/OpportunityLightingButtonController.queryForNewOpportunityAgencyButtonToRecTypeList';
import queryForRecords2 from '@salesforce/apex/OpportunityLightingButtonController.queryForNewOpportunityAgencyButtonToRecords2';
-export default class LexNewOpportunityAgency extends LightningElement {
+import { NavigationMixin } from 'lightning/navigation';
+import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
+import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
+import {loadStyle} from 'lightning/platformResourceLoader';
+
+export default class LexNewOpportunityAgency extends NavigationMixin(LightningElement) {
@api recordId;
agency1Id;
agencyOpportunity;
@@ -39,6 +44,10 @@
}
}
connectedCallback(){
+ Promise.all([
+ loadStyle(this, lwcCSS)
+ ]);
+
init({
recordId: this.recordId
}).then(result=>{
@@ -57,6 +66,22 @@
this.opportunityCategory = result.opportunityCategory;
this.agency1Name = result.agency1Name;
console.log("1");
+ if(this.closeForecastedDate == undefined){
+ this.closeForecastedDate = '';
+ }else{
+ this.closeForecastedDate = new String(this.closeForecastedDate).replaceAll("-","/");
+ }
+ console.log(this.closeForecastedDate);
+ if(this.bidPlannedDate == undefined){
+ this.bidPlannedDate = '';
+ }else{
+ this.bidPlannedDate = new String(this.bidPlannedDate).replaceAll("-","/");
+ }
+ if(this.dealerFinalPrice == undefined){
+ this.dealerFinalPrice = '';
+ }
+ console.log(this.bidPlannedDate);
+ console.log(this.dealerFinalPrice);
this.newOpportunityAgency();
}).catch(error=>{
console.log("error");
@@ -69,15 +94,18 @@
var newflag = true;
if (this.agency1Id == undefined) {
newflag = false;
- alert("缁忛攢鍟嗕笉瀛樺湪锛屼笉鑳借浆鎴愩�愮粡閿�鍟嗙洰鏍囪浠枫�戙��");
+ this.showToast("缁忛攢鍟嗕笉瀛樺湪锛屼笉鑳借浆鎴愩�愮粡閿�鍟嗙洰鏍囪浠枫�戙��","error");
+ this.dispatchEvent(new CloseActionScreenEvent());
}
else if (this.agencyOpportunity != undefined) {
newflag = false;
- alert("宸茬粡杞垚杩囥�愮粡閿�鍟嗙洰鏍囪浠枫�戙��");
+ this.showToast("宸茬粡杞垚杩囥�愮粡閿�鍟嗙洰鏍囪浠枫�戙��","error");
+ this.dispatchEvent(new CloseActionScreenEvent());
}
else if (this.trade != '鍐呰部') {
newflag = false;
- alert("涓嶆槸鍐呰锤锛屼笉鑳借浆鎴愩�愮粡閿�鍟嗙洰鏍囪浠枫�戙��");
+ this.showToast("涓嶆槸鍐呰锤锛屼笉鑳借浆鎴愩�愮粡閿�鍟嗙洰鏍囪浠枫�戙��","error");
+ this.dispatchEvent(new CloseActionScreenEvent());
}
else {
var records = null;
@@ -87,9 +115,11 @@
hospitalId: this.hospitalId
}).then(result=>{
records = result;
+ console.log(records.length);
if (records == null || records.length == 0) {
newflag = false;
- alert("娌℃湁鏈夋晥鐨勩�愮粡閿�鍟嗗尰闄€�戙��");
+ this.showToast("娌℃湁鏈夋晥鐨勩�愮粡閿�鍟嗗尰闄€�戙��","error");
+ this.dispatchEvent(new CloseActionScreenEvent());
}
if (newflag) {
console.log("5");
@@ -101,7 +131,8 @@
console.log("6");
var recTypeList = result;
if (recTypeList.length == 0) {
- alert("娌℃湁鎵惧埌锛岀粡閿�鍟嗚浠风殑瀹氫箟銆�");
+ this.showToast("娌℃湁鎵惧埌锛岀粡閿�鍟嗚浠风殑瀹氫箟銆�","error");
+ this.dispatchEvent(new CloseActionScreenEvent());
} else {
console.log("7");
queryForRecords2({
@@ -154,33 +185,73 @@
console.log("10");
console.log(records[0]);
var ahl = records[0];
+
try {
- var url = "/a2Y/e?retURL=%2F"
- + this.recordId
- + "&Name='(OLYMPUS)'"
- + encodeURIComponent(this.name)
- + "&RecordType=" + recTypeId + "&" + fId_Close_Forecasted_Date__c + "="
- + encodeURIComponent(this.closeForecastedDate)
- + "&" + fId_Bid_Planned_Date__c + "="
- + encodeURIComponent(this.bidPlannedDate)
- + "&" + fId_OCM_Change_To_Opportunity_Flg__c + "=1" + "&CF" + fId_Agency_Hospital__c + "_lkid=" + ahl.Id + "&CF" + fId_Agency_Hospital__c + "=" + encodeURIComponent(ahl.Name) + "&" + fId_Amount__c + "="
- + encodeURIComponent(this.dealerFinalPrice)
- + "&" + fId_OCMSale_Price__c + "="
- + encodeURIComponent(this.wholesalePrice)
- + "&CF" + fId_Agency__c + "_lkid="
- + encodeURIComponent(this.agency1Id)
- + "&CF" + fId_Agency__c + "="
- + encodeURIComponent(this.agency1Name)
- + "&" + fId_StageName__c + "="
- + encodeURIComponent(this.opportunityStage)
- + "&CF" + fId_Change_To_Opportunity__c + "_lkid="
- + encodeURIComponent(this.recordId )
- + "&CF" + fId_Change_To_Opportunity__c + "="
- + encodeURIComponent(this.name )
- + "&" + fId_Department_Cateogy__c + "="
- + encodeURIComponent(this.opportunityCategory);
- console.log(url);
- window.open(url);
+ // var url = "/a2Y/e?retURL=%2F"
+ // + this.recordId
+ // + "&Name='(OLYMPUS)'"
+ // + encodeURIComponent(this.name)
+ // + "&RecordType=" + recTypeId + "&" + fId_Close_Forecasted_Date__c + "="
+ // + encodeURIComponent(this.closeForecastedDate)
+ // + "&" + fId_Bid_Planned_Date__c + "="
+ // + encodeURIComponent(this.bidPlannedDate)
+ // + "&" + fId_OCM_Change_To_Opportunity_Flg__c + "=1" + "&CF" + fId_Agency_Hospital__c + "_lkid=" + ahl.Id + "&CF" + fId_Agency_Hospital__c + "=" + encodeURIComponent(ahl.Name) + "&" + fId_Amount__c + "="
+ // + encodeURIComponent(this.dealerFinalPrice)
+ // + "&" + fId_OCMSale_Price__c + "="
+ // + encodeURIComponent(this.wholesalePrice)
+ // + "&CF" + fId_Agency__c + "_lkid="
+ // + encodeURIComponent(this.agency1Id)
+ // + "&CF" + fId_Agency__c + "="
+ // + encodeURIComponent(this.agency1Name)
+ // + "&" + fId_StageName__c + "="
+ // + encodeURIComponent(this.opportunityStage)
+ // + "&CF" + fId_Change_To_Opportunity__c + "_lkid="
+ // + encodeURIComponent(this.recordId )
+ // + "&CF" + fId_Change_To_Opportunity__c + "="
+ // + encodeURIComponent(this.name )
+ // + "&" + fId_Department_Cateogy__c + "="
+ // + encodeURIComponent(this.opportunityCategory);
+ // console.log(url);
+ // window.open(url);
+ if(this.closeForecastedDate){
+ if(!this.closeForecastedDate.includes(' ')){
+ this.closeForecastedDate += ' 00:00:00'
+ }
+ this.closeForecastedDate = this.closeForecastedDate.replace(' ','T').replaceAll('/','-') + '.000Z';
+ console.log(this.closeForecastedDate);
+ }
+ if(this.bidPlannedDate){
+ if(!this.bidPlannedDate.includes(' ')){
+ this.bidPlannedDate += ' 00:00:00'
+ }
+ this.bidPlannedDate = this.bidPlannedDate.replace(' ','T').replaceAll('/','-') + '.000Z';
+ }
+ const defaultValues = encodeDefaultFieldValues({
+ Name: '(OLYMPUS)' + this.name,
+ Close_Forecasted_Date__c: this.closeForecastedDate,
+ Bid_Planned_Date__c: this.bidPlannedDate,
+ OCM_Change_To_Opportunity_Flg__c: '1',
+ Agency_Hospital__c: ahl.Id,
+ Amount__c: this.dealerFinalPrice,
+ OCMSale_Price__c: this.wholesalePrice,
+ Agency__c: this.agency1Id,
+ StageName__c: this.opportunityStage,
+ Change_To_Opportunity__c: this.recordId,
+ Department_Cateogy__c: this.opportunityCategory
+ });
+ this[NavigationMixin.Navigate]({
+ type: 'standard__objectPage',
+ attributes: {
+ objectApiName: 'Agency_Opportunity__c',
+ actionName: 'new'
+ },
+ state: {
+ nooverride: '1',
+ defaultFieldValues: defaultValues,
+ recordTypeId: recTypeId
+ }
+ });
+ this.dispatchEvent(new CloseActionScreenEvent());
} catch (error) {
console.log(error)
}
@@ -189,20 +260,28 @@
})
}
});
- console.log("4");
}
this.IsLoading = false;
- this.dispatchEvent(new CloseActionScreenEvent());
}
showToast(msg,type) {
- const event = new ShowToastEvent({
- title: '',
- message: msg,
- variant: type
- });
- this.dispatchEvent(event);
+ if(type == 'success'){
+ const event = new ShowToastEvent({
+ message: msg,
+ variant: type,
+ });
+ this.dispatchEvent(event);
+ this.dispatchEvent(new CloseActionScreenEvent());
+ }else{
+ const event = new ShowToastEvent({
+ message: msg,
+ variant: type,
+ mode: 'sticky'
+ });
+ this.dispatchEvent(event);
+ this.dispatchEvent(new CloseActionScreenEvent());
+ }
}
updateRecordView(recordId) {
updateRecord({fields: { Id: recordId }});
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.1