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
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
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import init from '@salesforce/apex/lexLoanerArrangedEmailLWCController.initFromLoanerArrangedEmailLButton';
import selectRentalApplyCByName from '@salesforce/apex/lexLoanerArrangedEmailLWCController.selectRentalApplyCByName';
import selectCampaignById from '@salesforce/apex/lexLoanerArrangedEmailLWCController.selectCampaignById';
import selectRaesById1 from '@salesforce/apex/lexLoanerArrangedEmailLWCController.selectRaesById1';
import selectRaesById2 from '@salesforce/apex/lexLoanerArrangedEmailLWCController.selectRaesById2';
import getSessionId from '@salesforce/apex/lexLoanerArrangedEmailLWCController.getSessionId';
import approvalCheck from '@salesforce/apex/lexLoanerArrangedEmailLWCController.approvalCheck';
import setRaesShipment_request from '@salesforce/apex/lexLoanerArrangedEmailLWCController.setRaesShipment_request';
// import { label } from '@salesforce/label';
import STATUS_PROCESS_STATE from '@salesforce/label/c.StatusProcessState';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { updateRecord } from 'lightning/uiRecordApi';
import getStatusList from '@salesforce/apex/lexLoanerArrangedEmailLWCController.getStatusList';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import TradeComplianceStatusFlagBP from '@salesforce/label/c.TradeComplianceStatusFlagBP';
import IFTradeComplianceAlertBP from '@salesforce/label/c.IFTradeComplianceAlertBP'
export default class lexLoanerArrangedEmailLWC extends LightningElement {
 
