FUYU
2023-12-13 4488f711dbc01a8db6753907cae2ef4021dede68
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
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 {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
 
export default class LexSendRepairsToEtQ extends LightningElement {
    @api recordId;
    str;
    IsLoading = true;
    Id;;
    PAEDetermineC;
    ETQUPLOADSTATUSC;
    AEDetermineResultC;
    PAEDetermineACC;
    RepairInspectionDateC;
    ContainUseRSAC;
    userID;
    profileId;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if (urlValue) {
                let str = `${urlValue}`;
                this.recordId = str;
            }
        }
    }
 
    connectedCallback() {
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.PAEDetermineC = result.PAEDetermineC;
                this.ETQUPLOADSTATUSC = result.ETQUPLOADSTATUSC;
                this.AEDetermineResultC = result.AEDetermineResultC;
                this.PAEDetermineACC = result.PAEDetermineACC;
                this.RepairInspectionDateC = result.RepairInspectionDateC;
                this.ContainUseRSAC = result.ContainUseRSAC;
                this.userID = result.userID;
                this.profileId = result.profileId;
 
                this.myDate();
                this.myReload();
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        }).catch(error => {
            console.log(error);
        }).finally(() => {
 
        });
    }
 
    // 根据日期构建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() {
        selectRecords({
            recordId: this.Id
        }).then(result => {
            console.log(result);
            if (result.AsyncData__c == 'true' && result.ETQ_UPLOAD_STATUS__c != '3' || result.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.ShowToastEvent('该修理之前已经发送过了', "error");
                // alert('该修理之前已经发送过了')
            } else {
                this.SendRepairsToEtQ();
            }
        }).catch(error => {
            console.log(error);
        }).finally(() => {
 
        });
    }
 
    // 发送ETQ
    SendRepairsToEtQ() {
        console.log(this.userID);
        console.log(this.profileId);
 
        var uid = this.userID;
        if (this.profileId != "00e10000000xnoO" && this.profileId != "00e10000000hl7w" && this.profileId != '00e10000000Y3o5') {
            this.ShowToastEvent("您没有发送修理到EtQ的权限。", "error");
            // alert("您没有发送修理到EtQ的权限。");
            return;
        }
        var statu = '';
        if (this.PAEDetermineC == undefined) {
            this.ShowToastEvent("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。", "error");
            // alert("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。");
            return;
        }
        if (this.ETQUPLOADSTATUSC == "3") {
            if (!confirm("是否清空EtQ同步状态,重新同步数据?")) {
                return;
            }
        }
        if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && uid != "005100000068zJ6") {
            this.ShowToastEvent("Close Complait的时候,不可以发送到EtQ", "error");
            // alert("Close Complait的时候,不可以发送到EtQ");
            return;
        }
        if (this.PAEDetermineC != undefined && this.AEDetermineResultC != undefined && this.PAEDetermineACC == undefined) {
            statu = "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 == "") {
                this.ShowToastEvent("5.修理检测日是空的时候,不可以发送到EtQ。", "error");
                // alert("5.修理检测日是空的时候,不可以发送到EtQ。");
                return;
            }
            if (this.ContainUseRSAC == 1) {
                this.ShowToastEvent("Final universal code为空,或者包含UseRSA,请确认。", "error");
                // alert("Final universal code为空,或者包含UseRSA,请确认。");
                return;
            }
        }
 
        var result;
        try {
            var repairids = new Array()
            repairids[0] = this.Id;
 
            var statuArr = new Array();
            statuArr.push(statu);
 
            sendToETQ({
                iflog_Id: "",
                rowDataSFDC: "",
                repairIds: repairids,
                statu: statuArr[0]
            }).then(result => {
                this.ShowToastEvent(result, "error");
                // alert(result);
            }).catch(error => {
                console.log(error);
            })
 
            var btns = document.getElementsByName("sendrepairstoetq");
            for (var i = 0; i < btns.length; i++) {
                btns[i].disabled = true;
                btns[i].className = 'btnDisabled';
            }
            location.reload();
        } catch (error) {
            this.ShowToastEvent("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode, "error");
            // alert("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode);
        }
    }
 
    // 弹窗
    ShowToastEvent(msg, type) {
        const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
    }
}