import { LightningElement, track, wire, api } from 'lwc'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { CurrentPageReference,NavigationMixin } from 'lightning/navigation'; import { updateRecord } from 'lightning/uiRecordApi'; import LightningConfirm from 'lightning/confirm'; import init from '@salesforce/apex/LexAddSubmitApprovalProcessController.init'; import submitApproval from '@salesforce/apex/LexAddSubmitApprovalProcessController.submitApproval'; import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare'; import changeAddApprovalStatus from '@salesforce/apex/LexAddSubmitApprovalProcessController.changeAddApprovalStatus'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; export default class lexAddSubmitApprovalProcess extends LightningElement { @api recordId; IsLoading = true; RecordTypeId; @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) ]); init({ recordId: this.recordId }).then(result=>{ console.log('result==='+JSON.stringify(result)); if(JSON.stringify(result) == '{}'){ this.ToastShow('没有查到需要的数据','warning'); return; } if(result.addApprovalStatus != '草案中' || result.detailSize == 0){ this.ToastShow('没有需要审批的追加附属品','warning'); return; } // if (!confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) { // this.dispatchEvent(new CloseActionScreenEvent()); // return; // } LightningConfirm.open({ message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?", variant: 'headerless', label: '提示信息', // setting theme would have no effect }).then(submit=>{ if(!submit){ this.dispatchEvent(new CloseActionScreenEvent()); return; }else{ // 希望到货日不能早于申请提交日-0418追加 //if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') { // alert('希望到货日不能早于申请提交日'); // return; // } console.log(JSON.stringify(result)); if(result.repairId != null){ if(result.demoPurpose1 == '维修代用' && result.demoPurpose2 == '一般用户'){ if(result.repairEstimatedDateFormula == null){ this.ToastShow('一般维修无报价日,不可借用备品','warning'); return; }else if(result.repairEstimatedDateFormula <'2019-07-01' && result.agreedDate == null){ this.ToastShow('报价日在2019/7/1之前且户同意日为空,不可借用备品','warning'); return; } } if(result.recordTypeId!=result.demoRequestPastDataId && result.profileId != result.adminProfileId && result.newProductGuaranteeObject== '8: 市场多年保修' && result.demoPurpose2 != '市场多年保修'){ this.ToastShow('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。','warning'); return; } if(result.repairFinalInspectionDate != null){ this.ToastShow('存在修理最终检测日,不可借用备品','warning'); return; } if(result.repairShippedDate != null){ this.ToastShow('存在RC修理返送日,不可借用备品','warning'); return; } if(result.status1 == '0.删除' ||result.status1 == '0.取消' || result.status1 =='5.完毕'){ this.ToastShow('修理已经结束,不能申请备品','warning'); return; } // if(result.demoPurpose2 =='再修理' || !result.reRepairObjectF || result.reRepairObjectFs == 'false'){ if(result.demoPurpose2 =='再修理' || result.reRepairObjectF == 'false'){//20231110 李文涛 this.ToastShow('不属于再受理参考对象,不可借用备品','warning'); return; } // 20231207 ljh 修复原有逻辑 start // if(result.recordTypeId != result.demoRequestPastDataId && result.demoPurpose2 !='保修用户' && result.demoPurpose2 != '市场多年保修' && result.numberOfEffectiveContract !='有'){ if(result.recordTypeId != result.demoRequestPastDataId && result.demoPurpose2 !='保修用户' && result.demoPurpose2 != '市场多年保修' && result.numberOfEffectiveContract =='有'){ // 20231207 ljh 修复原有逻辑 end this.ToastShow('有维修合同,必须选择保修用户.','warning'); return; } if(result.recordTypeId != result.demoRequestPastDataId && result.numberOfEffectiveContract=='无' && (result.newProductGuaranteeObject == '2: 服务多年保修' && (result.assetModelNo== 'LTF-190-10-3D' || result.assetModelNo=='LTF-S190-5' || result.assetModelNo== 'CYF-VHA' || result.assetModelNo== 'CYF-VA2' || result.assetModelNo=='CYF-5A' ||result.assetModelNo=='LTF-S190-10'||result.assetModelNo=='OER-AW'||result.assetModelNo=='URF-V'||result.assetModelNo=='URF-V2'||result.assetModelNo=='URF-P6')) && result.demoPurpose2 != '保修用户'){ this.ToastShow('此设备型号多年保修,请选择保修用户.','warning'); return; } //备品申请 过去历史转移 if(result.recordTypeId != result.demoRequestPastDataId && result.newProductGuaranteeObject=='2: 服务多年保修' && (result.assetModelNo=='CV-V1' ||result.assetModelNo=='CV-V1(A)'||result.assetModelNo=='CV-V1(B)'||result.assetModelNo=='GIF-LV1'||result.assetModelNo=='CF-LV1L'||result.assetModelNo=='CF-LV1I'||result.assetModelNo=='MAJ-1910') &&(result.demoPurpose2=='一般用户'||result.demoPurpose2=='再修理')){ this.ToastShow('奥辉设备,保修期内不提供备品.','warning'); return; } } if(result.campaignId!=null || result.campaignId!=''){ if(result.campaignStatus == '草案中'){ this.ToastShow('学会状态为草案中,不能提交','warning'); return; } if(result.campaignStatus == '申请中'){ this.ToastShow('学会状态为申请中,不能提交','warning'); return; } if(result.campaignStatus == '已结束'){ this.ToastShow('学会状态为已结束,不能提交','warning'); return; } if(result.campaignStatus == '已提交报告'){ this.ToastShow('学会状态为已提交报告,不能提交','warning'); return; } if(result.campaignStatus == '取消申请中'){ this.ToastShow('学会状态为取消申请中,不能提交','warning'); return; } if(result.campaignStatus == '取消'){ this.ToastShow('学会状态为取消,不能提交','warning'); return; } } if(result.qISNumber!=null || result.qISNumber!=''){ if(result.nextAction=='送回'){ this.ToastShow('QIS 已送回,不能再申请备品了','warning'); return; } } //share var userAccess = new Array(); userAccess.push(result.applyUserId + '_Edit'); //SWAG-BZMA8W 去掉 服务经理部长共享 start //update lxy DLIU-BZNBG9 去掉服务经理部长共享 //userAccess.push('{!Rental_Apply__c.JingliApprovalManagerId__c}_Read'); //userAccess.push('{!Rental_Apply__c.SalesManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成 //update lxy DLIU-BZNBG9 去掉服务经理部长共享 //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerId__c}_Read'); //SWAG-BZMA8W 去掉 服务经理部长共享 end //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerSalesId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成 //userAccess.push('{!Rental_Apply__c.ZongjianApprovalManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成 //userAccess.push('{!Rental_Apply__c.Status__c}_Read'); console.log('参数==='+result.rentalApplyId+' '+userAccess+' '+result.ownerId); setSObjectShare({ sobjectName:'Rental_Apply__Share', rowCause:'ApplyUserShare__c', parentId:result.rentalApplyId, userAccess:userAccess, ownerId:result.ownerId }).then(res=>{ if(res!='OK'){ this.ToastShow(res,'warning'); return; }else{ console.log('setSObjectShareSuccess====OK'); //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c if (result.rentalApplyStatus != '已批准' && result.rentalApplyStatus != '已出库指示') { this.ToastShow('请备品申请状态确认,申请状态已批准后才可以提交追加审批','warning'); return; } changeAddApprovalStatus({ recordId: this.recordId, status: '填写完毕' }).then(changeResult=>{ if(changeResult == '更新成功'){ submitApproval({ recordId: this.recordId }).then(submitApprovalRes=>{ if(submitApprovalRes == 'OK'){ this.ToastShow('提交追加待审批成功','success'); this.updateRecordView(this.recordId); }else{ this.ToastShow('追加待审批失败','error'); } }) }else{ this.ToastShow(changeResult,'error'); } }) } }).catch(err=>{ console.log('setSObjectShareErr===='+err); }) } }) }).catch(err=>{ console.log('====1111====',err); }) } ToastShow(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 }}); } async handleConfirmClick(msg) { const result = await LightningConfirm.open({ message: msg, variant: 'headerless', label: 'this is the aria-label value' }); if (result) { this.ll(); } else { window.history.go(-1); } } }