unknown
2023-08-24 ddb0231ef7c5cf2bad9d3f1afc2f733674ad38a5
force-app/main/default/lwc/rentalApplyLWT/rentalApplyLWT.js
@@ -15,6 +15,9 @@
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import STATUS_PROCESS_STATE from '@salesforce/label/c.StatusProcessState';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import Id from '@salesforce/user/Id';
export default class rentalApplyLWT extends LightningElement {
    contactFirstName = 'Yan';
@@ -89,7 +92,12 @@
            }).catch(err=>{
               console.log("error:");
               console.log(err.message);
               alert("操作失败,错误信息:"+err.message);
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:"操作失败,提示信息:"+err.message,
                 });
                 this.dispatchEvent(event);
               //alert("操作失败,提示信息:"+err.message);
            });
            console.log("end");
         }
@@ -105,35 +113,6 @@
   }
    handleClick(event) {
        this.clickedButtonLabel = event.target.label;
    }
    handleContactFirstNameInputChange(event) {
        this.contactFirstName = event.target.value;
    }
    cancelSubmit(){
       console.log('djwaijd');
       if (this.Rental_Apply__c.Status__c == "取消") {
         alert("已经取消!");
         console.log('1');
         return;
      }
      if (this.Rental_Apply__c.Status__c == "删除") {
         alert("已经删除!");
         console.log('2');
         return;
      }
      if(this.RA_Status__c == "已出库" || this.Yi_loaner_arranged__c > 0) {
         alert("备品已经出库,不能取消!");
         console.log('2');
         return;
      }
      let raid = this.Id;
      window.open("/apex/RentalApplyCancel?objId="+raid, 'RentalApplyCancel', 'width=500,height=250');
   }
   async sumit(){
      let buttons = document.getElementsByName('submit_approval_process'.toLowerCase());
      for (let i=0; i<buttons.length; i++) {
@@ -141,12 +120,24 @@
         buttons[i].disabled = true;
      }
      //kk
      if (!confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
      const result = await LightningConfirm.open({
            message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
            variant: 'headerless',
            label: 'this is the aria-label value',
            // setting theme would have no effect
        });
      if (result==false) {
         return;
      }
      //1540 you 试用(无询价)目的的备品申请单,不能关联询价信息!
      if(this.Rental_Apply__c.demo_purpose2__c == '试用(无询价)' && this.Rental_Apply__c.Follow_UP_Opp__c !=null && this.Rental_Apply__c.Follow_UP_Opp__c != ''){
         alert('试用(无询价)目的的备品申请单,不能关联询价信息!');
         //alert('试用(无询价)目的的备品申请单,不能关联询价信息!');
         const event = new ShowToastEvent({
               title: '提示信息',
               message:'试用(无询价)目的的备品申请单,不能关联询价信息!',
           });
           this.dispatchEvent(event);
         return;
      }
      // 已购待货的申请单审批时,需要check注残的状态
@@ -155,14 +146,24 @@
         let SaID=this.Rental_Apply__c.Statu_Achievements_ID__c;
         let rtn = sforce.apex.execute("RentalApplyWebService","RentalApplyCheckForSAoneEle",{SaID:SaID});
         if(rtn!='Fin'){
            alert(rtn);
            //alert(rtn);
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:rtn,
              });
              this.dispatchEvent(event);
            return;
         }
      }
      // 希望到货日不能早于申请提交日-0418追加
      let d=new Date();
      if (this.Rental_Apply__c.Request_shipping_day__c < d ) {
         alert('希望到货日不能早于申请提交日');
         //alert('希望到货日不能早于申请提交日');
         const event = new ShowToastEvent({
               title: '提示信息',
               message:'希望到货日不能早于申请提交日',
           });
           this.dispatchEvent(event);
         return;
      }
      let raesdList = new Array();
