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 init from '@salesforce/apex/LexInvalidDelegationController.init';
|
import getQuoteIraiC from '@salesforce/apex/LexInvalidDelegationController.getQuoteIraiC';
|
import updateTask from '@salesforce/apex/LexInvalidDelegationController.updateTask';
|
import updateLead from '@salesforce/apex/LexInvalidDelegationController.updateLead';
|
|
export default class lexInvalidDelegation extends LightningElement {
|
@api recordId;
|
@api isDoneRendering;
|
IsLoading=true;
|
isShow=true;
|
Id;
|
Status;
|
QuoteIraiIdC;
|
AnswerC;
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference){
|
|
if(currentPageReference){
|
const urvalue=currentPageReference.state.recordId;
|
if(urvalue){
|
let str=`${urvalue}`;
|
this.recordId=str;
|
}
|
}
|
}
|
|
|
|
connectedCallback(){
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this.isDoneRendering=false;
|
init({recordId:this.recordId}).then(result=>{
|
this.Id=this.recordId;
|
this.Status=result.Status;
|
this.QuoteIraiIdC=result.QuoteIraiIdC;
|
this.AnswerC=result.AnswerC;
|
this.cancelSubmit().then(res=>{
|
this.isShow=false;
|
this.IsLoading=false;
|
this.dispatchEvent(new CloseActionScreenEvent());
|
this.isDoneRendering=false;
|
const passOneEvent = new CustomEvent('closem', {
|
detail: '111'
|
});
|
this.dispatchEvent(passOneEvent);
|
});
|
}).catch(err=>{
|
// console.log("error:");
|
// console.log(err.message);
|
}).finally(()=>{
|
this.dispatchEvent(new CloseActionScreenEvent());
|
});
|
}
|
|
|
|
async cancelSubmit(){
|
var flag=false;
|
if(this.Status == '未着手'||this.Status == '進行中'){
|
this.isDoneRendering=true;
|
if(this.AnswerC ==null || this.AnswerC==''){
|
// alert('请填写回答内容');
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"操作失败:"+'请填写回答内容',
|
});
|
this.dispatchEvent(event);
|
this.isDoneRendering=true;
|
return;
|
}else{
|
var Id = this.recordId;
|
var Status = "无效委托";
|
await updateTask({
|
recordId:Id,
|
Status:Status
|
}).then(res=>{
|
console.log(res);
|
|
if(res!=null&&res.success==false){
|
var messages=res.errors[0];
|
if (messages!=null&&messages!="") {
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"操作失败:"+messages,
|
});
|
this.dispatchEvent(event);
|
flag=true;
|
return;
|
}
|
}
|
}).catch(err=>{
|
// console.log("updateTask error:");
|
// console.log(err.message);
|
});
|
if (flag) {return;}
|
var messages2 = '';
|
if(this.QuoteIraiIdC != null&&this.QuoteIraiIdC !='') {
|
// 获得报价委托
|
var sqlResult2 = await getQuoteIraiC({recordId:this.QuoteIraiIdC});
|
if(sqlResult2!=null&&sqlResult2.Lead__c!=null){
|
//alert(sqlResult2.Lead__r.LatestQuotationEntrustment__c + '|' + sqlResult2.Lead__r.QuotationDelegationStatus__c);
|
if(!sqlResult2.Lead__r.LatestQuotationEntrustment__c || (sqlResult2.Lead__r.LatestQuotationEntrustment__c && sqlResult2.Lead__r.QuotationDelegationStatus__c != '已有询价' && sqlResult2.Lead__r.QuotationDelegationStatus__c != '更新完毕')){
|
// Lead更新
|
await updateLead({
|
recordId:Id,
|
LatestQuotationEntrustmentC:sqlResult2.Lead__r.LatestQuotationEntrustment__c
|
}).then(res=>{
|
if(res!=null&&res.success==false){
|
var messages=res.errors[0];
|
if (messages!=null&&messages!="") {
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"操作失败:"+messages,
|
});
|
this.dispatchEvent(event);
|
flag=true;
|
return;
|
}
|
}
|
}).catch(err=>{
|
// console.log("updateLead error:");
|
// console.log(err.message);
|
});
|
}
|
}
|
if(flag)return;
|
var id = this.QuoteIraiIdC;
|
var QuoteIrai_Status__c = '无效委托';
|
await updateLead({
|
recordId:id,
|
QuoteIraiStatusC:QuoteIrai_Status__c
|
}).then(res=>{
|
if(res!=null&&res.success==false){
|
var messages=res.errors[0];
|
if (messages!=null&&messages!="") {
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"操作失败:"+messages,
|
});
|
this.dispatchEvent(event);
|
flag=true;
|
return;
|
}else{
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:'更新已完成',
|
});
|
this.dispatchEvent(event);
|
return;
|
//发送成功后,希望自动刷新画面。
|
window.location.reload();
|
}
|
}
|
}).catch(err=>{
|
// console.log("updateLead error:");
|
// console.log(err.message);
|
});
|
if (flag) {return;}
|
}
|
}
|
}else{
|
// alert('任务已结束,如需修改请联系管理员');
|
const event = new ShowToastEvent({
|
title: '提示信息',
|
message:"操作失败:"+'任务已结束,如需修改请联系管理员',
|
});
|
this.dispatchEvent(event);
|
}
|
}
|
|
}
|