buli
2023-05-04 d4a4ce824f3b2f3a335a3ad8e8c9efb3b37d630f
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { NavigationMixin } from 'lightning/navigation';
import  init  from '@salesforce/apex/OtherButtonOppCtl.init';
import  changeTrade  from '@salesforce/apex/OpportunityWebService.changeTrade';
import  selectAgencyHospital  from '@salesforce/apex/OtherButtonOppCtl.selectAgencyHospital';
import  selectRecordType  from '@salesforce/apex/OtherButtonOppCtl.selectRecordType';
import  selectFieldDefinition  from '@salesforce/apex/OtherButtonOppCtl.selectFieldDefinition';
 
 
 
export default class reportInOpportunity extends LightningElement {
    @api recordId;//OpportunityId
    currencyIsoCode;
    str;
    status;
    quostatus;
    win;
    Auth;
    agency1Id;
    agencyOpportunity;
    trade;
    oppName;
    opp;
    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.currencyIsoCode = result.currencyIsoCode;
                this.status = result.stageName;
                this.quostatus = result.estimationDecision;
                this.win = result.SAPSendOK;
                this.Auth = result.IfAuthorizingLock;
                this.agency1Id = result.agency1Id;
                this.agencyOpportunity = result.agencyOpportunity;
                this.trade = result.trade;
                this.oppName = result.oppName;
                this.opp = result.opp;
 
