liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-12 14:51:44
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-11-07 11:43:00
 */
import { api, wire,LightningElement } from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import init  from '@salesforce/apex/OpportunityLightingButtonController.initForAgencyAuthorizeButton';
import updateForAgencyAuthorizeButton  from '@salesforce/apex/OpportunityLightingButtonController.updateForAgencyAuthorizeButton';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import checkDangerItem from '@salesforce/apex/OpportunityWebService.checkDangerItem';
import accSendEmail from '@salesforce/apex/OpportunityWebService.accSendEmail';
import oppCheck from '@salesforce/apex/OpportunityWebService.oppCheck';
import updReg from '@salesforce/apex/OpportunityWebService.updReg';
import TradeComplianceStatusFlag from '@salesforce/label/c.TradeComplianceStatusFlag';
import IFTradeComplianceAlert from '@salesforce/label/c.IFTradeComplianceAlert';
import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2'; //zzm 贸易合规2期 20231124 add
import lidongFengId from '@salesforce/label/c.lidongFengId'; //zzm 贸易合规2期 20240124 add
import proTradeComplianceSendEmail from '@salesforce/apex/LexContractAuthorizeController.proTradeComplianceSendEmail';//zzm 贸易合规2期 20231218 add
import LightningConfirm from 'lightning/confirm';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import queryQuote from '@salesforce/apex/OpportunityLightingButtonController.queryQuote';
 
export default class LexAgencyAuthorize extends LightningElement {
    @api recordId;
    agency1Id;
    stageName;
    sapSendOK;
    oppOrderType;
    ifHave170;
    ifHaveAH;
    cntLostCancelDraft;
    cntLostCancelReport;
    estimationId;
    detailNum;
    estimationDecision;
    salesRoot;
    acecideCntCheck;
    ifSubmit;
    trade;
    isCorrosion;
    profileId;
    ifAuthorizingLock;
    systemProfileId;
    j3ProfileId;
    s61ProfileId;
    s62ProfileId;
    m4ProfileId;
    AccDealerBlacklist;
    angency1;
    angency2;
    accname;
    ownerids;
    ddid;
 
    //zzm 贸易合规2期 20231120 add start 
    tradeComplianceStatus;
    proTradeComplianceStatus;
    latestQuoteAllPoducts;
 
