binxie
2024-01-22 4688e276eee13cd2e521aa55afb5725cb0fda270
force-app/main/default/lwc/lexOPDPlanCommitNeedApproval/lexOPDPlanCommitNeedApproval.js
@@ -8,14 +8,8 @@
import {loadStyle} from 'lightning/platformResourceLoader';
import init  from '@salesforce/apex/LexOPDSupplementaryController.init2';
import NewAndUpdateOPDStatus  from '@salesforce/apex/LexOPDSupplementaryController.NewAndUpdateOPDStatus';
// import UpdateSign  from '@salesforce/apex/LexOPDSupplementaryController.UpdateSign';
import STATUS_PROCESS_STATE from '@salesforce/label/c.StatusProcessState';
import { updateRecord } from 'lightning/uiRecordApi';
import UserInfo_Owner from '@salesforce/apex/LexOPDSupplementaryController.UserInfo_Owner';
import newApply from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.newApplyInit';
import newApplyInitApp from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.newApplyInitApp';
import sendFailEmail from '@salesforce/apex/LexOPDSupplementaryController.sendTemperatureEmail';
import newRentalApply from '@salesforce/apex/LexOPDSupplementaryController.newRentalApply';
const event1 = new ShowToastEvent({
                  message:
@@ -42,20 +36,11 @@
   @api recordId;
   OPDPlan;
   IsLoading=true;
   opdCampaignTypeId;
   opdInternalinchargeprovince;
   @track proSameNum;
   @track proModelNum;
   @track proStopNum;
   @track proNewNum;
   @track proAccSameNum;
   @track renAppName;
   @track RepeatRentalSign = false;
   @track StatusProcessState=STATUS_PROCESS_STATE;
   @track rentalReson1;
   @wire(CurrentPageReference)
   getStateParameters(currentPageReference) {
   if (currentPageReference) {
   @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
@@ -72,17 +57,7 @@
            recordId: this.recordId
        }).then(result => {
            if (result != null) {
               this.rentalReson1 = result.rentalReson;
                this.OPDPlan = result.opdPlanRecord;
                this.proSameNum = result.proSameNum;
                this.proModelNum = result.proModelNum;
                this.proStopNum = result.proStopNum;
                this.proNewNum = result.proNewNum;
                this.proAccSameNum = result.proAccSameNum;
                this.renAppName = result.renAppName;
                this.opdStatusProcessState = result.opdStatusProcessState;
                this.opdCampaignTypeId = result.opdCampaignTypeId;
                this.opdInternalinchargeprovince = result.opdInternalinchargeprovince;
                this.OPDPlan = result;
                this.commitNeedApproval().then(result=>{
                   this.IsLoading=false;
                   this.dispatchEvent(new CloseActionScreenEvent());
@@ -90,6 +65,7 @@
            }
        }).catch(error => {
         const eventInItError = new ShowToastEvent({
                 message:
               error.message,
               variant : 'error',
@@ -103,31 +79,16 @@
    async commitNeedApproval(){
       var changeFlg=0;
      //0.当前状态(只有草案中才可以进行审批)
      var NowStatus = this.OPDPlan.Status__c;
      var NowStatus = this.OPDPlan.opdPlanRecord.Status__c;
      //获取出借目的
      var RentalReson__c = this.OPDPlan.RentalReson__c;
      var RentalReson__c = this.OPDPlan.opdPlanRecord.RentalReson__c;
      //获取附件证明
      var AttachmentCertificate__c = this.OPDPlan.AttachmentCertificate__c;
      //获取是否需要填写报告书
      var NeedReport = this.OPDPlan.NeedReport__c;
      var IFApproved = this.OPDPlan.IF_Approved__c;
      var ApprovedNo = this.OPDPlan.Approved_No__c;
      var ApprovedStatus = this.OPDPlan.Approved_Status__c;
      var RentalApply2 = this.OPDPlan.Rental_Apply2__c;
      var HaveValue = this.OPDPlan.Rental_Apply2__c;
      var OPDType = this.OPDPlan.OPDType__c;
      var CampaignId = this.OPDPlan.Campaign__c;
      var Days = this.OPDPlan.Rental_Apply_Flag__c;
      var CampaignTypeId = this.OPDPlan.CampaignRecodeTypeId__c;
      var cp = this.OPDPlan.Internal_in_charge_province__c;
      var up = "{!Text($User.Province__c)}";
      var ups = up.slice(0, 2);
      var CampaignStatus = this.OPDPlan.CampaignStatus__c;
      var OriginalOpdPlanApplication = this.OPDPlan.OriginalOpdPlanApplication__c;
      var opdAccountLaboratory = this.OPDPlan.Account_Laboratory__c;
      var rentalReson = this.OPDPlan.RentalReson__c;
      var StayOrNot = this.OPDPlan.StayOrNot__c;
      var NeedReport = this.OPDPlan.opdPlanRecord.NeedReport__c;
      console.log('NowStatus>>>>>' + NowStatus);
      console.log('this.OPDPlan>>>>' + JSON.stringify(this.OPDPlan));
      debugger;
      if(NowStatus != "草案中"){
         this.dispatchEvent(event1);
         return;
@@ -142,41 +103,6 @@
         this.dispatchEvent(event3);
         return;
      }
      //2023-11-28 Add by du Start 防止出借目的修改,提交时存在不符合条件的数据
        if (this.proStopNum == 1 || this.proModelNum == 1) {
            this.showToast('OPD计划下存在不符合出借目的的备品数据。','error');
            return;
        }
        //2023-12-15 Add by du Start 新产品评价下的产品至少要有一个新产品标记的产品存在
        if (this.proNewNum === 0 && this.rentalReson1 === '新产品评价') {
            this.showToast('新产品试用时,至少要有一个新产品。','error');
            return;
        }
      //同一科室下,进行关联性验证
      if (this.proSameNum === 0) {
            this.showToast('出借备品明细至少有一个和关联的询价报价产品相符, 请同步报价产品。','error');
            return;
        }
        //同一科室下,进行重复性验证
      console.log('this.proAccSameNum----------' + this.rentalReson1);
        if (this.proAccSameNum !== 0 && this.rentalReson1 == 'OPD'){
         const result3 = await LightningConfirm.open({
            message: '同医院同科室借用重复型号产品(' + this.renAppName + '),审批到副总裁, 请确定是否继续申请借用?',
            variant: 'headerless',
            label: 'this is the aria-label value',
           });
           if(!result3){
              return;
             }else{
                this.RepeatRentalSign = true;
             }
      }
      // 2023-11-28 Add by du End
      //2.提示
      const result1 = await LightningConfirm.open({
            message: '一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?',
@@ -186,9 +112,7 @@
        if(!result1){
           return;
        }
        console.log('123123');
      //2022-07-20 zyh
      var RentalReson = this.OPDPlan.RentalReson__c;
      var Related_Opportunity1_ID = this.OPDPlan.Related_Opportunity1_ID__c;
@@ -203,137 +127,34 @@
              return;
             }
      }
      //20231008 sx 借用机会可视化-提交审批逻辑改造 start
      if(StayOrNot == '已离职'){
         this.showToast('所有人已经离职,请联系系统管理员修改所有人。','warning');
         sendFailEmail({opdName:this.OPDPlan.Name ,ErrorMessage: '所有人已经离职,请联系系统管理员修改所有人。' , recordId: this.recordId});
            return;
      }
      if(IFApproved && (ApprovedNo == '' || ApprovedNo == undefined)){
         this.showToast('需要决裁时,决裁编码不能为空','warning');
         sendFailEmail({opdName:this.OPDPlan.Name ,ErrorMessage: '需要决裁时,决裁编码不能为空' , recordId: this.recordId});
         return;
      }
      if (IFApproved && (ApprovedNo != '' || ApprovedNo == undefined)  && this.opdStatusProcessState.indexOf(ApprovedStatus)!=-1 && ApprovedStatus != '草稿'){
         this.showToast('已申请决裁但决裁状态不符合条件','error');
         sendFailEmail({opdName:this.OPDPlan.Name ,ErrorMessage: '已申请决裁但决裁状态不符合条件' , recordId: this.recordId});
         return;
      }
      if((HaveValue!= null || HaveValue!= undefined) && OPDType != '学会'){
         this.showToast('一个OPD计划只可关联创建一个备品申请单','error');
         sendFailEmail({opdName:this.OPDPlan.Name ,ErrorMessage: '一个OPD计划只可关联创建一个备品申请单' , recordId: this.recordId});
         return;
      }
      console.log('12312312hhhh');
      //2022-07-20 zyh
      await NewAndUpdateOPDStatus({Id : this.OPDPlan.Id, RepeatRentalSign : this.RepeatRentalSign}).then(result=>{
      await NewAndUpdateOPDStatus({Id : this.OPDPlan.Id}).then(result=>{
         if(result!='success'){
            const eventError = new ShowToastEvent({
                    message:result,
                  variant:'error',
                  mode:'sticky'
                    message:
                  result,
                  variant :'error',
                  mode : 'sticky'
              });
              changeFlg+=1;
              this.dispatchEvent(eventError);            
         }else{
            console.log('NewAndUpdateOPDStatus======'+result);
         }
      });
      if(changeFlg!=0){
         return;
      }
      await UserInfo_Owner({}).then(res=>{
         if (OPDType == '学会' && CampaignId != '') {
            let campaignRecodeType = CampaignTypeId.slice(0,15);
            let getCampaignRecodeType = opdCampaignTypeId.slice(0,15);
            let ups = res.userProvince.slice(0, 2);
            if (campaignRecodeType != getCampaignRecodeType && res.userJobCategory == '销售服务' ) {
                    this.showToast('FSE不能申请该学会类型备品','warning');
                    return;
                }else if ((res.userJobCategory == '销售服务' || res.userJobCategory == '支援') && campaignRecodeType != getCampaignRecodeType && opdInternalinchargeprovince.indexOf(ups) == -1) {
                    this.showToast("与FSE所在省一致,才可使用备品",'warning');
                    return;
                }else if(CampaignStatus == '已结束'){
                   this.showToast("已结束,不能申请",'warning');
                    return;
                }else if(CampaignStatus == '已提交报告'){
                   this.showToast("已提交报告,不能申请",'warning');
                    return;
                }else if(CampaignStatus == '取消申请中'){
                   this.showToast("取消申请中,不能申请",'warning');
                    return;
                }else if(CampaignStatus == '取消'){
                   this.showToast("已经取消,不能申请",'warning');
                    return;
                }
         }
      })
      newRentalApply({
         recordId: this.recordId
      }).then(res=>{
         console.log('newRentalApply======'+res);
      }).catch(err=>{
         console.log(err)
      })
      this.dispatchEvent(new CloseActionScreenEvent());
      //20231008 sx 借用机会可视化-提交审批逻辑改造 end
      //4. 进程生成器
      //5. 重新刷新页面
      setTimeout(function(){
      window.location.href = window.location;
      }, 1500 )
   }
   //20240103 sx 备品智能化 add start
   showToast(msg,type) {
        if(type == 'success'){
           const event = new ShowToastEvent({
               message: msg,
               variant: type
           });
            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 }});
    }
   navigateEvents(defaultValues){
        console.log("--------navigateEvents------",defaultValues);
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Rental_Apply__c',
                actionName: 'new'
            },
            state:{
                // nooverride : 1,
                defaultFieldValues: defaultValues
            }
        });
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    //20240103 sx 备品智能化 add end
}