                this.changeContractType();
                this.dispatchEvent(new CloseActionScreenEvent());
                // window.location.reload();
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        }).finally(() => {
            
        });        
    }
 
     navigateReportDetail(){
        /*this[NavigationMixin.Navigate]({
            type:'standard__recordPage',
            attributes:{
                recordId:"00O10000002jviu",
                objectApiName:'Report',
                actionName:'view'
            }
        });*/
        var Currency = this.currencyIsoCode;
        var OppID = this.recordId;
 
 
        if (Currency == 'CNY'){
        var url = '/00O10000002jviu?pv0=' + OppID;
        }
        else if (Currency == 'USD'){
        var url = '/00O10000005Ju6L?pv0=' + OppID;
        }
 
        window.open(url);
 
    }
    changeContractType(){
        if(this.status != '引合'){
            alert('只有状态1是询价的可以更改合同类型');
            return null;
        }
        if(this.Auth == '1'){
            alert('询价正在授权申请中,请在SPO中驳回后再做转换。');
            return null;
        }
        if(this.quostatus == 'true' || this.quostatus == true){
            alert('已决定报价,不能修改内贸/外贸');
             // window.location.reload();
            return null;
        }
        if(this.win == 'true' || this.win == true){
            alert('请先取消WIN, 再转换内外贸');
            return null;
        }
        if(confirm('变更合同类型会删除全部报价,是否继续?')){
            changeTrade({
                oppId: this.recordId
            }).then(result => {
                console.log(result);
                this.str = result;
                if(this.str != '1'){
                    alert(this.str);
                }
                window.location.reload();
            }).catch(error => {
                console.log("error");
            }).finally(() => {
                // $A.get("e.force:closeQuickAction").fire();
            });
        }else{
            return null;
        }
    }
    sharedToDealers(){
        /*if (document.getElementsByName('newopportunity_agency')[0].className == 'btn') {
            console.log("sharedToDealers");
 
            var bottons = document.getElementsByName('newopportunity_agency');
            for (var i=0;i<bottons.length;i++){
                bottons[i].className += "btnDisabled";
                bottons[i].disabled = true;
            }*/
 
            var newflag = true;
            var records;
            if (this.agency1Id == '' || this.agency1Id == null) {
                newflag = false;
                alert("经销商不存在,不能转成【经销商目标询价】。");
            //this.agencyOpportunity != '' 
            }else if (this.agencyOpportunity != null) {
                newflag = false;
                alert("已经转成过【经销商目标询价】。");
            }else if (this.trade != '内貿') {
                newflag = false;
                alert("不是内贸,不能转成【经销商目标询价】。");
            }else {
                selectAgencyHospital({
                    recordId: this.recordId
                }).then(result => {
                    console.log(result);
                    records = result;
                    if (records == null || records.length == 0) {
                        newflag = false;
                        alert("没有有效的【经销商医院】。");
                    }
                }).catch(error => {
                    console.log("error11");
                }).finally(() => {
                    
                });
                /*var resultSet = sforce.connection.query("SELECT Id, Name FROM Agency_Hospital_Link__c WHERE Agency__c = '{!Opportunity.Agency1Id__c}' AND Hospital__c = '{!Opportunity.HospitalId__c}'");
                var records = resultSet.getArray("records");
                if (records == null || records.length == 0) {
                    newflag = false;
                    alert("没有有效的【经销商医院】。");
                }*/
            }
 
            if (newflag) {
                selectRecordType({
                }).then(result => {
                    console.log(result);
                    //var query = "SELECT Id, Name FROM RecordType WHERE SobjectType='Agency_Opportunity__c' And developerName='Opportunity' And IsActive = TRUE";
                    var recTypeList = result;
                    if (recTypeList.length == 0) {
                        alert("没有找到,经销商询价的定义。");
                    } else {
                        var recTypeId = recTypeList[0].Id;
                        var prefix, fId_Close_Forecasted_Date__c, fId_Agency_Hospital__c
                            , fId_OCM_Change_To_Opportunity_Flg__c, fId_Amount__c
                            , fId_OCMSale_Price__c, fId_Agency__c
                            , fId_StageName__c, fId_Change_To_Opportunity__c
                            , fId_Department_Cateogy__c, fId_Bid_Planned_Date__c;
                        selectFieldDefinition({
                        }).then(res => {
                            console.log(res);
                            var records2 = res;
                            for (var i=0; i< records2.length; i++) {
                                var record = records2[i];
                                prefix = record.EntityDefinition.KeyPrefix.toString();
                                if (record.QualifiedApiName == 'Close_Forecasted_Date__c') {
                                    fId_Close_Forecasted_Date__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'OCM_Change_To_Opportunity_Flg__c') {
                                    fId_OCM_Change_To_Opportunity_Flg__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'Agency_Hospital__c') {
                                    fId_Agency_Hospital__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'Amount__c') {
                                    fId_Amount__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'OCMSale_Price__c') {
                                    fId_OCMSale_Price__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'Agency__c') {
                                    fId_Agency__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'StageName__c') {
                                    fId_StageName__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'Change_To_Opportunity__c') {
                                    fId_Change_To_Opportunity__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'Department_Cateogy__c') {
                                    fId_Department_Cateogy__c = record.DurableId.toString().split('.')[1];
                                }
                                if (record.QualifiedApiName == 'Bid_Planned_Date__c') {
                                    fId_Bid_Planned_Date__c = record.DurableId.toString().split('.')[1];
                                }
                            }
                        }).catch(error => {
                            console.log("error22");
                        }).finally(() => {
                            var ahl = records[0];
 
                            console.log("222");
                            console.log(this.opp);
                            console.log(this.opp.Bid_Planned_Date__c);
                            console.log(this.recordId);
                            /*window.open("/a2Y/e?retURL=%2F{!URLENCODE(Opportunity.Id)}&Name={!URLENCODE('(OLYMPUS)'+Opportunity.Name)}&RecordType=" + recTypeId +
                            "&"+fId_Close_Forecasted_Date__c+"={!Opportunity.Close_Forecasted_Date__c}" +
                            "&"+fId_Bid_Planned_Date__c+"={!Opportunity.Bid_Planned_Date__c}"+
                            "&"+fId_OCM_Change_To_Opportunity_Flg__c+"=1" +
                            "&CF"+fId_Agency_Hospital__c+"_lkid=" + ahl.Id +
                            "&CF"+fId_Agency_Hospital__c+"=" + encodeURIComponent(ahl.Name) +
                            "&"+fId_Amount__c+"=" + '{!Opportunity.Dealer_Final_Price__c}'.substr(4) +
                            "&"+fId_OCMSale_Price__c+"=" + '{!Opportunity.Wholesale_Price__c}'.substr(4) +
                            "&CF"+fId_Agency__c+"_lkid={!URLENCODE(Opportunity.Agency1Id__c)}" +
                            "&CF"+fId_Agency__c+"={!URLENCODE(Opportunity.Agency1__c)}" +
                            "&"+fId_StageName__c+"={!URLENCODE(text(Opportunity.Opportunity_stage__c))}" +
                            "&CF"+fId_Change_To_Opportunity__c+"_lkid={!Opportunity.Id}" +
                            "&CF"+fId_Change_To_Opportunity__c+"={!URLENCODE(Opportunity.Name)}" +
                            "&"+fId_Department_Cateogy__c+"={!URLENCODE(text(Opportunity.Opportunity_Category__c))}");*/
                            let url = "/a2Y/e?retURL=%2F{!URLENCODE(" + this.recordId + ")}&Name={!URLENCODE('(OLYMPUS)'+" + this.opp.Name + ")}&RecordType=" + recTypeId;
                            url +=
                            // "&"+fId_Close_Forecasted_Date__c+ "=" + this.opp.Close_Forecasted_Date__c +
                            this.opp.Close_Forecasted_Date__c == null ? "" : "&"+fId_Close_Forecasted_Date__c+ "=" + this.opp.Close_Forecasted_Date__c;
                            url +=
                            // "&"+fId_Bid_Planned_Date__c+"=" + this.opp.Bid_Planned_Date__c  +
                            this.opp.Bid_Planned_Date__c == null ? "" : "&"+fId_Bid_Planned_Date__c+"=" + this.opp.Bid_Planned_Date__c;
                            url +=
                            "&"+fId_OCM_Change_To_Opportunity_Flg__c+"=1" +
                            "&CF"+fId_Agency_Hospital__c+"_lkid=" + ahl.Id +
                            "&CF"+fId_Agency_Hospital__c+"=" + encodeURIComponent(ahl.Name);
                            url +=
                            // "&"+fId_OCMSale_Price__c+"=" + this.opp.Wholesale_Price__c.substr(4) +
                            this.opp.Wholesale_Price__c == null ? "" : "&"+fId_OCMSale_Price__c+"=" + this.opp.Wholesale_Price__c.substr(4);
                            url +=
                            "&CF"+fId_Agency__c+"_lkid={!URLENCODE("+ this.opp.Agency1_ID_18__c+")}" +
                            "&CF"+fId_Agency__c+"={!URLENCODE("+this.opp.Agency1__c+")}" ;
                            url +=
                            // "&"+fId_StageName__c+"={!URLENCODE(text("+ this.opp.Opportunity_stage__c+"))}" +
                            this.opp.Opportunity_stage__c == null ? "" : "&"+fId_StageName__c+"={!URLENCODE(text("+ this.opp.Opportunity_stage__c+"))}" ;
                            url +=
                            "&CF"+fId_Change_To_Opportunity__c+"_lkid="+ this.recordId +
                            "&CF"+fId_Change_To_Opportunity__c+"={!URLENCODE("+ this.opp.Name+")}";
                            url +=
                            // "&"+fId_Department_Cateogy__c+"={!URLENCODE(text("+ this.opp.Opportunity_Category__c+
                            this.opp.Opportunity_Category__c == null ? "" :"&"+fId_Department_Cateogy__c+"={!URLENCODE(text("+ this.opp.Opportunity_Category__c+
                            "))}";
                            console.log(url);
                            window.open(url);
                           /* window.open("/a2Y/e?retURL=%2F{!URLENCODE(" + this.recordId + ")}&Name={!URLENCODE('(OLYMPUS)'+" + this.opp.Name + ")}&RecordType=" + recTypeId +
                            "&"+fId_Close_Forecasted_Date__c+ "=" + this.opp.Close_Forecasted_Date__c +
                            "&"+fId_Bid_Planned_Date__c+"=" + this.opp.Bid_Planned_Date__c +
                            "&"+fId_OCM_Change_To_Opportunity_Flg__c+"=1" +
                            "&CF"+fId_Agency_Hospital__c+"_lkid=" + ahl.Id +
                            "&CF"+fId_Agency_Hospital__c+"=" + encodeURIComponent(ahl.Name) +
                            "&"+fId_OCMSale_Price__c+"=" + this.opp.Wholesale_Price__c.substr(4) +
                            "&CF"+fId_Agency__c+"_lkid={!URLENCODE("+ this.opp.Agency1_ID_18__c+")}" +
                            "&CF"+fId_Agency__c+"={!URLENCODE("+this.opp.Agency1__c+")}" +
                            "&"+fId_StageName__c+"={!URLENCODE(text("+ this.opp.Opportunity_stage__c+"))}" +
                            "&CF"+fId_Change_To_Opportunity__c+"_lkid="+ this.recordId +
                            "&CF"+fId_Change_To_Opportunity__c+"={!URLENCODE("+ this.opp.Name+")}" +
                            "&"+fId_Department_Cateogy__c+"={!URLENCODE(text("+ this.opp.Opportunity_Category__c+"))}");*/
                        });
                    }
                
                }).catch(error => {
                    console.log("error");
                }).finally(() => {
                    
                });
                
            }
        // ==}
    }
    authorisationRequest(){
        var btns = document.getElementsByName("agency_authorize");
        /*for (var i=0; i<btns.length; i++) {
        btns[i].disabled = true;
        btns[i].className = 'btnDisabled';
        }
        {!RequireScript("/soap/ajax/51.0/connection.js")}
        {!RequireScript("/soap/ajax/51.0/apex.js")}
        {!RequireScript("/resource/CommonUtilJs")}
        //2021-10-21 gwy 版本更改为51.0
        var foo = function() {
        var oppid = '{!Opportunity.Id}';
        var angency = '{!Opportunity.Agency1Id__c}';
        var profileId = '{!$User.ProfileId}';
 
        if (profileId != '00e10000000Y3o5' && profileId != '00e10000000Nab7' && profileId != '00e10000000xnpR' && profileId != '00e10000000xyK6' && profileId != '00e10000000NbCE'
        && profileId != '00e10000000xyK6' && profileId != '00e10000000Nb7i') {
        alert("您没有授权申请的权限。请联系系统管理员。");
        return;
        }
 
        if ('{!Opportunity.StageName}' != '引合' && '{!Opportunity.StageName}' != '询价' ) {
        alert("状态1:" + '{!Opportunity.StageName}' + "、不能做授权申请!");
        return;
 
        } else if ('{!Opportunity.SAP_Send_OK__c}' == '1') {
        alert("已经上传SAP、不能做授权申请了!");
        return;
 
        } else if ('{!Opportunity.Opp_order_Type__c}' != '' && '{!Opportunity.If_Have_170__c}' == true) {
        alert("耗材不可与170产品同时存在!");
        return;
        } else if ('{!Opportunity.Opp_order_Type__c}' != '' && '{!Opportunity.If_Have_AH__c}' == true) {
        alert("耗材不可与奥辉产品同时存在!");
        return;
        } else if ('{!Opportunity.Cnt_Lost_cancel_Draft__c}' > 0) {
        if(!confirm('询价有草案中的取消/失单报告,是否继续?')){
        return ;
        }
        } else if ('{!Opportunity.Cnt_Lost_cancel_report__c}' - '{!Opportunity.Cnt_Lost_cancel_Draft__c}' > 0) {
        alert('询价有已提交的取消/失单报告。');
        return;
        } else if ('{!Opportunity.Estimation_Id__c}' == '' || '{!Opportunity.DetailNum__c}' == 0) {
        alert('报价未完成,请先报价。');
        return;
 
        } else if ('{!Opportunity.Estimation_Decision__c}' == '1') {
        alert('报价已决定,不能进行授权申请。');
        return;
 
        } else if ('{!Opportunity.Sales_Root__c}' != '販売店') {
        alert('医院直销不需要授权申请。');
        return;
 
        }
        // else if ('{!Opportunity.AcecideCntCheck__c}' != '1') {
        // alert('阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。');
        // return;
 
        // }
        else if ('{!Opportunity.IF_Submit__c }' == '1') {
        alert('上传失败,请联系系统管理员!');
        return;
        }
 
        var sql = "select Id,If_Authorizing_Lock__c from Opportunity where Id ='" + oppid + "'";
        var sqlResult = sforce.connection.query(sql);
        var records = sqlResult.getArray("records");
        if (records[0].If_Authorizing_Lock__c == 'true') {
        alert('询价正在授权中,请不要重复提交。');
        return;
        }
        if ('{!Opportunity.Trade__c}' == '内貿') {
        if('{!Opportunity.Is_Corrosion__c}' == '1'){
 
        var rtn1 = sforce.apex.execute("OpportunityWebService", "checkDangerItem",{agency1:angency });
        if (rtn1 != 'OK') {
        alert(rtn1);
        return;
        }
        }else{
        var rtn = sforce.apex.execute("OpportunityWebService", "oppCheck",{"oppid":oppid,"saveFlg":'1'});
        if (rtn != 'OK') {
        alert(rtn);
        return;
        }
        }
 
        } else {
        var rtn = sforce.apex.execute("OpportunityWebService", "updReg",{oppid:oppid});
        }
 
 
        var opp = new sforce.SObject('Opportunity');
        opp.Id = '{!Opportunity.Id}';
        opp.If_Authorizing__c = '1';
        opp.if_Interface_Lock__c = '1';
        opp.IF_Submit__c = '1';
        var result = sforce.connection.update([opp]);
        var messages = getConnectDMLErrorMessages(result);
        if (messages.length > 0) {
        alert(messages.join("\n"));
        return;
        }
        alert('提交成功。请在SPO系统中完成授权申请。');
        //window.location.reload();
 
        window.open("https://olympus.sharepoint.cn/sites/GSPWF/SitePages/HomePage.aspx");
 
        };
        foo();*/
        
    }
    contractApply(){
 
       /* var btns = document.getElementsByName("contract_authorize");
for (var i=0; i<btns.length; i++) {
btns[i].disabled = true;
btns[i].className = 'btnDisabled';
}
 
{!REQUIRESCRIPT("/soap/ajax/51.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/51.0/apex.js")};
{!RequireScript("/resource/CommonUtilJs")};
//2021-10-21 gwy 版本更改为51.0
 
 
var foo = function() {
    var oppid = '{!Opportunity.Id}';
    var decide_quote = '{!Opportunity.Estimation_Decision__c}';
    var complete_day = '{!Opportunity.Contract_DB_complite_day__c}';
    var if_contract_auth = '{!Opportunity.Contract_Authorize__c}';
    var if_contract_lock = '{!Opportunity.Contract_Authorize_Lock__c}';
    var If_Need_Authorize = '{!Opportunity.If_Need_Authorize__c}';
    var Authorized_DB_No = '{!Opportunity.Authorized_DB_No__c}';
    var profileId = '{!$User.ProfileId}';
    var spoURL = '{!Opportunity.SPO_URL__c}';
    //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start
    var DecidedQuoteNo = '{!Opportunity.Estimation_No__c}';
    //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end
    //2022-03-22 yjk SWAG-CCL6R7
    var Closing_Bid_Date = '{!Opportunity.Closing_Bid_Date__c}';//13.中标日
    var Closing_Bid_Date_Bid = '{!Opportunity.Closing_Bid_Date_Bid__c}';
 
    var AccDealerBlacklist = '{!Opportunity.AccDealerBlacklist__c}';//判断客户/经销商是否为黑名单
    var angency1 = '{!Opportunity.Agency1__c}';
    var angency2 = '{!Opportunity.Agency2__c}';
    var accname = '{!Opportunity.Hospital__c}';
    var ownerids = '{!Opportunity.OwnerId}';
    var ddid = '{!Opportunity.Opportunity_sub_ownerId__c}';
 
    if (profileId != '00e10000000Y3o5' && profileId != '00e10000000Nab7' &&
    profileId != '00e10000000xnpR' && profileId != '00e10000000xyK6' && profileId != '00e10000000xnpW' && profileId != '00e10000000NbCE' && profileId != '00e10000000Nb7i'
    && profileId != '00e10000000xyK6') {
    alert("您没有合同申请的权限。请联系系统管理员。");
    return;
    }
 
    //贸易合规 you
    var oppflag=false;
    if (AccDealerBlacklist=='123') {
    alert('客户,经销商1,经销商2都为黑名单,不能做授权申请!');
    oppflag=true;
 
    }else if(AccDealerBlacklist=='12'){
    alert('客户,经销商1都为黑名单,不能做授权申请!');
    oppflag=true;
    }else if(AccDealerBlacklist=='23'){
    alert('经销商1,经销商2都为黑名单,不能做授权申请!');
    oppflag=true;
    }else if(AccDealerBlacklist=='13'){
    alert('客户,经销商1都为黑名单,不能做授权申请!');
    oppflag=true;
    }else if(AccDealerBlacklist=='1'){
    alert('客户为黑名单,不能做授权申请!');
    oppflag=true;
    }else if(AccDealerBlacklist=='2'){
    alert('经销商1为黑名单,不能做授权申请!');
    oppflag=true;
    }else if(AccDealerBlacklist=='3'){
    alert('经销商2为黑名单,不能做授权申请!');
    oppflag=true;
    }
    if(oppflag){
    var opprtn = sforce.apex.execute("OpportunityWebService", "accSendEmail",{"AccDealerBlacklist":AccDealerBlacklist,"accname":accname,"angency1":angency1,"angency2":angency2,"ownerids":ownerids,"angency2":angency2,"oppid":oppid});
    if (opprtn = true) {
    return;
    }
    }
    //贸易合规 you
 
    if(!Closing_Bid_Date){
    alert("请填写13.中标日。");
    return;
    }
 
    if (decide_quote != '1') {
    alert('请先决定报价。');
    return;
    }
    //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start
    if (DecidedQuoteNo !="") {
    var judg=sforce.apex.execute("OpportunityWebService","judgeIsAssistantAppliedOutTime",{Quoteid:DecidedQuoteNo});
    // alert('judg得值:'+judg);
    // return;
    if(judg == 'false'){
    alert('经销商协议已过期,请重新做报价计算。');
    return;
    }
    }
    //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end
    // 20221009 ljh SWAG-CK29AJ start
    var ClosingBidDate = '{!Opportunity.Closing_Bid_Date__c}';
    var BidDate = '{!Opportunity.Bid_Date__c}';
    if( ClosingBidDate < BidDate){
    alert('13.中标日不能早于12.招标日');
    return;
    }
        // 20221009 ljh SWAG-CK29AJ end
    if(If_Need_Authorize == '1' && (Authorized_DB_No == null || Authorized_DB_No == '')){
    alert('请先做授权申请。');
    return;
    }
 
    if ('{!Opportunity.Cnt_Lost_cancel_Draft__c}' > 0) {
    if(!confirm('询价有草案中的取消/失单报告,是否继续?')){
    return ;
    }
    } else if ('{!Opportunity.Cnt_Lost_cancel_report__c}' - '{!Opportunity.Cnt_Lost_cancel_Draft__c}' > 0) {
    alert('询价有已提交的取消/失单报告。');
    return;
    }
 
 
 
// 2022-03-31 新财年价格调整 start
    var decide_date = '{!Opportunity.DecideQuoteDate__c}';
    if (decide_date != null && decide_date < {!DATE(2022,4,1)}) {
    alert('报价变更,请重新做Decide。');
    return;
    }
 
    // 2022-03-31 新财年价格调整 end
    var sql = "select Id,Contract_Authorize_Lock__c from Opportunity where Id ='" + oppid + "'";
    var sqlResult = sforce.connection.query(sql);
    var records = sqlResult.getArray("records");
 
    if ((complete_day != null && complete_day != '') && records[0].Contract_Authorize_Lock__c== 'true') {
    alert('合同申请已经完成,请不要重复提交。');
    return;
    }
    // if ('{!Opportunity.AcecideCntCheck__c}' != '1') {
    // alert('阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。');
    // return;
    // }
    if ((complete_day == null || complete_day == '') && records[0].Contract_Authorize_Lock__c== 'true') {
    alert('合同正在申请中,请不要重复提交。');
    return;
    }
 
    if ('{!Opportunity.IF_Submit__c }' == '1') {
    alert('上传失败,请联系系统管理员!');
    return;
    }
 
    var angency = '{!Opportunity.Agency1Id__c}';
    if('{!Opportunity.Trade__c}' == '外貿' || '{!Opportunity.Sales_Root__c}' == 'OCM直接販売'){
    var rtn = sforce.apex.execute("OpportunityWebService", "updReg",{oppid:oppid});
    } else {
    if('{!Opportunity.Is_Corrosion__c}' == '1'){
    var rtn1 = sforce.apex.execute("OpportunityWebService", "checkDangerItem",{agency1:angency });
    if (rtn1 != 'OK') {
    alert(rtn1);
    return;
    }
    }else{
    var rtn = sforce.apex.execute("OpportunityWebService", "oppCheck",{oppid:oppid, saveFlg:'1'});
 
    if (rtn != 'OK') {
    alert(rtn);
    return;
    }
    }
 
 
}
 
var opp = new sforce.SObject('Opportunity');
opp.Id = '{!Opportunity.Id}';
opp.Contract_Authorize__c = '1';
opp.if_Interface_Lock__c = '1';
opp.IF_Submit__c = '1';
var result = sforce.connection.update([opp]);
var messages = getConnectDMLErrorMessages(result);
if (messages.length > 0) {
alert(messages.join("\n"));
return;
}
alert('提交成功!请在SPO系统中完成合同申请。');
 
//window.location.reload();
window.open(spoURL);
};
foo();*/
    }
 
}