binxie
2024-01-18 b1d36ea3e6653e59bd767aa192c688ee0d9d4c58
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
import { LightningElement,api, track, wire } from 'lwc';
 
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import customJSFile from '@salesforce/resourceUrl/CommonUtilJs';
import { loadScript } from 'lightning/platformResourceLoader';
 
import init from '@salesforce/apex/LexContractAuthorizeController.init';
import getProfileId from '@salesforce/apex/LexContractAuthorizeController.getProfileId';
import judgeIsAssistantAppliedOutTime from '@salesforce/apex/LexContractAuthorizeController.judgeIsAssistantAppliedOutTime';
import searchOpportunity from '@salesforce/apex/LexContractAuthorizeController.searchOpportunity';
import checkDangerItem from '@salesforce/apex/LexContractAuthorizeController.checkDangerItem';
import oppCheck from '@salesforce/apex/LexContractAuthorizeController.oppCheck';
import updReg from '@salesforce/apex/LexContractAuthorizeController.updReg';
import updateOppotunity from '@salesforce/apex/LexContractAuthorizeController.updateOppotunity';
import queryProfileId from '@salesforce/apex/LexContractAuthorizeController.queryProfileId';
import accSendEmail from '@salesforce/apex/LexContractAuthorizeController.accSendEmail';
 
