zhangqian
2023-07-04 586d34ae6c5a292e04fcf8ca1df711b6ea5204bf
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
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 { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
 
// 新建备品借出申请 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) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.recordId = str;
          }
        }
    }
 
    connectedCallback(){
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            this.IsLoading = false;
            if (result != null) {
                console.log("-------result--------------",JSON.stringify(result))
                if (result.opdStayOrNot == '已离职') {
                    this.showToast('所有人已经离职,请联系系统管理员修改所有人。','error');
                    return;
                }
                if (result.opdIFApproved == true && result.opdApprovedNo == ''){
                this.showToast('需要决裁时,决裁编码不能为空','error');
                return;
                }
                if (result.opdIFApproved == true && result.opdApprovedNo != '' && result.opdStatusProcessState.indexOf(result.opdApprovedStatus)!= -1 && result.opdApprovedStatus != '草稿' ){
                this.showToast('已申请决裁但决裁状态不符合条件','error');
                return;
                }
                var HaveValue = "{!OPDPlan__c.Rental_Apply2__c}";
                if (result.opdRentalApply2 != '' && result.opdType != '学会') {
                    this.showToast('一个OPD计划只可关联创建一个备品申请单','error');
                    return;
                }
                if (result.opdStatus != '计划中') {
                this.showToast('OPD计划的状态不是计划中,不能新建备品借出申请','error');
                return;
                }
                
                UserInfo_Owner({}).then(res=>{
                    console.log("-------UserInfo_Owner------------",res);
                    if(res.isFormalStuff == 'true'){
                        this.showToast('试用期内,不能申请','error');
                        return;
                    }
                    console.log("-------UserInfo_Owner---1111---------",result);
                    if (result.opdType == '学会' && result.opdCampaignId != '') {
                        console.log("-------UserInfo_Owner---2222---------");
                        if (result.opdRentalApplyFlag < 7) {
                        this.showToast("申请提交必须在7天(含)以上才可以",'error');
                        return;
                        }
                        var ups = res.userProvince.slice(0, 2);
                        if (result.opdCampaignTypeId != '01210000000R26P' && res.userJobCategory == '销售服务' ) {
                        this.showToast('FSE不能申请该学会类型备品','error');
                        return;
                        } else if ((res.userJobCategory == '销售服务' || res.userJobCategory == '支援') && result.opdCampaignTypeId == '01210000000R26P' && result.opdInternalinchargeprovince.indexOf(ups) == -1) {
                        this.showToast("与FSE所在省一致,才可使用备品",'error');
                        return;
                        } else if (result.opdCampaignStatus == '已结束') {
                        this.showToast("已结束,不能申请",'error');
                        return;
                        } else if (result.opdCampaignStatus == '已提交报告') {
                        this.showToast("已提交报告,不能申请",'error');
                        return;
                        } else if (result.opdCampaignStatus == '取消申请中') {
                        this.showToast("取消申请中,不能申请",'error');
                        return;
                        } else if (result.opdCampaignStatus == '取消') {
                        this.showToast("已经取消,不能申请",'error');
                        return;
                        }  
                    }
 
                    if (result.opdOriginalOpdPlan == '') {
                        if (result.opdOriginalOpdPlanApplication == '') {
                            if (result.opdType == '学会' && result.opdCampaignId != '') {
                                // var purposeStr = '&00N10000003Msk0=产品试用' +
                                // '&00N10000003Msk5=学会展会' +
                                // '&CF00N10000003Mp2q_lkid={!URLENCODE(OPDPlan__c.CampaignId__c)}' +
                                // '&CF00N10000003Mp2q={!URLENCODE(OPDPlan__c.CampaignName__c)}';
                                const defaultValues = encodeDefaultFieldValues({
                                    // OPDPlan__c:this.recordId,
                                    Demo_purpose1__c:'产品试用',
                                    demo_purpose2__c:'学会展会',
                                    Campaign__c:result.opdCampaign,
                                    Account__c:result.opdAccountLaboratory,
                                    Strategic_dept__c:result.opdOCMcategoryName,
                                    Hospital__c:result.opdHospitalName,
                                    OPDPlan__c:opdName,
                                    Person_In_Charge__c:res.lastName + res.firstName,
                                    applyUser__c:res.lastName + res.firstName,
                                    Loaner_received_staff__c:res.lastName + res.firstName,
                                    IsJump__c:result.opdIsJump,
                                    JumpCause__c:result.opdJumpCause,
                                    Name:'*',
                                    Approved_State_Create__c:result.ApprovedStatus,
                                    ApprovedNo_Create__c:result.opdApprovedNo
                                });
                                this.navigateEvents(defaultValues);
                            } else if (result.opdOpportunityId != '') {
                                // var purposeStr = '&00N10000003Msk0=产品试用' +
                                // '&00N10000003Msk5=试用(有询价)' +
                                // '&CF00N10000003O3VB_lkid={!OPDPlan__c.Related_Opportunity1_IDId__c}' +
                                // '&CF00N10000003O3VB={!HTMLENCODE(OPDPlan__c.Related_Opportunity1_Name__c)}';
                                console.log("--------defaultValues------")
                                const defaultValues = encodeDefaultFieldValues({
                                    // OPDPlan__c:this.recordId,
                                    Demo_purpose1__c:'产品试用',
                                    demo_purpose2__c:'试用(有询价)',
                                    Follow_UP_Opp__c:result.opdRelatedOpportunity1Name,
 
                                    Account__c:result.opdAccountLaboratory,
                                    // Strategic_dept__c:result.opdOCMcategoryName,
                                    // Hospital__c:result.opdHospitalName,
                                    // OPDPlan__c:opdName,
                                    // Person_In_Charge__c:res.lastName + res.firstName,
                                    // applyUser__c:res.lastName + res.firstName,
                                    // Loaner_received_staff__c:res.lastName + res.firstName,
                                    // IsJump__c:result.opdIsJump,
                                    // JumpCause__c:result.opdJumpCause,
                                    // Name:'*',
                                    // Approved_State_Create__c:result.ApprovedStatus,
                                    // ApprovedNo_Create__c:result.opdApprovedNo
                                });
                                console.log("--------defaultValues---1111---",defaultValues);
                                
                                this.navigateEvents(defaultValues);
                            } else {
                                console.log("-------UserInfo_Owner---77777---------");
                                // var purposeStr = '&00N10000003Msk0=产品试用' +
                                // '&00N10000003Msk5=试用(无询价)' +
                                // '&00N100000098amW={!OPDPlan__c.NoOpp_Reason__c}';
                                const 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.opdOCMcategoryName,
                                    Hospital__c:result.opdHospitalName,
                                    OPDPlan__c:opdName,
                                    Person_In_Charge__c:res.lastName + res.firstName,
                                    applyUser__c:res.lastName + res.firstName,
                                    Loaner_received_staff__c:res.lastName + res.firstName,
                                    IsJump__c:result.opdIsJump,
                                    JumpCause__c:result.opdJumpCause,
                                    Name:'*',
                                    Approved_State_Create__c:result.ApprovedStatus,
                                    ApprovedNo_Create__c:result.opdApprovedNo
                                });
                                this.navigateEvents(defaultValues);
                            }
                
                            // var urlStr = '&CF00N10000003Mp2R={!HTMLENCODE(OPDPlan__c.Account_Laboratory__c)}' +
                            // '&CF00N10000003O3V6={!HTMLENCODE(OPDPlan__c.OCM_category_Name__c)}' +
                            // '&CF00N10000003Mp1d={!HTMLENCODE(OPDPlan__c.HospitalName__c)}' +
                            // '&CF00N10000008ps61={!HTMLENCODE(OPDPlan__c.Name)}' +
 
                            // '&CF00N10000005HzRr={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                            // '&CF00N10000005HzRz={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                            // '&00N10000003OJzc={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                            // '&00N100000098dmS={!OPDPlan__c.IsJump__c}' +
                            // '&00N100000098dmI={!HTMLENCODE(OPDPlan__c.JumpCause__c)}' +
                            // '&Name=*'+
                            // '&00N10000009HBWg= {!OPDPlan__c.Approved_Status__c} ' +
                            // '&00N10000009HBXK= {!OPDPlan__c.Approved_No__c} '; //// 20220211 sx add 备品借出申请-决裁控制 No.2
                            // window.open('/a0t/e?retURL=%2F{!OPDPlan__c.Id}' + purposeStr + urlStr );
                            
                        } else {
                            const defaultValues = encodeDefaultFieldValues({
                                // OPDPlan__c:this.recordId,
                                Cancel_Reason__c:'',
                                Loaner_cancel_reason__c:'',
                                Loaner_cancel_request__c:'',
                                Request_demo_time__c:'',
 
                                Request_approval_time__c:'',
                                Application_accept_time__c:'',
                                Response__c:'',
                                Status__c:'草案中',
                                Zsq_Rental_Apply__c:result.opdRentalApplyName,
                                OPDPlan__c:result.opdName,
                                Assign_Person__c:'',
                                Old_Rental_Apply__c:'',
                                Split_Apply_Reason__c:''
                            });
                            this.navigateEvents(defaultValues);
 
                            // var url = "/{!OPDPlan__c.originalOpdRentalApply__c}/e?newclone=1&retURL=%2F{!OPDPlan__c.originalOpdRentalApply__c}&common.udd.actions.ActionsUtilORIG_URI=%2F{!OPDPlan__c.RentalApplyId__c}%2Fe&cloneli=1&00N10000007MNF8=&00N100000098uKJ=&00N10000004oFTC=&00N10000003O1JF=&00N10000003O1JK=&00N10000006pvpZ=&00N10000003O1JU=&00N10000006gY9x=&00N10000003Mp2H=草案中&CF00N10000009EKKp_lkid={!OPDPlan__c.RentalApplyId__c}&CF00N10000009EKKp={!OPDPlan__c.RentalApplyName__c}&CF00N10000008ps61={!OPDPlan__c.Name}&CF00N10000008ps61_lkid={!OPDPlan__c.Id}&CF00N10000008poFM=&CF00N10000008poFM_lkid=&CF00N10000005HzRq=&CF00N10000005HzRq_lkid=&00N10000007oQKh=";
                            // window.open(url);
                        }
                    }else {
                        console.log("-------UserInfo_Owner---00000--else-------");
                        const defaultValues = encodeDefaultFieldValues({
                            // OPDPlan__c:this.recordId,
                            Cancel_Reason__c:'',
                            Loaner_cancel_reason__c:'',
                            Loaner_cancel_request__c:'',
                            Request_shipping_day__c:'',
 
                            Hope_Lonaer_date_Num__c:'',
                            Request_return_day__c:'',
                            Status__c:'草案中',
                            Zsq_Rental_Apply__c:result.opdRentalApplyName,
                            OPDPlan__c:result.opdName,
                            Assign_Person__c:'',
                            Old_Rental_Apply__c:'',
                            Split_Apply_Reason__c:''
                        });
                        console.log("-------UserInfo_Owner---00000--else-------" + defaultValues);
 
                        this.navigateEvents(defaultValues);
 
                    //     var url = "/{!OPDPlan__c.RentalApplyId__c}/e?newclone=1&retURL=%2F{!OPDPlan__c.RentalApplyId__c}&common.udd.actions.ActionsUtilORIG_URI=%2F{!OPDPlan__c.RentalApplyId__c}%2Fe&cloneli=1&00N10000007MNF8=&00N100000098uKJ=&00N10000004oFTC=&00N10000003Ntz7=&00N10000008rG1M=&00N10000005HzRw=&00N10000003Mp2H=草案中&CF00N10000009EKKp_lkid={!OPDPlan__c.RentalApplyId__c}&CF00N10000009EKKp={!OPDPlan__c.RentalApplyName__c}&CF00N10000008ps61={!OPDPlan__c.Name}&CF00N10000008ps61_lkid={!OPDPlan__c.Id}&CF00N10000008poFM=&CF00N10000008poFM_lkid=&CF00N10000005HzRq=&CF00N10000005HzRq_lkid=&00N10000007oQKh=";
                    //     window.open(url);
                    }
                    
                })
                this.dispatchEvent(new CloseActionScreenEvent());
                // window.location.reload();
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        });   
    }
 
    showToast(message, type) {
        const evt = new ShowToastEvent({
            title: 'Error',
            message: message,
            variant: type
        });
        this.dispatchEvent(evt);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
 
    navigateEvents(defaultValues){
        console.log("--------navigateEvents------",defaultValues)
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Rental_Apply__c',
                actionName: 'new'
            },
            state:{
                defaultFieldValues: defaultValues
 
            }
        })
    }
}