unknown
2023-07-19 f3ff606d272bf6427d4d2c1ef6e0ccb47ce74038
force-app/main/default/lwc/lexSubmitExtensionApprovalProcess/lexSubmitExtensionApprovalProcess.js
@@ -1,8 +1,11 @@
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 init from '@salesforce/apex/SubmitExtensionApprovalProcessController.init';
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;
@@ -22,46 +25,77 @@
   connectedCallback(){
      init({
         recordId:this.recordId
      }).then(result=>{
         var today = new Date();
      }).then(res=>{
         console.log('res==='+JSON.stringify(res));
         if(JSON.stringify(res) == '{}'){
            this.ToastShow('没有查到需要的数据','warning');
            return;
         }
         let today = new Date();
         //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c 
         if(result.ExtensionStatus == '填写完毕' || result.ExtensionStatus == '申请中') {
            alert('请确认延期申请状态,已经提交过的申请,不能重复提交');
         if(res.extensionStatus == '填写完毕' || res.extensionStatus == '申请中') {
            this.showToast('请确认延期申请状态,已经提交过的申请,不能重复提交','error');
            return; 
         }
         var rs1 = sforce.apex.execute("RentalApplyWebService", "extension_approval_processCheck", {rentalApplyId: this.recordId});
         if(rs1 != '1'){
            if(rs1 == '2'){
               //返回值为2,判断入口为从单还是主单,如果是从单,那么就需要跳原来的单个延期页面
               if(result.RootRentalApply == '' || result.RootRentalApply == null){
                  window.open("/apex/RentalApplyMultiPostpone?parentId=" + this.recordId);
               }else {
                  window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
         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{
               alert(rs1);
               return
               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;
               }
            }
         }else{
            if(result.demoPurpose2 == '协议借用'){
               alert('请在[附件]内上传新的合同附件,并依据合同内期限进行日期填写,之后提交审批');
               return;
            }
            if(result.AgreementBorrowingExtensionDate =='' || result.AgreementBorrowingExtensionDate == null){
               alert('协议借用的延期申请的【协议借用延期日期】不能为空');
               return;
            }
            if(result.AgreementBorrowingExtensionDate <= result.ReturnDadelineFinal){
               alert('协议借用的延期申请的【协议借用延期日期】必须大于最新预定归还日');
               return;
            }
            if(result.AgreementBorrowingExtensionDate <= today ){
               alert('协议借用的延期申请的【协议借用延期日期】必须大于今天');
               return;
            }
         }
         window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
            window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId);
            this.dispatchEvent(new CloseActionScreenEvent());
         }).catch(err=>{
            console.log('extension_approval_processCheckerr==='+err);
         })
      })
      .catch(err=>{
         console.log('error====>'+err);
      })
   }
   showToast(msg,type) {
        const event = new ShowToastEvent({
            message: msg,
            variant: type
        });
        if(type == 'success'){
            this.updateRecordView();
        }
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
}