binxie
2024-01-18 b1d36ea3e6653e59bd767aa192c688ee0d9d4c58
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
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/LexTaskCloseController.init';
import getProfileId from '@salesforce/apex/LexTaskCloseController.getProfileId';
import updateQuoteIraic from '@salesforce/apex/LexTaskCloseController.updateQuoteIraic';
import updateTask from '@salesforce/apex/LexTaskCloseController.updateTask';
import getQuoteIraic from '@salesforce/apex/LexTaskCloseController.getQuoteIraic';
import updateLead from '@salesforce/apex/LexTaskCloseController.updateLead';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class lexTaskClose extends LightningElement {
    @api recordId;
    @api isDoneRendering;
    IsLoading=true;
    QuoteIraiId;
    Status;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                this.recordId=str;
            }
        }
    }
 
 
 
    connectedCallback(){
        
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        this.dispatchEvent(new CloseActionScreenEvent());
        init({recordId:this.recordId}).then(result=>{
            console.log(result);
            this.QuoteIraiId=result.QuoteIraiId__c;
            this.Status=result.Status;
            this.cancelSubmit().then(res=>{
                this.IsLoading=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(){
        if(this.Status != '未着手'&&this.Status != '進行中'){
            const event = new ShowToastEvent({
                message:""+'任务已结束,如需修改请联系管理员',
                variant: 'error',
                mode: 'sticky'
            });        
            this.dispatchEvent(event);
            return;
        }else{
            var re = await getQuoteIraic({recordId:this.QuoteIraiId});
            console.log("报价委托信息:");
            console.log(re);
            let flag=false;
            if(re!=null&&re.Lead__c){
                // Lead作成
                var Id = re.Lead__c;
                if(this.QuoteIraiId != '') {
                    var LatestQuotationEntrustment__c=this.QuoteIraiId;
                    // Lead更新
                    await updateLead({
                        recordId:Id,
                        LatestQuotationEntrustmentc:LatestQuotationEntrustment__c
                    }).then(res=>{
                        console.log("更新意向:");
                        console.log(res);
                        if(res!=null&&res.success==false){
                            var messages=res.errors[0];
                            if (messages!=null&&messages!="") {
                                const event = new ShowToastEvent({
                                    message:""+messages,
                                    variant: 'error',
                                    mode: 'sticky'
                                });        
                                this.dispatchEvent(event);
                                flag=true;
                                return;
                            }
                        }
                    }).catch(err=>{
                        // console.log("updateLead error:");
                        // console.log(err.message);
                    });
                }
            }
            if(flag)return;
            if(this.QuoteIraiId != '') {
                var QId =this.QuoteIraiId;
                var QuoteIrai_Status__c = '更新完毕';
                await updateQuoteIraic({
                    recordId:QId,
                    QuoteIraiStatusc:QuoteIrai_Status__c
                }).then(res=>{
                    console.log("更新报价委托:");
                    console.log(res);
                    if(res!=null&&res.success==false){
                        var messages=res.errors[0];
                        if (messages!=null&&messages!="") {
                            const event = new ShowToastEvent({
                                message:""+messages,
                                variant: 'error',
                                mode: 'sticky'
                            });        
                            this.dispatchEvent(event);
                            flag=true;
                            return;
                        }
                    }
                }).catch(err=>{
                    // console.log("updateLead error:");
                    // console.log(err.message);
                });
            }
            if(flag)return;
            var Id = this.recordId;
            var Status = "完了";
            await updateTask({
                recordId:Id,
                Status:Status
            }).then(res=>{
                console.log("更新任务:");
                console.log(res);
                if(res!=null&&res.success==false){
                    var message=res.errors[0];
                    if (messages!=null&&messages!="") {
                        const event = new ShowToastEvent({
                            message:""+messages,
                            variant: 'error',
                            mode: 'sticky'
                        });        
                        this.dispatchEvent(event);
                        flag=true;
                        return;
                    }
                }else{
                    console.log('=======================')
                    const event = new ShowToastEvent({
                        message:'更新已完成',
                        variant:'success'
                    });
                    this.dispatchEvent(event);
                    setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }
            }).catch(err=>{
                // console.log("updateLead error:");
                // console.log(err.message);
            });
        }
 
    }
 
}