liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference, NavigationMixin} from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import  init  from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.init';
import UserInfo_Owner from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.UserInfo_Owner';
import newApply from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.newApplyInit';
import newApplyInitApp from '@salesforce/apex/lexNewSparePartsLoanApplicationCtl.newApplyInitApp';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
// 新建备品借出申请 opd计划
export default class LexNewSparePartsLoanApplication extends NavigationMixin(LightningElement) {
    @api recordId;
    defaultValues1;
    IsLoading = true;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(111);
            console.log(currentPageReference);
 
        if (currentPageReference) {
          let urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.recordId = str;
          }
        }
    }
 
    connectedCallback(){
        console.log(this.recordId);
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        init({
            recordId: this.recordId
        }).then(result => {
            this.IsLoading = false;
            if (result != null) {
                console.log("-------result--------------",JSON.stringify(result));
                console.log("---------学会-5555---result.opdIsJump-----",result.opdIsJump);
                //     StayOrNot__c 所有人在离职状态
                if (result.opdStayOrNot == '已离职') {
                    this.showToast('所有人已经离职,请联系系统管理员修改所有人。','warning');
                    return;
                }
                // IF_Approved__c 是否需要申请决裁 ; Approved_No__c 决裁编码
                if (result.opdIFApproved == true && result.opdApprovedNo == ''){
                    this.showToast('需要决裁时,决裁编码不能为空','warning');
                    return;
                }
                // 决裁状态  Approved_Status__c  
                if (result.opdIFApproved == true && result.opdApprovedNo != '' && result.opdStatusProcessState.indexOf(result.opdApprovedStatus)!== -1 && result.opdApprovedStatus != '草稿' ){
                    this.showToast('已申请决裁但决裁状态不符合条件','warning');
                    return;
                }
                // var HaveValue = "{!OPDPlan__c.Rental_Apply2__c}";
                //  备品借出申请1   Rental_Apply2__c ;  OPD计划来源  OPDType__c
                if (result.opdRentalApply2 != '' && result.opdType != '学会') {
                    this.showToast('一个OPD计划只可关联创建一个备品申请单','warning');
                    return;
                }
                //  状态  Status__c
                if (result.opdStatus != '计划中') {
                    this.showToast('OPD计划的状态不是计划中,不能新建备品借出申请','warning');
                    return;
                }
                
                UserInfo_Owner({}).then(res=>{
                    console.log("-------UserInfo_Owner---1111---------",res);
                    // 是否在试用期  isFormal_Stuff__c
                    if(res.isFormalStuff){
                        this.showToast('试用期内,不能申请','warning');
                        return;
                    }
                    
                    // 学会  Campaign__c
                    if (result.opdType == '学会' && result.opdCampaignId != '') {
                        console.log("-------UserInfo_Owner---2222---------");
                        //  提交申请FLG  Rental_Apply_Flag__c
                        if (result.opdRentalApplyFlag < 7) {
                            this.showToast("申请提交必须在7天(含)以上才可以",'warning');
                            return;
                        }
                        // userProvince 省 Province__c
                        var ups = res.userProvince.slice(0, 2);
                        let campaignRecodeType = result.opdCampaignRecodeTypeId.slice(0,15)
                        let getCampaignRecodeType = result.opdCampaignTypeId.slice(0,15)
                        console.log("-------opdCampaignRecodeTypeId---2222---------",getCampaignRecodeType,campaignRecodeType);
                        // 职种 Job_Category__c
                        if (campaignRecodeType != getCampaignRecodeType && res.userJobCategory == '销售服务' ) {
                            this.showToast('FSE不能申请该学会类型备品','warning');
                            return;
                        } else if ((res.userJobCategory == '销售服务' || res.userJobCategory == '支援') && campaignRecodeType != getCampaignRecodeType && result.opdInternalinchargeprovince.indexOf(ups) == -1) {
                            this.showToast("与FSE所在省一致,才可使用备品",'warning');
                            return;
                        } else if (result.opdCampaignStatus == '已结束') {
                            // 学会状态   CampaignStatus__c
                            this.showToast("已结束,不能申请",'warning');
                            return;
                        } else if (result.opdCampaignStatus == '已提交报告') {
                            this.showToast("已提交报告,不能申请",'warning');
                            return;
                        } else if (result.opdCampaignStatus == '取消申请中') {
                            this.showToast("取消申请中,不能申请",'warning');
                            return;
                        } else if (result.opdCampaignStatus == '取消') {
                            this.showToast("已经取消,不能申请",'warning');
                            return;
                        }
                    } 
 
                    if (result.opdOriginalOpdPlan == '' && result.opdOriginalOpdPlanApplication == '') {
                        //备品智能化 add  使用目的为 新产品评价
                        if(result.rentalReson == '新产品评价'){
                            let defaultValues = encodeDefaultFieldValues({
                                Demo_purpose1__c:'产品试用',
                                demo_purpose2__c:'新产品评价',
                                OPDPlan__c:result.opdPlanId,
                                Hospital__c:result.opdHospitalId,
                                Strategic_dept__c:result.opdOCMcategoryId,
                                Person_In_Charge__c:res.id,
                                applyUser__c:res.id,
                                Account__c:result.opdAccountLaboratory,
                                Loaner_received_staff__c:res.lastName + res.firstName,
                                IsJump__c:result.opdIsJump,
                                JumpCause__c:result.opdJumpCause,
                                Name:'*',
                                Approved_State_Create__c:result.opdApprovedStatus,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 start
                                Product_category__c:result.planProdDetail,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 end
                                ApprovedNo_Create__c:result.opdApprovedNo
                            });
                            this.navigateEvents(defaultValues);
                        }
                        else if (result.opdType == '学会' && result.opdCampaignId != ''){
 
                            let defaultValues = encodeDefaultFieldValues({
                                // OPDPlan__c:this.recordId,
                                Demo_purpose1__c:'产品试用',
                                demo_purpose2__c:'学会展会',
                                Campaign__c:result.opdCampaignId,
                                Account__c:result.opdAccountLaboratory,
                                Strategic_dept__c:result.opdOCMcategoryId,
                                Hospital__c:result.opdHospitalId,
                                OPDPlan__c:result.opdPlanId,
                                Person_In_Charge__c:res.id,
                                applyUser__c:res.id,
                                Loaner_received_staff__c:res.lastName + res.firstName,
                                IsJump__c:result.opdIsJump,
                                JumpCause__c:result.opdJumpCause,
                                Name:'*',
                                Approved_State_Create__c:result.opdApprovedStatus,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 start
                                Product_category__c:result.planProdDetail,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 end
                                ApprovedNo_Create__c:result.opdApprovedNo
                            });
                            console.log("---------学会---defaultValues--111----",defaultValues);
                            this.navigateEvents(defaultValues);
                        }
                        else if (result.opdOpportunityId != '') {
                            // 跟进询价ID1
                            // var purposeStr = '&00N10000003Msk0=产品试用' +
                            // '&00N10000003Msk5=试用(有询价)' +
                            // '&CF00N10000003O3VB_lkid={!OPDPlan__c.Related_Opportunity1_IDId__c}' +
                            // '&CF00N10000003O3VB={!HTMLENCODE(OPDPlan__c.Related_Opportunity1_Name__c)}';
                            console.log("--------defaultValues------")
                            console.log('result.opdRelatedOpportunity1ID = ' + result.opdRelatedOpportunity1ID);
                            let defaultValues = encodeDefaultFieldValues({
                                // OPDPlan__c:this.recordId,
                                Demo_purpose1__c:'产品试用',
                                demo_purpose2__c:'试用(有询价)',
                                Follow_UP_Opp__c:result.opdRelatedOpportunity1ID,
                                Account__c:result.opdAccountLaboratory,
                                Strategic_dept__c:result.opdOCMcategoryId,
                                Hospital__c:result.opdHospitalId,
                                OPDPlan__c:result.opdPlanId,
                                Person_In_Charge__c:res.id,
                                applyUser__c:res.id,
                                Loaner_received_staff__c:res.lastName + res.firstName,
                                IsJump__c:result.opdIsJump,
                                JumpCause__c:result.opdJumpCause,
                                Name:'*',
                                Approved_State_Create__c:result.opdApprovedStatus,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 start
                                Product_category__c:result.planProdDetail,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 end
                                ApprovedNo_Create__c:result.opdApprovedNo
                            });
                            console.log("--------defaultValues--222-1111---",defaultValues);
                            
                            this.navigateEvents(defaultValues);
                        } 
                        else {
                            console.log("-------UserInfo_Owner---77777---------");
                            // var purposeStr = '&00N10000003Msk0=产品试用' +
                            // '&00N10000003Msk5=试用(无询价)' +
                            // '&00N100000098amW={!OPDPlan__c.NoOpp_Reason__c}';
                            let defaultValues = encodeDefaultFieldValues({
                                // OPDPlan__c:this.recordId,
                                Demo_purpose1__c:'产品试用',
                                demo_purpose2__c:'试用(无询价)',
                                NoOpp_Reason__c:result.opdNoOppReason,
    
                                Account__c:result.opdAccountLaboratory,
                                Strategic_dept__c:result.opdOCMcategoryId,
                                Hospital__c:result.opdHospitalId,
                                OPDPlan__c:result.opdPlanId,
                                Person_In_Charge__c:res.id,
                                applyUser__c:res.id,
                                Loaner_received_staff__c:res.lastName + res.firstName,
                                IsJump__c:result.opdIsJump,
                                JumpCause__c:result.opdJumpCause,
                                Name:'*',
                                Approved_State_Create__c:result.opdApprovedStatus,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 start
                                Product_category__c:result.planProdDetail,
                                // 借用机会可视化_上线前遗留问题 zyh 2024-01-15 end
                                ApprovedNo_Create__c:result.opdApprovedNo
                            });
    
                            this.navigateEvents(defaultValues);
                        }
                    }
                })
 
                // 原OPD计划(再申请)   OriginalOpdPlan__c  原OPD计划(补充申请) OriginalOpdPlanApplication__c
                if (result.opdOriginalOpdPlan != '') {
                    
                    // 2023-09-10 zyh add start
                    newApply({
                        recordId : this.recordId
                    })
                    .then(rares=>{
                        
                        let defaultValues = 'Name=*,newclone=1'
                        // + ',Cancel_Reason__c=' + rares.cancelReason
                        // + ',Loaner_cancel_reason__c=' + rares.loanerCancelReason
                        // + ',Loaner_cancel_request__c=' + rares.loanerCancelRequest
                        // + ',Request_shipping_day__c=' + rares.requestShippingDay
                        // + ',Hope_Lonaer_date_Num__c=' + rares.hopeLonaerDateNum
                        //deloitte-zhj 20231204 PIPL还原
                        // + ',loanerMedicalStaffAWSDataId=' + rares.loanerMedicalStaffAWSDataId //deloitte-zhj 20230916
                        // + ',rentalApplyAWSDataId=' + rares.rentalApplyAWSDataId //deloitte-zhj 20230916
                        + ',Follow_UP_OppName=' + rares.Follow_UP_OppName //deloitte-zhj 20230922
                        + ',RepairName=' + rares.RepairName //deloitte-zhj 20230922
                        + ',Request_return_day__c=' + rares.requestReturnDay
                        + ',Assign_Person__c=' + rares.assignPerson
                        // + ',Old_Rental_Apply__c=' + rares.id
                        + ',Status__c=草案中'
                        + ',Zsq_Rental_Apply__c=' + result.opdRentalApplyName
                        + ',OPDPlan__c=' + result.opdPlanId
                        + ',Split_Apply_Reason__c=';
                        console.log("再申请>>1234567890>>>>>  ",rares.opdCloneData)
 
                        this.navigateEvents(rares.opdCloneData + "," + defaultValues);
                    })
                }
 
                if(result.opdOriginalOpdPlan == '' && result.opdOriginalOpdPlanApplication != ''){
                    // 2023-09-10 zyh add start
                    newApplyInitApp({
                        recordId : this.recordId
                    }).then(rares=>{
                        console.log("-------原OPD计划(补充申请)----opdOriginalOpdPlanApplication != ''---",rares);
 
                        let defaultValues = 'Name=*,newclone=1'
                        // + ',Cancel_Reason__c=' + rares.cancelReason
                        // + ',Loaner_cancel_reason__c=' + rares.loanerCancelReason
                        // + ',Loaner_cancel_request__c=' + rares.loanerCancelRequest
                        //deloitte-zhj 20231204 PIPL还原
                        // + ',loanerMedicalStaffAWSDataId=' + rares.loanerMedicalStaffAWSDataId //deloitte-zhj 20230916
                        // + ',rentalApplyAWSDataId=' + rares.rentalApplyAWSDataId //deloitte-zhj 20230916
                        + ',Follow_UP_OppName=' + rares.Follow_UP_OppName //deloitte-zhj 20230922
                        + ',RepairName=' + rares.RepairName //deloitte-zhj 20230922
                        + ',Request_demo_time__c=' + rares.requestDemoTime
                        + ',Request_approval_time__c=' + rares.requestApprovalTime
                        + ',Application_accept_time__c=' + rares.applicationAcceptTime
                        + ',Response__c=' + rares.response
                        // + ',Old_Rental_Apply__c=' + rares.id
                        + ',Status__c=草案中'
                        + ',Zsq_Rental_Apply__c=' + result.opdRentalApplyName
                        + ',OPDPlan__c=' + result.opdPlanId
                        + ',Split_Apply_Reason__c=';
                        if(rares.cancelReason){
                            defaultValues = defaultValues + ',Cancel_Reason__c='+rares.cancelReason;
                        }
                        if(rares.loanerCancelReason){
                            defaultValues = defaultValues + ',Loaner_cancel_reason__c='+rares.loanerCancelReason;
                        }
                        if(rares.loanerCancelRequest){
                            defaultValues = defaultValues + ',Loaner_cancel_request__c='+rares.loanerCancelRequest;
                        }
                        
                        console.log("补充申请>>123456>>>>>  ",defaultValues)
 
                        this.navigateEvents(rares.opdCloneData + "," + defaultValues);
                    }).catch(error => {
                        console.log("error补充申请");
                        console.log(error);
                        this.dispatchEvent(new CloseActionScreenEvent());
                    });
                }
                // 
                // window.location.reload();
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
            this.dispatchEvent(new CloseActionScreenEvent());
        })
    }
 
    showToast(msg, type) {
        if(type == "success"){
            const event = new ShowToastEvent({
                // title: '',
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
          }else{
            const event = new ShowToastEvent({
                // title: '',
                message: msg,
                variant: type,
                mode:'sticky'
            });
            this.dispatchEvent(event);
        }
        this.dispatchEvent(new CloseActionScreenEvent());
    }
 
    navigateEvents(defaultValues){
        console.log("--------navigateEvents------",defaultValues);
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Rental_Apply__c',
                actionName: 'new'
            },
            state:{
                // nooverride : 1,
                defaultFieldValues: defaultValues
            }
        });
        this.dispatchEvent(new CloseActionScreenEvent());
    }
}