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 initList from '@salesforce/apex/otherButtonRepairController.initList'; import initUserName from '@salesforce/apex/otherButtonRepairController.initUserName'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import LightningConfirm from 'lightning/confirm'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader' export default class LexSendRepairsToEtQ extends LightningElement { @api recordId; str; IsLoading = true; Id;; PAEDetermineC; ETQUPLOADSTATUSC; AEDetermineResultC; PAEDetermineACC; RepairInspectionDateC; ContainUseRSAC; userID; profileId; profileName; userName; ifList; @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) ]); console.log(this.recordId); init({ recordId: this.recordId }).then(resu => { console.log(resu); if (resu != null) { this.IsLoading = false; this.Id = resu.Id; this.PAEDetermineC = resu.PAEDetermineC; this.ETQUPLOADSTATUSC = resu.ETQUPLOADSTATUSC; this.AEDetermineresuC = resu.AEDetermineresuC; this.AEDetermineResultC = resu.AEDetermineResultC this.PAEDetermineACC = resu.PAEDetermineACC; this.RepairInspectionDateC = resu.RepairInspectionDateC; this.ContainUseRSAC = resu.ContainUseRSAC; this.userID = resu.userID; this.profileId = resu.profileId; initUserName({ userId: this.userID }).then(result => { console.log(result); if (result != null) { this.IsLoading = false; this.userName = result[0].Name; } initList().then(res => { console.log(res,'iflist') this.ifList = res initSelectProfile({ profileId: this.profileId }).then(result => { console.log(result) if (result != null) { this.IsLoading = false; // this.profileName = result[0].Name; this.profileName = result; console.log('到了执行函数') 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() { console.log('进来了') selectRecords({ recordId: this.Id }).then(result => { console.log(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.showToast('该修理之前已经发送过了','error'); this.dispatchEvent(new CloseActionScreenEvent()); } else { this.SendRepairsToEtQ(); } }).catch(error => { console.log(error,'err<<<<<<'); }) } // 发送ETQ SendRepairsToEtQ() { console.log('etq') if (this.profileName != this.ifList.oshact && this.profileName != this.ifList.oshqualityregulations && this.profileName != this.ifList.administrator) { this.showToast("您没有发送修理到EtQ的权限。",'error'); this.dispatchEvent(new CloseActionScreenEvent()); console.log('您没有发送修理到EtQ的权限。') return; } if (this.PAEDetermineC == undefined) { this.showToast("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。",'error'); this.dispatchEvent(new CloseActionScreenEvent()); console.log('OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。') return; } if (this.ETQUPLOADSTATUSC == "3") { // if (!confirm("是否清空EtQ同步状态,重新同步数据?")) { // return; // } LightningConfirm.open({ message: "是否清空EtQ同步状态,重新同步数据?", variant: 'headerless', label: '提示信息' }).then(submit => { if(!submit){ return; }else{ this.Etqreload() } }) }else{ this.Etqreload() } } Etqreload(){ debugger // let this = this console.log('qqq') var statu = ''; if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && this.userName != this.ifList.leixinjian) { this.showToast("Close Complait的时候,不可以发送到EtQ",'error'); this.dispatchEvent(new CloseActionScreenEvent()); console.log('Close Complait的时候,不可以发送到EtQ') return; } if (this.PAEDetermineC != undefined && this.AEDetermineResultC != undefined && this.PAEDetermineACC == undefined) { statu = "R1"; console.log('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.showToast("5.修理检测日是空的时候,不可以发送到EtQ。",'error'); console.log('sscasd') const event = new ShowToastEvent({ message: "5.修理检测日是空的时候,不可以发送到EtQ。", variant: 'error', mode:'Sticky' }); this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); return; } if (this.ContainUseRSAC == 1) { this.showToast("Final universal code为空,或者包含UseRSA,请确认。",'error'); this.dispatchEvent(new CloseActionScreenEvent()); return; } } // debugger console.log(statu,'statu') try { var repairids = new Array() repairids[0] = this.Id; var statuArr = new Array(); statuArr.push(statu); console.log('发送etq') sendToETQ({ iflog_Id: "", rowDataSFDC: "", repairIds: repairids, statu: statuArr[0] }).then(result => { console.log('发送etq返回') this.showToast(result,'error'); this.dispatchEvent(new CloseActionScreenEvent()); window.location.href = ' /lightning/r/Repair__c/'+this.recordId+'/view'; // location.reload(); }) var btns = document.getElementsByName("sendrepairstoetq"); for (var i = 0; i < btns.length; i++) { btns[i].disabled = true; btns[i].className = 'btnDisabled'; } window.location.href = ' /lightning/r/Repair__c/'+this.recordId+'/view'; } catch (error) { console.log(error,'xxxx') this.showToast("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode,'error'); this.dispatchEvent(new CloseActionScreenEvent()); } } // 弹窗 showToast(msg, type) { if(type == 'success'){ const event = new ShowToastEvent({ message: msg, variant: 'success' }); this.dispatchEvent(event); }else{ const event = new ShowToastEvent({ message: msg, variant: 'error', mode:'Sticky' }); this.dispatchEvent(event); } } }