import { LightningElement,api, track, wire } from 'lwc'; import {CurrentPageReference} from 'lightning/navigation'; import { CloseActionScreenEvent } from 'lightning/actions'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import LightningConfirm from 'lightning/confirm'; import customJSFile from '@salesforce/resourceUrl/CommonUtilJs'; import { loadScript } from 'lightning/platformResourceLoader'; import init from '@salesforce/apex/LexContractAuthorizeController.init'; import getProfileId from '@salesforce/apex/LexContractAuthorizeController.getProfileId'; import judgeIsAssistantAppliedOutTime from '@salesforce/apex/LexContractAuthorizeController.judgeIsAssistantAppliedOutTime'; import searchOpportunity from '@salesforce/apex/LexContractAuthorizeController.searchOpportunity'; import checkDangerItem from '@salesforce/apex/LexContractAuthorizeController.checkDangerItem'; import oppCheck from '@salesforce/apex/LexContractAuthorizeController.oppCheck'; import updReg from '@salesforce/apex/LexContractAuthorizeController.updReg'; import updateOppotunity from '@salesforce/apex/LexContractAuthorizeController.updateOppotunity'; export default class lexContractAuthorize extends LightningElement { @api recordId; IsLoading=true; data; @wire(CurrentPageReference) getStateParameters(currentPageReference){ console.log("进入页面"); console.log(currentPageReference); if(currentPageReference){ const urvalue=currentPageReference.state.recordId; if(urvalue){ let str=`${urvalue}`; console.log('str'); console.log(str); this.recordId=str; } } } connectedCallback(){ console.log(this.recordId); init({recordId:this.recordId}).then(result=>{ console.log(result); if(result!=null){ this.data=result; this.cancelSubmit().then(res=>{ this.IsLoading=false; this.dispatchEvent(new CloseActionScreenEvent()); }); } }).catch(err=>{ console.log("error:"); console.log(err.message); }).finally(()=>{ }); } async cancelSubmit(){ let oppid = this.data.Id; let decide_quote = this.data.Estimation_Decision__c; let complete_day = this.data.Contract_DB_complite_day__c; let if_contract_auth = this.data.Contract_Authorize__c; let if_contract_lock = this.data.Contract_Authorize_Lock__c; let If_Need_Authorize = this.data.If_Need_Authorize__c; let Authorized_DB_No =this.data.Authorized_DB_No__c; let profileId = await getProfileId({}); let spoURL = this.data.SPO_URL__c; //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start let DecidedQuoteNo = this.data.Estimation_No__c; //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end //2022-03-22 yjk SWAG-CCL6R7 let Closing_Bid_Date = this.data.Closing_Bid_Date__c;//13.中标日 let Closing_Bid_Date_Bid = this.data.Closing_Bid_Date_Bid__c; if (profileId != '00e10000000Y3o5' && profileId != '00e10000000Nab7' && profileId != '00e10000000xnpR' && profileId != '00e10000000xyK6' && profileId != '00e10000000xnpW' && profileId != '00e10000000NbCE' && profileId != '00e10000000Nb7i' && profileId != '00e10000000xyK6') { const event = new ShowToastEvent({ title: '提示信息', message:"您没有合同申请的权限。请联系系统管理员。" }); this.dispatchEvent(event); return; } if(!Closing_Bid_Date){ const event = new ShowToastEvent({ title: '提示信息', message:"请填写13.中标日。" }); this.dispatchEvent(event); return; } if (decide_quote != '1') { const event = new ShowToastEvent({ title: '提示信息', message:'请先决定报价。' }); this.dispatchEvent(event); return; } //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start if (DecidedQuoteNo !="") { let judg=await judgeIsAssistantAppliedOutTime({Quoteid:DecidedQuoteNo}); // alert('judg得值:'+judg); // return; if(judg == 'false'){ const event = new ShowToastEvent({ title: '提示信息', message:'经销商协议已过期,请重新做报价计算。' }); this.dispatchEvent(event); return; } } //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end // 20221009 ljh SWAG-CK29AJ start let ClosingBidDate =this.data.Closing_Bid_Date__c; let BidDate = this.data.Bid_Date__c; if( ClosingBidDate < BidDate){ const event = new ShowToastEvent({ title: '提示信息', message:'13.中标日不能早于12.招标日' }); this.dispatchEvent(event); return; } // 20221009 ljh SWAG-CK29AJ end if(If_Need_Authorize == '1' && (Authorized_DB_No == null || Authorized_DB_No == '')){ const event = new ShowToastEvent({ title: '提示信息', message:'请先做授权申请。' }); this.dispatchEvent(event); return; } if (this.data.Cnt_Lost_cancel_Draft__c > 0) { if(!confirm('询价有草案中的取消/失单报告,是否继续?')){ return ; } } else if (this.data.Cnt_Lost_cancel_report__c - this.data.Cnt_Lost_cancel_Draft__c > 0) { const event = new ShowToastEvent({ title: '提示信息', message:'询价有已提交的取消/失单报告。' }); this.dispatchEvent(event); return; } console.log("11"); // 2022-03-31 新财年价格调整 start let decide_date = this.data.DecideQuoteDate__c; let before = new Date("2022-4-1"); if (decide_date != null && decide_date < before) { const event = new ShowToastEvent({ title: '提示信息', message:'报价变更,请重新做Decide。' }); this.dispatchEvent(event); return; } // 2022-03-31 新财年价格调整 end let sqlResult = await searchOpportunity({oppid:oppid}); let records = sqlResult; console.log(records); if ((complete_day != null && complete_day != '') && records.Contract_Authorize_Lock__c== 'true') { const event = new ShowToastEvent({ title: '提示信息', message:'合同申请已经完成,请不要重复提交。' }); this.dispatchEvent(event); return; } // if ('{!Opportunity.AcecideCntCheck__c}' != '1') { // alert('阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。'); // return; // } console.log("111"); if ((complete_day == null || complete_day == '') && records.Contract_Authorize_Lock__c== 'true') { const event = new ShowToastEvent({ title: '提示信息', message:'合同正在申请中,请不要重复提交。' }); this.dispatchEvent(event); return; } if (this.data.IF_Submit__c == '1') { const event = new ShowToastEvent({ title: '提示信息', message:'上传失败,请联系系统管理员!' }); this.dispatchEvent(event); return; } console.log("111"); let angency = this.data.Agency1__c; if(this.data.Trade__c == '外貿' || this.data.Sales_Root__c == 'OCM直接販売'){ let rtn = await updReg({oppid:oppid}); } else { if(this.data.Is_Corrosion__c == '1'){ let rtn1 = await checkDangerItem({agency1:angency}); if (rtn1 != 'OK') { const event = new ShowToastEvent({ title: '提示信息', message:rtn1 }); this.dispatchEvent(event); return; } }else{ let rtn = await oppCheck({oppid:oppid, saveFlg:'1'}); if (rtn != 'OK') { const event = new ShowToastEvent({ title: '提示信息', message:rtn }); this.dispatchEvent(event); return; } } } console.log("222"); let flag=false; await updateOppotunity({recordId:this.recordId}).then(res=>{ console.log(res); if(res!=null&&res.success==false){ let messages =""; flag=true; messages=res.errors[0]; const event = new ShowToastEvent({ title: '提示信息', message:"操作失败,提示信息:"+messages, }); this.dispatchEvent(event); return; } }); if(flag)return; console.log("333"); const event = new ShowToastEvent({ title: '提示信息', message:'提交成功!请在SPO系统中完成合同申请。' }); this.dispatchEvent(event); //window.location.reload(); window.open(spoURL); } }