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
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
import { LightningElement,wire,track,api} from 'lwc';
import { CurrentPageReference } from "lightning/navigation";
import { CloseActionScreenEvent } from 'lightning/actions';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
 
import  init  from '@salesforce/apex/lexToAddMaintenanceContractController.initMcpPreSubmit';
import  updateMcDate  from '@salesforce/apex/lexToAddMaintenanceContractController.updateMcDate';
import  processResults  from '@salesforce/apex/otherButtonMaintenanceContractCtl.processResults';
 
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import lexSendNfm103 from '@salesforce/resourceUrl/lexSendNfm103';  
 
 
export default class lexCmpPreSubmit extends LightningElement {
    @api recordId;
    @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),
            loadStyle(this, lexSendNfm103)
        ]);
        init({
            recordId: this.recordId
        }).then(returnData => {
            if(returnData) {
                console.log(returnData);
                
                debugger
                this.IsLoading = false;
                if(!returnData.mcp.Estimation_Id__c) {
                    this.showToast('没有决定的报价组合,不能进行合同复核。','error');
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                if(returnData.mcpeList.length ==0){
                    this.showToast('没有决定的报价组合,不能进行合同复核。','error');
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
 
                var dateMsg = '请先填写';
                if(!returnData.mcp.OCM_Print_request__c) {
                    dateMsg += '【OCM盖章申請】';
                }
                if(!returnData.mcp.HP_Dealer_print__c) {
                    dateMsg += ' 【医院(经销商)印】';
                }
                if(!returnData.mcp.Contract_print_completed__c){
                    dateMsg += ' 【合同盖章完毕】';
                }
                if(!returnData.mcp.Submit_contract_to_Financial_dept__c) {
                    dateMsg += ' 【财务提交日】';
                }
                if(!returnData.mcp.Contract_Conclusion_Date__c) {
                    dateMsg += ' 【合同日】';
                }
                if(dateMsg!='请先填写') {
                    this.showToast(dateMsg,'error');
                    this.dispatchEvent(new CloseActionScreenEvent());
                    return;
                }
                var records = returnData.mcList;
 
                //判断小合同是否符合合同复核条件
                var msg = '';
                for(var i=0;i<records.length;i++) {
                    console.log('result'+records[i]);
                    var mc = records[i];
                    //判断是否是引合中
                    console.log('mc.Status__c'+mc.Status__c)
                    if(mc.Status__c!='引合中') {
                        this.showToast(mc.Name +'\n 合同状态不是引合中,不能进行复核。','error');
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                    if(!mc.Decided_Estimation__c) {
                        this.showToast(mc.Name +'\n 合同报价还没有decide,不能进行复核。','error');
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                    //update wangweipeng 2022/01/04 start
                    //判断是否需要先上传认款合同吗,如果需要那么判断他是否已经上传,如果上传,那么判断他是否完成认款,如果都满足,那么才能正常走接口上传SAP
                    //判断是认款合同吗
                    if(mc.old_Is_RecognitionModel__c==true ||mc.old_Is_RecognitionModel__c=='true'){
                        if(!mc.upload_to_RM_time__c ){//判断是否已经上传认款合同
                            this.showToast(mc.Name +'\n 当前维修合同的经销商是先款对象,需要先【上传认款合同】,然后完成认款以后才能复核。','error');
                            this.dispatchEvent(new CloseActionScreenEvent());
                            return;
                        }else{
                            //判断是否完成认款
                            if(mc.Is_Recognition_Model_True__c==false||mc.Is_Recognition_Model_True__c=='false'){
                                this.showToast(mc.Name +'\n 当前维修合同没有完成认款,不能进行复核。','error');
                                this.dispatchEvent(new CloseActionScreenEvent());
                                return;
                            }
                        }
                    }
                    var status = mc.MC_approval_status__c;
                    console.log(status);
                    if (status != 'Draft' && status != 'Reject' && status != '' && status != null) {
                        this.showToast(mc.Name +'\n 复核已经提交,请确认状态。','error');
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    }
                }
            debugger
                LightningConfirm.open({
                    message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
                    variant: 'headerless',
                    label: '提示信息',
                }).then(submit=>{
                    if(!submit){
                        this.dispatchEvent(new CloseActionScreenEvent());
                        return;
                    } else {
                        updateMcDate({
                            recordId: this.recordId
                        }).then(result=>{
                            if(result=='2') {
                                this.showToast('小合同日期更新失败','error');
                                this.dispatchEvent(new CloseActionScreenEvent());
                                return;
                            } else {
                                processResults({
                                    recordId: this.recordId
                                }).then(processResult=>{
 
                                    if(processResult=='1') {
                                        this.showToast('合同复核提交申请成功!','success');
                                        this.dispatchEvent(new CloseActionScreenEvent());
                                        window.location.href = '/'+this.recordId;
                                    } else {
                                        this.showToast(returnData.mcp.Name+'更新失败。\n','error'); //zzm 20231121 bug修复
                                        this.dispatchEvent(new CloseActionScreenEvent());
                                        return;
                                    }
                                });
                            }
                        });
                    }
                }) ;
            } else {
                console.log('没有查到数据');
            }
 
        });    
    }
    showToast(msg,type) {
        if(type == 'success'){
            const event = new ShowToastEvent({
                message: msg,
                variant: type
            });
            this.dispatchEvent(event);
        }else{
            const event = new ShowToastEvent({
                message: msg,
                variant: type,
                mode: 'sticky'
            });
            this.dispatchEvent(event);
        }
    }
}
 
//old js
//zhangzhengmei 20230629 start
/*var excuteFoo =function () {
    var decideEstimationId = '{!MaintanceContractPack__c.Estimation_Id__c}';
    if(decideEstimationId ) {
        var decideEstimationSql = "select Id,Decide__c from MaintanceContractPackEstimate__c where Name='" + decideEstimationId + "' and Decide__c=true" ;
        var decideEstimationResult = sforce.connection.query(decideEstimationSql );
        var decideEstimationRecords = decideEstimationResult.getArray("records");
        if(decideEstimationRecords.length==0) {
            alert('没有决定的报价组合,不能进行合同复核。');
            return;
        }
    } else {
        alert('没有决定的报价组合,不能进行合同复核。');
        return;
    }
 
    var dateMsg = '请先填写';
    console.log('mcp.OCM_Print_request__c typeof:'+typeof('{!MaintanceContractPack__c.OCM_Print_request__c}'));
    if(!'{!MaintanceContractPack__c.OCM_Print_request__c}') {
        dateMsg += '【OCM盖章申請】';
    }
    if(!'{!MaintanceContractPack__c.HP_Dealer_print__c}') {
        dateMsg += ' 【医院(经销商)印】';
    }
    if(!'{!MaintanceContractPack__c.Contract_print_completed__c}'){
        dateMsg += ' 【合同盖章完毕】';
    }
    if(!'{!MaintanceContractPack__c.Submit_contract_to_Financial_dept__c}') {
        dateMsg += ' 【财务提交日】';
    }
    if(!'{!MaintanceContractPack__c.Contract_Conclusion_Date__c}') {
        dateMsg += ' 【合同日】';
    }
    if(dateMsg!='请先填写') {
        alert(dateMsg);
        return;
    }
    var mcpid = '{!MaintanceContractPack__c.Id}';
    console.log('mcpid ='+mcpid);
    var sql = "select Id,Name,Decided_Estimation__c,Status__c,MC_approval_status__c,Is_Recognition_Model_True__c,Contract_print_completed__c,Contract_quotation_or_not__c,Maintenance_Contract_No__c,upload_to_sap_time__c,upload_to_RM_time__c,old_Is_RecognitionModel__c,Payment_Plan_Sum_First__c from Maintenance_Contract__c where MaintanceContractPack__c='" + mcpid + "'";
    var sqlResult = sforce.connection.query(sql);
    var records = sqlResult.getArray("records");
 
 
    //判断小合同是否符合合同复核条件
    var msg = '';
    for(var i=0;i<records.length;i++) {
        console.log('result'+records[i]);
        mc = records[i];
        //判断是否是引合中
        console.log('mc.Status__c'+mc.Status__c)
        if(mc.Status__c!='引合中') {
            alert(mc.Name +'\n 合同状态不是引合中,不能进行复核。');
            return;
        }
        if(!mc.Decided_Estimation__c) {
            alert(mc.Name +'\n 合同报价还没有decide,不能进行复核。');
            return;
        }
        //update wangweipeng 2022/01/04 start
        //判断是否需要先上传认款合同吗,如果需要那么判断他是否已经上传,如果上传,那么判断他是否完成认款,如果都满足,那么才能正常走接口上传SAP
        //判断是认款合同吗
        if(mc.old_Is_RecognitionModel__c==true ||mc.old_Is_RecognitionModel__c=='true'){
            if(!mc.upload_to_RM_time__c ){//判断是否已经上传认款合同
                alert(mc.Name +'\n 当前维修合同的经销商是先款对象,需要先【上传认款合同】,然后完成认款以后才能复核。');
                return;
            }else{
            //判断是否完成认款
                if(mc.Is_Recognition_Model_True__c==false||mc.Is_Recognition_Model_True__c=='false'){
                    alert(mc.Name +'\n 当前维修合同没有完成认款,不能进行复核。');
                    return;
                }
            }
        }
        var status = mc.MC_approval_status__c;
        console.log(status);
        if (status != 'Draft' && status != 'Reject' && status != '' && status != null) {
            alert(mc.Name +'\n 复核已经提交,请确认状态。');
            return;
        }
 
 
    }
 
 
    if(!confirm('一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?')){
        return;
    }
    //大合同的相关日期更新到小合同上
    for(var i=0;i<records.length;i++) {
        console.log('date:'+new Date('{!MaintanceContractPack__c.OCM_Print_request__c}'));
        var mcUpdate = new sforce.SObject("Maintenance_Contract__c");
        mcUpdate.OCM_Print_request__c = new Date('{!MaintanceContractPack__c.OCM_Print_request__c}');
        mcUpdate.HP_Dealer_print__c = new Date('{!MaintanceContractPack__c.HP_Dealer_print__c}');
        mcUpdate.Contract_print_completed__c = new Date('{!MaintanceContractPack__c.Contract_print_completed__c}');
        mcUpdate.Submit_contract_to_Financial_dept__c = new Date('{!MaintanceContractPack__c.Submit_contract_to_Financial_dept__c}');
        mcUpdate.Contract_Conclusion_Date__c= new Date('{!MaintanceContractPack__c.Contract_Conclusion_Date__c}');
        mcUpdate.Id = records[i].Id;
        var result = sforce.connection.update([mcUpdate]);
        console.log(result);
    }
 
    var request = new sforce.ProcessSubmitRequest();
    request.objectId = mcpid;
    var processResults = sforce.connection.process([request]);
    if (processResults[0].errors != null) {
        var errmsg = processResults[0].errors.message.toString();
        alert('{!MaintanceContractPack__c.Name}'+'更新失败。\n'+errmsg+'_sys');
        return;
    }
    alert('合同复核提交申请成功!');
    window.location.reload();
}
 
excuteFoo();*/
//zhangzhengmei 20230629 endL