@@ -180,12 +181,17 @@
               }
            }
            if(stoppedSet.size> 0) {
               alert( Array.from(stoppedSet).join(',') + ' 产品注册证状态为停止,不可申请');
               //alert( Array.from(stoppedSet).join(',') + ' 产品注册证状态为停止,不可申请');
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:Array.from(stoppedSet).join(',') + ' 产品注册证状态为停止,不可申请',
                 });
                 this.dispatchEvent(event);
               return;
            }
         }
      }).catch(err=>{
         console.log("selectRentalApplyEquipmentSetDetailByRacId error:");
         console.log("select1 error:");
         console.log(err.message);
         console.log("报错结束");
      }).finally(()=>{
@@ -199,14 +205,19 @@
            console.log(result);
            DeliveryGood=result;   
         }).catch(err=>{
            console.log("selectQISReportById error:");
            console.log("select1 error:");
            console.log(err.message);
         }).finally(()=>{
         });
         console.log(DeliveryGood);   
         let records= DeliveryGood;
         if(records.length == 0 || !modelSet.has(records[0].nonyushohin__r.Product2.Fixture_Model_No_T__c)){
            alert('申请的型号必须与QIS申请型号一致');
            //alert('申请的型号必须与QIS申请型号一致');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'申请的型号必须与QIS申请型号一致',
              });
              this.dispatchEvent(event);
            return;
         }
      }
@@ -222,7 +233,7 @@
               DeliveryGood=result;   
               records=result;
            }).catch(err=>{
               console.log("selectRepairById error:");
               console.log("select1 error:");
               console.log(err.message);
            }).finally(()=>{
            });
