import { LightningElement, track, wire, api } from 'lwc';
|
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { updateRecord } from 'lightning/uiRecordApi';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
|
import init from '@salesforce/apex/LexSubmitExtensionController.init';
|
import extension_approval_processCheck from '@salesforce/apex/RentalApplyWebService.extension_approval_processCheck'
|
export default class lexSubmitExtensionApprovalProcess extends LightningElement {
|
@api
|
recordId;
|
IsLoading = true;
|
|
@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(res=>{
|
console.log('res==='+JSON.stringify(res));
|
if(JSON.stringify(res) == '{}'){
|
this.ToastShow('没有查到需要的数据','warning');
|
return;
|
}
|
let today = new Date();
|
//追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c
|
if(res.extensionStatus == '填写完毕' || res.extensionStatus == '申请中') {
|
this.showToast('请确认延期申请状态,已经提交过的申请,不能重复提交','error');
|
return;
|
}
|
extension_approval_processCheck({rentalApplyId:this.recordId}).then(result =>{
|
console.log('result==='+result);
|
if(result != '1'){
|
if(result == '2'){
|
//返回值为2,判断入口为从单还是主单,如果是从单,那么就需要跳原来的单个延期页面
|
if(result.rootRentalApply == '' || result.rootRentalApply == null){
|
window.open("/apex/RentalApplyMultiPostpone?parentId=" + this.recordId);
|
}else {
|
window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
|
}
|
}else{
|
this.showToast(result,'error');
|
return
|
}
|
}else{
|
// 20230926 ljh update start
|
// if(res.demoPurpose2 == '协议借用'){
|
// this.showToast('请在[附件]内上传新的合同附件,并依据合同内期限进行日期填写,之后提交审批','error');
|
// return;
|
// }
|
// console.log('typeof'+typeof(res.agreementBorrowingExtensionDate));
|
// if(res.agreementBorrowingExtensionDate =='' || res.agreementBorrowingExtensionDate == null){
|
// this.showToast('协议借用的延期申请的【协议借用延期日期】不能为空','error');
|
// return;
|
// }
|
// typeof(res.agreementBorrowingExtensionDate) == 'string' ? res.agreementBorrowingExtensionDate = new Date(res.agreementBorrowingExtensionDate) : '';
|
// typeof(res.returnDadelineFinal) == 'string' ? res.returnDadelineFinal = new Date(res.returnDadelineFinal) : '';
|
// if(res.agreementBorrowingExtensionDate <= res.returnDadelineFinal){
|
// this.showToast('协议借用的延期申请的【协议借用延期日期】必须大于最新预定归还日','error');
|
// return;
|
// }
|
// if(res.agreementBorrowingExtensionDate <= today ){
|
// this.showToast('协议借用的延期申请的【协议借用延期日期】必须大于今天','error');
|
// return;
|
// }
|
// window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
|
if(res.demoPurpose2 == '协议借用'){
|
const event = new ShowToastEvent({
|
message: '请在[附件]内上传新的合同附件,并依据合同内期限进行日期填写,之后提交审批',
|
variant: 'info',
|
mode: 'dismissible'
|
});
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
if(res.agreementBorrowingExtensionDate =='' || res.agreementBorrowingExtensionDate == null){
|
this.showToast('协议借用的延期申请的【协议借用延期日期】不能为空','error');
|
return;
|
}
|
typeof(res.agreementBorrowingExtensionDate) == 'string' ? res.agreementBorrowingExtensionDate = new Date(res.agreementBorrowingExtensionDate) : '';
|
typeof(res.returnDadelineFinal) == 'string' ? res.returnDadelineFinal = new Date(res.returnDadelineFinal) : '';
|
if(res.agreementBorrowingExtensionDate <= res.returnDadelineFinal){
|
this.showToast('协议借用的延期申请的【协议借用延期日期】必须大于最新预定归还日','error');
|
return;
|
}
|
if(res.agreementBorrowingExtensionDate <= today ){
|
this.showToast('协议借用的延期申请的【协议借用延期日期】必须大于今天','error');
|
return;
|
}
|
setTimeout(() => {
|
window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
|
}, 4000);
|
}else{
|
window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
|
}
|
// 20230926 ljh update end
|
|
}
|
this.dispatchEvent(new CloseActionScreenEvent());
|
|
}).catch(err=>{
|
console.log('extension_approval_processCheckerr==='+err);
|
})
|
})
|
.catch(err=>{
|
console.log('error====>'+err);
|
})
|
}
|
|
showToast(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 }});
|
}
|
}
|