import { LightningElement, track, wire,api } from 'lwc'; import {CurrentPageReference,NavigationMixin} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import LightningConfirm from 'lightning/confirm'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import applyPermission from '@salesforce/apex/TransferApplyController.applyPermission'; import submitApply from '@salesforce/apex/TransferApplyWebService.submitApply'; export default class lexSubmitApprovalProcess extends LightningElement { @api recordId; transferApplyPermission; IsLoading=true; @wire(CurrentPageReference) getStateParameters(currentPageReference) { console.log(currentPageReference); if(currentPageReference) { const urlValue = currentPageReference.state.recordId; if(urlValue) { let str = `${urlValue}`; console.log("str"); console.log(str); this.recordId = str; } } } connectedCallback() { console.log('this.transferApplyId:' + this.recordId); applyPermission().then(result => { console.log(result); this.transferApplyPermission = result; this.cancelSubmit(); }).catch( error =>{ console.log(error); }); } cancelSubmit(){ if (this.transferApplyPermission == false) { this.showToast('','没有提交申请的权限','warning'); } else{ LightningConfirm.open({ message: '一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?', variant: 'headerless', }).then(cancel=>{ if(cancel) { submitApply({taId:this.recordId}).then(submitRes=>{ if(submitRes == '1'){ this.showToast('','提交成功','success'); window.location.href = window.location; }else{ this.showToast("",submitRes,"warning"); } this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } }); } } 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')} var result = sforce.connection.describeSObject('TransferApply__c'); if (result.createable == 'false') { alert('没有提交申请的权限'); } else{ if (confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) { var rs = sforce.apex.execute("TransferApplyWebService","submitApply",{taId:'{!TransferApply__c.Id}'}); if(rs == '1'){ alert('提交成功'); window.location.href = window.location; } else{ alert(rs); } } } */