import { LightningElement, wire, api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import init from '@salesforce/apex/otherButtonRepairController.init'; import updateRepair from '@salesforce/apex/otherButtonRepairController.updateRepair'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; export default class LexOCSMToReportRepair extends LightningElement { @api recordId; str; IsLoading = true; Id; AwareDateC; OCSMAdministrativeReportStatusC; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback() { console.log(this.recordId); init({ recordId: this.recordId }).then(result => { console.log(result); if (result != null) { this.IsLoading = false; this.Id = result.Id; this.AwareDateC = result.AwareDateC; this.OCSMAdministrativeReportStatusC = result.OCSMAdministrativeReportStatusC; this.OCSMToReport(); this.dispatchEvent(new CloseActionScreenEvent()); } }).catch(error => { console.log(error); }).finally(() => { }); } // OCSM要报告 OCSMToReport() { if (!confirm("报告后无法撤回,是否继续?")) { return; } if (this.OCSMAdministrativeReportStatusC == undefined && this.AwareDateC != undefined) { updateRepair({ recordId: this.Id }).catch(error => { if (error.body.pageErrors.length > 0) { // alert(messages.join("\n")); var errmsg = error.body.pageErrors[0].message.toString(); this.ShowToastEvent(errmsg.join("\n"), "error") return; } }) window.location.reload(); } else { this.ShowToastEvent("没有AwareDate或已经OCSM行政报告,请确认。", "error") return; } } // 弹窗 ShowToastEvent(msg, type) { const event = new ShowToastEvent({ title: '', message: msg, variant: type }); this.dispatchEvent(event); } }