KKbes
2023-08-11 f66abb6dad1b8caa18aca9d65dceb34a34c022b6
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
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/LexOPDSupplementaryController.init';
import dataCheck  from '@salesforce/apex/OpdPlanWebService.dataCheck';
import getTheOPDPlan  from '@salesforce/apex/LexOPDSupplementaryController.getTheOPDPlan';
 
const event1 = new ShowToastEvent({
                    message:
                    "只有OPD计划状态为计划中,才能进行OPD补充申请",
                    variant : 'error'
});
const event2 = new ShowToastEvent({
                    message:
                    "OPD计划无法进行补充申请",
                    variant : 'error'
});
const event3 = new ShowToastEvent({
                    message:
                    "请转至OPD计划原单进行申请",
                    variant : 'error'
});
const event4 = new ShowToastEvent({
                    message:
                    "OPD计划已进行过补充申请,无法再次进行补充申请",
                    variant : 'error'
});
export default class lexOPDSupplementaryApplication extends NavigationMixin(LightningElement) {
 
    @api recordId;
    IsLoading=true;
    OPDPlan;
    TheOPDPlan;
 
    @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.SupplementaryApplication().then(result=>{
                    this.IsLoading=false;
                    this.dispatchEvent(new CloseActionScreenEvent());
                });
            }
        }).catch(error => {
            const event3 = new ShowToastEvent({
                   message:
                error.message,
                variant : 'error'
            });
            this.dispatchEvent(event3);
        });
 
    }
 
 
    async SupplementaryApplication(){
        var status = this.OPDPlan.Status__c;
        if(status != '计划中'){
            this.dispatchEvent(event1);
            return;
        }
        //补充申请
        var supplementaryApplication = this.OPDPlan.supplementaryApplication__c;
        if(supplementaryApplication == '1'){
            this.dispatchEvent(event2);
            return;
        }
        var rental = this.OPDPlan.OriginalOpdPlanRental__c;
        if(rental != '' && rental !=undefined){
            this.dispatchEvent(event3);
            return;
        }
        var raId = this.OPDPlan.Rental_Apply2__c;
        var datacheck = await dataCheck({rentalApplyId: raId});
        console.log(datacheck);
        if(datacheck != 'OK'){
            const event = new ShowToastEvent({
                   message:
                datacheck,
                variant : 'error'
            });
            this.dispatchEvent(event);
            return;
        }
        await getTheOPDPlan({Id : this.OPDPlan.Id}).then(result=>{
            this.TheOPDPlan = result;
        }).catch(error=>{
            console.log(error.message);
        });
        if(this.TheOPDPlan != null && this.TheOPDPlan > 0){
            this.dispatchEvent(event4);
            return;
        }
        const defaultFieldValues = encodeDefaultFieldValues({
        Name : this.OPDPlan.Name ,
        Status__c : '草案中',
        RentalReson__c : '追加配套' ,
        OPDPlan_ImplementDate__c : this.OPDPlan.OPDPlan_ImplementDate__c ,
        Account_Laboratory__c : this.OPDPlan.Account_Laboratory__c ,
        Related_Opportunity1_ID__c :this.OPDPlan.Related_Opportunity1_ID__c ,
        PlanProdDetail__c  : this.OPDPlan.PlanProdDetail__c,
        Cnt_OPD_LastYear__c : this.OPDPlan.Cnt_OPD_LastYear__c,
        Cnt_OPD_ThisYear__c : this.OPDPlan.Cnt_OPD_ThisYear__c,
        Cnt_Rentals__c : this.OPDPlan.Cnt_Rentals__c,
        lastMonth_Plan__c : this.OPDPlan.lastMonth_Plan__c,
        SalesManager__c : this.OPDPlan.SalesManager__c,
        OPDType__c : this.OPDPlan.OPDType__c,
        OriginalOpdPlanApplication__c :this.OPDPlan.Id,
        BuchangApprovalManagerSales__c :this.OPDPlan.BuchangApprovalManagerSales__c,
        SalesManager_Txt__c   :   this.OPDPlan.SalesManager_Txt__c 
 
        })
        this.IsLoading=false;
        this.dispatchEvent(new CloseActionScreenEvent());
        this[NavigationMixin.Navigate]({
              type: 'standard__objectPage',
              attributes: {
                objectApiName: 'OPDPlan__c',
                actionName: 'new'
              },
              state: {
                  nooverride: '1',
                defaultFieldValues: defaultFieldValues ,
              }
        });
 
    }
 
 
}