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'; import LightningConfirm from 'lightning/confirm'; export default class LexSendRepairsToEtQ extends LightningElement { @api recordId; str; IsLoading = true; Id;; PAEDetermineC; ETQUPLOADSTATUSC; AEDetermineResultC; PAEDetermineACC; RepairInspectionDateC; ContainUseRSAC; userID; profileId; profileName; userName; msg; statu = ''; @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.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.userName = result[0].Name; } }) initSelectProfile({ profileId: this.profileId }).then(result => { if (result != null) { this.profileName = result[0].Name; this.myDate(); this.myReload(); } }) } }).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"); this.dispatchEvent(new CloseActionScreenEvent()); return; } 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"); this.dispatchEvent(new CloseActionScreenEvent()); return; } if (this.PAEDetermineC == undefined) { this.ShowToastEvent("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。", "error"); this.dispatchEvent(new CloseActionScreenEvent()); return; } if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && this.userName != "雷 新建") { this.ShowToastEvent("Close Complait的时候,不可以发送到EtQ", "error"); this.dispatchEvent(new CloseActionScreenEvent()); return; } if (this.ETQUPLOADSTATUSC == "3") { this.handleConfirmClick("是否清空EtQ同步状态,重新同步数据?"); } else { this.ll(); } } ll() { if (this.PAEDetermineC != undefined && this.AEDetermineResultC != undefined && this.PAEDetermineACC == undefined) { this.statu = "R1"; } else if ((this.AEDetermineResultC != undefined && this.PAEDetermineC != undefined && this.PAEDetermineACC != undefined) && !(this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE")) { this.statu = "R2"; if (this.RepairInspectionDateC == undefined) { this.ShowToastEvent("5.修理检测日是空的时候,不可以发送到EtQ。", "error"); this.dispatchEvent(new CloseActionScreenEvent()); return; } if (this.ContainUseRSAC == 1) { this.ShowToastEvent("Final universal code为空,或者包含UseRSA,请确认。", "error"); this.dispatchEvent(new CloseActionScreenEvent()); return; } } var repairids = new Array() repairids[0] = this.Id; var statuArr = new Array(); statuArr.push(this.statu); sendToETQ({ iflog_Id: "", rowDataSFDC: "", repairIds: repairids, statu: statuArr[0] }).then(result => { console.log("result:" + result); if (result == "发送成功!") { this.ShowToastEvent(result, "success"); this.dispatchEvent(new CloseActionScreenEvent()); } else { this.ShowToastEvent("发送修理到EtQ失败," + result, "error"); this.dispatchEvent(new CloseActionScreenEvent()); } }) var btns = document.getElementsByName("sendrepairstoetq"); for (var i = 0; i < btns.length; i++) { btns[i].disabled = true; btns[i].className = 'btnDisabled'; } } // 弹窗 ShowToastEvent(msg, type) { const event = new ShowToastEvent({ title: '', message: msg, variant: type }); this.dispatchEvent(event); } async handleConfirmClick(msg) { const result = await LightningConfirm.open({ message: msg, variant: 'headerless', label: 'this is the aria-label value' }); if (result) { this.ll(); } else { this.dispatchEvent(new CloseActionScreenEvent()); } } }