//author : kk //not do: 没有测试 done import { LightningElement, track, wire , api } from 'lwc'; import { CurrentPageReference } from "lightning/navigation"; import { CloseActionScreenEvent } from 'lightning/actions'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import init from '@salesforce/apex/LexInquiryController.init'; import getOpportunityIds from '@salesforce/apex/LexInquiryController.getOpportunityIds'; import getQuoteIrai from '@salesforce/apex/LexInquiryController.getQuoteIrai'; import makeAndUpdateLead from '@salesforce/apex/LexInquiryController.makeAndUpdateLead'; import makeAndUpdateTask from '@salesforce/apex/LexInquiryController.makeAndUpdateTask'; import makeAndUpdateQuoteIrai from '@salesforce/apex/LexInquiryController.makeAndUpdateQuoteIrai'; const event1 = new ShowToastEvent({ message: '请填写询价的编码', variant : 'error', mode :'sticky' }); const event2 = new ShowToastEvent({ message: '更新已完成', variant : 'success' }); const event3 = new ShowToastEvent({ message: '报价委托未关联意向', variant : 'error', mode :'sticky' }); const event4 = new ShowToastEvent({ message: '编码有误!请确认正确的编码', variant : 'error', mode :'sticky' }); const event5 = new ShowToastEvent({ message: '任务已结束,如需修改请联系管理员', variant : 'error', mode :'sticky' }); export default class lexExistingInquiry extends LightningElement { @api recordId; Task; QuoteIrai; Opportunity; NewLead; NewTask; NewQuoteIrai; IsLoading=true; @wire(CurrentPageReference) getStateParameters(currentPageReference) { if (currentPageReference) { const urlValue = currentPageReference.state.recordId; if (urlValue) { let str = `${urlValue}`; this.recordId = str; } } } connectedCallback(){ Promise.all([ loadStyle(this, lwcCSS) ]); init({ recordId: this.recordId }).then(result => { if (result != null) { this.Task = result; console.log(this.Task.Related_Opportunity1__c); this.ExistingInquiry().then(result=>{ this.IsLoading=false; // chenjingwu 20240204 start this.dispatchEvent(new CustomEvent('closem')); // this.dispatchEvent(new CloseActionScreenEvent()); // chenjingwu 20240204 end }); } }); } async ExistingInquiry(){ var judage = 0; if( this.Task.Status == '未着手'|| this.Task.Status == '進行中'){ if(this.Task.Related_Opportunity1__c == undefined || this.Task.Related_Opportunity1__c ==''){ this.dispatchEvent(event1); } else{ await getOpportunityIds({ RelatedOpportunity1 : this.Task.Related_Opportunity1__c }).then(res =>{ this.Opportunity=res; }); if(this.Opportunity.length>0){ await getQuoteIrai({QuoteIraiId : this.Task.QuoteIraiId__c }).then(res=>{ this.NewTask=res; console.log('QuoteIraiId__c'); console.log(this.Task.QuoteIraiId__c); }); if(this.NewTask.Lead__c){ // Lead作成并更 await makeAndUpdateLead({ leadId : this.Opportunity[0].Id, Id : this.NewTask.Lead__c, QuoteIraiId : this.Task.QuoteIraiId__c }).then(res=>{ if(res !='success'){ const event6 = new ShowToastEvent({ message: res+',Lead更新错误', variant : 'error', mode :'sticky' }); judage +=1; this.dispatchEvent(event6); } }); if(judage!=0){ return; } // 判断报价委托 if( this.Task.QuoteIraiId__c != '' && this.Task.QuoteIraiId__c!=undefined) { // 报价委托作成 await makeAndUpdateQuoteIrai({ QuoteIraiStatus : "已有询价", Id : this.Task.QuoteIraiId__c }).then(res=>{ if(res!= 'success'){ const event8 = new ShowToastEvent({ message: res+',QuoteIrai更新错误', variant : 'error', mode :'sticky' }); this.dispatchEvent(event8); judage +=1; } }); if(judage!=0){ return; } } // Task做成并更新 await makeAndUpdateTask({ Status : "已有询价", Id : this.Task.Id }).then(res=>{ if(res !='success'){ const event7 = new ShowToastEvent({ message: res+',Task更新错误', variant : 'error', mode :'sticky' }); this.dispatchEvent(event7); judage +=1; } else{ this.dispatchEvent(event2); //发送成功后,希望自动刷新画面。 location.reload(); } if(judage!=0){ return; } }); } else{ this.dispatchEvent(event3); } } else{ this.dispatchEvent(event4); } } } else{ this.dispatchEvent(event5); } } }