KKbes
2023-08-07 890eafcf31f5f8d519bb9e6f9c15303be5328e2d
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
//author : kkbes  add  LexOPDPostPoneController
import { LightningElement, track, wire,api } 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 init  from '@salesforce/apex/LexOPDPostPoneController.init';
import findRecordId  from '@salesforce/apex/LexOPDPostPoneController.findRecordId';
import changeTrade  from '@salesforce/apex/OpdPlanWebService.changeTrade';
 
 
const event1 = new ShowToastEvent({
                    title: '状态错误',
                    message:
                    "OPD计划的状态为取消或完毕时,不能改期!",
});
export default class lexPostPoneReport extends  NavigationMixin(LightningElement) {
 
    @api recordId;
    IsLoading=true;
    OPDPlan;
    RecordType;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            this.recordId = str;
          }
        }
    }
 
    connectedCallback(){
        init({
            recordId: this.recordId
        }).then(result => {
            if (result != null) {
                this.OPDPlan = result;
                this.PostPoneReport().then(result=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });
            }
        }).catch(error => {
            const event3 = new ShowToastEvent({
                   title: '页面初始化错误',
                   message:
                error.message,
            });
            this.dispatchEvent(event3);
        });
 
    }
 
 
 
    async PostPoneReport(){
        var Status = this.OPDPlan.Status__c;
        if(Status == '取消' || Status == '完毕' ){
            this.dispatchEvent(event1);
            return;
        }
        var opdplanid = this.OPDPlan.Id;
        var rtn =await changeTrade({opdplanId:opdplanid})
        if (rtn != 'OK') {
            const event = new ShowToastEvent({
                   title: '失败',
                   message:
                rtn,
            });
            this.dispatchEvent(event);
            return;
        }    
        await findRecordId().then(result=>{
            if(result!=null){
                this.RecordType = result[0];
            }
            else{
                const eventIdIsNull = new ShowToastEvent({
                   message:
                '请及时联系管理员',
                variant : 'error'
                });
                this.dispatchEvent(eventIdIsNull);
            }
            
        }).catch(error=>{
            console.log(error.message);
        });    
        this.navigateToNewObjectPage();
    }
 
 
 
    navigateToNewObjectPage() {
        this.IsLoading=false;
        this.dispatchEvent(new CloseActionScreenEvent());
        const defaultFieldValues = encodeDefaultFieldValues({
        CancelOPDPlan__c : this.OPDPlan.Id ,
        Status__c : '延期报告'
        })
        this[NavigationMixin.Navigate]({
              type: 'standard__objectPage',
              attributes: {
                objectApiName: 'CancelPostponePlan__c',
                actionName: 'new'
              },
              state: {
                  nooverride: '1',
                defaultFieldValues: defaultFieldValues ,
                recordTypeId : this.RecordType.Id
              }
        });
 
 
    }
 
}