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
import { LightningElement,api, track, wire } from 'lwc';
import init from '@salesforce/apex/RentalApplyCancleButtonController.initRentalApplyCanle'
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';
export default class lexRentalApplyCanleButton extends LightningElement {
 
 
    @api recordId;
    Yi_loaner_arranged__c;
    Id;
    RA_Status__c;
    IsLoading=true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                console.log('str');
                console.log(str);
                this.recordId=str;
            }
        }
    }
 
        currentDay(){
        var date=new Date();    
        var toDay=new Date();
        toDay='';
        toDay+=date.getFullYear()+'/';
        toDay+=date.getMonth()+1+'/';
        toDay+=date.getDate();
        return toDay;
    }
 
 
    connectedCallback(){
        
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        console.log(this.recordId);
        init({recordId:this.recordId}).then(result=>{
            console.log(result);
            if(result!=null){
                this.IsLoading=false;
                var a=new Array('a');
                a.push('12');
                console.log('a='+a);
                this.Yi_loaner_arranged__c=result.YiLoanerArranged;
                this.Id=result.Id;
                this.RA_Status__c=result.RAStatus;
                console.log("end");
                console.log("RA_Status__c="+this.RA_Status__c);
                console.log("Yi_loaner_arranged__c="+this.Yi_loaner_arranged__c);
                this.cancelSubmit().then(res=>{
                    this.dispatchEvent(new CloseActionScreenEvent());
                });    
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err);
        }).finally(()=>{
 
        });
    }
 
 
 
    async cancelSubmit(){
        console.log('进入方法');
        if (this.RA_Status__c  == "取消") {
            this.dispatchEvent(new CloseActionScreenEvent());
            // alert("已经取消!");
 
            this.showToast("已经取消!",'error');
            return;
        }
        console.log("1  if  end ");
        if (this.RA_Status__c == "删除" ) {
            this.dispatchEvent(new CloseActionScreenEvent());
            // alert("已经删除!");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"已经删除!"
            });
            this.showToast("已经删除!",'error');
            return;
        }
        console.log('2  if  end');
        if(this.RA_Status__c  == "已出库" || this.Yi_loaner_arranged__c > 0) {
            this.dispatchEvent(new CloseActionScreenEvent());
            // alert("备品已经出库,不能取消!");
            this.showToast("备品已经出库,不能取消!",'error');
            return;
        }
        console.log("111111111111111111111111");
        var raid = this.Id;
        console.log("raid="+raid)
        window.open("/apex/RentalApplyCancel?objId="+raid, 'RentalApplyCancel', 'width=800,height=280');
        this.dispatchEvent(new CloseActionScreenEvent());
    }
 
    showToast(msg,type) {
        
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            // this.updateRecordView(this.recordId);
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            // this.updateRecordView(this.recordId);
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }
        
    }
}