@@ -231,7 +242,12 @@
            }else{
               if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c != '索赔QIS') {
                  if(!modelSet.has(records[0].Delivered_Product__r.Product2.Fixture_Model_No_T__c)){
                     alert('申请的型号必须与送修的型号一致');
                     //alert('申请的型号必须与送修的型号一致');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'申请的型号必须与送修的型号一致',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
               }
@@ -239,28 +255,53 @@
                  console.log("Demo_purpose1__c为空");
               }else if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c == '一般用户' ){
                  if (records[0].Repair_Estimated_date_formula__c == null) {
                     alert('一般维修无报价日,不可借用备品');
                     //alert('一般维修无报价日,不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'一般维修无报价日,不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
                  else if (records[0].Repair_Estimated_date_formula__c < '2019-07-01' && records[0].Agreed_Date__c == null) {
                     alert('报价日在2019/7/1之前且户同意日为空,不可借用备品');
                     //alert('报价日在2019/7/1之前且户同意日为空,不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'报价日在2019/7/1之前且户同意日为空,不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
                  //20210608 ljh SFDC-C3CCN4 start
                  if(records[0].Repair_Rank__c == '' || records[0].Repair_Rank__c == null){
                     alert('报价等级为空不能申请备品');
                     //alert('报价等级为空不能申请备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'报价等级为空不能申请备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }else{
                     if(records[0].DW_Sign_Txt__c == 'false' && records[0].Repair_Rank__c == 'DW'){
                        alert('DW报价等级下此型号不符合备品申请借用条件');
                        //alert('DW报价等级下此型号不符合备品申请借用条件');
                        const event = new ShowToastEvent({
                              title: '提示信息',
                              message:'DW报价等级下此型号不符合备品申请借用条件',
                          });
                          this.dispatchEvent(event);
                        return;
                     }
                     if(records[0].Repair_Rank__c == 'D1'
                        ||records[0].Repair_Rank__c == 'D2'
                        ||records[0].Repair_Rank__c == 'D3'
                        ||records[0].Repair_Rank__c == 'E2'){
                        alert('报价等级不符合备品申请借用条件');
                        //alert('报价等级不符合备品申请借用条件');
                        const event = new ShowToastEvent({
                              title: '提示信息',
                              message:'报价等级不符合备品申请借用条件',
                          });
                          this.dispatchEvent(event);
                        return;
                     }
                  }
@@ -270,21 +311,41 @@
                  console.log("Demo_purpose1__c为空");
               }else if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c == '市场多年保修' ){
                  if (records[0].FSE_ApplyForRepair_Day__c == null) {
                     alert('市场多年保修,没有[FSE修理申请日],不可借用备品');
                     // alert('市场多年保修,没有[FSE修理申请日],不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
               }
               if(this.Rental_Apply__c.Demo_purpose1__c == '维修代用' && this.Rental_Apply__c.demo_purpose2__c == '故障排查' ){
                  if (records[0].FSE_ApplyForRepair_Day__c == null) {
                     alert('故障排查,没有[FSE修理申请日],不可借用备品');
                     //alert('故障排查,没有[FSE修理申请日],不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
                  if(records[0].Repair_Ordered_Date__c != null) {
                     alert('故障排查,[4.修理品RC受理日]必须为空');
                     //alert('故障排查,[4.修理品RC受理日]必须为空');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
                  if(records[0].IfCheckFixture__c == 'false'){
                     alert('不满足故障排查目的');
                     //alert('不满足故障排查目的');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
                  }
               }
@@ -303,29 +364,59 @@
                  && profileId != '00e10000000Y3o5'
                  && records[0].NewProductGuaranteeObject__c == '8: 市场多年保修'
                  && this.Rental_Apply__c.demo_purpose2__c != '市场多年保修') {
                  alert('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。');
                  //alert('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。');
                  const event = new ShowToastEvent({
                        title: '提示信息',
                        message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                    });
                    this.dispatchEvent(event);
               }
               if(records[0].Repair_Final_Inspection_Date__c != null){
                  alert('存在修理最终检测日,不可借用备品');
                  //alert('存在修理最终检测日,不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                  return;
               }
               if(records[0].Repair_Shipped_Date__c != null){
                  alert('存在RC修理返送日,不可借用备品');
                  //alert('存在RC修理返送日,不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                  return;
               }
               if(records[0].Status1__c =='0.删除' ||records[0].Status1__c =='0.取消' ||records[0].Status1__c =='5.完毕' ){
                  alert('修理已经结束,不能申请备品');
                  //alert('修理已经结束,不能申请备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                  return;
               }
               if ( this.Rental_Apply__c.demo_purpose2__c == '再修理' && records[0].ReRepairObject_F__c == 'false') {
                  alert('不属于再受理参考对象,不可借用备品');
                  //alert('不属于再受理参考对象,不可借用备品');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                  return;
               }
               if (this.Rental_Apply__c.RecordTypeId != '01210000000RHIn'
                  && this.Rental_Apply__c.demo_purpose2__c != '保修用户'
                  && this.Rental_Apply__c.demo_purpose2__c != '市场多年保修'
                  && records[0].Number_of_EffectiveContract__c == '有' ) {
                  alert('有维修合同,必须选择保修用户.');
                  //alert('有维修合同,必须选择保修用户.');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                  return;
               }
               let AssetModelNo = records[0].Delivered_Product__r.Product2.Asset_Model_No__c;
@@ -333,7 +424,12 @@
                  && (records[0].NewProductGuaranteeObject__c == '2: 服务多年保修'
                  && (AssetModelNo == 'LTF-190-10-3D' || AssetModelNo == 'LTF-S190-5' || AssetModelNo == 'CYF-VHA' || AssetModelNo == 'CYF-VA2' || AssetModelNo == 'CYF-5A'|| AssetModelNo == 'LTF-S190-10'|| AssetModelNo == 'OER-AW'|| AssetModelNo == 'URF-V'|| AssetModelNo == 'URF-V2'|| AssetModelNo == 'URF-P6'))
                  && this.Rental_Apply__c.demo_purpose2__c != '保修用户' ) {
                  alert('此设备型号多年保修,请选择保修用户.');
                  //alert('此设备型号多年保修,请选择保修用户.');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                  return;
               }
@@ -342,7 +438,12 @@
                  && (AssetModelNo == 'CV-V1' || AssetModelNo == 'CV-V1(A)' || AssetModelNo == 'CV-V1(B)' || AssetModelNo == 'GIF-LV1' || AssetModelNo == 'CF-LV1L' || AssetModelNo == 'CF-LV1I' || AssetModelNo == 'MAJ-1910')
                  && (this.Rental_Apply__c.demo_purpose2__c == '一般用户' || this.Rental_Apply__c.demo_purpose2__c == '再修理')
                  ) {
                     alert('奥辉设备,保修期内不提供备品.');
                     //alert('奥辉设备,保修期内不提供备品.');
                     const event = new ShowToastEvent({
                           title: '提示信息',
                           message:'市场多年保修,没有[FSE修理申请日],不可借用备品',
                       });
                       this.dispatchEvent(event);
                     return;
               }
            }
