高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
import { LightningElement,wire,track,api} from 'lwc';
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;
 
    connectedCallback(){
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            console.log(result);
            if (result != null) {
                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;
            }
        }).catch(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('已决定报价,不能修改内贸/外贸');
            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(() => {
                
            });
        }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(){
 
    }
 
}