import { LightningElement,api, track, wire } from 'lwc'; import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { NavigationMixin } from 'lightning/navigation'; import init from '@salesforce/apex/StartTradingController2.init'; import start from '@salesforce/apex/StartTradingController2.start'; export default class LexStartTrading extends LightningElement { @api recordId; IsLoading=true; Hospital_Name__c; Close_Forecasted_Date__c; Opp_Name_Search__c; begin_opp_name__c; Status; @wire(CurrentPageReference) getStateParameters(currentPageReference){ console.log("进入页面"); console.log(currentPageReference); if(currentPageReference){ const urvalue=currentPageReference.state.recordId; if(urvalue){ let str=`${urvalue}`; this.recordId=str; } } } connectedCallback(){ init({Id:this.recordId}).then(result=>{ console.log('init result==========',result); if(result!=null){ // 给参数赋值 this.Hospital_Name__c = result.Hospital_Name__c; this.Close_Forecasted_Date__c = result.Close_Forecasted_Date__c; this.Opp_Name_Search__c = result.Opp_Name_Search__c; this.begin_opp_name__c = result.begin_opp_name__c; this.Status = result.Status; // 执行判断 this.InquiryJudgment(); } }); // .catch(err=>{ // console.log("init error:"); // console.log(err); // }).finally(()=>{}); } InquiryJudgment(){ console.log('InquiryJudgment check'); let status_list = ['完毕','无需求','已有询价','確認済み','不要','开始询价']; let lead_status = this.Status; let that = this; if(this.Hospital_Name__c == ''){ this.showToast('病院名称を設定してください','error'); } else if (this.comparDate(this.Close_Forecasted_Date__c)) { this.showToast('预测OCSM签约日不能小于今天','error'); } else if (this.Opp_Name_Search__c == '' || !this.begin_opp_name__c == '' || status_list.indexOf(lead_status) !== -1) { this.showToast('已存在转化的询价或不需要转化询价','error'); } else{ console.log('start at: ' + this.recordId); start({Id:this.recordId}).then(result=>{ console.log('start result==========',result); if(result!=null){ this.showToast('已成功转化询价','success'); window.open('/lightning/r/Opportunity/'+result+'/view','_parent'); // this[NavigationMixin.GenerateUrl]({ // type: "standard_recordPage", // attributes: { // recordId: result, // objectApiName:"Opportunity", // actionName:"edit" // } // }).then(url => { // window.open(url,"_blank"); // }); } }); // .catch(err=>{ // console.log("start error:"); // console.log(err); // }).finally(()=>{}); } } comparDate(dateValue) { return new Date().getTime() >= new Date(dateValue).getTime() + 3600 * 1000 * 24; } showToast(msg,type) { const event = new ShowToastEvent({ title: '', message: msg, variant: type }); this.IsLoading = false; this.dispatchEvent(event); } }