binxie
2024-01-20 e0de9222da210f9c8eb1a9f5400f936a14923e11
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
import { LightningElement, track, wire, api } from 'lwc';
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { updateRecord } from 'lightning/uiRecordApi';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
import init from '@salesforce/apex/LexSubmitExtensionController.init';
import extension_approval_processCheck from '@salesforce/apex/RentalApplyWebService.extension_approval_processCheck'
export default class lexSubmitExtensionApprovalProcess extends LightningElement {
    @api
    recordId;
    IsLoading = true;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        if(currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            
            if(urlValue) {
                let str = `${urlValue}`;
                this.recordId = str;
            }
        }
    }
 
    connectedCallback(){
        Promise.all([
            loadStyle(this,lwcCSS)
        ]);
        init({
            recordId:this.recordId
        }).then(res=>{
            console.log('res==='+JSON.stringify(res));
            if(JSON.stringify(res) == '{}'){
                this.ToastShow('没有查到需要的数据','warning');
                return;
            }
            let today = new Date();
            //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c 
            if(res.extensionStatus == '填写完毕' || res.extensionStatus == '申请中') {
                this.showToast('请确认延期申请状态,已经提交过的申请,不能重复提交','error');
                return; 
            }
            extension_approval_processCheck({rentalApplyId:this.recordId}).then(result =>{
                console.log('result==='+result);
                if(result != '1'){
                    if(result == '2'){
                        //返回值为2,判断入口为从单还是主单,如果是从单,那么就需要跳原来的单个延期页面 
                        if(result.rootRentalApply == '' || result.rootRentalApply == null){
                            window.open("/apex/RentalApplyMultiPostpone?parentId=" + this.recordId); 
                        }else {
                            window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId); 
                        }
                    }else{
                        this.showToast(result,'error');
                        return
                    }
                }else{
                    if(res.demoPurpose2 == '协议借用'){
                        this.showToast('请在[附件]内上传新的合同附件,并依据合同内期限进行日期填写,之后提交审批','error'); 
                        return;
                    }
                    console.log('typeof'+typeof(res.agreementBorrowingExtensionDate));
                    if(res.agreementBorrowingExtensionDate =='' || res.agreementBorrowingExtensionDate == null){
                        this.showToast('协议借用的延期申请的【协议借用延期日期】不能为空','error'); 
                        return;
                    }
                    typeof(res.agreementBorrowingExtensionDate) == 'string' ? res.agreementBorrowingExtensionDate = new Date(res.agreementBorrowingExtensionDate) : '';
                    typeof(res.returnDadelineFinal) == 'string' ? res.returnDadelineFinal = new Date(res.returnDadelineFinal) : '';
                    if(res.agreementBorrowingExtensionDate <= res.returnDadelineFinal){
                        this.showToast('协议借用的延期申请的【协议借用延期日期】必须大于最新预定归还日','error'); 
                        return; 
                    }
                    if(res.agreementBorrowingExtensionDate <= today ){
                        this.showToast('协议借用的延期申请的【协议借用延期日期】必须大于今天','error'); 
                        return; 
                    }
                    window.open("/apex/RentalApplyExtensions?parentId=" + this.recordId); 
                }
                this.dispatchEvent(new CloseActionScreenEvent());
 
            }).catch(err=>{
                console.log('extension_approval_processCheckerr===',err);
                console.log(err);
            })
        })            
        .catch(err=>{
            console.log('error====>'+err);
        })
    }
 
    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.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
}