import { LightningElement,api, track, wire } from 'lwc'; import init from '@salesforce/apex/RentalApplyApprovalButtonController.initRentalApply' import select01 from '@salesforce/apex/RentalApplyApprovalButtonController.getRasdList' import select02 from '@salesforce/apex/RentalApplyApprovalButtonController.getDeliveryGood1' import select03 from '@salesforce/apex/RentalApplyApprovalButtonController.getDeliveryGood2' import getProfileId from '@salesforce/apex/RentalApplyApprovalButtonController.getProfileId' import select05 from '@salesforce/apex/RentalApplyApprovalButtonController.getDeliveryGood3' import select06 from '@salesforce/apex/RentalApplyApprovalButtonController.getDeliveryGood4' import select07 from '@salesforce/apex/RentalApplyApprovalButtonController.getRasdList2' import select08 from '@salesforce/apex/RentalApplyApprovalButtonController.getRace' import getUserId from '@salesforce/apex/RentalApplyApprovalButtonController.getUserId' import select09 from '@salesforce/apex/RentalApplyApprovalButtonController.getManagerUers' import execute3 from '@salesforce/apex/RentalApplyApprovalButtonController.setSObjectShare' import updatedRentalApply from '@salesforce/apex/RentalApplyApprovalButtonController.updatedRentalApply' import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; /** 对象:备品借出申请 按钮:提交待审批 author:kkbes **/ export default class lexRentalApplySubmitedApprovalButton extends LightningElement { @api recordId; IsLoading=true; Id; applyUser__c; Campaign__c; Demo_purpose1__c; demo_purpose2__c; Follow_UP_Opp__c; Statu_Achievements__c; Status__c; Statu_Achievements_ID__c; SupplementCreated__c; Request_shipping_day__c; Repair__c; RecordTypeId; OPDPlan__c; Rental_Apply__c; OwnerId; @wire(CurrentPageReference) getStateParameters(currentPageReference){ if(currentPageReference){ console.log(currentPageReference); console.log("进入获取page参数") const IdValue=currentPageReference.state.recordId; if(IdValue){ let str=`${IdValue}`; this.recordId=str; console.log("recordId="+str); } } } connectedCallback(){ init({recordId:this.recordId}).then(res=>{ if(res!=null){ this.IsLoading=false; console.log("res"); console.log(res); console.log("进入初始化对象其他属性"); // Rental_Apply__c=res; // console.log(Rental_Apply__c); this.Id=res.Id; this.applyUser__c=res.applyUser; this.Campaign__c=res.Campaign; this.Demo_purpose1__c=res.Demo_purpose1; this.demo_purpose2__c=res.demo_purpose2; this.Follow_UP_Opp__c=res.Follow_UP_Opp; this.Statu_Achievements__c=res.Statu_Achievements; this.Status__c=res.Status; this.Statu_Achievements_ID__c=res.Statu_Achievements_ID; this.SupplementCreated__c=res.SupplementCreated; this.Request_shipping_day__c=res.Request_shipping_day; this.Repair__c=res.Repair; this.RecordTypeId=res.RecordTypeId; this.OPDPlan__c=res.OPDPlan; this.QIS_number__c=res.QIS_number; this.OwnerId=res.OwnerId; console.log(this); this.submitForReview(); } }).catch(error =>{ console.log("error"); console.log(error.message); }).finally(()=>{ }); } // currentDay(date){ // let toDay=new Date(); // toDay=''; // toDay+=date.getFullYear()+'/'; // toDay+=date.getMonth()+1+'/'; // toDay+=date.getDate(); // return toDay; // } getConnectDMLErrorMessages (results) { let messages = [], i = 0, len = results.length, r; for (; i < len; i++) { r = results[i]; if (!r.getBoolean("success")) { messages = messages.concat(getConnectDMLMessagesOfAResult(r)); } } return messages; }; getConnectDMLMessagesOfAResult(res) { let messages = [], errors = res.getArray("errors"), i = 0, len = errors.length, e; for (; i < len; i++) { e = errors[i]; messages.push(e.message + " " + getConnectDMLErrorFields(e)); } return messages; }; getConnectDMLErrorFields (error) { let fields = error.getArray('fields'); if (fields.length > 0) { return "[" + fields.join(",") + "]" } else { return ""; } }; async submitForReview(){ console.log("进入submitForReview函数") let buttons = document.getElementsByName('submit_approval_process'.toLowerCase()); for (let i=0; i{ if(equipmentList!=null){ console.log("equipmentList"); console.log(equipmentList); raesdList=equipmentList; } }).catch(err=>{ console.log(err.message); }).finally(()=>{ }); console.log("01 end"); console.log("5 for if"); let modelSet = new Set(); let stoppedSet = new Set(); //相当于对长度进行了判断 for(let i=0;i 0) { alert( Array.from(stoppedSet).join(',') + ' 产品注册证状态为停止,不可申请'); return; } console.log("7 if"); console.log("select2"); if( this.demo_purpose2__c == '索赔QIS'){ let DeliveryGood = new Array(); await select02({QIS_number : JSENCODE(this.QIS_number__c)}).then(qisList=>{ if(qisList!=null){ DeliveryGood=qisList; console.log("select2:"+qisList); } }).catch(err=>{ console.log("select2 error"); console.log(err.message); }).finally(()=>{ console.log("2 finally"); }); let records=DeliveryGood; // let records= DeliveryGood.getArray("records"); console.log("8 if"); if(records.length == 0 || !modelSet.has(records[0].nonyushohin__r.Product2.Fixture_Model_No_T__c)){ alert('申请的型号必须与QIS申请型号一致'); return; } } console.log('9 if'); if (this.Repair__c != "") { let DeliveryGood; console.log("99999999999999!"); await select03({ Repair: this.Repair__c }) .then((result) => { console.log("ddddddd"); console.log(result); if (result != null) { DeliveryGood = result; console.log("result=" + result); }}) .catch((err) => { console.log("select3 error"); console.log(err.message); }); console.log("dd"); if(DeliveryGood!=null &&DeliveryGood.length>0){ let records = DeliveryGood; console.log("select3" + records); // 修理Data records[0] // let records= DeliveryGood.getArray("records"); if ( this.Demo_purpose1__c == "维修代用" && this.demo_purpose2__c != "索赔QIS" ) { if ( !modelSet.has( records[0].Delivered_Product__r.Product2.Fixture_Model_No_T__c ) ) { alert("申请的型号必须与送修的型号一致"); return; } } if ( this.Demo_purpose1__c == "维修代用" && this.demo_purpose2__c == "一般用户" ) { if (records[0].Repair_Estimated_date_formula__c == null) { alert("一般维修无报价日,不可借用备品"); return; } else if ( records[0].Repair_Estimated_date_formula__c < "2019-07-01" && records[0].Agreed_Date__c == null ) { alert("报价日在2019/7/1之前且户同意日为空,不可借用备品"); return; } //20210608 ljh SFDC-C3CCN4 start if (records[0].Repair_Rank__c == "" || records[0].Repair_Rank__c == null) { alert("报价等级为空不能申请备品"); return; } else { if ( records[0].DW_Sign_Txt__c == "false" && records[0].Repair_Rank__c == "DW" ) { alert("DW报价等级下此型号不符合备品申请借用条件"); 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("报价等级不符合备品申请借用条件"); return; } } //20210608 ljh SFDC-C3CCN4 end } if ( this.Demo_purpose1__c == "维修代用" && this.demo_purpose2__c == "市场多年保修" ) { if (records[0].FSE_ApplyForRepair_Day__c == null) { alert("市场多年保修,没有[FSE修理申请日],不可借用备品"); return; } } if ( this.Demo_purpose1__c == "维修代用" && this.demo_purpose2__c == "故障排查" ) { if (records[0].FSE_ApplyForRepair_Day__c == null) { alert("故障排查,没有[FSE修理申请日],不可借用备品"); return; } if (records[0].Repair_Ordered_Date__c != null) { alert("故障排查,[4.修理品RC受理日]必须为空"); return; } if (records[0].IfCheckFixture__c == "false") { alert("不满足故障排查目的"); return; } } if ( this.RecordTypeId != "01210000000RHIn" && getProfileId() != "00e10000000Y3o5" && records[0].NewProductGuaranteeObject__c == "8: 市场多年保修" && this.demo_purpose2__c != "市场多年保修" ) { alert("无偿区别标志为8: 市场多年保修,必须选择市场多年保修。"); } if (records[0].Repair_Final_Inspection_Date__c != null) { alert("存在修理最终检测日,不可借用备品"); return; } if (records[0].Repair_Shipped_Date__c != null) { alert("存在RC修理返送日,不可借用备品"); return; } if ( records[0].Status1__c == "0.删除" || records[0].Status1__c == "0.取消" || records[0].Status1__c == "5.完毕" ) { alert("修理已经结束,不能申请备品"); return; } if ( "{!Rental_Apply__c.demo_purpose2__c}" == "再修理" && records[0].ReRepairObject_F__c == "false" ) { alert("不属于再受理参考对象,不可借用备品"); return; } if ( this.RecordTypeId != "01210000000RHIn" && this.demo_purpose2__c != "保修用户" && this.demo_purpose2__c != "市场多年保修" && records[0].Number_of_EffectiveContract__c == "有" ) { alert("有维修合同,必须选择保修用户."); return; } let AssetModelNo = records[0].Delivered_Product__r.Product2.Asset_Model_No__c; if ( this.RecordTypeId != "01210000000RHIn" && records[0].Number_of_EffectiveContract__c == "无" && 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.demo_purpose2__c != "保修用户" ) { alert("此设备型号多年保修,请选择保修用户."); return; } if ( this.RecordTypeId != "01210000000RHIn" && records[0].NewProductGuaranteeObject__c == "2: 服务多年保修" && (AssetModelNo == "CV-V1" || AssetModelNo == "CV-V1(A)" || AssetModelNo == "CV-V1(B)" || AssetModelNo == "GIF-LV1" || AssetModelNo == "CF-LV1L" || AssetModelNo == "CF-LV1I" || AssetModelNo == "MAJ-1910") && (this.demo_purpose2__c == "一般用户" || this.demo_purpose2__c == "再修理") ) { alert("奥辉设备,保修期内不提供备品."); return; } } } //有疑问 console.log("10 if"); if (this.SupplementCreated__c == "1" && this.OPDPlan__c != "") { let Id = this.Id; let raId = "Id"; // let raId = "{!Rental_Apply__c.Id}"; //?????? execute 啥意思 let raesCountCheck = sforce.apex.execute( "OpdPlanWebService", "raesCountCheck", { thisId: raId } ); if (raesCountCheck != "OK") { alert(raesCountCheck); return; } } console.log("11 if"); if(this.Campaign__c != null && this.OPDPlan__c != ''){ let DeliveryGood = new Array(); // 20220324 ljh obpm update start 不知道是什么东西 let statusSting = "{!$Label.StatusProcessState}"; let statusList = statusSting.split(','); await select05({CampaignId : this.CampaignId__c}).then(result=>{ if(result!=null){ DeliveryGood=result; } }).catch(err=>{ console.log(err.message); }).finally(()=>{ }); // 20220324 ljh obpm update start // let records= DeliveryGood.getArray("records"); let records= DeliveryGood; console.log("select5"+ records); let interval = records[0].Status; let records_Date = records[0].Rental_Apply_Flag__c; if (interval == '草案中') { alert('学会状态为草案中,不能提交'); return; } if (interval == '申请中') { alert('学会状态为申请中,不能提交'); return; } if (interval == '已结束') { alert('学会状态为已结束,不能提交'); return; } if (interval == '已提交报告') { alert('学会状态为已提交报告,不能提交'); return; } if (interval == '取消申请中') { alert('学会状态为取消申请中,不能提交'); return; } if (interval == '取消') { alert('学会状态为取消,不能提交'); return; } let today=new Date(); if (today >= this.Request_shipping_day__c -7) { alert("必须提前于希望到货日7天以上提交申请"); return; } if(records.length>0){ // 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("没有决裁号的,暂不能出借,请更新裁决信息。"); 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("已申请决裁但决裁状态不符合条件。"); return; } } // 20220324 ljh obpm add end } console.log("12 if"); if(this.QIS_number__c != null && this.QIS_number__c != ''){ let DeliveryGood = new Array(); await select06({QIS_ID_Line : this.QIS_ID_Line__c}).then(result=>{ if(result!=null){ DeliveryGood=result; } }).catch(err=>{ console.log(err.message); }).finally(()=>{ }); // let records= DeliveryGood.getArray("records"); let records= DeliveryGood; console.log("select6"+records); let interval; if(interval.length>0){ interval = records[0].next_action__c; } if (interval == '送回') { alert("QIS 已送回,不能再申请备品了"); return; } } console.log("select6 结束"); // share 这里的push啥意思 let userAccess =[]; //向数组的屁股加元素 // userAccess.push('{!Rental_Apply__c.applyUserId__c}_Edit'); let UserId=this.applyUser__c; // userAccess[userAccess.length]=UserId+'_Edit'; // console.log("length去定义"); userAccess.push( UserId+'_Edit'); // 这里的push有问题 console.log('userAccess='+userAccess); console.log('OwnerId='+this.OwnerId); console.log('Id='+this.Id); let rtn; await execute3({sobjectName:'Rental_Apply__Share',rowCause:'ApplyUserShare__c',parentId:this.Id,userAccess:userAccess,ownerId:this.OwnerId}).then(result=>{ if(result!=null){ rtn=result; } }).catch(err=>{ console.log("execute3 出问题"); console.log(err.message); }).finally(()=>{ }); if (rtn != 'OK') { alert(rtn); return; } console.log("ssssssssssssssssss"); //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c if (this.Status__c == '填写完毕' || this.Status__c == '申请中' || this.Status__c == '已批准' || //现在申请书的Status__c已经没有引当完了状态。所以这里不需要判断 //this.Status__c == '引当完了' || this.Status__c == '已出库指示' || this.Status__c == '删除' || this.Status__c == '取消' ) { alert('请备品申请状态确认,已经提交过的申请,不能重复提交'); return; } // 没有明细的一览check let records = new Array(); console.log("select07"); console.log(this.Id); await select07({Id : this.Id}).then(result=>{ if(result!=null){ records=result; console.log(records); } }).catch(err=>{ console.log(err.message); }).finally(()=>{ }); // let records= raesList.getArray('records'); if(records.length > 0){ alert('有没有明细的借出备品配套一览,不能提交'); return; } let racNew=new Array(); await select08({Id : this.Id}).then(result=>{ if(result!=null){ racNew=result; console.log(racNew); } }).catch(err=>{ console(err.message); }).finally(()=>{ }); //有疑问 // let racNew = racs.getArray("records")[0]; // 20220930 ljh SWAG-CJR8S7 end console.log("sssssssssssssssssssssssssss"); console.log("xinbuxxxxxxxx"); // let userId = "{!$User.Id}"; let userId= await getUserId(); let manageUsers=new Array(); let SalesManagerSubmit__c; let OPDManagerApprover__c; let BuchangApprovalManagerSalesSubmit__c; let OPDBuchangApprover__c; await select09({userId : userId}).then(result=>{ if(result!=null){ manageUsers=result; console.log(manageUsers); console.log(result); } }).catch(err=>{ console.log(err.message); }).finally(()=>{ }); console.log('manageUsers'); if(manageUsers.length>0){ if(manageUsers[0].JingliEquipmentManager__c != null){ SalesManagerSubmit__c = manageUsers[0].JingliEquipmentManager__r.Name; // 20220930 ljh SWAG-CJR8S7 start if(racNew.OPDPlan__c != null){ OPDManagerApprover__c = rac.SalesManagerSubmit__c == racNew.OPDPlan__r.SalesManager_Txt__c?rac.SalesManagerSubmit__c:' '; } // 20220930 ljh SWAG-CJR8S7 end } if(manageUsers[0].Buzhang_Equipment_Manager__c != null){ BuchangApprovalManagerSalesSubmit__c= manageUsers[0].Buzhang_Equipment_Manager__r.Name; //2022-07-22 zyh // 20220930 ljh SWAG-CJR8S7 start if(racNew.OPDPlan__c != null){ OPDBuchangApprover__c = rac.BuchangApprovalManagerSalesSubmit__c == racNew.OPDPlan__r.BuchangApprovalManagerSales_Txt__c?rac.BuchangApprovalManagerSalesSubmit__c:' '; } // 20220930 ljh SWAG-CJR8S7 end } } // 20220704 ljh update SFDC-CFWBBU end console.log('update'); // let result = sforce.connection.update([rac]); // await updatedRentalApply({Id : this.Id,Status:"填写完毕",SalesManagerSubmit:SalesManagerSubmit__c, // OPDManagerApprover:OPDManagerApprover__c, // BuchangApprovalManagerSalesSubmit:BuchangApprovalManagerSalesSubmit__c, // OPDBuchangApprover:OPDBuchangApprover__c}).then(result=>{ // if(result==1){ // console.log("update success") // } // }).catch(err=>{ // console.log(err.message); // }).finally(()=>{ // }); let res=await updatedRentalApply({Id : this.Id,Status:"填写完毕",SalesManagerSubmit:SalesManagerSubmit__c, OPDManagerApprover:OPDManagerApprover__c, BuchangApprovalManagerSalesSubmit:BuchangApprovalManagerSalesSubmit__c, OPDBuchangApprover:OPDBuchangApprover__c}); console.log(res); console.log('getConnectDMLErrorMessages'); let message = res.split(",")[1]; if(res=="success"){ messages.join("\n"); return; } window.location.href = window.location; }; }