liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { LightningElement, track, wire,api } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import submitApproval  from '@salesforce/apex/LexUtils.submitApproval';
import getRecord  from '@salesforce/apex/LexUtils.getRecord';
 
export default class lexadjustSubmitApproval extends LightningElement {
 
    @api recordId;
    IsLoading=true;    
    adjust;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
            console.log(this.recordId);
          }
        }
    }
 
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        this.submitApproval().then(res=>{
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());        
        });    
    }
    async submitApproval(){
        //提交前的check
        this.adjust = await getRecord({recordId: this.recordId, objectApiName: 'PreProduct_StorageAdjust__c' });
        if(this.adjust.AcceptStorage__c){
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());   
            this.dispatchEvent(
            new ShowToastEvent({ title: '', message: '产品预留接收方所属本部为其他或市场本部时,不允许提交审批', variant: 'error', mode: 'sticky' }),
            );
            return;
        }
        if(this.adjust.GiveStorage__c){
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());   
            this.dispatchEvent(
            new ShowToastEvent({ title: '', message: '产品预留调出方所属本部为其他或市场本部时,不允许提交审批', variant: 'error', mode: 'sticky' }),
            );
            return;
        }
        //后台方法提交审批
        let mes = await submitApproval({recordId : this.recordId});
        if(mes != 'OK'){
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());   
            this.dispatchEvent(
            new ShowToastEvent({ title: '', message: mes, variant: 'error', mode: 'sticky' }),
            );
            console.log(mes);
            return;
        }
        else{
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());   
            this.dispatchEvent(
            new ShowToastEvent({ title: '', message:'提交审批成功', variant: 'success'}),
            );
            setTimeout(function() {
                location.reload();
            }, 2000); 
            return;
        }
    }
}