import { LightningElement, api, track, wire } from 'lwc'; import init from '@salesforce/apex/lexCustomDeleteController.initForCustomDelete'; import {CurrentPageReference} from 'lightning/navigation' import UserInfo_Owner from '@salesforce/apex/TaskFeedbackController.UserInfo_Owner'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import deleteRepair from '@salesforce/apex/ControllerUtil.deleteRepair'; export default class lexCustomDeleteLWC extends LightningElement { @api recordId; @api message; @track Status ; @track FSE ; @track SAP; @track cre ; @track Rep ; @track acc ; @track fSE ; @track id; @track rtn; @wire(CurrentPageReference) getStateParameters(currentPageReference){ console.log(111); 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.recordId); init({ recordId:this.recordId }).then(result=>{ console.log(result); if(result!=null){ this.FSE=result.FSEApplyForRepairtime; this.Rep=result.Rep; this.SAP=result.SAP; this.Status=result.Status; this.acc=result.acc; this.id=result.Id; this.cre=result.cre; this.fSE=result.FSEownerId; console.log("end"); this.handleDeleteAction(); console.log("end2"); } }) } handleDeleteAction(){ if (this.Status != null && this.Status.length > 0) { if (this.Status != "草案中"&& this.Status != "1.受理完毕(SAP待发送)"&& this.Status != "4.修理品返送阶段") { this.message = "不是草案中,不能删除"; const event = new ShowToastEvent({ title: 'error', variant:'error', message: this.message, }); this.dispatchEvent(event); } else if (this.Status == "0.申请完毕"&& (this.FSE != "")) { message = "FSE已经申请,不能删除"; console.log('***action4'); const event = new ShowToastEvent({ title: 'warning', message: this.message, }); this.dispatchEvent(event); } else if (this.Status == "4.修理品返送阶段"&& (this.SAP != "" || this.Rep!= "")){ message = "已经发送过SAP,不能删除"; const event = new ShowToastEvent({ title: 'warning', message: this.message, }); this.dispatchEvent(event); } else if (UserInfo_Owner.Id.substring(0,15) != this.cre.substring(0,15) && UserInfo_Owner.Id.substring(0,15) != this.acc.substring(0,15)&& UserInfo_Owner.Id.substring(0,15) != this.fSE.substring(0,15)) { message = "不是所有人、创建人或FSE主负责人,不能删除"; const event = new ShowToastEvent({ title: 'warning', message: this.message, }); this.dispatchEvent(event); } else { // sforce.connection.sessionId = '{!$Api.Session_ID}'; // var rtn=sforce.apex.execute("ControllerUtil","deleteRepair",{rid:this.id}); deleteRepair({ rid:this.id }).then(result=>{ console.log(result); if(result!=null){ this.rtn=result; } }) if (this.rtn == "OK") { reload(); } else { alert(this.rtn); } } } function reload(){ var str=""; if(getParam('retURL')!==null){ str +=getParam('retURL'); } window.open(str,'_self'); } function getParam(paramName) { paramValue = "", isFound = !1; if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) { arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0; while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++ } return paramValue == "" && (paramValue = null), paramValue } } }