黄千龙
2023-08-09 626f3c3bb25e204568019e8d568e2d7547d1037a
force-app/main/default/lwc/lexRCSubmit/lexRCSubmit.js
@@ -1,28 +1,33 @@
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import LightningConfirm from 'lightning/confirm';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import init  from '@salesforce/apex/QISReportController.initForRCSubmitButton';
import updateQis  from '@salesforce/apex/QISReportController.updateQisWithRC';
import UserInfo_Owner from '@salesforce/apex/TaskFeedbackController.UserInfo_Owner';
import { updateRecord } from 'lightning/uiRecordApi';
/*
 * @Description: 提交待审批
 * @Author: hql
 * @Date: 2023-07-12 09:45:19
 * @LastEditTime: 2023-07-12 15:44:33
 * @LastEditors:
 */
export default class lexRCSubmit extends LightningElement {
   @api recordId;
   IsLoading = true;
   qisReportId;
   qisStatus;
   OSHstaff;
   OSHstaffEmail;
   CancelQISReason;
   Rcid;
   RCinspectionDate;
   QISReplyDay;
   RCproblemnotfound;
   type;
    @api recordId;
    IsLoading = true;
    qisReportId;
    qisStatus;
    OSHstaff;
    OSHstaffEmail;
    CancelQISReason;
    Rcid;
    RCinspectionDate;
    QISReplyDay;
    RCproblemnotfound;
    type;
    err;
   @wire(CurrentPageReference)
    @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
             console.log(111);
             console.log(currentPageReference);
@@ -52,7 +57,7 @@
            this.RCinspectionDate = result.rCinspectionDate;
            this.QISReplyDay = result.qISReplyDay;
            this.RCproblemnotfound = result.rCproblemnotfound;
            if (this.qisStatus!='RC检测中') {
            if (this.qisStatus!='RC检测中') {
                const evt = new ShowToastEvent({
                        title : '已经提交审批',
                        message: '',
@@ -60,96 +65,112 @@
                    });
                 this.dispatchEvent(evt);
                this.dispatchEvent(new CloseActionScreenEvent());
               return;
            }
            if (this.CancelQISReason!=null) {
               if (this.qisStatus == 'RC检测申请') {
                return;
            }
            console.log('this.RCproblemnotfound='+(this.QISReplyDay!=null  && this.RCproblemnotfound));
            if (this.CancelQISReason==null) {
                if (this.qisStatus == 'RC检测申请') {
                    const evt = new ShowToastEvent({
                        title : '需要先点击[OCM服务本部收到实物]',
                        message: '',
                        title : '',
                        message: '需要先点击[OCM服务本部收到实物]',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
               return;
               }
               if (this.Rcid ==null) {
                    const evt = new ShowToastEvent({
                        title : '判定担当必须填写',
                        message: '',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
               return;
               }
               if (this.RCinspectionDate == null) {
                    const evt = new ShowToastEvent({
                        title : 'OCM服务本部还没有检测完毕',
                        message: '',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
               return;
               }
               if (this.QISReplyDay!=null  && this.RCproblemnotfound) {
                    const evt = new ShowToastEvent({
                        title : '最终判定时,请取消[故障未发现留下继续观察]并选择[对应方法]',
                        message: '',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
               return;
               }
               if (confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
                  this.type = '1';
            }else{
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
            }else{
               if (confirm("一旦提交关闭此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
               this.type = '2';
            }else{
                if (this.Rcid ==null) {
                    const evt = new ShowToastEvent({
                        title : '',
                        message: '判定担当必须填写',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
            }
            console.log('this.type='+this.type);
            // this.dispatchEvent(new CloseActionScreenEvent());
            this.updateQisSubmit();
                if (this.RCinspectionDate == null) {
                    const evt = new ShowToastEvent({
                        title : '',
                        message: 'OCM服务本部还没有检测完毕',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                if (this.QISReplyDay!=null  && this.RCproblemnotfound) {
                    const evt = new ShowToastEvent({
                        title : '',
                        message: '最终判定时,请取消[故障未发现留下继续观察]并选择[对应方法]',
                        variant: 'error'
                    });
                    this.dispatchEvent(evt);
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                LightningConfirm.open({
                message: '一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?',
                variant: 'headerless',
                label: 'this is the aria-label value',
                }).then(res=>{
                    if(res) {
                        this.type = '1';
                        console.log('this.type='+this.type);
                        this.updateQisSubmit();
                    }else{
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                });
            }else{
                LightningConfirm.open({
                message: '一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?',
                variant: 'headerless',
                label: 'this is the aria-label value',
                }).then(res=>{
                    if(res) {
                        this.type = '2';
                        console.log('this.type='+this.type);
                        this.updateQisSubmit();
                    }else{
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                });
            }
            // this.dispatchEvent(new CloseActionScreenEvent());
        }).catch(error => {
            console.log('error='+error);
        }).finally(() => {
            
        }); 
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
    updateQisSubmit(){
           updateQis({
               recordId: this.recordId,
               type: this.type,
               oldQIStatus: this.qisStatus
              }).then(result =>{
                 console.log('result'+result);
            updateQis({
                 recordId: this.recordId,
                 type: this.type,
                 oldQIStatus: this.qisStatus
                }).then(result =>{
                    console.log('result'+result);
                     this.err = result;
                 if (result!='成功') {
                    if (result!='成功') {
                        const evt = new ShowToastEvent({
                            title : '更新失败',
                            message: this.err,
                            title : '',
                            message: '更新失败'+this.err,
                            variant: 'error'
                        });
                        this.dispatchEvent(evt);
                        updateRecord({fields: { Id: this.recordId }});
                    }
                    updateRecord({fields: { Id: this.recordId }});
                this.dispatchEvent(new CloseActionScreenEvent());
                this.updateRecordView(this.recordId);
              }).catch(error => {
                }).catch(error => {
            console.log('error='+error);
        }).finally(() => {