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/lexSubmitApprovalRentalApplyController.init';
|
import updateRentalApply from '@salesforce/apex/lexSubmitApprovalRentalApplyController.updateRentalApply'
|
import RentalApplyCheckForSAoneEle from '@salesforce/apex/RentalApplyWebService.RentalApplyCheckForSAoneEle';
|
import raesCountCheck from '@salesforce/apex/OpdPlanWebService.raesCountCheck';
|
import STATUS_PROCESS_STATE from '@salesforce/label/c.StatusProcessState';
|
import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
|
|
export default class lexSubmitApprovalRentalApply extends LightningElement {
|
@api recordId;
|
@track StatusProcessState=STATUS_PROCESS_STATE;
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference){
|
if(currentPageReference){
|
const urvalue=currentPageReference.state.recordId;
|
if(urvalue){
|
let str=`${urvalue}`;
|
this.recordId=str;
|
}
|
}
|
}
|
|
connectedCallback(){
|
init({
|
recordId:this.recordId
|
}).then(res=>{
|
if(JSON.stringify(res) == '{}'){
|
this.ToastShow('没有查到需要的数据','warning');
|
return;
|
}
|
const SUBMIT = LightningConfirm.open({
|
message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
|
variant: 'headerless',
|
label: '提示信息',
|
});
|
if(SUBMIT==false){
|
this.dispatchEvent(new CloseActionScreenEvent());
|
return;
|
}
|
|
//1540 you 试用(无询价)目的的备品申请单,不能关联询价信息!
|
if(res.demoPurpose2 == '试用(无询价)' && res.followUPOpp!= null && res.followUPOpp !=''){
|
this.showToast('试用(无询价)目的的备品申请单,不能关联询价信息!','warning');
|
return;
|
}
|
// 已购待货的申请单审批时,需要check注残的状态
|
if(res.statuAchievements != ''){
|
RentalApplyCheckForSAoneEle({
|
SaID:res.statuAchievementsId
|
}).then(checkForSAoneEle=>{
|
if(checkForSAoneEle!='Fin'){
|
this.showToast(Fin,'warning');
|
return;
|
}
|
})
|
}
|
let today=new Date();
|
console.log('today==='+today);
|
// 希望到货日不能早于申请提交日-0418追加
|
if(res.requestShippingDay < today){
|
this.showToast('希望到货日不能早于申请提交日','warning');
|
return;
|
}
|
|
if(res.stoppedSet && res.stoppedSet.length > 0){
|
this.showToast(Array.from(stoppedSet).join(',')+' 产品注册证状态为停止,不可申请','warning');
|
return;
|
}
|
|
if(res.demoPurpose2 == '索赔QIS'){
|
if(res.qisSize==0 || res.qISisAgree){
|
this.showToast('申请的型号必须与QIS申请型号一致','warning');
|
return;
|
}
|
}
|
|
if(res.repairId!='' || res.repairId!= null){
|
if(res.demoPurpose1 == '维修代用' && res.demoPurpose2 == '索赔QIS'){
|
if(!res.modelSet.has(deliveredProductFixtureModelNo)){
|
this.showToast('申请的型号必须与送修的型号一致','warning');
|
return;
|
}
|
}
|
}
|
|
if(res.demoPurpose1 == '维修代用' && res.demoPurpose2 == '一般用户'){
|
if(res.repairEstimatedDateFormula == null){
|
this.showToast('一般维修无报价日,不可借用备品','warning');
|
return;
|
}else if(res.repairEstimatedDateFormula<'2019-07-01' && res.agreedDate == null){
|
this.showToast('报价日在2019/7/1之前且户同意日为空,不可借用备品','warning');
|
return;
|
}
|
//20210608 ljh SFDC-C3CCN4 start
|
if(res.repairRank==''||res.repairRank==null){
|
this.showToast('报价等级为空不能申请备品','warning');
|
return;
|
}else{
|
if(!res.dWSignTxt && res.repairRank == 'DW'){
|
this.showToast('DW报价等级下此型号不符合备品申请借用条件');
|
return;
|
}
|
if(res.repairRank == 'D1' || res.repairRank == 'D2' || res.repairRank == 'D3' || res.repairRank == 'E2'){
|
this.showToast('报价等级不符合备品申请借用条件','warning');
|
return;
|
}
|
}
|
//20210608 ljh SFDC-C3CCN4 end
|
}
|
|
if(res.demoPurpose1 == '维修代用' && res.demoPurpose2 == '市场多年保修'){
|
if(res.fSEApplyForRepairDay == null){
|
this.showToast('市场多年保修,没有[FSE修理申请日],不可借用备品','warning');
|
return;
|
}
|
}
|
if(res.demoPurpose1 == '维修代用' && res.demoPurpose2 == '故障排查'){
|
if(res.fSEApplyForRepairDay == null){
|
this.showToast('故障排查,没有[FSE修理申请日],不可借用备品','warning');
|
return;
|
}
|
if(res.repairOrderedDate!=null){
|
this.showToast('故障排查,[4.修理品RC受理日]必须为空','warning');
|
return;
|
}
|
if(!res.ifCheckFixture){
|
this.showToast('不满足故障排查目的','warning');
|
return;
|
}
|
}
|
|
if(res.demoRequestPastDataId != res.recordTypeId && res.profileId!='00e10000000Y3o5' && res.newProductGuaranteeObject == '8: 市场多年保修' && res.demoPurpose2!= '市场多年保修'){
|
this.showToast('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。','warning');
|
return;
|
}
|
if(res.repairFinalInspectionDate != null){
|
this.showToast('存在修理最终检测日,不可借用备品','warning');
|
return;
|
}
|
if(res.status1 == '0.删除' || res.status1 == '0.取消' || res.status1 == '5.完毕'){
|
this.showToast('修理已经结束,不能申请备品','warning');
|
return;
|
}
|
if(res.demoPurpose2 == '再修理' && !res.reRepairObjectF){
|
this.showToast('不属于再受理参考对象,不可借用备品','warning');
|
return;
|
}
|
if(res.demoRequestPastDataId != res.recordTypeId && res.demoPurpose2 != '保修用户' && res.demoPurpose2 != '市场多年保修' && res.numberOfEffectiveContract == '有'){
|
this.showToast('有维修合同,必须选择保修用户.','warning');
|
return;
|
}
|
if(res.demoRequestPastDataId != res.recordTypeId && res.newProductGuaranteeObject == '2: 服务多年保修' && (res.assetModelNo == 'LTF-190-10-3D' || res.assetModelNo == 'LTF-S190-5' || res.assetModelNo == 'CYF-VHA' || res.assetModelNo == 'CYF-VA2' || res.assetModelNo == 'CYF-5A' || res.assetModelNo == 'LTF-S190-10'
|
|| res.assetModelNo == 'OER-AW' || res.assetModelNo == 'URF-V' || res.assetModelNo == 'URF-V2' || res.assetModelNo == 'URF-P6') && res.demoPurpose2 != '保修用户'){
|
this.showToast('此设备型号多年保修,请选择保修用户.','warning');
|
return;
|
}
|
if(res.recordTypeId != result.demoRequestPastDataId && result.newProductGuaranteeObject=='2: 服务多年保修' && (res.assetModelNo == 'CV-V1' || res.assetModelNo == 'CV-V1(A)' || res.assetModelNo == 'CV-V1(B)' || res.assetModelNo == 'GIF-LV1' || res.assetModelNo == 'CF-LV1L' || res.assetModelNo == 'CF-LV1I' || res.assetModelNo == 'MAJ-1910') && (res.demoPurpose2 || res.demoPurpose2=='再修理')){
|
this.showToast('奥辉设备,保修期内不提供备品.','warning');
|
return;
|
}
|
if(res.supplementCreated == '1' && res.oPDPlanId != ''){
|
raesCountCheck({
|
rentalApplyId: this.recordId
|
}).then(opdResult=>{
|
if(opdResult != 'OK'){
|
this.showToast(opdResult,'warning');
|
return;
|
}
|
})
|
}
|
|
if(res.campaignId != null && res.campaignId != ''){
|
let statusSting = this.StatusProcessState;
|
let statusList = statusSting.split(',');
|
if(res.campaignStatus == '草案中'){
|
this.showToast('学会状态为草案中,不能提交','warning');
|
return;
|
}
|
if(res.campaignStatus == '申请中'){
|
this.showToast('学会状态为申请中,不能提交','warning');
|
return;
|
}
|
if(res.campaignStatus == '已结束'){
|
this.showToast('学会状态为已结束,不能提交','warning');
|
return;
|
}
|
if(res.campaignStatus == '已提交报告'){
|
this.showToast('学会状态为已提交报告,不能提交','warning');
|
return;
|
}
|
if(res.campaignStatus == '取消申请中'){
|
this.showToast('学会状态为取消申请中,不能提交','warning');
|
return;
|
}
|
if(res.campaignStatus == '取消'){
|
this.showToast('学会状态为取消,不能提交','warning');
|
return;
|
}
|
let today=new Date();
|
if(today >= res.requestShippingDay - 7){
|
this.showToast('必须提前于希望到货日7天以上提交申请','warning');
|
return;
|
}
|
// 20220324 ljh obpm add start
|
if(res.campaignId!= null && res.iFApproved && (res.meetingApprovedNo==null || res.meetingApprovedNo=='')){
|
this.showToast('没有决裁号的,暂不能出借,请更新裁决信息。','warning');
|
return;
|
}
|
if(res.campaignId!= null && res.iFApproved && res.meetingApprovedNo!='' && statusList.indexOf(res.approvedStatus)!=-1 && res.approvedStatus != '草稿'){
|
this.showToast("已申请决裁但决裁状态不符合条件。");
|
return;
|
}
|
// 20220324 ljh obpm add end
|
}
|
|
//QIS部分
|
if(res.qISNumber != null && res.qISNumber != ''){
|
if(res.nextAction == '送回'){
|
this.showToast("QIS 已送回,不能再申请备品了");
|
return;
|
}
|
}
|
|
//share
|
let userAccess = new Array();
|
userAccess.push(res.applyUserId +'_Edit');
|
|
setSObjectShare({
|
sobjectName: 'Rental_Apply__Share',
|
rowCause: 'ApplyUserShare__c',
|
parentId: this.recordId,
|
userAccess: userAccess,
|
ownerId: res.ownerId,
|
}).then(shareResult=>{
|
if(shareResult != 'OK'){
|
this.showToast(shareResult);
|
return;
|
}else{
|
if(res.rentalApplyStatus =='填写完毕' || res.rentalApplyStatus =='申请中' || res.rentalApplyStatus =='已批准' || res.rentalApplyStatus =='已出库指示' || res.rentalApplyStatus =='删除' || res.rentalApplyStatus =='取消'){
|
this.showToast('请备品申请状态确认,已经提交过的申请,不能重复提交','warning');
|
return;
|
}
|
|
// 没有明细的一览check
|
if(res.raesListSize > 0){
|
this.showToast('有没有明细的借出备品配套一览,不能提交','warning');
|
}
|
|
let updateStatus = '填写完毕';
|
let SalesManagerSubmit;
|
let OPDManagerApprover;
|
let BuchangApprovalManagerSalesSubmit;
|
let OPDBuchangApprover;
|
// 20220930 ljh SWAG-CJR8S7 start
|
// 获取 OPDPlan__r.SalesManager_Txt__c,OPDPlan__r.BuchangApprovalManagerSales_Txt__c
|
// 20220930 ljh SWAG-CJR8S7 end
|
if(res.manageUsersJingliEquipmentManager != null){
|
SalesManagerSubmit = res.manageUsersJingliEquipmentManagerTxt;
|
// 20220930 ljh SWAG-CJR8S7 start
|
if(res.oPDPlanId != null){
|
OPDManagerApprover = res.salesManagerSubmit == oPDSalesManagerTxt ? res.salesManagerSubmit : '';
|
}
|
// 20220930 ljh SWAG-CJR8S7 end
|
}
|
|
if(res.manageUsersBuzhangEquipmentManager != null){
|
BuchangApprovalManagerSalesSubmit = res.manageUsersBuzhangEquipmentManagerTxt;
|
// 20220930 ljh SWAG-CJR8S7 start
|
if(res.oPDPlanId != null){
|
OPDBuchangApprover = res.manageUsersBuzhangEquipmentManagerTxt == res.buchangApprovalManagerSalesSubmit? res.buchangApprovalManagerSalesSubmit :'';
|
}
|
// 20220930 ljh SWAG-CJR8S7 end
|
|
//更新借出申请
|
updateRentalApply({
|
recordId: this.recordId,
|
status: '填写完毕',
|
salesManagerSubmit: SalesManagerSubmit,
|
oPDManagerApprover: OPDManagerApprover,
|
buchangApprovalManagerSalesSubmit: BuchangApprovalManagerSalesSubmit,
|
oPDBuchangApprover: OPDBuchangApprover
|
}).then(updateResult=>{
|
if(updateResult == '更新成功'){
|
this.ToastShow('更新成功','success');
|
return;
|
}else{
|
this.ToastShow(updateResult,'warning');
|
return;
|
}
|
})
|
}
|
|
}
|
})
|
})
|
}
|
|
ToastShow(msg,type){
|
const evt = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
this.dispatchEvent(evt);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
|
updateRecordView(recordId) {
|
updateRecord({fields: { Id: recordId }});
|
}
|
}
|