    @api recordId;
    @track TradeComplianceStatusFlagBP = TradeComplianceStatusFlagBP;
    @track IFTradeComplianceAlertBP = IFTradeComplianceAlertBP;
    id;
    IsLoading=true;
    ra;
    @track statusStringg = STATUS_PROCESS_STATE;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                this.recordId=str;
            }
        }
    }
 
 
 
    connectedCallback(){
        
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        let raes;
        let campaign;
        let campaignStatus;
        init({
            recordId: this.recordId
        }).then(res=>{
            //一览数据
            raes = res;
            let statusList = res.statusList;
            //获取备品借出申请数据
            selectRentalApplyCByName({recordId: raes.RentalApplyC}).then(result=>{
                this.ra = result[0];
                if(this.ra.Campaign__c != null){
                //获取学会数据
                    selectCampaignById({recordId: ra[0].Campaign__c}).then(campaignRes=>{
                        campaign = campaignRes[0];
                        campaignStatus = campaignRes[0].Status;
                    })
                }
                console.log(JSON.stringify(raes)+'==='+JSON.stringify(this.ra)+'==='+JSON.stringify(campaign)+'==='+statusList);
                //贸易合规 you 
                //var EquipmentGuaranteeFlg = '{!Rental_Apply__c.EquipmentGuaranteeFlg__c}';
                if(TradeComplianceStatusFlagBP=='true'){
                    //if(EquipmentGuaranteeFlg==false){
                    if(raes.accDealerBlacklist == '1'){
                        this.showToast(IFTradeComplianceAlertBP,'warning');
                        return;
                    }
                    //}
                }
                console.log("贸易合规");
                console.log(this.TradeComplianceStatusFlagBP);
                console.log(this.IFTradeComplianceAlertBP);
                console.log(result.accDealerBlacklist);
                //贸易合规 you 
                //判断条件
                if(this.ra.Wei_Assigned_Cnt__c > 0){
                    this.showToast("申请单内存在未分配的配套,请分配备品或分割申请单",'warning');
                    return;
                }else if( campaignStatus == '取消'){
                    this.showToast("学会取消,不可出库指示",'warning');
                    return;
                }else if(raes.AssignedNotShipmentC == 0){
                    this.showToast("没有可以出库指示的明细",'warning');
                    return;
                }else if(this.ra.Demo_purpose1__c =='长期借出' && this.ra.Contract_pdf_updated__c == 0){
                    this.showToast("长期借出时,必须先上传契约书",'warning');
                    return;
                }else if(this.ra.Repair__c != '' && this.ra.Repair__c != null && (this.ra.Repair_Final_Inspection_Date_F__c !=null && this.ra.Repair_Final_Inspection_Date_F__c != '') || (this.ra.RC_return_to_office__c != null && this.ra.RC_return_to_office__c !='')){
                    this.showToast("修理有最终检测日或修理品返送日,不可出库指示",'warning');
                    return;
                }
                // 20220217 ljh add OBPM市场活动联动 start 
                else if(campaign!= null && campaign.IF_Approved__c ==true && (campaign.Meeting_Approved_No__c ==null || campaign.Meeting_Approved_No__c == '')){
                    this.showToast("没有决裁号的,暂不能出借,请更新裁决信息。",'warning');
                    return;
                }else if(campaign!= null && campaign.IF_Approved__c ==true && campaign.Meeting_Approved_No__c != '' && statusList.indexOf(campaign.Approved_Status__c)!= -1){
                    this.showToast("已申请决裁但决裁状态不符合条件。",'warning');
                    return;
                }// 20220217 ljh add OBPM市场活动联动 end 
                else{
                    //154p 1388 yc 20211020
                    let raidString = this.ra.Id+";"+ this.recordId;
                    approvalCheck({
                        rentalApplyId: raidString
                    }).then(rs1=>{
                        rs1 = 1;
                        if(rs1 != '1'){
                            this.showToast(rs1, 'warning');
                        }else{
                            setRaesShipment_request({
                                raesid: this.recordId
                            }).then(finalResult=>{
                                console.log('finalResult==='+finalResult);
                                if(finalResult == "状态更新到已出库指示"){
                                    this.showToast("状态更新到已出库指示",'success');
                                    if(this.ra.Bollow_Date__c==undefined || this.ra.Bollow_Date__c == ''){
                                        selectRaesById2({recordId2:this.ra.Id}).then(sqlResult=>{
                                            let size = sqlResult.length;
                                            console.log('sqlResult2==='+size%10 == 0 ? size/10 : parseInt(size/10) +1);
                                            let length = size%10 == 0 ? size/10 : parseInt(size/10) +1;
                                            for(let i = 0; i<length; i++){
                                                console.log('/apex/FixtureRentalPDF?raid=' + this.ra.Id + '&page=' + i);
                                                window.open('/apex/FixtureRentalPDF?raid=' + this.ra.Id + '&page=' + i); 
                                            }
                                        }).catch(err=>{
                                            console.log('selectRaesById2==='+err);
                                        })
                                    }else{
                                        selectRaesById1({recordId1:this.ra.Id}).then(sqlResult=>{
                                            let size = sqlResult.length;
                                            let length = size%10 == 0 ? size/10 : parseInt(size/10) +1;
                                            for(let i = 0; i<length; i++){
                                                console.log('/apex/FixtureRentalPDF?raid=' + this.ra.Id + '&page=' + i);
                                                window.open('/apex/FixtureRentalPDF?raid=' + this.ra.Id + '&page=' + i); 
                                            }
                                        }).catch(err=>{
                                            console.log('selectRaesById1==='+err);
                                        })
                                    }
                                    window.location.href='/lightning/r/Rental_Apply_Equipment_Set__c/' + this.recordId + '/view';
                                }else{
                                    this.showToast(finalResult,'warning');
                                }
                            }).catch(err=>{
                                console.log('setRaesShipment_requestErr==='+err);
                            })
                        }
                    }).catch(err=>{
                        console.log('approvalCheck==='+err);
                    })
                }
            }).catch(err=>{
                console.log('selectRentalApplyCByName==='+err);
            })
        }).catch(err=>{
            console.log('initerr===='+err);
        })
    }
 
    print(raid, bollowDate){
        let sqlResult;
        let size;
        let length;
        console.log('id===='+raid + 'bollowDate==='+bollowDate);
        if(bollowDate != ''){
            selectRaesById1({recordId1:raid}).then(res=>{
                sqlResult = res;
                console.log('sqlResult1==='+sqlResult);
                size = sqlResult.length;
                length = size%10 == 0 ? size/10 : parseInt(size/10) +1;
                for(let i = 0; i<length; i++){
                    window.open('/apex/FixtureRentalPDF?raid=' + raid + '&page=' + i); 
                }
            })
        }else{
            selectRaesById2({recordId2:raid}).then(res=>{
                sqlResult = res;
                console.log('sqlResult2==='+sqlResult);
                size = sqlResult.length;
                length = size%10 == 0 ? size/10 : parseInt(size/10) +1;
                for(let i = 0; i<length; i++){
                    window.open('/apex/FixtureRentalPDF?raid=' + raid + '&page=' + i); 
                }
            })
        }
        
    }
 
    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());
        }
    }
 
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
}