buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
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.updateOppotunity';
 
export default class lexContractAuthorize extends LightningElement {
 
 
    @api recordId;
    IsLoading=true;
    data;
    @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(){
        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;
        let res=await queryProfileId();
        if (!res) {
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"您没有合同申请的权限。请联系系统管理员。"
            });
            this.dispatchEvent(event);    
            return;
        }
        if(!Closing_Bid_Date){
            const event = new ShowToastEvent({
                title: '提示信息',
                message:"请填写13.中标日。"
            });
            this.dispatchEvent(event);
            return;
        }
 
        if (decide_quote != '1') {
            const event = new ShowToastEvent({
                title: '提示信息',
                message:'请先决定报价。'
            });
            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:'经销商协议已过期,请重新做报价计算。'
                });
                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.招标日'
            });
            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:'请先做授权申请。'
            });
            this.dispatchEvent(event);
            return;
        }
 
        if (this.data.Cnt_Lost_cancel_Draft__c > 0) {
            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:'询价有已提交的取消/失单报告。'
            });
            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。'
            });
            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:'合同申请已经完成,请不要重复提交。'
            });
            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:'合同正在申请中,请不要重复提交。'
            });
            this.dispatchEvent(event);
            return;
        }    
 
        if (this.data.IF_Submit__c  == '1') {
            const event = new ShowToastEvent({
                title: '提示信息',
                message:'上传失败,请联系系统管理员!'
            });
            this.dispatchEvent(event);
            return;
        }
        console.log("111");
        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
                    });
                    this.dispatchEvent(event);
                    return;
                }
            }else{
                let rtn =  await oppCheck({oppid:oppid, saveFlg:'1'});
                if (rtn != 'OK') {
                    const event = new ShowToastEvent({
                        title: '提示信息',
                        message:rtn
                    });
                    this.dispatchEvent(event);
                    return;
                }
            }
        }
        console.log("222");
 
        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,
                });        
                this.dispatchEvent(event);
                return;
            }
        });
        if(flag)return;
        console.log("333");
        const event = new ShowToastEvent({
            title: '提示信息',
            message:'提交成功!请在SPO系统中完成合同申请。'
        });
        this.dispatchEvent(event);
        //window.location.reload();
        window.open(spoURL);
    }
 
 
 
 
    
}