import { LightningElement, wire, api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import init from '@salesforce/apex/buttonQISSCReportCtl.init'; import updateQISSCReport from '@salesforce/apex/buttonQISSCReportCtl.updateQISSCReport'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import LightningConfirm from 'lightning/confirm'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; export default class lexSCSubmit extends LightningElement { @api recordId; str; IsLoading = true; Id; StatusC; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback() { Promise.all([ loadStyle(this, lwcCSS) ]); init({ recordId: this.recordId }).then(result => { console.log(result); if (result != null) { this.Id = result.Id; this.StatusC = result.StatusC; this.SCSubmit(); } }).catch(error => { console.log(error); }) } // 提交待审批 SCSubmit() { if (this.StatusC != '草案中') { this.ShowToastEvent("已经提交审批", "error"); this.dispatchEvent(new CloseActionScreenEvent()); return; } this.handleConfirmClick("一旦OCM提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?"); } ShowToastEvent(msg, type) { if (type=='success') { const event = new ShowToastEvent({ title: '', message: msg, variant: type }); this.dispatchEvent(event); }else{ const event = new ShowToastEvent({ title: '', message: msg, variant: type, mode: 'sticky' }); this.dispatchEvent(event); } } async handleConfirmClick(msg) { const result = await LightningConfirm.open({ message: msg, variant: 'headerless', label: 'this is the aria-label value' }); if(result){ updateQISSCReport({ QId: this.Id }).then(result1 => { console.log('result1=='+result1); if (result1.length > 0) { var split = result.split(", "); this.ShowToastEvent(split[1], "error"); this.dispatchEvent(new CloseActionScreenEvent()); // alert(split[1]); } else { this.url1 = '/lightning/r/QIS_SC_Report__c/'+this.recordId+'/view'; window.open(this.url1,'_self'); this.ShowToastEvent("已提交", "success"); this.dispatchEvent(new CloseActionScreenEvent()); // window.location.reload(); } }) }else{ this.dispatchEvent(new CloseActionScreenEvent()); } } }