import { LightningElement, wire, api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import init from '@salesforce/apex/otherButtonRepairController.init'; import selectRecords from '@salesforce/apex/otherButtonRepairController.selectRecords'; import sendToETQ from '@salesforce/apex/otherButtonRepairController.sendToETQ'; import initSelectProfile from '@salesforce/apex/otherButtonRepairController.initSelectProfile'; import initUserName from '@salesforce/apex/otherButtonRepairController.initUserName'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; export default class LexSendRepairsToEtQ extends LightningElement { @api recordId; str; IsLoading = true; Id;; PAEDetermineC; ETQUPLOADSTATUSC; AEDetermineResultC; PAEDetermineACC; RepairInspectionDateC; ContainUseRSAC; userID; profileId; profileName; userName; @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.PAEDetermineC = result.PAEDetermineC; this.ETQUPLOADSTATUSC = result.ETQUPLOADSTATUSC; this.AEDetermineResultC = result.AEDetermineResultC; this.PAEDetermineACC = result.PAEDetermineACC; this.RepairInspectionDateC = result.RepairInspectionDateC; this.ContainUseRSAC = result.ContainUseRSAC; this.userID = result.userID; this.profileId = result.profileId; initUserName({ userId: this.userID }).then(result => { console.log(result); if (result != null) { this.IsLoading = false; this.userName = result[0].Name; } }) initSelectProfile({ profileId: this.profileId }).then(result => { if (result != null) { this.IsLoading = false; this.profileName = result[0].Name; this.myDate(); this.myReload(); } }) this.dispatchEvent(new CloseActionScreenEvent()); } }).catch(error => { console.log(error); }) } // 根据日期构建MessageGroupNumber myDate() { let messageNumber = ''; let today = new Date(); messageNumber = today.getFullYear() + '' + (today.getMonth() + 1) + '' + today.getDate() + '' + today.getHours() + '' + today.getMinutes() + '' + today.getSeconds(); return messageNumber; } // 按钮点击后触发,判断是否发送过ETQ,如果发送过给出提示并灰掉按钮 // 如果没有发送过调用发送方法 myReload() { selectRecords({ recordId: this.Id }).then(result => { if (result[0].AsyncData__c == 'true' && result[0].ETQ_UPLOAD_STATUS__c != '3' || result[0].Complaint_Number__c != null) { var btns = document.getElementsByName("sendrepairstoetq"); for (var i = 0; i < btns.length; i++) { btns[i].disabled = true; btns[i].className = 'btnDisabled'; } this.ShowToastEvent('该修理之前已经发送过了','error'); } else { this.SendRepairsToEtQ(); } }).catch(error => { console.log(error); }) } // 发送ETQ SendRepairsToEtQ() { if (this.profileName != "2F7_OSH担当" && this.profileName != "2F7_OSH质量法规" && this.profileName != '系统管理员') { this.ShowToastEvent("您没有发送修理到EtQ的权限。",'error'); return; } var statu = ''; if (this.PAEDetermineC == undefined) { this.ShowToastEvent("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。",'error'); return; } if (this.ETQUPLOADSTATUSC == "3") { if (!confirm("是否清空EtQ同步状态,重新同步数据?")) { return; } } if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && this.userName != "雷 新建") { this.ShowToastEvent("Close Complait的时候,不可以发送到EtQ",'error'); return; } if (this.PAEDetermineC != undefined && this.AEDetermineResultC != undefined && this.PAEDetermineACC == undefined) { statu = "R1"; } else if ((this.AEDetermineResultC != undefined && this.PAEDetermineC != undefined && this.PAEDetermineACC != undefined) && !(this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE")) { statu = "R2"; if (this.RepairInspectionDateC == undefined) { this.ShowToastEvent("5.修理检测日是空的时候,不可以发送到EtQ。",'error'); return; } if (this.ContainUseRSAC == 1) { this.ShowToastEvent("Final universal code为空,或者包含UseRSA,请确认。",'error'); return; } } try { var repairids = new Array() repairids[0] = this.Id; var statuArr = new Array(); statuArr.push(statu); sendToETQ({ iflog_Id: "", rowDataSFDC: "", repairIds: repairids, statu: statuArr[0] }).then(result => { this.ShowToastEvent(result,'error'); this.dispatchEvent(new CloseActionScreenEvent()); location.reload(); }) var btns = document.getElementsByName("sendrepairstoetq"); for (var i = 0; i < btns.length; i++) { btns[i].disabled = true; btns[i].className = 'btnDisabled'; } } catch (error) { this.ShowToastEvent("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode,'error'); } } // 弹窗 ShowToastEvent(msg, type) { const event = new ShowToastEvent({ title: '', message: msg, variant: type }); this.dispatchEvent(event); } }