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.init3';
|
import reapplyFindOPD from '@salesforce/apex/LexOPDSupplementaryController.reapplyFindOPD';
|
const event1 = new ShowToastEvent({
|
message:
|
"只有OPD计划状态为取消,并且延期取消理由为备品不足时才能再申请OPD计划",
|
variant : 'error',
|
mode :'sticky'
|
});
|
const event2 = new ShowToastEvent({
|
message:
|
"OPD计划已进行过再申请,无法再次进行再申请",
|
variant : 'error',
|
mode :'sticky'
|
});
|
export default class lexOPDReapply 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(){
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
init({
|
recordId: this.recordId
|
}).then(result => {
|
if (result != null) {
|
this.OPDPlan = result;
|
console.log('zheli:');
|
console.log(this.OPDPlan);
|
this.Reapply().then(result=>{
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
}).catch(error => {
|
const event3 = new ShowToastEvent({
|
message:
|
error.message,
|
variant : 'error',
|
mode :'sticky'
|
});
|
this.dispatchEvent(event3);
|
});
|
|
}
|
|
async Reapply(){
|
//状态
|
var status = this.OPDPlan.Status__c;
|
//取消延期理由
|
var dr = this.OPDPlan.DelayCancel_Reason__c;
|
var Opportunity1_ID = this.OPDPlan.Related_Opportunity1_ID__c;
|
if(status != '取消' || dr != '备品不足' ){
|
this.dispatchEvent(event1);
|
return;
|
}
|
await reapplyFindOPD({Id : this.OPDPlan.Id}).then(result=>{
|
console.log('TheOPDPlan');
|
console.log(result);
|
if (result.length > 0) {
|
this.TheOPDPlan = result;
|
}
|
else{
|
this.TheOPDPlan=null;
|
}
|
}).catch(error=>{
|
const eventError = new ShowToastEvent({
|
message:
|
error.message,
|
variant : 'error',
|
mode :'sticky'
|
});
|
this.dispatchEvent(eventError);
|
})
|
if(this.TheOPDPlan != null && this.TheOPDPlan.length > 0){
|
this.dispatchEvent(event2);
|
return;
|
}
|
const defaultFieldValues = encodeDefaultFieldValues({
|
Name : '*',
|
Account_Laboratory__c : this.OPDPlan.Account_Laboratory__c ,
|
OPDType__c : this.OPDPlan.OPDType__c,
|
RentalReson__c : this.OPDPlan.RentalReson__c,
|
OriginalOpdPlan__c : this.OPDPlan.Id,
|
Related_Opportunity1_ID__c : this.OPDPlan.Related_Opportunity1_ID__c,
|
CorrespondingRepairNo__c : this.OPDPlan.CorrespondingRepairNo__c,
|
AdditionalSupport__c : this.OPDPlan.AdditionalSupport__c,
|
Campaign__c : this.OPDPlan.Campaign__c,
|
NoOpp_Reason__c : this.OPDPlan.NoOpp_Reason__c,
|
ModelLending__c : this.OPDPlan.ModelLending__c,
|
ModelLendingProduct__c : this.OPDPlan.ModelLendingProduct__c,
|
PlanProdDetail__c : this.OPDPlan.PlanProdDetail__c,
|
// 20240303 ljh add start
|
EquipmentNotFromOpp__c : this.OPDPlan.EquipmentNotFromOpp__c,
|
EquipmentFromOpp__c : this.OPDPlan.EquipmentFromOpp__c,
|
PlanProdDetailSys__c : this.OPDPlan.PlanProdDetailSys__c,
|
PlanProdDetailSysT__c : this.OPDPlan.PlanProdDetail__c.length > 255 ? this.OPDPlan.PlanProdDetail__c.substring(0, 255):this.OPDPlan.PlanProdDetail__c // 计划出借战略产品文本
|
// 20240303 ljh add end
|
})
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'OPDPlan__c',
|
actionName: 'new'
|
},
|
state: {
|
nooverride: '1',
|
defaultFieldValues: defaultFieldValues ,
|
}
|
});
|
}
|
}
|