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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { LightningElement, track, wire,api } from 'lwc';
import {CurrentPageReference,NavigationMixin} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import LightningConfirm from 'lightning/confirm';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
 
 
 
import applyPermission from '@salesforce/apex/TransferApplyController.applyPermission';
import submitApply from '@salesforce/apex/TransferApplyWebService.submitApply';
 
export default class lexSubmitApprovalProcess extends LightningElement {
    @api recordId;
    transferApplyPermission;
    IsLoading=true;
    cancelResult;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        console.log(currentPageReference);
 
        if(currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if(urlValue) {
                let str = `${urlValue}`;
                console.log("str");
                console.log(str);
                this.recordId = str;
 
            }
        }
    }
 
    connectedCallback() {
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        console.log('this.transferApplyId:' + this.recordId);
        applyPermission().then(result => {
            console.log(result);
            this.transferApplyPermission = result;
            if (this.transferApplyPermission == false) {
            this.showToast('没有提交申请的权限','warning');
            this.IsLoading=false;
            this.dispatchEvent(new CloseActionScreenEvent());
        } else{
            LightningConfirm.open({
                message: '一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?',
                variant: 'headerless',
              
            }).then(cancel=>{
                if(cancel) {
                    submitApply({taId:this.recordId}).then(submitRes=>{
                        console.log(submitRes);
                        this.cancelResult = submitRes;
                        this.cancelSubmit().then(res=>{
                            this.IsLoading=false;
                            this.dispatchEvent(new CloseActionScreenEvent());
                        });    
                        
                    }).catch( error =>{
                        this.showToast(error,"error");
                    });
                    // this.IsLoading=false;
                    // this.dispatchEvent(new CloseActionScreenEvent());
                } else{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                }
                
                
            });
            
        }    
 
                    
        }).catch( error =>{
            console.log(error);
        });
    }
    
 
    async cancelSubmit(){
        console.log(this.cancelResult);
        if(this.cancelResult == '1') {
            console.log(this.cancelResult);
            this.dispatchEvent( 
                new ShowToastEvent({
                    message:'提交成功',
                    variant: "success"
                })
            );
            setTimeout(function(){
                window.location.href = window.location;
            }, 1500 )
        } else {
            this.dispatchEvent( 
                new ShowToastEvent({
                    message:this.cancelResult,
                    variant: "warning",
                    mode: 'sticky'
                })
            );
            console.log("result:",this.cancelResult);
            // await this.showToast("",this.cancelResult,"warning");     
        }
            
    }
    
    // showToast(_title,_message,_variant) {
    //     const event = new ShowToastEvent({
    //         title: _title,
    //         message:_message,
    //         variant: _variant,
    //     });
    //     this.dispatchEvent(event);
    // }
 
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                // title: _title,
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                // title: _title,
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
        }
    }
}
 
//old js
/*
{!REQUIRESCRIPT('/soap/ajax/51.0/connection.js')}
{!REQUIRESCRIPT('/soap/ajax/51.0/apex.js')}
var result = sforce.connection.describeSObject('TransferApply__c');
if (result.createable == 'false') {
    alert('没有提交申请的权限');
}
else{
    if (confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
        var rs = sforce.apex.execute("TransferApplyWebService","submitApply",{taId:'{!TransferApply__c.Id}'});
        if(rs == '1'){
            alert('提交成功');
            window.location.href = window.location;
        }
        else{
            alert(rs);
        }
    }
}
*/