unknown
2023-08-23 50ce6a5e5ae7ac6ce3e6281acca9a0db568306e6
force-app/main/default/lwc/lexSendRepairsToEtQ/lexSendRepairsToEtQ.js
@@ -12,9 +12,12 @@
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 initUserName from '@salesforce/apex/otherButtonRepairController.initUserName';
import {
    ShowToastEvent
} from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
export default class LexSendRepairsToEtQ extends LightningElement {
    @api recordId;
@@ -29,6 +32,10 @@
    ContainUseRSAC;
    userID;
    profileId;
    profileName;
    userName;
    msg;
    statu = '';
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
@@ -48,7 +55,6 @@
        }).then(result => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.Id = result.Id;
                this.PAEDetermineC = result.PAEDetermineC;
                this.ETQUPLOADSTATUSC = result.ETQUPLOADSTATUSC;
@@ -58,16 +64,29 @@
                this.ContainUseRSAC = result.ContainUseRSAC;
                this.userID = result.userID;
                this.profileId = result.profileId;
                initUserName({
                    userId: this.userID
                }).then(result => {
                    console.log(result);
                    if (result != null) {
                        this.userName = result[0].Name;
                    }
                })
                initSelectProfile({
                    profileId: this.profileId
                }).then(result => {
                    if (result != null) {
                        this.profileName = result[0].Name;
                this.myDate();
                this.myReload();
                this.dispatchEvent(new CloseActionScreenEvent());
                        this.myDate();
                        this.myReload();
                    }
                })
            }
        }).catch(error => {
            console.log(error);
        }).finally(() => {
        });
        })
    }
    // 根据日期构建MessageGroupNumber
@@ -85,98 +104,91 @@
        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) {
            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.ShowToastEvent('该修理之前已经发送过了', "error");
                // alert('该修理之前已经发送过了')
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            } 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') {
        if (this.profileName != "2F7_OSH担当" && this.profileName != "2F7_OSH质量法规" && this.profileName != '系统管理员') {
            this.ShowToastEvent("您没有发送修理到EtQ的权限。", "error");
            // alert("您没有发送修理到EtQ的权限。");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        var statu = '';
        if (this.PAEDetermineC == undefined) {
            this.ShowToastEvent("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。", "error");
            // alert("OCSM QARA的PAE判定是空的时候,不可以发送到EtQ。");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && this.userName != "雷 新建") {
            this.ShowToastEvent("Close Complait的时候,不可以发送到EtQ", "error");
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        if (this.ETQUPLOADSTATUSC == "3") {
            if (!confirm("是否清空EtQ同步状态,重新同步数据?")) {
                return;
            }
            this.handleConfirmClick("是否清空EtQ同步状态,重新同步数据?");
        } else {
            this.ll();
        }
        if (this.PAEDetermineC == "nonPAE" && this.AEDetermineResultC == "nonAE" && this.PAEDetermineACC == "nonPAE" && uid != "005100000068zJ6") {
            this.ShowToastEvent("Close Complait的时候,不可以发送到EtQ", "error");
            // alert("Close Complait的时候,不可以发送到EtQ");
            return;
        }
    }
    ll() {
        if (this.PAEDetermineC != undefined && this.AEDetermineResultC != undefined && this.PAEDetermineACC == undefined) {
            statu = "R1";
            this.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.statu = "R2";
            if (this.RepairInspectionDateC == undefined) {
                this.ShowToastEvent("5.修理检测日是空的时候,不可以发送到EtQ。", "error");
                // alert("5.修理检测日是空的时候,不可以发送到EtQ。");
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
            if (this.ContainUseRSAC == 1) {
                this.ShowToastEvent("Final universal code为空,或者包含UseRSA,请确认。", "error");
                // alert("Final universal code为空,或者包含UseRSA,请确认。");
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
        }
        var result;
        try {
            var repairids = new Array()
            repairids[0] = this.Id;
        var repairids = new Array()
        repairids[0] = this.Id;
            var statuArr = new Array();
            statuArr.push(statu);
        var statuArr = new Array();
        statuArr.push(this.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';
        sendToETQ({
            iflog_Id: "",
            rowDataSFDC: "",
            repairIds: repairids,
            statu: statuArr[0]
        }).then(result => {
            console.log("result:" + result);
            if (result == "发送成功!") {
                this.ShowToastEvent(result, "success");
                this.dispatchEvent(new CloseActionScreenEvent());
            } else {
                this.ShowToastEvent("发送修理到EtQ失败," + result, "error");
                this.dispatchEvent(new CloseActionScreenEvent());
            }
            location.reload();
        } catch (error) {
            this.ShowToastEvent("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode, "error");
            // alert("发送修理到EtQ失败" + error.faultstring + ' code:' + error.faultcode);
        })
        var btns = document.getElementsByName("sendrepairstoetq");
        for (var i = 0; i < btns.length; i++) {
            btns[i].disabled = true;
            btns[i].className = 'btnDisabled';
        }
    }
@@ -189,4 +201,19 @@
        });
        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());
        }
    }
}