import { LightningElement, track, wire, api } from 'lwc'; import LightningConfirm from 'lightning/confirm'; import {CurrentPageReference,NavigationMixin} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import cancelApply from '@salesforce/apex/TransferApplyWebService.cancelApply'; export default class lexCancelApply extends LightningElement { @api recordId; IsLoading=true; cancelResult; @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; } } } connectedCallback() { console.log('this.raeSetId:' + this.recordId); LightningConfirm.open({ message: '确定取消?', variant: 'headerless', label: 'this is the aria-label value', }).then(cancel=>{ // this.IsLoading=false; // this.dispatchEvent(new CloseActionScreenEvent()); if(cancel) { cancelApply({ taId : this.recordId }).then(result => { this.cancelResult = result; this.cancelSubmit().then(res=>{ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); }).catch( error =>{ console.log(error); }).finally(()=>{ }); } }); } async cancelSubmit(){ if(this.cancelResult == '1') { await this.showToast("",'取消成功',"success"); window.location.href = window.location; } else { console.log("result:",this.cancelResult); await this.showToast("",this.cancelResult,"warning"); } } showToast(_title,_message,_variant) { const event = new ShowToastEvent({ title: _title, message:_message, variant: _variant, }); this.dispatchEvent(event); } } //old js // {!REQUIRESCRIPT('/soap/ajax/51.0/connection.js')} // {!REQUIRESCRIPT('/soap/ajax/51.0/apex.js')} // if (confirm("确定取消?")) { // var rs = sforce.apex.execute("TransferApplyWebService","cancelApply",{taId:'{!TransferApply__c.Id}'}); // if(rs == '1'){ // alert('取消成功'); // window.location.href = window.location; // } // else{ // alert(rs); // } // }