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
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
import {
    LightningElement,
    wire,
    api
} from 'lwc';
import {
    CurrentPageReference
} from "lightning/navigation";
import {
    CloseActionScreenEvent
} from 'lightning/actions';
import init from '@salesforce/apex/buttonQISReportCtl.init';
import sendToETQ from '@salesforce/apex/buttonQISReportCtl.sendToETQ';
import updateQISReportC from '@salesforce/apex/buttonQISReportCtl.updateQISReportC';
import selectQISReportC from '@salesforce/apex/buttonQISReportCtl.selectQISReportC';
import initSelectProfile from '@salesforce/apex/buttonQISReportCtl.initSelectProfile';
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
export default class lexSendQISToEtQ extends LightningElement {
    @api recordId;
    str;
    IsLoading = true;
    Id;
    userId;
    profileId;
    PAEDetermineC;
    PAEDetermineACC;
    OCMJudgementC;
    QISFinalJudgementC;
    ETQUPLOADSTATUSC;
    AEDetermineResultC;
    profileName;
    statu = '';
 
    @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 => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.userId = result.userId;
                this.profileId = result.profileId;
                this.PAEDetermineC = result.PAEDetermineC;
                this.PAEDetermineACC = result.PAEDetermineACC;
                this.OCMJudgementC = result.OCMJudgementC;
                this.QISFinalJudgementC = result.QISFinalJudgementC;
                this.ETQUPLOADSTATUSC = result.ETQUPLOADSTATUSC;
                this.AEDetermineResultC = result.AEDetermineResultC;
 
                initSelectProfile({
                    profileId: this.profileId
                }).then(result => {
                    console.log('11111');
                    if (result != null) {
                        this.IsLoading = false;
                        this.profileName = result[0].Name;
 
                        this.myDate();
                        this.myReload();
                    }
                })
            }
        }).catch(error => {
            console.log(error);
        })
    }
 
    myDate() {
        let messageNumber = '';
        let today = new Date();
        messageNumber = today.getFullYear() + '' + (today.getMonth() + 1) + '' + today.getDate() + '' + today.getHours() + '' +
            today.getMinutes() + '' + today.getSeconds();
        return messageNumber;
    }
 
    // 发送QIS到EtQ    
    SendQISToEtQ() {
        if (this.profileName != "2F7_OSH担当" && this.profileName != "2F7_OSH质量法规") {
            this.ShowToastEvent("您没有发送QIS到EtQ的权限。", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.PAEDetermineC == undefined) {
            this.ShowToastEvent("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.AEDetermineResultC == "nonAE" && this.PAEDetermineC == "nonPAE" && this.PAEDetermineACC == "nonPAE" && this.OCMJudgementC == undefined && this.QISFinalJudgementC == undefined) {
            this.ShowToastEvent("nonAE并nonPAE的QIS同步到EtQ的时候,检测结论(OCSM)是必填的。不可以发送到EtQ。", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.ETQUPLOADSTATUSC == "3") {
            this.handleConfirmClick("是否清空EtQ同步状态,重新同步数据?");
        } else {
            this.ll();
        }
    }
 
    myReload() {
        selectQISReportC({
            QId: this.Id
        }).then(record => {
            console.log(record);
            if (record[0].AsyncData__c == 'true' && record[0].ETQ_UPLOAD_STATUS__c != '3' || record[0].Complaint_Number__c != null) {
                var btns = document.getElementsByName("sendqistoetq");
                for (var i = 0; i < btns.length; i++) {
                    btns[i].disabled = true;
                    btns[i].className = 'btnDisabled';
                }
                this.ShowToastEvent('该QIS之前已经发送过了', "error");
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            } else {
                this.SendQISToEtQ();
            }
        })
    }
 
    ll() {
        if (this.AEDetermineResultC != undefined && this.PAEDetermineC != undefined && this.PAEDetermineACC == undefined) {
            this.statu = "Q1";
        } else if (
            (this.AEDetermineResultC != undefined && this.PAEDetermineC != undefined && this.PAEDetermineACC != "nonPAE" && this.PAEDetermineACC != undefined) ||
            (this.AEDetermineResultC == "nonAE" && this.PAEDetermineC == "nonPAE" && this.PAEDetermineACC == "nonPAE") &&
            ((this.OCMJudgementC == undefined &&
                    this.QISFinalJudgementC == "质量问题") ||
                ((this.OCMJudgementC == "质量问题" || this.OCMJudgementC == "质量问题+非质量问题") &&
                    (this.QISFinalJudgementC == undefined || this.QISFinalJudgementC == "质量问题")) ||
                (this.OCMJudgementC == "非质量问题" || this.OCMJudgementC == "现象未发现") &&
                this.QISFinalJudgementC == "质量问题")) {
            this.statu = "Q2";
        } else if ((this.AEDetermineResultC == "nonAE" && this.PAEDetermineC == "nonPAE" && this.PAEDetermineACC == "nonPAE") &&
            ((this.OCMJudgementC == undefined || this.OCMJudgementC == "质量问题" || this.OCMJudgementC == "质量问题+非质量问题") && this.QISFinalJudgementC == "非质量问题") ||
            ((this.OCMJudgementC == "非质量问题" || this.OCMJudgementC == "现象未发现") && (this.QISFinalJudgementC == undefined || this.QISFinalJudgementC == "非质量问题"))) {
            this.statu = "Q3";
        }
        updateQISReportC({
            QId: this.Id,
            uid: this.userId
        }).then(result => {
            if (result == "更新成功!") {
                this.ShowToastEvent(result, "success");
                this.dispatchEvent(new CloseActionScreenEvent());
                var qisreports = new Array()
                qisreports[0] = this.Id;
 
                var statuArr = new Array();
                statuArr.push(this.statu);
 
                sendToETQ({
                    iflog_Id: "",
                    rowDataSFDC: "",
                    repairIds: qisreports,
                    statu: statuArr[0]
                }).then(result => {
                    if (result == "发送成功!") {
                        this.ShowToastEvent(result, "success");
                        this.dispatchEvent(new CloseActionScreenEvent());
                        window.open('/lightning/r/QIS_Report__c/'+this.recordId+'/view','_self');
                    } else {
                        this.ShowToastEvent("发送QIS到EtQ失败," + result, "error");
                        this.dispatchEvent(new CloseActionScreenEvent());
                    }
                })
 
                var btns = document.getElementsByName("sendqistoetq");
                for (var i = 0; i < btns.length; i++) {
                    btns[i].disabled = true;
                    btns[i].className = 'btnDisabled';
                }
                
            } else {
                this.ShowToastEvent(result, "error");
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        })
 
 
        
    }
 
    // 弹窗
    ShowToastEvent(msg, type) {
          if (type=='success') {
            const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type,
            mode: 'sticky'
            });
            this.dispatchEvent(event);
        }
    }
 
    async handleConfirmClick(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
 
        if (result) {
            this.ll();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
}