twysparks
2023-06-26 a8628cfe2640797ba9265e9be46c42430d9e7eba
force-app/main/default/lwc/lexSendQISToEtQ/lexSendQISToEtQ.js
@@ -17,6 +17,7 @@
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
export default class LexSendQISToEtQ extends LightningElement {
    @api recordId;
@@ -32,6 +33,7 @@
    ETQUPLOADSTATUSC;
    AEDetermineResultC;
    profileName;
    statu = '';
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
@@ -50,7 +52,6 @@
        }).then(result => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.userId = result.userId;
                this.profileId = result.profileId;
@@ -72,7 +73,6 @@
                        this.myReload();
                    }
                })
                this.dispatchEvent(new CloseActionScreenEvent());
            }
        }).catch(error => {
            console.log(error);
@@ -89,76 +89,25 @@
    // 发送QIS到EtQ   
    SendQISToEtQ() {
        console.log(this.profileName);
        var QId = this.Id;
        var uid = this.userId;
        if (this.profileName != "2F7_OSH担当" && this.profileName != "2F7_OSH质量法规") {
            alert("您没有发送QIS到EtQ的权限。");
            this.ShowToastEvent("您没有发送QIS到EtQ的权限。", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.PAEDetermineC == undefined) {
            alert("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。");
            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) {
            alert("nonAE并nonPAE的QIS同步到EtQ的时候,检测结论(OCSM)是必填的。不可以发送到EtQ。");
            this.ShowToastEvent("nonAE并nonPAE的QIS同步到EtQ的时候,检测结论(OCSM)是必填的。不可以发送到EtQ。", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.ETQUPLOADSTATUSC == "3") {
            if (!confirm("是否清空EtQ同步状态,重新同步数据?")) {
                return;
            }
        }
        var statu = '';
        if (this.AEDetermineResultC != undefined && this.PAEDetermineC != undefined && this.PAEDetermineACC == undefined) {
            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 == "质量问题")) {
            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 == "非质量问题"))) {
            statu = "Q3";
        }
        try {
            updateQISReportC({
                QId: QId,
                uid: uid
            })
            var qisreports = new Array()
            qisreports[0] = this.Id;
            var statuArr = new Array();
            statuArr.push(statu);
            sendToETQ({
                iflog_Id: "",
                rowDataSFDC: "",
                repairIds: qisreports,
                statu: statuArr[0]
            }).then(result => {
                alert(result);
            })
            alert("发送成功!")
            var btns = document.getElementsByName("sendqistoetq");
            for (var i = 0; i < btns.length; i++) {
                btns[i].disabled = true;
                btns[i].className = 'btnDisabled';
            }
            location.reload();
        } catch (error) {
            alert("发送QIS到EtQ失败" + error.faultstring + ' code:' + error.faultcode)
            this.handleConfirmClick("是否清空EtQ同步状态,重新同步数据?");
        } else {
            this.ll();
        }
    }
@@ -173,11 +122,64 @@
                    btns[i].disabled = true;
                    btns[i].className = 'btnDisabled';
                }
                alert('该QIS之前已经发送过了')
                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
        })
        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());
            } 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';
        }
    }
    // 弹窗
@@ -189,4 +191,18 @@
        });
        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());
        }
    }
}