@@ -357,7 +458,12 @@
         //kk
         let raesCountCheck = sforce.apex.execute("OpdPlanWebService", "raesCountCheck", {rentalApplyId: raId});
         if(raesCountCheck != 'OK'){
            alert(raesCountCheck);
            //alert(raesCountCheck);
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:raesCountCheck,
              });
              this.dispatchEvent(event);
            return;
         }
      }
@@ -387,49 +493,104 @@
         let interval = records[0].Status;
         let records_Date = records[0].Rental_Apply_Flag__c;
         if (interval==null ) {
            alert("请确认学会状态");
            //alert("请确认学会状态");
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:"请确认学会状态",
              });
              this.dispatchEvent(event);
            return;
         }
         else if (interval == '草案中') {
            alert('学会状态为草案中,不能提交');
            //alert('学会状态为草案中,不能提交');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'学会状态为草案中,不能提交',
              });
              this.dispatchEvent(event);
            return;
         }
         else if (interval == '申请中') {
            alert('学会状态为申请中,不能提交');
            //alert('学会状态为申请中,不能提交');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'学会状态为申请中,不能提交',
              });
              this.dispatchEvent(event);
            return;
         }
         else if (interval == '已结束') {
            alert('学会状态为已结束,不能提交');
            // alert('学会状态为已结束,不能提交');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'学会状态为已结束,不能提交',
              });
              this.dispatchEvent(event);
            return;
         }
         else if (interval == '已提交报告') {
            alert('学会状态为已提交报告,不能提交');
            // alert('学会状态为已提交报告,不能提交');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'学会状态为已提交报告,不能提交',
              });
              this.dispatchEvent(event);
            return;
         }
         else if (interval == '取消申请中') {
            alert('学会状态为取消申请中,不能提交');
            // alert('学会状态为取消申请中,不能提交');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'学会状态为取消申请中,不能提交',
              });
              this.dispatchEvent(event);
            return;
         }
         else if (interval == '取消') {
            alert('学会状态为取消,不能提交');
            // alert('学会状态为取消,不能提交');
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:'学会状态为取消,不能提交',
              });
              this.dispatchEvent(event);
            return;
         }
         //kk
         if(this.Rental_Apply__c.Request_shipping_day__c==null){
            alert("请确认希望到货日期");
            // alert("请确认希望到货日期");
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:"请确认希望到货日期",
              });
              this.dispatchEvent(event);
            return;
         }else{
            if (d >= this.Rental_Apply__c.Request_shipping_day__c -7) {
               alert("必须提前于希望到货日7天以上提交申请");
               // alert("必须提前于希望到货日7天以上提交申请");
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:"必须提前于希望到货日7天以上提交申请",
                 });
                 this.dispatchEvent(event);
               return;
            }
            // 20220324 ljh obpm add start
            if (records != null && records[0].IF_Approved__c == "true" && (records[0].Meeting_Approved_No__c == null || records[0].Meeting_Approved_No__c == "") ) {
               alert("没有决裁号的,暂不能出借,请更新裁决信息。");
               // alert("没有决裁号的,暂不能出借,请更新裁决信息。");
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:"没有决裁号的,暂不能出借,请更新裁决信息。",
                 });
                 this.dispatchEvent(event);
               return;
            }
            if (records != null && records[0].IF_Approved__c == "true" && records[0].Meeting_Approved_No__c != "" && statusList.indexOf(records[0].Approved_Status__c) != -1 && records[0].Approved_Status__c != '草稿' ) {
               alert("已申请决裁但决裁状态不符合条件。");
               // alert("已申请决裁但决裁状态不符合条件。");
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:"已申请决裁但决裁状态不符合条件。",
                 });
                 this.dispatchEvent(event);
               return;
            }
         }
