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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import {
    LightningElement,
    wire,
    api
} from 'lwc';
import {
    CurrentPageReference
} from "lightning/navigation";
import {
    CloseActionScreenEvent
} from 'lightning/actions';
import init from '@salesforce/apex/otherButtonRepairController.init';
import selectRecords from '@salesforce/apex/otherButtonRepairController.selectRecords';
import sendToETQ from '@salesforce/apex/otherButtonRepairController.sendToETQ';
import initSelectProfile from '@salesforce/apex/otherButtonRepairController.initSelectProfile';
import initList from '@salesforce/apex/otherButtonRepairController.initList';
import initUserName from '@salesforce/apex/otherButtonRepairController.initUserName';
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';        
import {loadStyle} from 'lightning/platformResourceLoader'    
export default class LexSendRepairsToEtQ extends LightningElement {
    @api recordId;
    str;
    IsLoading = true;
    Id;;
    PAEDetermineC;
    ETQUPLOADSTATUSC;
    AEDetermineResultC;
    PAEDetermineACC;
    RepairInspectionDateC;
    ContainUseRSAC;
    userID;
    profileId;
    profileName;
    userName;
    ifList;
    @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)            
        ]);    
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(resu => {
            console.log(resu);
            if (resu != null) {
                this.IsLoading = false;
                this.Id = resu.Id;
                this.PAEDetermineC = resu.PAEDetermineC;
                this.ETQUPLOADSTATUSC = resu.ETQUPLOADSTATUSC;
                this.AEDetermineresuC = resu.AEDetermineresuC;
                this.AEDetermineResultC = resu.AEDetermineResultC
                this.PAEDetermineACC = resu.PAEDetermineACC;
                this.RepairInspectionDateC = resu.RepairInspectionDateC;
                this.ContainUseRSAC = resu.ContainUseRSAC;
                this.userID = resu.userID;
                this.profileId = resu.profileId;
                initUserName({
                    userId: this.userID
                }).then(result => {
                    console.log(result);
                    if (result != null) {
                        this.IsLoading = false;
                        this.userName = result[0].Name;
                    }
                    initList().then(res => {
                        console.log(res,'iflist')
                        this.ifList = res
                        initSelectProfile({
                            profileId: this.profileId
                        }).then(result => {
                            console.log(result)
                            if (result != null) {
                                this.IsLoading = false;
                                // this.profileName = result[0].Name;
                                this.profileName = result;
                                console.log('到了执行函数')
                                this.myDate();
                                this.myReload();
                            }
                        })
                    })
                })
                
                
                
                // this.dispatchEvent(new CloseActionScreenEvent());
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    // 根据日期构建MessageGroupNumber
    myDate() {
        let messageNumber = '';
        let today = new Date();
        messageNumber = today.getFullYear() + '' + (today.getMonth() + 1) + '' + today.getDate() + '' + today.getHours() + '' +
            today.getMinutes() + '' + today.getSeconds();
        return messageNumber;
    }
 
    // 按钮点击后触发,判断是否发送过ETQ,如果发送过给出提示并灰掉按钮
    // 如果没有发送过调用发送方法
    myReload() {
        console.log('进来了')
        selectRecords({
            recordId: this.Id
        }).then(result => {
            console.log(result)   
            if (result[0].AsyncData__c == 'true' && result[0].ETQ_UPLOAD_STATUS__c != '3' || result[0].Complaint_Number__c != null) {
                // var btns = document.getElementsByName("sendrepairstoetq");
                // for (var i = 0; i < btns.length; i++) {
                //     btns[i].disabled = true;
                //     btns[i].className = 'btnDisabled';
                // }
                this.showToast('该修理之前已经发送过了','error');
                this.dispatchEvent(new CloseActionScreenEvent());
            } else {
                this.SendRepairsToEtQ();
            }
        }).catch(error => {
            console.log(error,'err<<<<<<');
        })
    }
 
    // 发送ETQ
    SendRepairsToEtQ() {
        console.log('etq')
        if (this.profileName != this.ifList.oshact && this.profileName != this.ifList.oshqualityregulations && this.profileName != this.ifList.administrator) {
            this.showToast("您没有发送修理到EtQ的权限。",'error');
            this.dispatchEvent(new CloseActionScreenEvent());
            console.log('您没有发送修理到EtQ的权限。')
            return;
        }
        if (this.PAEDetermineC == undefined) {
            this.showToast("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。",'error');
            this.dispatchEvent(new CloseActionScreenEvent());
            console.log('OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。')
 
            return;
        }
        if (this.ETQUPLOADSTATUSC == "3") {
            // if (!confirm("是否清空EtQ同步状态,重新同步数据?")) {
            //     return;
            // }
            LightningConfirm.open({
                message: "是否清空EtQ同步状态,重新同步数据?",
                variant: 'headerless',
                label: '提示信息'
            }).then(submit => {
                if(!submit){
                    return;
                }else{
                    this.Etqreload()
                }
            })
        }else{
            this.Etqreload()
        }
        
    }
    Etqreload(){
        debugger
        // let this = this
        console.log('qqq')
        var statu = '';
        if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && this.userName != this.ifList.leixinjian) {
            this.showToast("Close Complait的时候,不可以发送到EtQ",'error');
            this.dispatchEvent(new CloseActionScreenEvent());
            console.log('Close Complait的时候,不可以发送到EtQ')
            return;
        }
        if (this.PAEDetermineC != undefined && this.AEDetermineResultC != undefined && this.PAEDetermineACC == undefined) {
            statu = "R1";
            console.log('r1')
        } else if ((this.AEDetermineResultC != undefined && this.PAEDetermineC != undefined && this.PAEDetermineACC != undefined) &&
            !(this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE")) {
            statu = "R2";
            if (this.RepairInspectionDateC == undefined) {
                // this.showToast("5.修理检测日是空的时候,不可以发送到EtQ。",'error');
                console.log('sscasd')
                const event = new ShowToastEvent({
                    message: "5.修理检测日是空的时候,不可以发送到EtQ。",
                    variant: 'error',
                    mode:'Sticky'
                });
                this.dispatchEvent(event);
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
            if (this.ContainUseRSAC == 1) {
                this.showToast("Final universal code为空,或者包含UseRSA,请确认。",'error');
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
        }
        // debugger
        console.log(statu,'statu')
        try {
            var repairids = new Array()
            repairids[0] = this.Id;
 
            var statuArr = new Array();
            statuArr.push(statu);
            console.log('发送etq')
            sendToETQ({
                iflog_Id: "",
                rowDataSFDC: "",
                repairIds: repairids,
                statu: statuArr[0]
            }).then(result => {
                console.log('发送etq返回')
                this.showToast(result,'error');
                this.dispatchEvent(new CloseActionScreenEvent());
                window.location.href = ' /lightning/r/Repair__c/'+this.recordId+'/view';
                // location.reload();
            })
 
            var btns = document.getElementsByName("sendrepairstoetq");
            for (var i = 0; i < btns.length; i++) {
                btns[i].disabled = true;
                btns[i].className = 'btnDisabled';
            }
            window.location.href = ' /lightning/r/Repair__c/'+this.recordId+'/view';
        } catch (error) {
            console.log(error,'xxxx')
            this.showToast("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode,'error');
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
    
    // 弹窗
    showToast(msg, type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: 'success'
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: 'error',
                mode:'Sticky'
            });
            this.dispatchEvent(event);
        }
    }
}