import { LightningElement, track, wire,api } from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
import init from '@salesforce/apex/LexOPDSupplementaryController.init';
|
import dataCheck from '@salesforce/apex/OpdPlanWebService.dataCheck';
|
import getTheOPDPlan from '@salesforce/apex/LexOPDSupplementaryController.getTheOPDPlan';
|
import cloneOPD from '@salesforce/apex/LexOPDSupplementaryController.cloneOPD';
|
|
|
const event1 = new ShowToastEvent({
|
message:
|
"只有OPD计划状态为计划中,才能进行OPD补充申请",
|
variant : 'error',
|
mode : 'sticky'
|
});
|
const event2 = new ShowToastEvent({
|
message:
|
"OPD计划无法进行补充申请",
|
variant : 'error',
|
mode : 'sticky'
|
});
|
const event3 = new ShowToastEvent({
|
message:
|
"请转至OPD计划原单进行申请",
|
variant : 'error',
|
mode : 'sticky'
|
});
|
const event4 = new ShowToastEvent({
|
message:
|
"OPD计划已进行过补充申请,无法再次进行补充申请",
|
variant : 'error',
|
mode : 'sticky'
|
});
|
export default class lexOPDSupplementaryApplication extends NavigationMixin(LightningElement) {
|
|
@api recordId;
|
IsLoading=true;
|
OPDPlan;
|
dateF;
|
TheOPDPlan;
|
|
@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 => {
|
if (result != null) {
|
this.OPDPlan = result;
|
console.log(this.OPDPlan.OPDPlan_ImplementDate__c);
|
this.SupplementaryApplication().then(result=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
}).catch(error => {
|
const eventError = new ShowToastEvent({
|
message:
|
error.message,
|
variant : 'error',
|
mode : 'sticky'
|
});
|
this.dispatchEvent(eventError);
|
});
|
|
}
|
|
|
async SupplementaryApplication(){
|
var status = this.OPDPlan.Status__c;
|
if(status != '计划中'){
|
this.dispatchEvent(event1);
|
return;
|
}
|
//补充申请
|
var supplementaryApplication = this.OPDPlan.supplementaryApplication__c;
|
if(supplementaryApplication == '1'){
|
this.dispatchEvent(event2);
|
return;
|
}
|
var rental = this.OPDPlan.OriginalOpdPlanRental__c;
|
if(rental != '' && rental !=undefined){
|
this.dispatchEvent(event3);
|
return;
|
}
|
var raId = this.OPDPlan.Rental_Apply2__c;
|
var datacheck = await dataCheck({rentalApplyId: raId});
|
console.log(datacheck);
|
if(datacheck != 'OK'){
|
const event = new ShowToastEvent({
|
message:
|
datacheck,
|
variant : 'error',
|
mode : 'sticky'
|
});
|
this.dispatchEvent(event);
|
return;
|
}
|
await getTheOPDPlan({Id : this.OPDPlan.Id}).then(result=>{
|
this.TheOPDPlan = result;
|
console.log('this.OPDPlan');
|
console.log(this.TheOPDPlan.length);
|
}).catch(error=>{
|
console.log(error.message);
|
});
|
if(this.TheOPDPlan != null && this.TheOPDPlan.length > 0){
|
this.dispatchEvent(event4);
|
return;
|
}
|
//这一串就是为了两个(无用)字段传值格式不对的判断 kk 20230921 start
|
let oPDPlanImplementDate = new Date(Date.parse(this.OPDPlan.OPDPlan_ImplementDate__c));
|
console.log(oPDPlanImplementDate);
|
var endDateTime;
|
var startDateTime;
|
if(this.OPDPlan.EndDateTime__c!=undefined ){
|
endDateTime = new Date(Date.parse(this.OPDPlan.EndDateTime__c));
|
|
}
|
else{
|
endDateTime = new Date();
|
}
|
if(this.OPDPlan.StartDateTime__c !=undefined){
|
startDateTime = new Date(Date.parse(this.OPDPlan.StartDateTime__c));
|
}
|
else{
|
startDateTime = new Date();
|
}
|
let isoString1 = oPDPlanImplementDate.toISOString();
|
let isoString2 = endDateTime.toISOString();
|
let isoString3 = startDateTime.toISOString();
|
console.log(isoString3);
|
console.log(this.OPDPlan.StartDateTime__c);
|
//这一串就是为了两个(无用)字段传值格式不对的判断 kk 20230921 end
|
|
|
console.log(this.OPDPlan.OPDPlan_ImplementDate__c);
|
this.dateF = await cloneOPD({recordId : this.recordId});
|
console.log(this.dateF);
|
const defaultFieldValues = encodeDefaultFieldValues({
|
Name : this.OPDPlan.Name ,
|
Status__c : '草案中',
|
RentalReson__c : '追加配套' ,
|
SortSaveDate__c : '' ,
|
OriginalOpdPlan__c : '',
|
SortOperator__c : '',
|
SystemDelayMark__c : '',
|
JumpDate__c : '',
|
JumpCause__c : '',
|
IsJump__c : '',
|
SortDate__c : '',
|
OPDLendSortBefore__c : '',
|
OPDLendSort__c : '',
|
OPDLendSortDraft__c : '',
|
OriginalOpdPlanRental__c : '',
|
Rental_Apply2__c : '' ,
|
OriginalOpdPlanApplication__c : this.OPDPlan.Id ,
|
OPDPlan_ImplementDate__c : isoString1 ,
|
EndDateTime__c : isoString2 ,
|
StartDateTime__c : isoString3 ,
|
//备品智能化 2023-11-25 Add by dzk Start 清空报价外、报价内产品信息
|
EquipmentFromOpp__c : '',
|
EquipmentFromOppNum__c : '',
|
EquipmentNotFromOpp__c : '',
|
EquipmentNotFromOppNum__c : '',
|
PlanProdDetailSys__c : '',
|
RepeatRentalModel__c : '',
|
RepeatRentalSign__c : false,
|
//备品智能化 2023-11-25 Add by dzk End 清空报价外、报价内产品信息
|
// 任务、OPD计划最新延期取消、计划出借备品信息、是否营业目标客户、上期OPD次数、本期OPD次数、出借次数、是否有询价(最新)、是否营业目标借用、是否OPD目标借用、是否已有设备、是否有询价(申请时)、是否选择询价 不传值
|
Task_ID__c : '',
|
OPD_DelayCancel_Last__c : '',
|
PlanProdDetail__c : '',
|
// Customers_Confirmation__c : '',
|
Cnt_OPD_LastYear__c : '',
|
Cnt_OPD_ThisYear__c : '',
|
Cnt_Rentals__c : '',
|
if_Newest_HaveOpportunity__c : '',
|
if_HaveSalestarget__c : '',
|
if_OPDTarget__c : '',
|
if_HaveEquipment__c : '',
|
if_HaveOpportunity__c : '',
|
Select_inquiry__c : '' ,
|
OPD_Customers_Target__c : ''
|
})
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'OPDPlan__c',
|
actionName: 'new'
|
},
|
state: {
|
// nooverride: '1',
|
defaultFieldValues: this.dateF+","+defaultFieldValues,
|
}
|
});
|
|
}
|
|
|
|
}
|