import { LightningElement,api, track, wire } from 'lwc'; import init from '@salesforce/apex/RentalApplyCancleButtonController.initRentalApplyCanle' import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; export default class lexRentalApplyCanleButton extends LightningElement { @api recordId; Yi_loaner_arranged__c; Id; RA_Status__c; IsLoading=true; @wire(CurrentPageReference) getStateParameters(currentPageReference){ console.log("进入页面"); console.log(currentPageReference); if(currentPageReference){ const urvalue=currentPageReference.state.recordId; if(urvalue){ let str=`${urvalue}`; console.log('str'); console.log(str); this.recordId=str; } } } currentDay(){ var date=new Date(); var toDay=new Date(); toDay=''; toDay+=date.getFullYear()+'/'; toDay+=date.getMonth()+1+'/'; toDay+=date.getDate(); return toDay; } connectedCallback(){ Promise.all([ loadStyle(this, lwcCSS) ]); console.log(this.recordId); init({recordId:this.recordId}).then(result=>{ console.log(result); if(result!=null){ this.IsLoading=false; var a=new Array('a'); a.push('12'); console.log('a='+a); this.Yi_loaner_arranged__c=result.YiLoanerArranged; this.Id=result.Id; this.RA_Status__c=result.RAStatus; console.log("end"); console.log("RA_Status__c="+this.RA_Status__c); console.log("Yi_loaner_arranged__c="+this.Yi_loaner_arranged__c); this.cancelSubmit().then(res=>{ this.dispatchEvent(new CloseActionScreenEvent()); }); } }).catch(err=>{ console.log("error:"); console.log(err); }).finally(()=>{ }); } async cancelSubmit(){ console.log('进入方法'); if (this.RA_Status__c == "取消") { this.dispatchEvent(new CloseActionScreenEvent()); // alert("已经取消!"); this.showToast("已经取消!",'error'); return; } console.log("1 if end "); if (this.RA_Status__c == "删除" ) { this.dispatchEvent(new CloseActionScreenEvent()); // alert("已经删除!"); const event = new ShowToastEvent({ title: '提示信息', message:"已经删除!" }); this.showToast("已经删除!",'error'); return; } console.log('2 if end'); if(this.RA_Status__c == "已出库" || this.Yi_loaner_arranged__c > 0) { this.dispatchEvent(new CloseActionScreenEvent()); // alert("备品已经出库,不能取消!"); this.showToast("备品已经出库,不能取消!",'error'); return; } console.log("111111111111111111111111"); var raid = this.Id; console.log("raid="+raid) window.open("/apex/RentalApplyCancel?objId="+raid, 'RentalApplyCancel', 'width=800,height=280'); this.dispatchEvent(new CloseActionScreenEvent()); } showToast(msg,type) { if(type == 'success'){ const event = new ShowToastEvent({ message: msg, variant: type }); // this.updateRecordView(this.recordId); this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); }else{ const event = new ShowToastEvent({ message: msg, variant: type, mode: 'sticky' }); // this.updateRecordView(this.recordId); this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); } } }