@@ -447,14 +608,19 @@
               console.log(result);
               DeliveryGood=result;   
            }).catch(err=>{
               console.log("selectQISreportById2 error:");
               console.log("selectCampaignById error:");
               console.log(err.message);
            }).finally(()=>{
            });
            let records= DeliveryGood;
            let interval = records[0].next_action__c;
            if (interval == '送回') {
               alert("QIS 已送回,不能再申请备品了");
               // alert("QIS 已送回,不能再申请备品了");
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:"QIS 已送回,不能再申请备品了",
                 });
                 this.dispatchEvent(event);
               return;
            }
         }
@@ -475,16 +641,31 @@
      });
      if(rtn==null){
         alert("rtn为空");
         // alert("rtn为空");
         const event = new ShowToastEvent({
               title: '提示信息',
               message:"rtn为空",
           });
           this.dispatchEvent(event);
         return;
      }else{
         if (rtn != 'OK') {
            alert(rtn);
            // alert(rtn);
            const event = new ShowToastEvent({
                  title: '提示信息',
                  message:rtn,
              });
              this.dispatchEvent(event);
            return;
         }   
      }
      if(this.Rental_Apply__c.Status__c == null){
         alert('请备品申请状态确认,不能为空');
         // alert('请备品申请状态确认,不能为空');
         const event = new ShowToastEvent({
               title: '提示信息',
               message:'请备品申请状态确认,不能为空',
           });
           this.dispatchEvent(event);
         return;
      }else{
         if (this.Rental_Apply__c.Status__c == '填写完毕' ||
@@ -495,7 +676,12 @@
            this.Rental_Apply__c.Status__c == '已出库指示' ||
            this.Rental_Apply__c.Status__c == '删除' ||
            this.Rental_Apply__c.Status__c == '取消' ) {
               alert('请备品申请状态确认,已经提交过的申请,不能重复提交');
               // alert('请备品申请状态确认,已经提交过的申请,不能重复提交');
               const event = new ShowToastEvent({
                     title: 'Get Help',
                     message:'请备品申请状态确认,已经提交过的申请,不能重复提交'
                 });
                 this.dispatchEvent(event);
               return;
         }
      }
@@ -506,14 +692,19 @@
         console.log(result);
         raesList=result;   
      }).catch(err=>{
         console.log("selectRentalApplyEquipmentSetByRacId error:");
         console.log("selectCampaignById error:");
         console.log(err.message);
      }).finally(()=>{
      });
      let records= raesList;
      if(records.length > 0){
         alert('有没有明细的借出备品配套一览,不能提交');
         // alert('有没有明细的借出备品配套一览,不能提交');
         const event = new ShowToastEvent({
               title: '提示信息',
               message:'有没有明细的借出备品配套一览,不能提交',
           });
           this.dispatchEvent(event);
         return;
      }
      
@@ -522,7 +713,7 @@
         console.log(result);
         racs=result;   
      }).catch(err=>{
         console.log("selectRentalApplyById error:");
         console.log("selectCampaignById error:");
         console.log(err.message);
      }).finally(()=>{
      });
@@ -534,7 +725,7 @@
         console.log(result);
         userId=result;   
      }).catch(err=>{
         console.log("getUserId error:");
         console.log("selectCampaignById error:");
         console.log(err.message);
      }).finally(()=>{
      });
@@ -543,7 +734,7 @@
         console.log(result);
         manageUsers=result;   
      }).catch(err=>{
         console.log("selectUserById error:");
         console.log("selectCampaignById error:");
         console.log(err.message);
      }).finally(()=>{
      });
@@ -583,7 +774,12 @@
            messages=resultt.errors[0].split(',')[1];
            if (messages!=null&&messages!="") {
               console.log("hhh26");
               alert("操作失败,错误信息:"+messages);
               // alert("操作失败,提示信息:"+messages);
               const event = new ShowToastEvent({
                     title: '提示信息',
                     message:"操作失败,提示信息:"+messages,
                 });
                 this.dispatchEvent(event);
               return;
            }
         }
@@ -654,6 +850,5 @@
         console.log("in 3");
         return "";
      }
   };
}