黄千龙
2023-08-09 626f3c3bb25e204568019e8d568e2d7547d1037a
force-app/main/default/lwc/lexSendQISToEtQ/lexSendQISToEtQ.js
@@ -13,12 +13,13 @@
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/otherButtonRepairController.initSelectProfile';
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
export default class LexSendQISToEtQ extends LightningElement {
export default class lexSendQISToEtQ extends LightningElement {
    @api recordId;
    str;
    IsLoading = true;
@@ -31,6 +32,8 @@
    QISFinalJudgementC;
    ETQUPLOADSTATUSC;
    AEDetermineResultC;
    profileName;
    statu = '';
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
@@ -49,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;
@@ -60,9 +62,17 @@
                this.ETQUPLOADSTATUSC = result.ETQUPLOADSTATUSC;
                this.AEDetermineResultC = result.AEDetermineResultC;
                this.myDate();
                this.myReload();
                this.dispatchEvent(new CloseActionScreenEvent());
                initSelectProfile({
                    profileId: this.profileId
                }).then(result => {
                    if (result != null) {
                        this.IsLoading = false;
                        this.profileName = result[0].Name;
                        this.myDate();
                        this.myReload();
                    }
                })
            }
        }).catch(error => {
            console.log(error);
@@ -79,33 +89,51 @@
    // 发送QIS到EtQ   
    SendQISToEtQ() {
        var QId = this.Id;
        var uid = this.userId;
        if (this.profileId != "00e10000000xnoO" && this.profileId != "00e10000000hl7w") {
            alert("您没有发送QIS到EtQ的权限。");
        if (this.profileName != "2F7_OSH担当" && this.profileName != "2F7_OSH质量法规") {
            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;
            }
            this.handleConfirmClick("是否清空EtQ同步状态,重新同步数据?");
        } else {
            this.ll();
        }
    }
        var statu = '';
    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) {
            statu = "Q1";
            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") &&
@@ -115,60 +143,43 @@
                    (this.QISFinalJudgementC == undefined || this.QISFinalJudgementC == "质量问题")) ||
                (this.OCMJudgementC == "非质量问题" || this.OCMJudgementC == "现象未发现") &&
                this.QISFinalJudgementC == "质量问题")) {
            statu = "Q2";
            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 == "非质量问题"))) {
            statu = "Q3";
            this.statu = "Q3";
        }
        try {
            updateQISReportC({
                QId: QId,
                uid: uid
            })
        updateQISReportC({
            QId: this.Id,
            uid: this.userId
        })
            var qisreports = new Array()
            qisreports[0] = this.Id;
        var qisreports = new Array()
        qisreports[0] = this.Id;
            var statuArr = new Array();
            statuArr.push(statu);
        var statuArr = new Array();
        statuArr.push(this.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)
        }
    }
    myReload() {
        selectQISReportC({
            QId: this.Id
        }).then(record => {
            if (record.AsyncData__c == 'true' && record.ETQ_UPLOAD_STATUS__c != '3' || record.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';
                }
                alert('该QIS之前已经发送过了')
        sendToETQ({
            iflog_Id: "",
            rowDataSFDC: "",
            repairIds: qisreports,
            statu: statuArr[0]
        }).then(result => {
            if (result == "发送成功!") {
                this.ShowToastEvent(result, "success");
                this.dispatchEvent(new CloseActionScreenEvent());
            } else {
                SendQISToEtQ();
                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';
        }
    }
    // 弹窗
@@ -180,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());
        }
    }
}