19626
2023-09-09 e14d6d0619330cad423f06493e3aa2371faa2a8f
force-app/main/default/lwc/lexSubmitSolutionSchemeForApproval/lexSubmitSolutionSchemeForApproval.js
@@ -2,6 +2,7 @@
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import updateSubmitSolutionSchemeForApprovalButton  from '@salesforce/apex/lexSolutionProgrammeController.updateSubmitSolutionSchemeForApprovalButton';
import submitApproval  from '@salesforce/apex/lexSolutionProgrammeController.submitApproval';
import init  from '@salesforce/apex/lexSolutionProgrammeController.initSubmitSolutionSchemeForApprovalButton';
import queryForAttachments  from '@salesforce/apex/lexSolutionProgrammeController.queryForAttachments';
import { updateRecord } from 'lightning/uiRecordApi';
@@ -28,15 +29,6 @@
          }
        }
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
@@ -46,8 +38,9 @@
        init({
            recordId: this.recordId
        }).then(result=>{
            this.schemeType = result.schemeType == undefined ? result.schemeType : '';
            this.confirmationResult = result.confirmationResult == undefined ? result.confirmationResult : '';
            console.log(result);
            this.schemeType = result.schemeType;
            this.confirmationResult = result.confirmationResult == undefined ?  '' : result.confirmationResult;
            this.submitSolutionSchemeForApproval();
        });
    }
@@ -68,22 +61,29 @@
        });
        console.log(result);
        if(result){
            if(this.schemeType == '结案' && this.confirmationResult == ''){
            console.log(this.schemeType);
            console.log(this.confirmationResult);
            if(this.schemeType == '结案' && (this.confirmationResult == '' || this.confirmationResult == undefined)){
                this.showToast('结案方案提交前,方案采纳结果必填','error');
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
            console.log('this.schemeType:'+this.schemeType);
            if((this.records.length > 0 && this.schemeType == '结案') || (this.schemeType == '初次')){
                updateSubmitSolutionSchemeForApprovalButton({
                    recordId: this.recordId
                }).then(result=>{
                    if(result){
                        this.showToast(result,'error');
                submitApproval({recordId:this.recordId}).then(rep => {
                    console.log(rep);
                    if(rep==='OK'){
                        console.log('1');
                        this.showToast('提交审批成功','success');
                    }else{
                        this.updateRecordView(this.recordId);
                        console.log('2');
                        this.showToast(rep,'error');
                    }
                    this.dispatchEvent(new CloseActionScreenEvent());
                });
                }).catch(err => {
                    console.log('3');
                    console.log(err);
                    this.showToast(err,'error');
                })
            }else{
                this.showToast('结案的方案提交前,必须上传结案附件','error');
                this.dispatchEvent(new CloseActionScreenEvent());
@@ -95,4 +95,15 @@
            return;
        }
    }
    showToast(msg, type) {
        const event = new ShowToastEvent({
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
        if(type==='success'){
            window.location.href = '/lightning/r/Solution_Programme__c/'+this.recordId+'/view';
        }
    }
}