import { LightningElement, track, wire, api } from 'lwc'; import { CurrentPageReference,NavigationMixin } from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { updateRecord } from 'lightning/uiRecordApi'; import init from '@salesforce/apex/LexLoanerArrangedEmailController.init'; import getRentalApplyEquipmentSet from '@salesforce/apex/LexLoanerArrangedEmailController.getRentalApplyEquipmentSet'; import approvalCheck from '@salesforce/apex/RentalApplyWebService.approvalCheck'; import setShipment_request from '@salesforce/apex/RentalApplyWebService.setShipment_request'; import TradeComplianceStatusFlagBP from '@salesforce/label/c.TradeComplianceStatusFlagBP'; import IFTradeComplianceAlertBP from '@salesforce/label/c.IFTradeComplianceAlertBP'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2'; import LightningConfirm from 'lightning/confirm'; import IFTradeComplianceAlertName from '@salesforce/label/c.IFTradeComplianceAlertName'; // WYL 贸易合规2期 add import tradeTempleSend from '@salesforce/apex/SendEmailUtil.tradeTempleSend'; //贸易合规二期 发邮件20240130 export default class lexLoanerArrangedEmail extends LightningElement { @api recordId; IsLoading = true; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if(currentPageReference) { const urlValue = currentPageReference.state.recordId; if(urlValue) { let str = `${urlValue}`; this.recordId = str; } } } async connectedCallback() { Promise.all([ loadStyle(this,lwcCSS) ]); console.log('111111111111'); await init({ recordId: this.recordId }).then(result => { let id = result.id; let statusArr = result.statusList; console.log('result==='+JSON.stringify(result)); if(result != null) { //贸易合规 you //var EquipmentGuaranteeFlg = '{!Rental_Apply__c.EquipmentGuaranteeFlg__c}'; if(TradeComplianceStatusFlagBP){ // WYL 贸易合规2期修改 start // if(result.accDealerBlacklist == '1'){ // this.showToast(IFTradeComplianceAlertBP,'warning'); // return; // } if (result.accDealerBlacklist2 == '1') { this.showToast('医院在黑名单中,存在贸易合规风险,无法进行出库指示,有问题请联系法务部贸易合规窗口'+IFTradeComplianceAlertName+'。','error'); tradeTempleSend({rentalId: this.recordId, stepName:'出库指示'}); //贸易合规二期 发邮件20240130 return; }else if (result.accDealerBlacklist2 == '2') { this.showToast('医院在冻结清单中,可能存在贸易合规风险,目前正在评估中(一般需5-10个工作日),暂时无法进行出库指示,有问题请联系法务部贸易合规窗口'+IFTradeComplianceAlertName+'。','error'); tradeTempleSend({rentalId: this.recordId, stepName:'出库指示'}); //贸易合规二期 发邮件20240130 return; } // WYL 贸易合规2期修改 end //贸易合规二期 add sx start if(result.accDealerBlacklist == '2'){ if(result.tradeComplianceStatus == '0'){ LightningConfirm.open({ message: '您此次申请的业务可能存在贸易合规风险,是否继续出库指示,'+ IFTradeComplianceAlert2 +'(一般需5-10个工作日)', variant: 'headerless', label: 'this is the aria-label value', }).then(confirm=>{ if(!confirm){ this.dispatchEvent(new CloseActionScreenEvent()); return; }else{ this.checkVailde(result, statusArr); } }) }else{ this.checkVailde(result, statusArr); } }else{ this.checkVailde(result, statusArr); } //贸易合规二期 add sx end } //贸易合规 you else{ this.checkVailde(result, statusArr); } } }) .catch(err=>{ console.log('err==='+err); }) } // 20230928 ljh 注释 start // print() { // getRentalApplyEquipmentSet({ // recordId: this.recordId // }).then(result => { // window.open("/apex/FixtureRentalPDF?raid=" + this.recordId + "&page=" + result); // }) // } // 20230928 ljh 注释 end checkVailde(result, statusArr){ if( result.weiAssignedCnt > 0 ) { this.showToast("申请单内存在未分配的配套,请分配备品或分割申请单",'error'); // 20231007 ljh start // }else if(result.campaignStatus == "取消") { // this.showToast("学会取消,不可出库指示",'error'); }else if(result.campaignStatus == '取消' || result.campaignStatus == '取消申请中'){ this.showToast("学会取消申请中或者已取消,不可出库指示"); // 20231007 ljh end }else if (result.raStatus == "已出库指示" && result.assignedNotShipment == 0){ this.showToast("所有的借出备品Set一览都进行过出库指示了",'error'); }else if (result.assignedNotShipment == 0) { this.showToast("没有可以出库指示的明细",'error'); }else if (result.demoPurpose1 == "长期借出" && result.contractPdfUpdated == false){ this.showToast("长期借出时,必须先上传契约书",'error'); }else if (result.repairId != '' && (result.repairFinalInspectionDateF != null && result.repairFinalInspectionDateF != '') || (result.rCReturnToOffice != null && result.rCReturnToOffice != '')){ this.showToast("修理有最终检测日或修理品返送日,不可出库指示",'error'); }else if (result.iFApproved == true && (result.meetingApprovedNo == null || result.meetingApprovedNo == "")){ this.showToast("没有决裁号的,暂不能出借,请更新裁决信息。",'error'); }else if (result.iFApproved == true && result.meetingApprovedNo != "" && statusArr.indexOf(result.approvedStatus) != -1){ this.showToast("已申请决裁但决裁状态不符合条件。",'error'); }else{ approvalCheck({ rentalApplyId: this.recordId }).then(res1 =>{ if (res1 != '1') { this.showToast(res1,'error'); }else{ //bp2 var rs2 = sforce.apex.execute("RentalApplyWebService", "reserve", {rentalApplyId: raid}); //bp2 if (rs2 != '1') { //bp2 alert(rs2); //bp2 } else { //var rs1 = sforce.apex.execute("RentalApplyWebService", "setShipment_request", {raid : "{!Rental_Apply__c.Id}"}); setShipment_request({ raid: this.recordId }).then(res=>{ console.log('res==',res); if (res == '状态更新到已出库指示') { this.showToast('状态更新到已出库指示','success'); // 20230928 ljh update start // print(); // this.updateRecordView(this.recordId); // return; getRentalApplyEquipmentSet({recordId: this.recordId}).then(result => { window.open("/apex/FixtureRentalPDF?raid=" + this.recordId + "&page=" + result); }) // 20230928 ljh update end }else { console.log('else==',res); const evt = new ShowToastEvent({ // title: 'Error',// 20231007 ljh 注释 message:res, variant: 'error', mode: 'sticky'// 20231007 ljh add }); this.dispatchEvent(evt); this.dispatchEvent(new CloseActionScreenEvent()); } }).catch(e=>{ console.log('approvalCheck==='+e); }) } }).catch(e=>{ console.log('setShipment_request==='+e); }) } } fixDate(date){ var Month = fixTime(date.getMonth() + 1); var Day = fixTime(date.getDate()); var UTC = date.toUTCString(); var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6); var Minutes = fixTime(date.getMinutes()); var Seconds = fixTime(date.getSeconds()); return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time; } showToast(msg,type) { if(type == 'success'){ const event = new ShowToastEvent({ message: msg, variant: type }); this.updateRecordView(this.recordId); this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); }else{ const event = new ShowToastEvent({ message: msg, variant: type, mode: 'sticky' }); this.dispatchEvent(event); this.dispatchEvent(new CloseActionScreenEvent()); } } updateRecordView(recordId) { updateRecord({fields: { Id: recordId }}); } }