binxie
2024-01-18 b1d36ea3e6653e59bd767aa192c688ee0d9d4c58
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
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import getUserId from '@salesforce/apex/lexCustomSubmitController.getUserId';
import init from '@salesforce/apex/lexCustomSubmitController.initFromCustomSubmitButton';
import updateRaesc from '@salesforce/apex/lexCustomSubmitController.updateRaesc';
import selectRacById from '@salesforce/apex/lexCustomSubmitController.selectRacById';
import postponeCheck from '@salesforce/apex/lexCustomSubmitController.postponeCheck';
import submitApprovalRequest from '@salesforce/apex/lexCustomSubmitController.submitApprovalRequest';
 
import { loadScript } from 'lightning/platformResourceLoader';
import { submitForApproval } from 'lightning/uiRecordApi';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class lexCustomSubmit extends LightningElement {
 
    @api recordId;
    id;
    RentalApplyId;
    Status;
    IsLoading=true;
    IsReload=false;
    @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;
            }
        }
    }
 
 
 
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        console.log(this.recordId);
        init({recordId:this.recordId}).then(result=>{
            console.log(result);
            if(result!=null){
                this.Rental_Apply_Equipment_Set__c=result;
                this.cancelSubmit().then(res=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });    
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err);
        }).finally(()=>{
 
        });
    }
 
 
 
    async cancelSubmit(){
        console.log("hhh1");
        if (this.Rental_Apply_Equipment_Set__c.Request_extend_day__c == ""
        || this.Rental_Apply_Equipment_Set__c.Request_extend_day__c == null
        || this.Rental_Apply_Equipment_Set__c.Extend_request_reason__c == ""
        || this.Rental_Apply_Equipment_Set__c.Extend_request_reason__c == null) {
            // alert("必须填写延期希望结束日,延期申请理由");
            this.showToast("必须填写延期希望结束日,延期申请理由",'warning');
            return;
        }
        console.log("hhh2");
        let rtn;
        let d=-5;
        await postponeCheck({
            endDate:this.Rental_Apply_Equipment_Set__c.Rental_End_Date__c,
            i:d
        }).then(res=>{
            console.log(res);
            rtn=res;
        }).catch(err=>{
            console.log("err:",err.message);
        });
 
        console.log(rtn);
        if (rtn != "OK") {
            // alert(rtn);
 
            this.showToast(rtn,'warning');
            return;
        }
        console.log("hhh3");
        let resultSet = await selectRacById({recordId:this.Rental_Apply_Equipment_Set__c.Rental_Apply__c})
        ;
        let records = resultSet;
        console.log("hhh4");
        let result = await updateRaesc({
            recordId:this.Rental_Apply_Equipment_Set__c.Id,
            JingliApprovalManagerc:records[0].JingliApprovalManager__c,
            BuchangApprovalManagerc:records[0].SalesManager__c,
            BuchangApprovalManagerSalesc:records[0].BuchangApprovalManager__c,
            ZongjianApprovalManagerc:records[0].BuchangApprovalManagerSales__c,
            ExtendStatusc:'填写完毕',
        });
        console.log("hhh5");
        console.log(result);
        // let messages = getConnectDMLErrorMessages(result);
        if(result!=null&&result.length>0&&result.errors.length>0){
            // alert(result.errors[0].split(",")[1]);
            this.showToast(result.errors[0].split(",")[1],'warning');
            return;
        }
        console.log("hhh7");
 
        await submitApprovalRequest({recordId:this.recordId}).then(res=>{
              console.log(res);
              if(res!=null&&res!=''){
                this.showToast(res,'warning');
                return;
              }else{
                  const event = new ShowToastEvent({
                    title: '提示信息',
                    message:"更新成功"
                });
                this.showToast("更新成功",'success');
                return;
              }
          })
    
    }
    updateRecordView(recordId){
        updateRecord({fields:{Id:recordId}});
    }
    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());
        }
        
    }
}