liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
import { LightningElement,api, track, wire } from 'lwc';
import {CurrentPageReference} from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
import init  from '@salesforce/apex/LexSubmitCampaignController.initMeetingDelayApply';
import findQualified1  from '@salesforce/apex/LexSubmitCampaignController.findQualified1';
import findQualified2  from '@salesforce/apex/LexSubmitCampaignController.findQualified2';
import findQualified3  from '@salesforce/apex/LexSubmitCampaignController.findQualified3';
import getRecordIdByName  from '@salesforce/apex/LexSubmitCampaignController.getRecordIdByName';
import changeCampaign  from '@salesforce/apex/OpdPlanWebService.changeCampaign';
const event1 = new ShowToastEvent({
                    message:
                    "存在审批中的会议延期申请,无法再次提交延期申请!",
                    variant : "error" ,
                    mode :'sticky'
});
const event2 = new ShowToastEvent({
                    message:
                    "耗材借出申请的状态未处于`草案中`或`取消`,该会议只能取消,无法延期。",
                     variant : "error" ,
                    mode :'sticky'
});
const event3 = new ShowToastEvent({
                    message:
                    "备品借出申请的状态未处于`草案中`或`取消`,该会议只能取消,无法延期。",
                     variant : "error" ,
                    mode :'sticky'
});
const event4 = new ShowToastEvent({
                    message:
                    "该活动信息已发送到智慧医疗,请确认后再操作",
                     variant : 'warning' ,
                     mode :'sticky'
});
const event5 = new ShowToastEvent({
                    message:
                    "该会议不在公开中或申请中,只能取消,无法延期。",
                     variant : "error" ,
                    mode :'sticky'
});
export default class lexMeetingDelayApplyCampaign extends NavigationMixin(LightningElement) {
    @api recordId;
    IsLoading=true;
    Campaign;
 
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
            console.log(this.recordId);
          }
        }
    }
 
    connectedCallback(){
        Promise.all([
            loadStyle(this, lwcCSS)
        ]);
        init({recordId:this.recordId}).then(res=>{
            console.log(res);
            this.Campaign=res;
            console.log(this.Campaign.Id);
            this.meetingDelayApply().then(res=>{
                const passOneEvent = new CustomEvent('closem', {
                        detail: '111'
                      });
             this.dispatchEvent(passOneEvent);
                
            })
        })
    }
 
 
    async meetingDelayApply(){
        var hasError='0';
        var CampaignId = this.Campaign.Id;
        var PlanBackData= this.Campaign.PlanBackData__c;
        var Meeting_Cooperate = this.Campaign.Meeting_Cooperate__c;
        var Meeting_Cooperate2 = this.Campaign.Meeting_Cooperate2__c;
        var Meeting_Cooperate3 = this.Campaign.Meeting_Cooperate3__c;
        var Meeting_Cooperate4 = this.Campaign.Meeting_Cooperate4__c;
        var MeetingType = this.Campaign.Meeting_Type__c;
        var HostName = this.Campaign.HostName__c;
        var cooperatorCompany = this.Campaign.cooperatorCompany__c;
        var meetingStartDate = this.Campaign.StartDate;
        var meetingEndDate = this.Campaign.EndDate;
        //OBPM LY 20211221 start
        var IFApproved = this.Campaign.IF_Approved__c;
        //OBPM LY 20211221 end
        var status = this.Campaign.Status;
        var CampaignStatus = this.Campaign.CampaignStatus__c; // 20221201 ljh DB202211527935 add
        var IF_Submit__c = this.Campaign.IF_Submit__c;
        var MeetingApprovedNoId = this.Campaign.Meeting_Approved_No__c;
 
        
        var meetingSize = await findQualified1({CampaignId : this.Campaign.Id});
        if(meetingSize.length>0){
            this.dispatchEvent(event1);
            return;
        }
 
        var consumSize = await findQualified2({CampaignId : this.Campaign.Id});
        console.log(consumSize);
        console.log('123123123');
        console.log(consumSize.length);
        if(consumSize.length>0){
            this.dispatchEvent(event2);
            return;
        }
 
        var rentalSize = await findQualified3({CampaignId : this.Campaign.Id});
        if(rentalSize.length>0){
            this.dispatchEvent(event3);
            return;        
        }
        //活动信息已经发送给智慧医疗
        if(IF_Submit__c != 0){
            this.dispatchEvent(event4);
        }
 
        // 会议延期检查 SWAG-BVH3Q7 20201120
        var rtn = await changeCampaign({campaignId:CampaignId});
        if (rtn != 'OK') {
            const event6 = new ShowToastEvent({
                message:
                rtn,
                variant : "error" ,
                mode :'sticky'
            });
            this.dispatchEvent(event6);
            return;
        }
        // 20221201 ljh DB202211527935 add start
        // 对于1 学会/会议和6 营业部专用会议这两种会议类型,请将公开中或申请中不允许提交变更申请的约束,改到会议状态字段。
        var recordTypeId1= await getRecordIdByName({Name : '%学会/会议%'});
        var recordTypeId2= await getRecordIdByName({Name : '%营业部专用会议%'});
        //开发环境没有此recordType
        var recordTypeId3= await getRecordIdByName({Name : '%会议延期%'});
        let canDelayFlag = false;
        console.log(this.Campaign.RecordTypeId == recordTypeId1);
        console.log(this.Campaign.RecordTypeId == recordTypeId2);
        console.log(recordTypeId1);
        console.log(recordTypeId2);
        console.log(this.Campaign.RecordTypeId == recordTypeId1);
        console.log(this.Campaign.RecordTypeId == recordTypeId2);
        console.log(CampaignStatus == '公开中');
        console.log('this.Campaign.RecordTypeId = ' + this.Campaign.RecordTypeId);
        console.log('recordTypeId1 = ' + recordTypeId1);
        console.log('recordTypeId2 = ' + recordTypeId2);
        console.log('CampaignStatus = ' + CampaignStatus);
        console.log('status = ' + status);
        if((this.Campaign.RecordTypeId == recordTypeId1 || this.Campaign.RecordTypeId == recordTypeId2)&&(CampaignStatus == '公开中' || CampaignStatus == '申请中' || CampaignStatus == '备品已申请')){
            console.log('h1');
            canDelayFlag = true;
        }else if(!(this.Campaign.RecordTypeId == recordTypeId1 || this.Campaign.RecordTypeId == recordTypeId2)&& (status == '公开中' || status == '申请中')){
            console.log('h2');
            canDelayFlag = true;
        }
        console.log('canDelayFlag');
        console.log(canDelayFlag);
        if(canDelayFlag){
            const defaultValues = encodeDefaultFieldValues({
                campaign__c: CampaignId,
                HostName__c: HostName,
                cooperatorCompany__c: cooperatorCompany,
                meeting_start_date__c: meetingStartDate,
                meeting_end_date__c: meetingEndDate,
                Meeting_Type__c: MeetingType,
                IF_Approved__c: IFApproved,
                dismantling_date__c: PlanBackData,
                Meeting_Cooperate1__c:Meeting_Cooperate,
                Meeting_Cooperate2__c: Meeting_Cooperate2,
                Meeting_Cooperate3__c: Meeting_Cooperate3,
                Meeting_Cooperate4__c:Meeting_Cooperate4,
                MeetingApproved__c: MeetingApprovedNoId,
                retURL : CampaignId
            });
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'meeting_delay_apply__c',
                    actionName: 'new'
                },
                state: {
                    nooverride: '1',
                    defaultFieldValues: defaultValues,
                    recordTypeId : recordTypeId3
                }
            });    
        }else{
            this.dispatchEvent(event5);
            return;
        }
 
 
    }
 
}