buli
2023-07-11 0c4796706fc9473d069b620321a54b20a119906c
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
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-04-12 14:51:44
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-04-19 09:11:02
 */
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 oppCheck from '@salesforce/apex/OpportunityWebService.oppCheck';
import updReg from '@salesforce/apex/OpportunityWebService.updReg';
 
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;
    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(){
        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.AgencyAuthorize();
        })
    }
    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;
        
        if (profileId != '00e10000000Y3o5' && profileId != '00e10000000Nab7' && profileId != '00e10000000xnpR' && profileId != '00e10000000xyK6' && profileId != '00e10000000NbCE'
        && profileId != '00e10000000xyK6' && profileId != '00e10000000Nb7i') {
            this.showToast("您没有授权申请的权限。请联系系统管理员。","error");
            return;
        }
        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('询价有草案中的取消/失单报告,是否继续?')){
            return ;
        }
        } 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 ('{!Opportunity.AcecideCntCheck__c}' != '1') {
        // alert('阿西赛多询价只能包含危化品,或者,普通询价不能包含危化品。');
        // return;
        // }
        else if (this.ifSubmit == '1') {
            this.showToast('上传失败,请联系系统管理员!',"error");
            return;
        }
        if (this.ifAuthorizingLock == 'true') {
            this.showToast('询价正在授权中,请不要重复提交。',"error");
            return;
        }
        if (this.trade == '内貿') {
            if(this.isCorrosion == '1'){
                checkDangerItem({
                    agency1: angency
                }).then(result=>{
                    var rtn1 = result;
                    if (rtn1 != 'OK') {
                        this.showToast(rtn1,"error");
                        return;
                    }
                    this.update();
            });
            }else{
                oppCheck({
                    oppid: oppid,
                    saveFlg: '1'
                }).then(result=>{
                    var rtn = result;
                    if (rtn != 'OK') {
                        this.showToast(rtn,"error");
                        return;
                    }
                    this.update();
                })
            }
        } else {
            updReg({
                oppid: oppid
            }).then(()=>{
                this.update();
            });
        }  
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
        });
        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;
        })
    }
}