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
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
/*
 * @Date: 2023-04-06 13:41:29
 * @Author: @zyh
 * @LastEditTime: 2023-04-17 15:52:15
 * @Descripttion: 
 */
import { LightningElement,wire,track,api } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import UserInfo_Owner from '@salesforce/apex/TaskFeedbackController.UserInfo_Owner';
import init from '@salesforce/apex/OPDLwcController.initOPDCancelSubmit';
import RecordType from '@salesforce/apex/OPDLwcController.RecordType';
// import applySelect from '@salesforce/apex/OPDLwcController.applySelect';
import changeTrade from '@salesforce/apex/OpdPlanWebService.changeTrade';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
 
export default class OpdNewSparePartsLoanApplication extends LightningElement {
    @api recordId;
    Status;
    Name;
    Days;
    OPDType;
    CampaignId;
    CampaignStatus;
    CampaignTypeId;
    cp;
    StayOrNot;
    OriginalOpdPlanApplication;
    IFApproved;
    ApprovedNo;
    ApprovedStatus;
    HaveValue;
    OriginalOpdPlan;
    OpportunityId;
    accountLaboratory;
    OCMcategoryID;
    HospitalID;
    isJump;
    jumpCause;
    Id;
    userId;
    userName;
    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 => {
            console.log(result);
            if (result != null) {
                this.IsLoading = false;
                this.ownerId = result.ownerId;
                this.monthlyReportId = result.Id;
                this.Days = result.rentalApplyFlag;
                this.OPDType = result.oPDType;
                this.CampaignId = result.campaignId;
                this.CampaignStatus = result.campaignStatus;
                this.CampaignTypeId = result.campaignRecodeTypeId;
                this.cp = result.internalinchargeprovince;
                this.StayOrNot = result.stayOrNot;
                this.OriginalOpdPlanApplication = result.originalOpdPlanApplication;
                this.IFApproved = result.iFApproved;
                this.ApprovedNo = result.approvedNo;
                this.ApprovedStatus = result.approvedStatus;
                this.HaveValue = result.Rental_Apply2;
                this.OriginalOpdPlan = result.originalOpdPlan;
                this.OpportunityId = result.Related_Opportunity1_ID;
                this.accountLaboratory = result.accountLaboratory;
                this.OCMcategoryID = result.OCM_category_ID;
                this.HospitalID = result.HospitalID;
                this.isJump = result.isJump;
                this.jumpCause = result.jumpCause;
                this.newSpa();
                console.log("end");
            //  this.handleSuccess();
            //  this.dispatchEvent(new CloseActionScreenEvent());
            //  this.updateRecordView(this.recordId);
 
                //window.location.replace("https://ocsm--partial.sandbox.lightning.force.com/lightning/r/Monthly_Report__c/" + this.monthlyReportId + "/view");
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
            
        });   
    }
    newSpa(){
        UserInfo_Owner({
 
        }).then(result => {
            console.log(result);
 
        })
        if (this.StayOrNot == '已离职') {
            const evt = new ShowToastEvent({
                title : 'Error',
                message : '所有人已经离职,请联系系统管理员修改所有人。',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('所有人已经离职,请联系系统管理员修改所有人。');
            return;
        }
        if (this.IFApproved == true && this.ApprovedNo == ''){
            const evt = new ShowToastEvent({
                title : 'Error',
                message : '需要决裁时,决裁编码不能为空',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('需要决裁时,决裁编码不能为空');
            return;
        }
        var statusSting = "{!$Label.StatusProcessState}"; 
        console.log(statusSting+'=====statusSting');
        if (this.IFApproved == true && this.ApprovedNo != '' && statusSting.indexOf(this.ApprovedStatus)!= -1 && this.ApprovedStatus != '草稿' ){
            const evt = new ShowToastEvent({
                title : 'Error',
                message : '已申请决裁但决裁状态不符合条件',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('已申请决裁但决裁状态不符合条件');
            return;
        }
        if (this.HaveValue != '' && this.OPDType != '学会') {
            const evt = new ShowToastEvent({
                title : 'Error',
                message : '一个OPD计划只可关联创建一个备品申请单',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('一个OPD计划只可关联创建一个备品申请单');
            return;
        }
        if (this.Status != '计划中') {
            const evt = new ShowToastEvent({
                title : 'Error',
                message : 'OPD计划的状态不是计划中,不能新建备品借出申请',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('OPD计划的状态不是计划中,不能新建备品借出申请');
            return;
        }
        if (UserInfo_Owner.isFormal_Stuff__c == 'true') {
            const evt = new ShowToastEvent({
                title : 'Error',
                message : '试用期内,不能申请',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('试用期内,不能申请');
            return;
        }
        if (this.Status != '计划中') {
            const evt = new ShowToastEvent({
                title : 'Error',
                message : 'OPD计划的状态不是计划中,不能新建备品借出申请',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('OPD计划的状态不是计划中,不能新建备品借出申请');
            return;
        }
        if (UserInfo_Owner.isFormal_Stuff__c == 'true') {
            const evt = new ShowToastEvent({
                title : 'Error',
                message : '试用期内,不能申请',
                variant : 'error'
            });
            this.dispatchEvent(evt);
            // alert('试用期内,不能申请');
            return;
        }
        
        if (this.OPDType == '学会' && this.CampaignId != '') {
            if (this.Days < 7) {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '申请提交必须在7天(含)以上才可以',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert("申请提交必须在7天(含)以上才可以");
                return;
            }
            if (this.CampaignTypeId != '01210000000R26P' && UserInfo_Owner.Job_Category__c == '销售服务' ) {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : 'FSE不能申请该学会类型备品',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert('FSE不能申请该学会类型备品');
                return;
            } else if (('{!Text($User.Job_Category__c)}' == '销售服务' || '{!Text($User.Job_Category__c)}' == '支援') && this.CampaignTypeId == '01210000000R26P' && this.cp.indexOf(ups) == -1) {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '与FSE所在省一致,才可使用备品',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert("与FSE所在省一致,才可使用备品");
                return;
            } else if (this.CampaignStatus == '已结束') {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '已结束,不能申请',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert("已结束,不能申请");
                return;
            } else if (this.CampaignStatus == '已提交报告') {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '已提交报告,不能申请',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert("已提交报告,不能申请");
                return;
            } else if (this.CampaignStatus == '取消申请中') {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '取消申请中,不能申请',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert("取消申请中,不能申请");
                return;
            } else if (this.CampaignStatus == '取消') {
                const evt = new ShowToastEvent({
                    title : 'Error',
                    message : '已经取消,不能申请',
                    variant : 'error'
                });
                this.dispatchEvent(evt);
                // alert("已经取消,不能申请");
                return;
            }
        }
 
        if (this.OriginalOpdPlan == '') {
            // SWAG-BZL695 you 20210413 end
            if (this.OriginalOpdPlanApplication == '') {
                if (this.OPDType == '学会' && this.CampaignId != '') {
                    // var purposeStr = '&00N10000003Msk0=产品试用' +
                    // '&00N10000003Msk5=学会展会' +
                    // '&CF00N10000003Mp2q_lkid={!URLENCODE(OPDPlan__c.CampaignId__c)}' +
                    // '&CF00N10000003Mp2q={!URLENCODE(OPDPlan__c.CampaignName__c)}';
                    const defaultValues = encodeDefaultFieldValues({
                        Demo_purpose1__c: '产品试用',
                        demo_purpose2__c: '学会展会',
                        Campaign__c: this.CampaignId
                    });
                    console.log(defaultValues);
                } else if (this.OpportunityId != '') {
                    // var purposeStr = '&00N10000003Msk0=产品试用' +
                    // '&00N10000003Msk5=试用(有询价)' +
                    // '&CF00N10000003O3VB_lkid={!OPDPlan__c.Related_Opportunity1_IDId__c}' +
                    // '&CF00N10000003O3VB={!HTMLENCODE(OPDPlan__c.Related_Opportunity1_Name__c)}';
                    const defaultValues = encodeDefaultFieldValues({
                        Demo_purpose1__c: '产品试用',
                        demo_purpose2__c: '试用(有询价)',
                        Follow_UP_Opp__c: this.OpportunityId
                    });
                    console.log(defaultValues);
                } else {
                    // var purposeStr = '&00N10000003Msk0=产品试用' +
                    // '&00N10000003Msk5=试用(无询价)' +
                    // '&00N100000098amW={!OPDPlan__c.NoOpp_Reason__c}';
                    const defaultValues = encodeDefaultFieldValues({
                        Demo_purpose1__c: '产品试用',
                        demo_purpose2__c: '试用(有询价)',
                        NoOpp_Reason__c: this.noOppReason
                    });
                    console.log(defaultValues);
                }
            
                // var urlStr = '&CF00N10000003Mp2R={!HTMLENCODE(OPDPlan__c.Account_Laboratory__c)}' +
                // '&CF00N10000003Mp2R_lkid={!OPDPlan__c.Account_LaboratoryId__c}' +
                // '&CF00N10000003O3V6_lkid={!OPDPlan__c.OCM_category_ID__c}' +
                // '&CF00N10000003O3V6={!HTMLENCODE(OPDPlan__c.OCM_category_Name__c)}' +
                // '&CF00N10000003Mp1d_lkid={!OPDPlan__c.HospitalID__c}' +
                // '&CF00N10000003Mp1d={!HTMLENCODE(OPDPlan__c.HospitalName__c)}' +
                // '&CF00N10000008ps61={!HTMLENCODE(OPDPlan__c.Name)}' +
                // '&CF00N10000008ps61_lkid={!OPDPlan__c.Id}' +
                // '&CF00N10000005HzRr={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                // '&CF00N10000005HzRr_lkid={!URLENCODE($User.Id)}' +
                // '&CF00N10000005HzRz={!URLENCODE($User.LastName&' '&$User.FirstName)}' +
                // '&CF00N10000005HzRz_lkid={!URLENCODE($User.Id)}' +
                // '&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
                const defaultValues1 = encodeDefaultFieldValues({
                    Account__c: this.accountLaboratory,
                    Strategic_dept__c: this.OCMcategoryID,
                    Hospital__c : this.HospitalID,
                    OPDPlan__c : this.Id,
                    Person_In_Charge__c : $User.Id,
                    applyUser__c : $User.Id,
                    Loaner_received_staff__c : $User.Name,
                    IsJump__c : this.isJump,
                    JumpCause__c : this.jumpCause,
                    Approved_State_Create__c : this.ApprovedStatus,
                    ApprovedNo_Create__c : this.ApprovedNo
                });
                console.log(defaultValues1);
                // window.open('/a0t/e?retURL=%2F{!OPDPlan__c.Id}' + purposeStr + urlStr );
            } else {
                //SWAG-C4H67U XHL 20210726 Start
                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);
                //SWAG-C4H67U XHL 20210726 End
            }
        } else {
            // SWAG-BZL695 you 20210413 start
            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);
            // SWAG-BZL695 you 20210413 end
        }
    }
}