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 lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; 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() { Promise.all([ loadStyle(this, lwcCSS) ]); console.log('this.raeSetId:' + this.recordId); LightningConfirm.open({ message: '确定取消?', variant: 'headerless', label: 'this is the aria-label value', }).then(cancel=>{ 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(()=>{ }); } else { this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); } }); } async cancelSubmit(){ if(this.cancelResult == '1') { await this.showToast('取消成功',"success"); setTimeout(function(){ window.location.href = window.location; }, 1500 ) } else { console.log("result:",this.cancelResult); await this.showToast(this.cancelResult,"warning"); } } showToast(msg, type) { if(type == 'success'){ const event = new ShowToastEvent({ message: msg, variant: type }); this.dispatchEvent(event); }else{ const event = new ShowToastEvent({ message: msg, variant: type, mode: 'sticky' }); 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); // } // }