binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
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
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-20 14:08:55
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-11-08 13:22:52
 */
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-14 10:16:19
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-14 10:41:46
 */
import { api, wire,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import init  from '@salesforce/apex/OpportunityLightingButtonController.initForLostReportButton';
import queryLostReport  from '@salesforce/apex/OpportunityLightingButtonController.queryLostReport';
import querySubmitCancelReport  from '@salesforce/apex/OpportunityLightingButtonController.querySubmitCancelReport';
import querySubmitLostReport  from '@salesforce/apex/OpportunityLightingButtonController.querySubmitLostReport';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class LexLoseReport extends LightningElement {
    @api recordId;
    stageName;
    sapSendOK;
    cntLostCancelReport;
    name;
    salesAssistantName;
    salesAssistantID;
    managerName;
    salesManagerDepartmentID;
    salesOwnerBuchang;
    salesOwnerBuchangID;
    cntLostCancelDraft;
    haveLostReport;
    //生产环境bug修改 陈京武 20231105 Start
    haveSubmitCancelReport;
    //生产环境bug修改 陈京武 20231105 End
    //生产环境bug修改 陈京武 20231106 Start
    haveSubmitLostReport;
    //生产环境bug修改 陈京武 20231106 End
    IsLoading = true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(111);
            console.log(currentPageReference);
 
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.recordId = str;
          }
        }
    }
    connectedCallback(){
        console.log('enter lexLoseReport');
        Promise.all([
            loadStyle(this, lwcCSS)
           ]);
           
        init({
            recordId: this.recordId
        }).then(result=>{
            debugger
            this.stageName = result.stageName;
            this.sapSendOK = result.sapSendOK;
            this.cntLostCancelReport = result.cntLostCancelReport;
            this.name = result.name;
            this.salesAssistantID = result.salesAssistantID;
            this.salesAssistantName = result.salesAssistantName;
            this.managerName = result.managerName;
            this.salesManagerDepartmentID = result.salesManagerDepartmentID;
            this.salesOwnerBuchang = result.salesOwnerBuchang;
            this.salesOwnerBuchangID = result.salesOwnerBuchangID;
            this.cntLostCancelDraft = result.cntLostCancelDraft;
            if(!result.isHavePower){
                this.showToast('您不能创建失单/部分失单报告!','error');
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
            queryLostReport({
                recordId: this.recordId
            }).then(result=>{
                this.haveLostReport = result;
                //生产环境bug修改 陈京武 20231105 Start
                querySubmitCancelReport({
                    recordId: this.recordId
                }).then(result1=>{
                    this.haveSubmitCancelReport = result1;
                    querySubmitLostReport({
                        recordId: this.recordId
                    }).then(result2=>{
                        this.haveSubmitLostReport = result2;
                        this.loseReport();
                    });
                });
                //生产环境bug修改 陈京武 20231105 End
            });
            
        })
    }
    loseReport(){
        // jsの場合、翻訳された値がでるので、要注意
        // 陈京武 20231108 Start
        // if (this.stageName != '引合'
        // && this.stageName != '询价'
        if (this.stageName == '敗戦'
        || this.stageName == '削除'
        // 陈京武 20231108 End
        ) {
            this.showToast("状态1:" + this.stageName + "、不能做 失单 了!","error");
        }
        // 陈京武 20231108 Start
        // else if (this.sapSendOK == '1') {
        //     this.showToast("已经上传SAP、不能做 失单 了!","error");
        // }
        // 陈京武 20231108 End
        //生产环境bug修改 陈京武 20231106 Start
        else if (this.haveSubmitLostReport) {
            this.showToast('已经有提交的失单报告,不可新建失单报告','error');
        }
        //生产环境bug修改 陈京武 20231106 End
        //生产环境bug修改 陈京武 20231105 Start
        else if (this.haveSubmitCancelReport) {
            this.showToast("已经有提交的取消报告,不可新建失单报告","error");
        }
        else if (this.haveLostReport) {
            this.showToast('已经有草案中的失单报告,请编辑草案中的进行提交','error');
        }
        //生产环境bug修改 陈京武 20231105 End
        else {
            // 陈京武 20231108 Start
            if(this.stageName == '注残' || this.stageName == '出荷' || this.stageName == '完了'){
                var url = '/lightning/n/PCLLostReportPageLwc#pageStatus=Create&oppId=' + this.recordId + '&lostType=部分失单';
                location.href = url;
            }else{
                var url = '/lightning/n/PCLLostReportPageLwc#pageStatus=Create&oppId=' + this.recordId + '&lostType=失单';
                location.href = url;
            }
            // 陈京武 20231108 End
            
        }
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }   
    }
    //显示信息
    showMyToast(title, message, variant) {
        console.log('show custom message');
        let iconName = '';
        let content = '';
        if (variant == 'success') {
            iconName = 'utility:check';
        } else {
            iconName = 'utility:error';
        }
        if (message != '') {
            content =
                '<h2><strong>' +
                title +
                '<strong/></h2><h5>' +
                message +
                '</h5>';
        } else {
            content = '<h2><strong>' + title + '<strong/></h2>';
        }
        this.template
            .querySelector('c-common-toast')
            .showToast(variant, content, iconName, 10000).then(result=>{
                this.dispatchEvent(new CloseActionScreenEvent());
            });
        this.isLoading = false;
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
}