import TradeComplianceStatusFlag from '@salesforce/label/c.TradeComplianceStatusFlag';
import IFTradeComplianceAlert from '@salesforce/label/c.IFTradeComplianceAlert';
 
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class lexContractAuthorize extends LightningElement {
 
 
    @api recordId;
    @track
    TradeComplianceStatusFlag = TradeComplianceStatusFlag;
    @track
    IFTradeComplianceAlert = IFTradeComplianceAlert;
    IsLoading=true;
    data;
    IsReload=true;
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        console.log("进入页面");
        console.log(currentPageReference);
        if(currentPageReference){
            const urvalue=currentPageReference.state.recordId;
            if(urvalue){
                let str=`${urvalue}`;
                console.log('str');
                console.log(str);
                this.recordId=str;
            }
        }
    }
 
 
 
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        console.log(this.recordId);
        init({recordId:this.recordId}).then(result=>{
            console.log(result);
            if(result!=null){
                this.data=result;
                this.cancelSubmit().then(res=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });    
            }
        }).catch(err=>{
            console.log("error:");
            console.log(err.message);
        }).finally(()=>{
 
        });
    }
 
 
 
    async cancelSubmit(){
 
        let oppid = this.data.Id;
        let decide_quote = this.data.Estimation_Decision__c;
        let complete_day = this.data.Contract_DB_complite_day__c;
        let if_contract_auth = this.data.Contract_Authorize__c;
        let if_contract_lock = this.data.Contract_Authorize_Lock__c;
        let If_Need_Authorize = this.data.If_Need_Authorize__c;
        let Authorized_DB_No =this.data.Authorized_DB_No__c;
        let profileId = await getProfileId({});
        let spoURL = this.data.SPO_URL__c;
        //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start
        let DecidedQuoteNo = this.data.Estimation_No__c;
        //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end
        //2022-03-22 yjk SWAG-CCL6R7
        let Closing_Bid_Date = this.data.Closing_Bid_Date__c;//13.中标日
        let Closing_Bid_Date_Bid = this.data.Closing_Bid_Date_Bid__c;
        var AccDealerBlacklist = this.data.AccDealerBlacklist__c;//判断客户/经销商是否为黑名单
        var angency1 = this.data.Agency1__c;
        var angency2 = this.data.Agency2__c;
        var accname = this.data.Hospital__c;
        var ownerids = this.data.OwnerId;
        var ddid = this.data.Sales_assistant_name_text__c;
        let res=await queryProfileId();
 
        if (!res) {
            const event = new ShowToastEvent({
                title: '',
                message:"您没有合同申请的权限。请联系系统管理员。",
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);    
            return;
        }
        //贸易合规 you
        var TradeComplianceStatusFlag = this.TradeComplianceStatusFlag;//贸易合规开关
        var IFTradeComplianceAlert= this.IFTradeComplianceAlert;//贸易合规提醒
        if(TradeComplianceStatusFlag=='true'){
        //拦截+邮件提醒
        var oppflag=false;
        if (AccDealerBlacklist=='123') {
            this.showToast('客户,经销商1,经销商2都为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }else if(AccDealerBlacklist=='12'){
            this.showToast('客户,经销商1都为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }else if(AccDealerBlacklist=='23'){
            this.showToast('经销商1,经销商2都为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }else if(AccDealerBlacklist=='13'){
            this.showToast('客户,经销商2都为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }else if(AccDealerBlacklist=='1'){
            this.showToast('客户为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }else if(AccDealerBlacklist=='2'){
            this.showToast('经销商1为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }else if(AccDealerBlacklist=='3'){
            this.showToast('经销商2为黑名单,不能做合同申请,'+IFTradeComplianceAlert,'error');
            oppflag=true;
        }
        if(oppflag){
            let res = await accSendEmail({AccDealerBlacklist:AccDealerBlacklist,accname:accname,angency1:angency1,angency2:angency2,ownerids:ownerids,ddid:ddid,oppid:oppid});
            if (res == true) {
                return;
            }
        }
        //警示提醒
        if (AccDealerBlacklist=='567') {
            let result = await LightningConfirm.open({
                message: '您所选择的客户,经销商1,经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }else if(AccDealerBlacklist=='56'){
            let result = await LightningConfirm.open({
                message: '您所选择的客户,经销商1存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }else if(AccDealerBlacklist=='67'){
            let result = await LightningConfirm.open({
                message: '您所选择的经销商1,经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }else if(AccDealerBlacklist=='57'){
            let result = await LightningConfirm.open({
                message: '您所选择的客户,经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }else if(AccDealerBlacklist=='5'){
            let result = await LightningConfirm.open({
                message: '您所选择的客户存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }else if(AccDealerBlacklist=='6'){
            let result = await LightningConfirm.open({
                message: '您所选择的经销商1存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }else if(AccDealerBlacklist=='7'){
            let result = await LightningConfirm.open({
                message: '您所选择的经销商2存在贸易合规警示风险,不建议做合同申请,请您确认是否继续申请,'+IFTradeComplianceAlert,
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
        }
        }
        //贸易合规 you
 
        if(!Closing_Bid_Date){
            const event = new ShowToastEvent({
                title: '',
                message:"请填写13.中标日。",
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
 
        if (decide_quote != '1') {
            const event = new ShowToastEvent({
                title: '',
                message:'请先决定报价。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
        
        //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy start
        if (DecidedQuoteNo !="") {
            let judg=await judgeIsAssistantAppliedOutTime({Quoteid:DecidedQuoteNo});
        // alert('judg得值:'+judg);
        // return;
            if(judg == 'false'){
                const event = new ShowToastEvent({
                    title: '',
                    message:'经销商协议已过期,请重新做报价计算。',
                    variant: 'error',
                    mode: 'sticky'
                });
                this.dispatchEvent(event);
                return;
            }
        }
        //SWAG-CG88AG【委托】提出价格申请是在协议有效期内,允许WIN fy end
        // 20221009 ljh SWAG-CK29AJ start
        let ClosingBidDate =this.data.Closing_Bid_Date__c;
        let BidDate = this.data.Bid_Date__c;
        if( ClosingBidDate < BidDate){
            const event = new ShowToastEvent({
                title: '',
                message:'13.中标日不能早于12.招标日',
                variant: 'error',
                mode: 'sticky'
            });
            this.showToast()
            this.dispatchEvent(event);
            return;
        }
        // 20221009 ljh SWAG-CK29AJ end
 
        if(If_Need_Authorize == '1' && (Authorized_DB_No == null || Authorized_DB_No == '')){
            const event = new ShowToastEvent({
                title: '',
                message:'请先做授权申请。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
 
        if (this.data.Cnt_Lost_cancel_Draft__c > 0) {
            //chenjingwu 20231107 Start
            let result = await LightningConfirm.open({
                message: '询价有草案中的取消/失单报告,是否继续?',
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            });
            if (result==false) {
                return;
            }
            //chenjingwu 20231107 End
            // if(!confirm('询价有草案中的取消/失单报告,是否继续?')){
            //     return ;
            // }
        } else if (this.data.Cnt_Lost_cancel_report__c - this.data.Cnt_Lost_cancel_Draft__c > 0) {
            const event = new ShowToastEvent({
                title: '',
                message:'询价有已提交的取消/失单报告。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
 
        console.log("11");
 
        // 2022-03-31 新财年价格调整 start
        let decide_date = this.data.DecideQuoteDate__c;
        let before = new Date("2022-4-1");
        if (decide_date != null && decide_date < before) {
            const event = new ShowToastEvent({
                title: '',
                message:'报价变更,请重新做Decide。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
        // 2022-03-31 新财年价格调整 end
        let sqlResult = await searchOpportunity({oppid:oppid});
        let records = sqlResult;
        console.log(records);
        if ((complete_day != null && complete_day != '') && records.Contract_Authorize_Lock__c== 'true') {
            const event = new ShowToastEvent({
                title: '',
                message:'合同申请已经完成,请不要重复提交。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }
        // if ('{!Opportunity.AcecideCntCheck__c}' != '1') {
        // alert('阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。');
        // return;
        // }
        console.log("111");
        if ((complete_day == null || complete_day == '') && records.Contract_Authorize_Lock__c== 'true') {
            const event = new ShowToastEvent({
                title: '',
                message:'合同正在申请中,请不要重复提交。',
                variant: 'error',
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            return;
        }    
 
        if (this.data.IF_Submit__c  == '1') {
            // const event = new ShowToastEvent({
      //           title: '提示信息',
      //           message:'上传失败,请联系系统管理员!'
      //       });
      //       this.dispatchEvent(event);
              this.showToast('上传失败,请联系系统管理员!','error');
            return;
        }
        let angency = this.data.Agency1__c;
        if(this.data.Trade__c == '外貿' || this.data.Sales_Root__c == 'OCM直接販売'){
            let rtn = await updReg({oppid:oppid});
        } else {
            if(this.data.Is_Corrosion__c == '1'){
                let rtn1 = await checkDangerItem({agency1:angency});
                if (rtn1 != 'OK') {
                    const event = new ShowToastEvent({
                        title: '',
                        message:rtn1,
                        variant: 'error',
                        mode: 'sticky'
                    });
                    this.dispatchEvent(event);
                    return;
                }
            }else{
                let rtn =  await oppCheck({oppid:oppid, saveFlg:'1'});
                if (rtn != 'OK') {
                    const event = new ShowToastEvent({
                        title: '',
                        message:rtn,
                        variant: 'error',
                        mode: 'sticky'
                    });
                    this.dispatchEvent(event);
                    return;
                }
            }
        }
 
        let flag=false;
        await updateOppotunity({recordId:this.recordId}).then(res=>{
            console.log(res);
            if(res!=null&&res.success==false){
                let messages ="";
                flag=true;
                messages=res.errors[0];
                const event = new ShowToastEvent({
                    title: '',
                    message:""+messages,
                    variant: 'error',
                    mode: 'sticky'
                });        
                this.dispatchEvent(event);
                return;
            }
        });
        if(flag)return;
        const event = new ShowToastEvent({
            title: '',
            message:'提交成功!请在SPO系统中完成合同申请。',
            variant: 'success'
        });
        this.dispatchEvent(event);
        //window.location.reload();
        window.open(spoURL);
    }
 
 
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.IsReload=false;
            this.dispatchEvent(event);
        }
        // this.dispatchEvent(new CloseActionScreenEvent());
    }
}