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
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
import { LightningElement, track, wire, api } from 'lwc';
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { updateRecord } from 'lightning/uiRecordApi';
import LightningConfirm from 'lightning/confirm';
import init from '@salesforce/apex/LexAddSubmitApprovalProcessController.init';
import submitApproval from '@salesforce/apex/LexAddSubmitApprovalProcessController.submitApproval';
import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
import changeAddApprovalStatus from '@salesforce/apex/LexAddSubmitApprovalProcessController.changeAddApprovalStatus';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
export default class lexAddSubmitApprovalProcess extends LightningElement {
    @api recordId;
    IsLoading = true;
    RecordTypeId;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference){
        if(currentPageReference) {
            const urlValue = currentPageReference.state.recordId;
            if(urlValue) {
                let str = `${urlValue}`;
                this.recordId = str;
            }
        }
    }
 
    connectedCallback(){
        Promise.all([
            loadStyle(this,lwcCSS)
        ]);
        init({
            recordId: this.recordId
        }).then(result=>{
            console.log('result==='+JSON.stringify(result));
            if(JSON.stringify(result) == '{}'){
                this.ToastShow('没有查到需要的数据','warning');
                return;
            }
 
            if(result.addApprovalStatus != '草案中' || result.detailSize == 0){
                this.ToastShow('没有需要审批的追加附属品','warning');
                return;
            }
            // if (!confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
            //     this.dispatchEvent(new CloseActionScreenEvent());
            //     return;
            // }
            LightningConfirm.open({
                message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
                variant: 'headerless',
                label: '提示信息',
                // setting theme would have no effect
            }).then(submit=>{
                if(!submit){
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }else{
 
                    // 希望到货日不能早于申请提交日-0418追加
                    //if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') {
                    // alert('希望到货日不能早于申请提交日');
                    // return;
                    // } 
                    console.log(JSON.stringify(result));
                    if(result.repairId != null){
                        if(result.demoPurpose1 == '维修代用' && result.demoPurpose2 == '一般用户'){
                            if(result.repairEstimatedDateFormula == null){
                                this.ToastShow('一般维修无报价日,不可借用备品','warning');
                                return;
                            }else if(result.repairEstimatedDateFormula <'2019-07-01' && result.agreedDate == null){
                                this.ToastShow('报价日在2019/7/1之前且户同意日为空,不可借用备品','warning');
                                return;
                            }
                        }
 
                        if(result.recordTypeId!=result.demoRequestPastDataId && result.profileId != result.adminProfileId && result.newProductGuaranteeObject== '8: 市场多年保修' && result.demoPurpose2 != '市场多年保修'){
                            this.ToastShow('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。','warning');
                            return;
                        }
 
                        if(result.repairFinalInspectionDate != null){
                            this.ToastShow('存在修理最终检测日,不可借用备品','warning');
                            return;
                        }
 
                        if(result.repairShippedDate != null){
                            this.ToastShow('存在RC修理返送日,不可借用备品','warning'); 
                            return;
                        }
 
                        if(result.status1 == '0.删除' ||result.status1 == '0.取消' || result.status1 =='5.完毕'){
                            this.ToastShow('修理已经结束,不能申请备品','warning');
                            return; 
                        }
 
                        // if(result.demoPurpose2 =='再修理' || !result.reRepairObjectF || result.reRepairObjectFs == 'false'){
                        
                        if(result.demoPurpose2 =='再修理'  || result.reRepairObjectF == 'false'){//20231110 李文涛
                            this.ToastShow('不属于再受理参考对象,不可借用备品','warning');
                            return; 
                        }
 
                        // 20231207 ljh 修复原有逻辑 start
                        // if(result.recordTypeId != result.demoRequestPastDataId && result.demoPurpose2 !='保修用户' && result.demoPurpose2 != '市场多年保修' && result.numberOfEffectiveContract !='有'){
                        if(result.recordTypeId != result.demoRequestPastDataId && result.demoPurpose2 !='保修用户' && result.demoPurpose2 != '市场多年保修' && result.numberOfEffectiveContract =='有'){
                        // 20231207 ljh 修复原有逻辑 end
                            this.ToastShow('有维修合同,必须选择保修用户.','warning');
                            return;
                        }
 
                        if(result.recordTypeId != result.demoRequestPastDataId && result.numberOfEffectiveContract=='无' && (result.newProductGuaranteeObject == '2: 服务多年保修' && 
                                                                                                                            (result.assetModelNo== 'LTF-190-10-3D' || result.assetModelNo=='LTF-S190-5' || result.assetModelNo== 'CYF-VHA' || result.assetModelNo== 'CYF-VA2' || result.assetModelNo=='CYF-5A' ||result.assetModelNo=='LTF-S190-10'||result.assetModelNo=='OER-AW'||result.assetModelNo=='URF-V'||result.assetModelNo=='URF-V2'||result.assetModelNo=='URF-P6')) && result.demoPurpose2 != '保修用户'){
 
                            
                            this.ToastShow('此设备型号多年保修,请选择保修用户.','warning');
                            return; 
                        }
 
                        //备品申请 过去历史转移
                        if(result.recordTypeId != result.demoRequestPastDataId && result.newProductGuaranteeObject=='2: 服务多年保修' && (result.assetModelNo=='CV-V1' ||result.assetModelNo=='CV-V1(A)'||result.assetModelNo=='CV-V1(B)'||result.assetModelNo=='GIF-LV1'||result.assetModelNo=='CF-LV1L'||result.assetModelNo=='CF-LV1I'||result.assetModelNo=='MAJ-1910') &&(result.demoPurpose2=='一般用户'||result.demoPurpose2=='再修理')){
                            this.ToastShow('奥辉设备,保修期内不提供备品.','warning');
                            return;
                        }
                    }
 
                    if(result.campaignId!=null || result.campaignId!=''){
                        if(result.campaignStatus == '草案中'){
                            this.ToastShow('学会状态为草案中,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '申请中'){
                            this.ToastShow('学会状态为申请中,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '已结束'){
                            this.ToastShow('学会状态为已结束,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '已提交报告'){
                            this.ToastShow('学会状态为已提交报告,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '取消申请中'){
                            this.ToastShow('学会状态为取消申请中,不能提交','warning');
                            return;
                        }
                        if(result.campaignStatus == '取消'){
                            this.ToastShow('学会状态为取消,不能提交','warning');
                            return;
                        }
                    }
 
                    if(result.qISNumber!=null || result.qISNumber!=''){
                        if(result.nextAction=='送回'){
                            this.ToastShow('QIS 已送回,不能再申请备品了','warning');
                            return;
                        }
                    }
 
                    //share
                    var userAccess = new Array();
                    userAccess.push(result.applyUserId + '_Edit'); 
 
                    //SWAG-BZMA8W 去掉 服务经理部长共享 start
                    //update lxy DLIU-BZNBG9 去掉服务经理部长共享
                    //userAccess.push('{!Rental_Apply__c.JingliApprovalManagerId__c}_Read');
                    //userAccess.push('{!Rental_Apply__c.SalesManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
                    //update lxy DLIU-BZNBG9 去掉服务经理部长共享
                    //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerId__c}_Read');
                    //SWAG-BZMA8W 去掉 服务经理部长共享 end
                    //userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerSalesId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
                    //userAccess.push('{!Rental_Apply__c.ZongjianApprovalManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
                    //userAccess.push('{!Rental_Apply__c.Status__c}_Read');
 
                    console.log('参数==='+result.rentalApplyId+' '+userAccess+' '+result.ownerId);
                    setSObjectShare({
                        sobjectName:'Rental_Apply__Share',
                        rowCause:'ApplyUserShare__c',
                        parentId:result.rentalApplyId,
                        userAccess:userAccess,
                        ownerId:result.ownerId
                    }).then(res=>{
                        
                        if(res!='OK'){
                            this.ToastShow(res,'warning');
                            return;
                        }else{
                            console.log('setSObjectShareSuccess====OK');
                            //追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c
                            if (result.rentalApplyStatus != '已批准' && result.rentalApplyStatus != '已出库指示') {
                                this.ToastShow('请备品申请状态确认,申请状态已批准后才可以提交追加审批','warning');
                                return;
                            }
 
                            changeAddApprovalStatus({
                                recordId: this.recordId,
                                status: '填写完毕'
                            }).then(changeResult=>{
                                if(changeResult == '更新成功'){
                                    submitApproval({
                                        recordId: this.recordId
                                    }).then(submitApprovalRes=>{
                                        if(submitApprovalRes == 'OK'){
                                            this.ToastShow('提交追加待审批成功','success');
                                            this.updateRecordView(this.recordId);
                                        }else{
                                            this.ToastShow('追加待审批失败','error');
                                        }
                                    })
                                }else{
                                    this.ToastShow(changeResult,'error');
                                }    
                            })
                        }
                    }).catch(err=>{
                        console.log('setSObjectShareErr===='+err);
                    })
                }
            })
        }).catch(err=>{
            console.log('====1111====',err);
        })    
    }
 
    ToastShow(msg,type){
        
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.updateRecordView(this.recordId);
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
            this.dispatchEvent(new CloseActionScreenEvent());
        }
    }
 
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
 
    async handleConfirmClick(msg) {
        const result = await LightningConfirm.open({
            message: msg,
            variant: 'headerless',
            label: 'this is the aria-label value'
        });
        if (result) {
            this.ll();
        } else {
            window.history.go(-1);
        }
    }
}