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 init from '@salesforce/apex/LexOPDSupplementaryController.init';
|
import dataCheck from '@salesforce/apex/OpdPlanWebService.dataCheck';
|
import getTheOPDPlan from '@salesforce/apex/LexOPDSupplementaryController.getTheOPDPlan';
|
|
const event1 = new ShowToastEvent({
|
message:
|
"只有OPD计划状态为计划中,才能进行OPD补充申请",
|
variant : 'error'
|
});
|
const event2 = new ShowToastEvent({
|
message:
|
"OPD计划无法进行补充申请",
|
variant : 'error'
|
});
|
const event3 = new ShowToastEvent({
|
message:
|
"请转至OPD计划原单进行申请",
|
variant : 'error'
|
});
|
const event4 = new ShowToastEvent({
|
message:
|
"OPD计划已进行过补充申请,无法再次进行补充申请",
|
variant : 'error'
|
});
|
export default class lexOPDSupplementaryApplication extends NavigationMixin(LightningElement) {
|
|
@api recordId;
|
IsLoading=true;
|
OPDPlan;
|
TheOPDPlan;
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
|
connectedCallback(){
|
init({
|
recordId: this.recordId
|
}).then(result => {
|
if (result != null) {
|
this.OPDPlan = result;
|
this.SupplementaryApplication().then(result=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
}).catch(error => {
|
const event3 = new ShowToastEvent({
|
message:
|
error.message,
|
variant : 'error'
|
});
|
this.dispatchEvent(event3);
|
});
|
|
}
|
|
|
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'
|
});
|
this.dispatchEvent(event);
|
return;
|
}
|
await getTheOPDPlan({Id : this.OPDPlan.Id}).then(result=>{
|
this.TheOPDPlan = result;
|
}).catch(error=>{
|
console.log(error.message);
|
});
|
if(this.TheOPDPlan != null && this.TheOPDPlan > 0){
|
this.dispatchEvent(event4);
|
return;
|
}
|
const defaultFieldValues = encodeDefaultFieldValues({
|
Name : this.OPDPlan.Name ,
|
Status__c : '草案中',
|
RentalReson__c : '追加配套' ,
|
OPDPlan_ImplementDate__c : this.OPDPlan.OPDPlan_ImplementDate__c ,
|
Account_Laboratory__c : this.OPDPlan.Account_Laboratory__c ,
|
Related_Opportunity1_ID__c :this.OPDPlan.Related_Opportunity1_ID__c ,
|
PlanProdDetail__c : this.OPDPlan.PlanProdDetail__c,
|
Cnt_OPD_LastYear__c : this.OPDPlan.Cnt_OPD_LastYear__c,
|
Cnt_OPD_ThisYear__c : this.OPDPlan.Cnt_OPD_ThisYear__c,
|
Cnt_Rentals__c : this.OPDPlan.Cnt_Rentals__c,
|
lastMonth_Plan__c : this.OPDPlan.lastMonth_Plan__c,
|
SalesManager__c : this.OPDPlan.SalesManager__c,
|
OPDType__c : this.OPDPlan.OPDType__c,
|
OriginalOpdPlanApplication__c :this.OPDPlan.Id,
|
BuchangApprovalManagerSales__c :this.OPDPlan.BuchangApprovalManagerSales__c,
|
SalesManager_Txt__c : this.OPDPlan.SalesManager_Txt__c
|
|
})
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'OPDPlan__c',
|
actionName: 'new'
|
},
|
state: {
|
nooverride: '1',
|
defaultFieldValues: defaultFieldValues ,
|
}
|
});
|
|
}
|
|
|
}
|