FUYU
2023-12-13 4488f711dbc01a8db6753907cae2ef4021dede68
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
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import getUserId from '@salesforce/apex/RentalApplyControllerLWT.getUserId';
import init from '@salesforce/apex/SelectSubstituteControllerLWT.initFromCustomSubmitButton';
import updateRaesc from '@salesforce/apex/SelectSubstituteControllerLWT.updateRaesc';
import selectRacById from '@salesforce/apex/SelectSubstituteControllerLWT.selectRacById';
import postponeCheck from '@salesforce/apex/SelectSubstituteControllerLWT.postponeCheck';
 
import { loadScript } from 'lightning/platformResourceLoader';
import { submitForApproval } from 'lightning/uiRecordApi';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class lexCustomSubmit extends LightningElement {
 
    @api recordId;
    id;
    RentalApplyId;
    Status;
    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;
            }
        }
    }
 
 
 
    connectedCallback(){
        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("必须填写延期希望结束日,延期申请理由");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"必须填写延期希望结束日,延期申请理由"
            });
            this.dispatchEvent(event);
            return;
        }
        console.log("hhh2");
        let rtn;
        await postponeCheck({
            endDate:this.Rental_Apply_Equipment_Set__c.Rental_End_Date__c,
            d:-5
        }).then(res=>{
            console.log(res);
            rtn=res;
        }).catch(err=>{
            console.log("err:",err.message);
        })
 
        console.log(rtn);
        if (rtn != "OK") {
            // alert(rtn);
            const event = new ShowToastEvent({
                title: '提示信息',
                message:rtn
            });
            this.dispatchEvent(event);
            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]);
            const event = new ShowToastEvent({
                title: '提示信息',
                message:result.errors[0].split(",")[1]
            });
            this.dispatchEvent(event);
        }
        console.log("hhh7");
 
        // let request = new sforce.ProcessSubmitRequest();
        // request.objectId = this.recordId;
        // let processResults = sforce.connection.process([request]);
        console.log("hhh8");
        // submitForApproval(this.Rental_Apply_Equipment_Set__c.Id).then(result => {
        //     console.log(result);
        //     if (processResults[0].errors != null) {
        //         alert(processResults[0].errors.message);
        //         return;
        //     }
        //     console.log("hhh9");
        //     window.location.reload();
        // })
        // .catch(error => {
        //   console.error('Error submitting record for approval:', error.message);
        // });
 
        // await submitForApproval(this.recordId);
        const fields = {}
        const recordInput = { fields };
        updateRecord({ fields: recordInput, recordId: this.recordId })
          .then(() => {
            console.log("更新成功");
          })
          .catch(error => {
              console.log(error.message);
              console.log(error);
              // alert(error.body.message);
            const event = new ShowToastEvent({
                title: '提示信息',
                message:error.body.message
            });
            this.dispatchEvent(event);
            return;
            // 处理异常情况
          });
    }
}