liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
import { LightningElement , wire, api} from 'lwc';
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
import { CloseActionScreenEvent } from 'lightning/actions';
import { updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import LightningConfirm from 'lightning/confirm';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
 
import init from '@salesforce/apex/ConsumApplyApprovalProcessController.initSubmitApprovalProcessController';
import selectCampaignById from '@salesforce/apex/ConsumApplyApprovalProcessController.selectCampaignById';
import selectReportById from '@salesforce/apex/ConsumApplyApprovalProcessController.selectReportById';
import selectEquipmentById from '@salesforce/apex/ConsumApplyApprovalProcessController.selectEquipmentById';
import approvalCheck from '@salesforce/apex/ConsumApplyApprovalProcessController.approvalCheck';
// import setSObjectShare from '@salesforce/apex/ConsumApplyApprovalProcessController.setSObjectShare';
import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
import updateConsumApply from '@salesforce/apex/ConsumApplyApprovalProcessController.updateConsumApply';
// import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
import IFTradeComplianceAlert from '@salesforce/label/c.IFTradeComplianceAlert';//kk 贸易合规2期 20240125 add
import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2'; //kk 贸易合规2期 20240125 add
import tradeConsumTempleSend from '@salesforce/apex/SendEmailUtil.tradeConsumTempleSend';   //贸易合规二期 发邮件20240130
 
export default class LexConsumApplySubmitApprovalProcess extends LightningElement {
 
    @api recordId;
    id;
    shippingDays;//希望到货日前7个工作日
    shippingDay;//希望到货日
    campaign ;//学会
    qISNumber;//QIS
    qISIDLine;//QIS的ID值
    status;//    状态
    minApprovalDate;//最小可以提交申请日期
    applyUser;//操作者
    jingliManager;//CL6 经理级(服务)
    salesManager;//CL6 经理级
    buchangManager;//CL5 总监级(服务)
    buchangManagerSale;//CL5 总监级
    zongjianManager;//CL4 高级总监
    accDealerBlacklistc;//客户是否为黑名单
    tradeComplianceStatusFlagBP;//贸易合规开关
    iFTradeComplianceAlertBP;//贸易合规提醒
    owner;//所有人
    directSend;//发送方
    // 20240103 fy  DB202312530994 start
    medicalInstitutionAddress;//医疗机构地址
    medicalInstitutionAddresssup;//医疗机构地址补充
    createdDate;//创建日期
    // 20240103 fy  DB202312530994 end
    accountTradeStatus;//kk 20240121 贸易合规2 add
    hgerqi;//kk 20240121 贸易合规2 add
    accountName;//kk 20240121 贸易合规2 add
    IsLoading = true;
 
    @wire(CurrentPageReference)
     getStateParameters(currentPageReference) {
         if (currentPageReference) {
           const urlValue = currentPageReference.state.recordId;
           if (urlValue) {
             let str = `${urlValue}`;
             console.log("str:"+str);
             this.recordId = str;
            }
         }
     }
 
 
     connectedCallback(){
 
      Promise.all([
        loadStyle(this, lwcCSS)
      ]);
 
        init({recordId : this.recordId}).then( result => {
        this.IsLoading = false;
        console.log('result'+result);
        if(result!= null){
          this.IsLoading = false;
          this.id = result.id;
          this.shippingDays = result.shippingDays;
          this.shippingDay = result.shippingDay;
          this.campaign = result.campaign;
          this.qISNumber = result.qISNumber;
          this.qISIDLine = result.qISIDLine;
          this.status = result.status;
          this.minApprovalDate = result.minApprovalDate;
          this.applyUser = result.applyUser;
          this.jingliManager = result.jingliManager;
          this.salesManager = result.salesManager;
          this.buchangManager = result.buchangManager;
          this.buchangManagerSale = result.buchangManagerSale;
          this.zongjianManager = result.zongjianManager;
          this.accDealerBlacklistc = result.accDealerBlacklistc;
          this.tradeComplianceStatusFlagBP = result.tradeComplianceStatusFlagBP;
          this.iFTradeComplianceAlertBP = result.iFTradeComplianceAlertBP;
          this.owner = result.owner;
          this.directSend = result.directSend;
          // 20240103 fy  DB202312530994 start
          this.medicalInstitutionAddress = result.medicalInstitutionAddress;
          this.medicalInstitutionAddresssup = result.medicalInstitutionAddresssup;
          this.createdDate = result.createdDate;
          // 20240103 fy  DB202312530994 end
          //kk 20240121 贸易合规2 add start
          this.accountTradeStatus = result.accountTradeStatus;
          this.hgerqi = result.hgerqi;
          this.accountName = result.accountName;
          //kk 20240121 贸易合规2 add end
 
          //kk 20240121 贸易合规一期的东西 暂时注释掉
          // if(this.tradeComplianceStatusFlagBP == 'true' && this.accDealerBlacklistc =='1'){
          //   this.showToast(this.iFTradeComplianceAlertBP,'error');
          //   return;
          // }
          console.log('hgerqi=='+this.hgerqi);
          //kk 20240121 贸易合规2 add start
          if(this.tradeComplianceStatusFlagBP == 'true' &&this.accountTradeStatus == '黑名单'){
            this.showToast('医院在黑名单中,存在贸易合规风险,无法继续提交待审批,'+IFTradeComplianceAlert,'error');
            tradeConsumTempleSend({consumlId: this.recordId, stepName:'提交待审批'});    //贸易合规二期 发邮件20240130
            return;  
          }
          if(this.tradeComplianceStatusFlagBP == 'true' &&this.accountTradeStatus == '冻结,人工审批中'){
            this.showToast( '医院在冻结清单中,可能存在贸易合规风险,目前正在评估中(一般需5-10个工作日),暂时无法提交待审批,'+IFTradeComplianceAlert,'error');
            tradeConsumTempleSend({consumlId: this.recordId, stepName:'提交待审批'});    //贸易合规二期 发邮件20240130
            return;  
          }
          if(this.tradeComplianceStatusFlagBP == 'true' &&this.hgerqi == 'true'){
            LightningConfirm.open({
              message: '您此次申请的业务可能存在贸易合规风险,是否继续提交待审批,'+IFTradeComplianceAlert2+'(一般需5-10个工作日)。',
              variant: 'headerless',
              label: 'this is the aria-label value'
            }).then(confirm=>{
              if(!confirm){
                this.IsLoading = false;
                this.dispatchEvent(new CloseActionScreenEvent());
                return;
              }
              else{
                var today = new Date();
                var shipping = new Date(this.shippingDays);
                console.log('shipping'+shipping);
                console.log('today'+today);
                if(shipping < today){
                  this.showToast('此申请已不满足(希望到货日-7工作日)前完成审批的情况,请重新修改申请。','error');
                  return;
                }
 
                LightningConfirm.open({
                    message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?\n\n※ 需要在"
                             +this.shippingDays+"前完成审批,否则申请单自动取消。",
                    variant: 'headerless',
                  }).then(submit=>{
                    if(!submit){
                      this.IsLoading = false;
                      this.showToast('已取消','error')
                      return;
                    }else{
                      console.log('shippingDay-----'+this.shippingDay);
                      
                      if(shipping < today){
                        this.showToast('希望到货日不能早于申请提交日','error');
                        return;
                      }
                      this.applySubmit().then(res=>{
                        this.IsLoading=false;
                        this.dispatchEvent(new CloseActionScreenEvent());
                      }); 
                      
                    }
                  }).catch(error => {
                    this.showToast(error,'error')
                })
              }
            });
          }
          else{
            var today = new Date();
            var shipping = new Date(this.shippingDays);
            console.log('shipping'+shipping);
            console.log('today'+today);
            if(shipping < today){
              this.showToast('此申请已不满足(希望到货日-7工作日)前完成审批的情况,请重新修改申请。','error');
              return;
            }
 
            LightningConfirm.open({
                message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?\n\n※ 需要在"
                         +this.shippingDays+"前完成审批,否则申请单自动取消。",
                variant: 'headerless',
              }).then(submit=>{
                if(!submit){
                  this.IsLoading = false;
                  this.showToast('已取消','error')
                  return;
                }else{
                  console.log('shippingDay-----'+this.shippingDay);
                  
                  if(shipping < today){
                    this.showToast('希望到货日不能早于申请提交日','error');
                    return;
                  }
                  this.applySubmit().then(res=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                  }); 
                  
                }
              }).catch(error => {
                this.showToast(error,'error')
            })
          }
          //kk 20240121 贸易合规2 add end
        }else{
          this.IsLoading = false;
          this.showToast('result为空','error')
          return;
        }
 
      })
        
    }
 
    async applySubmit(){
      console.log('directSend==='+this.directSend);
      //20231106 sx 课题DB202310484652 add start
      if(this.directSend =='办事处' || this.directSend =='经销商' || this.directSend =='上门自提'){
        const directResult = await LightningConfirm.open({
                message: "备品发送地为非医疗机构或会场,还请确认是否继续提交?",
                variant: 'headerless',
                label: '提示信息',
            });
        if(!directResult){
          return;
        }
      }
      //20231106 sx 课题DB202310484652 add end
      // 20240103 fy  DB202312530994 start
      debugger
      var creatDate =  new Date(this.createdDate);
      var GoLiveDate = new Date("2024-01-02");
      if(this.directSend == '医疗机构' && creatDate >= GoLiveDate && ((this.medicalInstitutionAddress == '' || this.medicalInstitutionAddress == undefined) || (this.medicalInstitutionAddresssup == '' || this.medicalInstitutionAddresssup == undefined ))){
        this.showToast('医疗机构地址和医疗机构地址补充不能为空,请点击按钮【选择医疗地址】进行选择','error');
        return;
      }
      // 20240103 fy  DB202312530994 end
 
      if(this.campaign != null &&  this.campaign != ''){
        console.log('selectCampaignById');
        let dataList = await selectCampaignById({recordId: this.campaign});
        var interval = dataList[0].Status;
        if (interval == '草案中') {
          this.showToast('学会状态为草案中,不能提交','error');
          return;
        }
        if (interval == '申请中') {
        this.showToast('学会状态为申请中,不能提交','error');
        return;
        }
        if (interval == '已结束') {
        this.showToast('学会状态为已结束,不能提交','error');
        return;
        }
        if (interval == '已提交报告') {
        this.showToast('学会状态为已提交报告,不能提交','error');
        return;
        }
        if (interval == '取消申请中') {
        this.showToast('学会状态为取消申请中,不能提交','error');
        return;
        }
        if (interval == '取消') {
        this.showToast('学会状态为取消,不能提交','error');
        return;
        }
      }
      if(this.qISNumber != null && this.qISNumber != ''){
        console.log('selectReportById');
        let resList = await selectReportById({recordId:this.qISIDLine});
        var interval = resList[0].next_action__c;
          if (interval == '送回') {
            this.showToast('QIS 已送回,不能再申请备品了','error');
            return;
          }
      }
      var userAccess = new Array();
      // 20231012 ljh update 判断空 start
      if(this.applyUser != undefined){userAccess.push(this.applyUser+'_Edit');}
      if(this.jingliManager != undefined){userAccess.push(this.jingliManager+'_Edit');}
      if(this.salesManager != undefined){userAccess.push(this.salesManager+'_Edit');}
      if(this.buchangManager != undefined){userAccess.push(this.buchangManager+'_Edit');}
      if(this.buchangManagerSale != undefined){userAccess.push(this.buchangManagerSale+'_Edit');}
      if(this.zongjianManager != undefined){userAccess.push(this.zongjianManager+'_Edit');}
      // 20231012 ljh update 判断空 end
      console.log('setSObjectShare');
      let res = await setSObjectShare({
        sobjectName:'Consum_Apply__Share',
        rowCause:'ApplyUserShare__c',
        parentId:this.id,
        userAccess:userAccess,
        ownerId:this.owner
      });
      if(res!='OK'){
        console.log('111111');
        this.showToast(res,'error');
        return;
      }
      
      if(this.status == '填写完毕' || this.status == '申请中' || this.status == '已批准'
        || this.status == '已出库指示' || this.status == '删除' || this.status == '取消'){
        this.showToast('请备品申请状态确认,已经提交过的申请,不能重复提交','error');
        return;
      }
      var today = new Date();
      var approvalDate = new Date(this.minApprovalDate);
      if(approvalDate > today){
        this.showToast('申请提交日到预计使用日必须在22个工作日以内才可以','error');
        return;
      }
      console.log('selectEquipmentById');
      let raesList = await selectEquipmentById({recordId:this.id});
      if(raesList.length > 0){
        this.showToast('有没有明细的耗材备品配套一览,不能提交','error');
        return;
      }
      console.log('approvalCheck');
      let re1 = await approvalCheck({recordId:this.id});
      if(re1 != '1'){
        this.showToast(re1,'error');
        return;
      }
      console.log('updateConsumApply');
      let re2 = await updateConsumApply({recordId:this.id});
            // console.log(re2);
      if(re2 != '1'){
                // 20231013 ljh update start
        // this.showToast(re1,'error');
                this.showToast(re2,'error');
                // 20231013 ljh update end
        return;
      }else{
        console.log("success");
        this.showToast('已提交','success');
      }
 
    }
 
  updateRecordView(recordId) {
    updateRecord({fields: { Id: recordId }});
  }
 
  showToast(msg,type) {
    console.log("type-----"+type);
    if(type == "success"){
      const event = new ShowToastEvent({
          message: msg,
          variant: type
      });
      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());
    }
    if(type == "success"){
      console.log("type2-----"+type);
      this.updateRecordView(this.recordId);
      setTimeout(function(){
                window.location.href = window.location;
            }, 1500 )
    }
  }
  //20240124  sx lightning上线遗漏 start
  closeAction() {
    window.open("/"+this.recordId,'_self');
  }
  //20240124  sx lightning上线遗漏 end
}