buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import init from '@salesforce/apex/SelectSubstituteControllerLWT.initFromLoanerArrangedEmailLButton';
import selectRentalApplyCByName from '@salesforce/apex/SelectSubstituteControllerLWT.selectRentalApplyCByName';
import selectRaesById1 from '@salesforce/apex/SelectSubstituteControllerLWT.selectRaesById1';
import selectRaesById2 from '@salesforce/apex/SelectSubstituteControllerLWT.selectRaesById2';
import getSessionId from '@salesforce/apex/SelectSubstituteControllerLWT.getSessionId';
import approvalCheck from '@salesforce/apex/SelectSubstituteControllerLWT.approvalCheck';
import setShipment_requests from '@salesforce/apex/SelectSubstituteControllerLWT.setShipment_requests';
// import { label } from '@salesforce/label';
import STATUS_PROCESS_STATE from '@salesforce/label/c.StatusProcessState';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class loanerArrangedEmailLWC extends LightningElement {
 
    @api recordId;
    id;
    RentalApplyC;
    Status;
    Wei_Assigned_Cnt__c;
    Bollow_Date__c;
    Assigned_Not_Shipment__c;
    IsLoading=true;
    @track statusStringg = STATUS_PROCESS_STATE;
    @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.id=result.id;
                this.RentalApplyC=result.RentalApplyC;
                this.Status=result.Status;
                this.Wei_Assigned_Cnt__c=result.WeiAssignedCntC;
                this.Bollow_Date__c=result.BollowDateC;
                this.Assigned_Not_Shipment__c=result.AssignedNotShipmentC;
                this.cancelSubmit().then(res=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });    
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err);
        }).finally(()=>{
 
        });
    }
 
 
 
    async cancelSubmit(){
        let campaignStatus = '';
        let records = null; // 20220217 ljh OBPM市场活动联动
        console.log("Ff");
        let statusSting = "{!$Label.StatusProcessState}"; // 20220322 ljh add
        let statusList = statusSting.split(',');
        console.log(statusSting);
        console.log(statusList);
        console.log(this.statusStringg);
        let raliveryGood;
        await selectRentalApplyCByName({recordId:this.RentalApplyC})
        .then(res=>{
            console.log(res);
            if (res!=null) {
                raliveryGood=res;
            }
        }).catch(err=>{
            console.log("selectRentalApplyCByName err:")
            console.log(err.message);
        });
        console.log(statusSting);
        console.log(raliveryGood);
        console.log("ddd");
        let RentalApply = raliveryGood[0];
        console.log(RentalApply);
 
        if(RentalApply.Campaign__c != null&&RentalApply.Campaign__c != '' ) {
            console.log();
            let DeliveryGood;
            // 20220217 ljh update OBPM市场活动联动 start
            // DeliveryGood = sforce.connection.query("select Status, Rental_Apply_Flag__c from Campaign where id ='" + RentalApply.Campaign__c + "'");
            // let records= DeliveryGood.getArray("records");
            await selectCampaignById({recordId:RentalApply.Campaign__c}).then(res=>{
                console.log(res);
                DeliveryGood=res;
            });
            console.log(RentalApply);
            records = DeliveryGood;
            console.log(DeliveryGood);
            // 20220217 ljh update OBPM市场活动联动 end
 
            campaignStatus = records[0].Status;
            console.log("hh3");
        }
        if(this.Wei_Assigned_Cnt__c > "0") {
            // alert("申请单内存在未分配的配套,请分配备品或分割申请单");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"申请单内存在未分配的配套,请分配备品或分割申请单"
            });
            this.dispatchEvent(event);
        }else if(campaignStatus == '取消'){
            // alert("学会取消,不可出库指示");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"学会取消,不可出库指示"
            });
            this.dispatchEvent(event);
        }else if (this.Assigned_Not_Shipment__c == "0") {
            // alert("没有可以出库指示的明细");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"没有可以出库指示的明细"
            });
            this.dispatchEvent(event);
        } else if (RentalApply.Demo_purpose1__c == "长期借出" && RentalApply.Contract_pdf_updated__c == "0") {
            // alert("长期借出时,必须先上传契约书");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"长期借出时,必须先上传契约书"
            });
            this.dispatchEvent(event);
        } else if(RentalApply.Repair__c != '' && RentalApply.Repair__c != null && (RentalApply.Repair_Final_Inspection_Date_F__c != null && RentalApply.Repair_Final_Inspection_Date_F__c != '') || (RentalApply.RC_return_to_office__c != null && RentalApply.RC_return_to_office__c != '')) {
            // alert("修理有最终检测日或修理品返送日,不可出库指示");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"修理有最终检测日或修理品返送日,不可出库指示"
            });
            this.dispatchEvent(event);
        // 20220217 ljh add OBPM市场活动联动 start
        } else if (records != null && records[0].IF_Approved__c == "true" && (records[0].Meeting_Approved_No__c == null || records[0].Meeting_Approved_No__c == "") ) {
            // alert("没有决裁号的,暂不能出借,请更新裁决信息。");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"没有决裁号的,暂不能出借,请更新裁决信息。"
            });
            this.dispatchEvent(event);
        } else if (records != null && records[0].IF_Approved__c == "true" && records[0].Meeting_Approved_No__c != "" && statusList.indexOf(records[0].Approved_Status__c) != -1 ) {
            // alert("已申请决裁但决裁状态不符合条件。");
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"已申请决裁但决裁状态不符合条件。"
            });
            this.dispatchEvent(event);
        // 20220217 ljh add OBPM市场活动联动 end
        } else {
            console.log("hhhh3");
            let t=await getSessionId();
            console.log(t);
            window.sforce = window.sforce || {};
            window.sforce.connection = window.sforce.connection || {};
            window.sforce.connection.sessionId =t;
            //154p 1388 yc 20211020
            console.log("hhhh4");
            let raid = RentalApply.Id+";"+this.id;
            console.log(raid);
            let rs1 = await approvalCheck({rentalApplyId:raid});
            console.log(rs1);
            if (rs1 != '1') {
                // alert(rs1);
                const event = new ShowToastEvent({
                    title: '提示信息',
                    message:rs1
                });
                this.dispatchEvent(event);
            } else {
                //bp2 let rs2 = sforce.apex.execute("RentalApplyWebService", "reserve", {rentalApplyId: raid});
                //bp2 if (rs2 != '1') {
                //bp2 alert(rs2);
                //bp2 } else {
                setShipment_requests({raid:null,raesid: this.id}).then(res=>{
                    if (res == "状态更新到已出库指示") {
                        // alert("状态更新到已出库指示");
                        const event = new ShowToastEvent({
                            title: '提示信息',
                            message:"状态更新到已出库指示"
                        });
                        this.dispatchEvent(event);
                        print().then(res=>{
                            setTimeout(function() {location.href = "/"+this.RentalApplyC;}, 100);
                        });
                    } else {
                        // alert(res);
                        const event = new ShowToastEvent({
                            title: '提示信息',
                            message:res
                        });
                        this.dispatchEvent(event);
                    }
                })
                // sforce.apex.execute("RentalApplyWebService", "setRaesShipment_request",
                //  {raesid: this.id}
                //     ,function(res) {
                //         if (res == "状态更新到已出库指示") {
                //             alert("状态更新到已出库指示");
                //             print().then(res=>{
                //                 setTimeout(function() {location.href = "/"+this.RentalApplyC;}, 100);
                //             });
                //         } else {
                //             alert(res);
                //         }
                // });
            }
        }
 
        async function print(){
            let sqlResult;
            if(this.Bollow_Date__c != ''){
                await selectRaesById1({recordId:RentalApply.Id}).then(res=>{
                    sqlResult=res;
                });
            }else{
                await selectRaesById2({recordId:RentalApply.Id}).then(res=>{
                    sqlResult=res;
                });
            }
            let records = sqlResult;
            let size =records.length;
            let length = size%10 ==0? size/10 : parseInt(size/10) +1;
            for(let i =0;i<length;i++){
                window.open('/apex/FixtureRentalPDF?raid=' + RentalApply.Id + '&page=' + i);
            }
        }
 
 
        // function fixTime(time){
        //     if(time < 10) {time = "0" + time};
        //         return time;
        // }
 
        // function fixDate(date){
        //     let Month = fixTime(date.getMonth() + 1);
        //     let Day = fixTime(date.getDate());
        //     let UTC = date.toUTCString();
        //     let Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
        //     let Minutes = fixTime(date.getMinutes());
        //     let Seconds = fixTime(date.getSeconds());
        //     return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
        // }
    }
}