liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//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);
        }   
     
    }
    
 
 
}