    //zzm 贸易合规2期 20231120 add end 
 
    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(){
        Promise.all([
            loadStyle(this, lwcCSS)
           ]);
        init({
            recordId: this.recordId
        }).then(result=>{
            console.log(result);
            this.agency1Id = result.agency1Id;
            this.stageName = result.stageName;
            this.sapSendOK = result.sapSendOK;
            this.oppOrderType = result.oppOrderType;
            this.ifHave170 = result.ifHave170;
            this.ifHaveAH = result.ifHaveAH;
            this.cntLostCancelDraft = result.cntLostCancelDraft;
            this.cntLostCancelReport = result.cntLostCancelReport;
            this.estimationId = result.estimationId;
            this.detailNum = result.detailNum;
            this.estimationDecision = result.estimationDecision;
            this.salesRoot = result.salesRoot;
            this.acecideCntCheck = result.acecideCntCheck;
            this.ifSubmit = result.ifSubmit;
            this.trade = result.trade;
            this.isCorrosion = result.isCorrosion;
            this.profileId = result.profileId;
            this.ifAuthorizingLock = result.ifAuthorizingLock;
            this.systemProfileId = result.systemProfileId;
            this.j3ProfileId = result.j3ProfileId;
            this.s61ProfileId = result.s61ProfileId;
            this.s62ProfileId = result.s62ProfileId;
            this.m4ProfileId = result.m4ProfileId;
            this.AccDealerBlacklist = result.AccDealerBlacklist;
            this.angency1 = result.angency1;
            this.angency2 = result.angency2;
            this.accname = result.accname;
            this.ownerids = result.ownerids;
            this.ddid = result.ddid;
 
            //zzm 贸易合规2期 20231120 add start 
            this.tradeComplianceStatus = result.tradeComplianceStatus;
            this.proTradeComplianceStatus = result.proTradeComplianceStatus;
            this.latestQuoteAllPoducts = result.proTradeComplianceStatus;
            //zzm 贸易合规2期 20231120 add end 
            console.log("w");
            this.AgencyAuthorize();
        }).catch(error=>{
            console.log("error");
            console.log(error);
        });
    }
    AgencyAuthorize(){
        var btns = document.getElementsByName("agency_authorize");
        for (var i=0; i<btns.length; i++) {
        btns[i].disabled = true;
        btns[i].className = 'btnDisabled';
        }
        //2021-10-21 gwy 版本更改为51.0
        var oppid = this.recordId;
        var angency = this.agency1Id;
        var profileId = this.profileId;
        this.detailNum = 1;
        if (profileId != this.systemProfileId && profileId != this.j3ProfileId && profileId != this.s61ProfileId && profileId != this.s62ProfileId && profileId != this.m4ProfileId) {
            this.showToast("您没有授权申请的权限。请联系系统管理员。","error");
            return;
        }
        queryQuote({
            estimationId: this.estimationId
        }).then(result=>{
            console.log(result);
            if(result == true){
                this.showToast("包含虚拟产品,不能授权,请更新报价单后申请","error");
                return;
            }
             //贸易合规 you
        var AccDealerBlacklist = this.AccDealerBlacklist;//判断客户/经销商是否为黑名单
        var angency1 = this.angency1;
        var angency2 = this.angency2;
        var accname = this.accname;
        var ownerids = this.ownerids;
        var ddid = this.ddid;
        if(TradeComplianceStatusFlag=='true'){
            //拦截+邮件提醒
            var oppflag=false;
            //zzm 贸易合规2期 2024011 start
            /*if (AccDealerBlacklist=='123') {
                // alert('客户,经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户,经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
 
            }else if(AccDealerBlacklist=='12'){
                // alert('客户,经销商1都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户,经销商1都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='23'){
                // alert('经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('经销商1,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='13'){
                // alert('客户,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户,经销商2都为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='1'){
                // alert('客户为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('客户为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='2'){
                // alert('经销商1为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('经销商1为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }else if(AccDealerBlacklist=='3'){
                // alert('经销商2为黑名单,不能做授权申请,'+IFTradeComplianceAlert);
                this.showToast('经销商2为黑名单,不能做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }*/
            if (AccDealerBlacklist=='123' 
                || AccDealerBlacklist=='12'
                || AccDealerBlacklist=='23'
                || AccDealerBlacklist=='13'
                || AccDealerBlacklist=='1'
                || AccDealerBlacklist=='2'
                || AccDealerBlacklist=='3'
 
                ) {
                this.showToast('医院或经销商存在贸易合规风险,无法做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }
            if (AccDealerBlacklist=='890' 
                || AccDealerBlacklist=='89'
                || AccDealerBlacklist=='80'
                || AccDealerBlacklist=='90'
                || AccDealerBlacklist=='8'
                || AccDealerBlacklist=='9'
                || AccDealerBlacklist=='0'
 
                ) {
                this.showToast('医院或经销商可能存在贸易合规风险,目前正在评估中(一般需5-10个工作日),暂时无法做授权申请,'+IFTradeComplianceAlert,'error');
                oppflag=true;
            }
            //zzm 贸易合规2期 2024011 end
            console.log('y');
            console.log(oppflag);
            if(oppflag){
                accSendEmail({
                    "AccDealerBlacklist":AccDealerBlacklist,
                    "accname":accname,
                    "angency1":angency1,
                    "angency2":angency2,
                    "ownerids":ownerids,
                    "ddid":ddid,
                    "oppid":oppid,
                    'lidongFengId':lidongFengId
                }).then(result=>{
                    console.log('q');
                    var opprtn = result;
                    if (opprtn == true) {
                        return;
                    }
                     //zzm 贸易合规2期 20231124 add start 
                    //警示提醒
                    // if (AccDealerBlacklist=='567') {
                    //     this.handleConfirmClick('您所选择的客户,经销商1,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }else if(AccDealerBlacklist=='56'){
                    //     this.handleConfirmClick('您所选择的客户,经销商1存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }else if(AccDealerBlacklist=='67'){
                    //     this.handleConfirmClick('您所选择的经销商1,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }else if(AccDealerBlacklist=='57'){
                    //     this.handleConfirmClick('您所选择的客户,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }else if(AccDealerBlacklist=='5'){
                    //     this.handleConfirmClick('您所选择的客户存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }else if(AccDealerBlacklist=='6'){
                    //     this.handleConfirmClick('您所选择的经销商1存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }else if(AccDealerBlacklist=='7'){
                    //     this.handleConfirmClick('您所选择的经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                    // }
 
                    // if((AccDealerBlacklist=='567' 
                    // || AccDealerBlacklist=='56' 
                    // ||AccDealerBlacklist=='67'
                    // ||AccDealerBlacklist=='57' 
                    // ||AccDealerBlacklist=='5' 
                    // ||AccDealerBlacklist=='6' 
                    // ||AccDealerBlacklist=='7')&& this.proTradeComplianceStatus =='0'){
                    //     this.handleConfirmClick('您所选择的客户/经销商和最新报价里的产品,存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert2+'(一般需5-10个工作日)。');
                    // }
                    //zzm 贸易合规2期 20231120 add end 
                });
            }else{
                //zzm 贸易合规2期 20231120 add start 
                //警示提醒
                // if (AccDealerBlacklist=='567') {
                //     this.handleConfirmClick('您所选择的客户,经销商1,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }else if(AccDealerBlacklist=='56'){
                //     this.handleConfirmClick('您所选择的客户,经销商1存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }else if(AccDealerBlacklist=='67'){
                //     this.handleConfirmClick('您所选择的经销商1,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }else if(AccDealerBlacklist=='57'){
                //     this.handleConfirmClick('您所选择的客户,经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }else if(AccDealerBlacklist=='5'){
                //     this.handleConfirmClick('您所选择的客户存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }else if(AccDealerBlacklist=='6'){
                //     this.handleConfirmClick('您所选择的经销商1存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }else if(AccDealerBlacklist=='7'){
                //     this.handleConfirmClick('您所选择的经销商2存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert);
                // }
 
                
                // if((AccDealerBlacklist=='567' 
                //     || AccDealerBlacklist=='56' 
                //     ||AccDealerBlacklist=='67'
                //     ||AccDealerBlacklist=='57' 
                //     ||AccDealerBlacklist=='5' 
                //     ||AccDealerBlacklist=='6' 
                //     ||AccDealerBlacklist=='7')&& this.proTradeComplianceStatus =='0'){
                //     this.handleConfirmClick('您所选择的客户/经销商和最新报价里的产品,存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert2+'(一般需5-10个工作日)。');
                // }
                //zzm 贸易合规2期 20231120 add end 
 
                // else{
                    this.ss();
                // }
                
            }
        }else{
            this.ss();
        }
        //贸易合规 you
        });
        
 
       
    }
    ss(){
        if (this.stageName != '引合' && this.stageName != '询价' ) {
            this.showToast("状态1:" + this.stageName + "、不能做授权申请!","error");
            return;
        } else if (this.sapSendOK == '1') {
            this.showToast("已经上传SAP、不能做授权申请了!","error");
            return;
        } else if (this.oppOrderType != undefined && this.ifHave170 == true) {
            this.showToast("耗材不可与170产品同时存在!","error");
            return;
        } else if (this.oppOrderType != undefined && this.ifHaveAH == true) {
            this.showToast("耗材不可与奥辉产品同时存在!","error");
            return;
        } else if (this.cntLostCancelDraft > 0) {
            // if(!confirm('询价有草案中的取消/失单报告,是否继续?')){
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return ;
            // }   
            this.handleConfirmClick1("询价有草案中的取消/失单报告,是否继续?");  
        } else if (this.cntLostCancelReport - this.cntLostCancelDraft > 0) {
            this.showToast('询价有已提交的取消/失单报告。',"error");
            return;
        } else if (this.estimationId == undefined || this.detailNum == 0) {
            this.showToast('报价未完成,请先报价。',"error");
            return;
        } else if (this.estimationDecision == '1') {
            this.showToast('报价已决定,不能进行授权申请。',"error");
            return;
        } else if (this.salesRoot != '販売店') {
            this.showToast('医院直销不需要授权申请。',"error");
            return;
        }else if (this.ifSubmit == '1') {
            this.showToast('上传失败,请联系系统管理员!',"error");
            return;
        }else{
            this.dd();
        }
        
    }
 
    async dd(){
        if (this.ifAuthorizingLock == true) {
            this.showToast('询价正在授权中,请不要重复提交。',"error");
            return;
        }
        //zzm 贸易合规2期 20231220 add start 
        //警示提醒
 
         if(TradeComplianceStatusFlag=='true' && (this.AccDealerBlacklist=='567' 
                    || this.AccDealerBlacklist=='56' 
                    ||this.AccDealerBlacklist=='67'
                    ||this.AccDealerBlacklist=='57' 
                    ||this.AccDealerBlacklist=='5' 
                    ||this.AccDealerBlacklist=='6' 
                    ||this.AccDealerBlacklist=='7')&& this.proTradeComplianceStatus =='0'){
            let warmingEmailRes = await proTradeComplianceSendEmail({oppid:this.recordId,btnType:'授权申请'});
            if(warmingEmailRes == false || warmingEmailRes =='false') {
                return;
            }
            let result = await LightningConfirm.open({
                message: '您所选择的客户/经销商和最新报价里的产品,存在贸易合规警示风险,不建议做授权申请,请您确认是否继续申请,'+IFTradeComplianceAlert2+'(一般需5-10个工作日)。',
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
            }
        }
        //zzm 贸易合规2期 20231220 add end
 
        if (this.trade == '内貿') {
            if(this.isCorrosion == '1'){
                checkDangerItem({
                    agency1: this.agency1Id
                }).then(result=>{
                    var rtn1 = result;
                    if (rtn1 != 'OK') {
                        this.showToast(rtn1,"error");
                        return;
                    }
                    this.update();
            });
            }else{
                oppCheck({
                    oppid: this.recordId,
                    saveFlg: '1'
                }).then(result=>{
                    var rtn = result;
                    if (rtn != 'OK') {
                        this.showToast(rtn,"error");
                        return;
                    }
                    this.update();
                })
            }
        } else {
            updReg({
                oppid: this.recordId
            }).then(()=>{
                this.update();
            });
        }  
    }
    async handleConfirmClick(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.ss();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    async handleConfirmClick1(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.dd();
        } else {
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }   
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
    update(){
        updateForAgencyAuthorizeButton({
            recordId: this.recordId
        }).then(result=>{
            if(result){
                this.showToast(result,"error");
            }else{
                this.updateRecordView(this.recordId);
                window.open("https://olympus.sharepoint.cn/sites/GSPWF/SitePages/HomePage.aspx");
                this.showToast('提交成功。请在SPO系统中完成授权申请。',"success");
            }
            this.IsLoading = false;
        })
    }
}