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
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 lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
import init from'@salesforce/apex/LexOPDSupplementaryController.initReportSubmit';
import getRecordTypeByNameAndSobject from'@salesforce/apex/LexOPDSupplementaryController.getRecordTypeByNameAndSobject';
const event1 = new ShowToastEvent({
                    message:
                    "OPD计划的状态为取消或完毕时,不能新建OPD报告!",
                    variant : "error" ,
                    mode : 'sticky'
});
const event2 = new ShowToastEvent({
                    message:
                    "没有出库的申请不允许创建OPD报告!",
                    variant : "error" ,
                    mode : 'sticky'
});
export default class lexOPDReportSubmit extends NavigationMixin(LightningElement) {
    @api recordId;
    @api showElement = false;
    // @api showIsLoading=false;
 //    IsLoading=true;
    OPDPlan;
    oppids;
    selectedRecordTypeId='3';
    recordTypeId1;
    recordTypeId2;
    recordTypeId3;
    recordTypeId4;
    recordTypeId5;
    recordTypeId6;
 
 
    recordTypes = [
        { label: 'NTC/TTC(不用)', value:'2'},
        { label: 'OPD', value: '3'},
        { label: 'SIS-ENG', value: '4' },
        { label: 'SIS-ET', value: '5' },
        { label: 'VOC', value: '6' },
        { label: '售后服务跟台', value: '1'},
        { label: '新品装机培训', value: '7'},
        { label: '故障预防培训', value: '8'},
        // 其他记录类型选项...
    ];
 
 
    handleChange(event) {
        this.selectedRecordTypeId = event.detail.value;
    }
 
    @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(res=>{
            // this.showIsLoading=true;
            console.log(this.recordId);
            this.OPDPlan=res;
            this.oppids=this.OPDPlan.Related_Opportunity1_ID__c
            console.log(this.oppids);
            console.log('123123123');
            console.log(this.OPDPlan);
            this.reportSubmit().then(res=>{
                console.log('123');
            }).catch(error=>{
                console.log(error);
            });
        })
    }
 
    async reportSubmit(){
        var Status = this.OPDPlan.Status__c;
        if(Status == '取消' || Status == '完毕' ){
            this.dispatchEvent(event1);
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        this.showElement = true;
        // this.showIsLoading=false;
        var status1=this.OPDPlan.Rental_Apply2_Status_New__c;
        var status2=this.OPDPlan.Rental_Apply1_Status_New__c;
        var status3=this.OPDPlan.Rental_Apply3_Status_New__c;
        var status4=this.OPDPlan.Rental_Apply4_Status_New__c;
        var status5=this.OPDPlan.Rental_Apply5_Status_New__c;
        if(status1 != "已出库" && status1 != "申请者已收货" && status1 != "医院已装机确认" 
            && status1 != "已回寄" && status1 != "已回收" && status1 != "完了" 
            && status1 != "欠品中" && status2 != "已出库" && status2 != "申请者已收货" 
            && status2 != "医院已装机确认" && status2 != "已回寄" && status2 != "已回收" 
            && status2 != "完了" && status2 != "欠品中" && status3 != "已出库" 
            && status3 != "申请者已收货" && status3 != "医院已装机确认" && status3 != "已回寄" 
            && status3 != "已回收" && status3 != "完了" && status3 != "欠品中" 
            && status4 != "已出库" && status4 != "申请者已收货" && status4 != "医院已装机确认" 
            && status4 != "已回寄" && status4 != "已回收" && status4 != "完了" 
            && status4 != "欠品中" && status5 != "已出库" && status5 != "申请者已收货" 
            && status5 != "医院已装机确认" && status5 != "已回寄" && status5 != "已回收" 
            && status5 != "完了" && status5 != "欠品中"){
            this.dispatchEvent(event2);
            this.dispatchEvent(new CloseActionScreenEvent());
            return;
        }
        this.recordTypeId1 = await getRecordTypeByNameAndSobject({Name : '售后服务跟台',SobjectType : 'Report__c'});
        this.recordTypeId2 = await getRecordTypeByNameAndSobject({Name : 'NTC/TTC(不用)',SobjectType : 'Report__c'});
        this.recordTypeId3 = await getRecordTypeByNameAndSobject({Name : 'OPD',SobjectType : 'Report__c'});
        this.recordTypeId4 = await getRecordTypeByNameAndSobject({Name : 'SIS-ENG',SobjectType : 'Report__c'});
        this.recordTypeId5 = await getRecordTypeByNameAndSobject({Name : 'SIS-ET',SobjectType : 'Report__c'});
        this.recordTypeId6 = await getRecordTypeByNameAndSobject({Name : 'VOC',SobjectType : 'Report__c'});
        this.recordTypeId7 = await getRecordTypeByNameAndSobject({Name : '新品装机培训',SobjectType : 'Report__c'});
        this.recordTypeId8 = await getRecordTypeByNameAndSobject({Name : '故障预防培训',SobjectType : 'Report__c'});
    }
 
 
    doNotGoPage(){
        this.dispatchEvent(new CloseActionScreenEvent());
    }
 
    goPage(){
        if(this.selectedRecordTypeId == '1'){
            this.selectedRecordTypeId = this.recordTypeId1;
        }
        else if(this.selectedRecordTypeId == '2'){
            this.selectedRecordTypeId = this.recordTypeId2;
        }
        else if(this.selectedRecordTypeId == '3'){
            this.selectedRecordTypeId = this.recordTypeId3;
        }
        else if(this.selectedRecordTypeId == '4'){
            this.selectedRecordTypeId = this.recordTypeId4;
        }
        else if(this.selectedRecordTypeId == '5'){
            this.selectedRecordTypeId = this.recordTypeId5;
        }
        else if(this.selectedRecordTypeId == '6'){
            this.selectedRecordTypeId = this.recordTypeId6;
        }
        else if(this.selectedRecordTypeId == '7'){
            this.selectedRecordTypeId = this.recordTypeId7;
        }
        else if(this.selectedRecordTypeId == '8'){
            this.selectedRecordTypeId = this.recordTypeId8;
        }        
 
        if(""!=this.oppids && null!=this.oppids){
            const defaultValues = encodeDefaultFieldValues({
                   Opportunity1__c: this.OPDPlan.Related_Opportunity1_ID__c,
                Opportunity2__c: this.OPDPlan.Related_Opportunity2_ID__c,
                Opportunity_Situation__c : '跟进询价' ,
                Hospital_Department__c :  this.OPDPlan.Account_Laboratory__c,
                Department_Class_Ref__c : this.OPDPlan.OCM_category_ID__c ,
                Hospital_Reference__c : this.OPDPlan.HospitalID__c,
                Loaner_request_no1__c : this.OPDPlan.Rental_Apply2__c,
                Report_OPDPlan__c : this.OPDPlan.Id
               });
            this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Report__c',
                actionName: 'new'
            },
            state: {
                // nooverride: '1',
                defaultFieldValues: defaultValues,
                recordTypeId : this.selectedRecordTypeId
            }
            });    
            return;        
        }
        var Activity_Type = this.OPDPlan.Activity_Type2__c;
        const defaultValues = encodeDefaultFieldValues({
            Hospital_Department__c :  this.OPDPlan.Account_Laboratory__c,
            Department_Class_Ref__c : this.OPDPlan.OCM_category_ID__c ,
            Hospital_Reference__c : this.OPDPlan.HospitalID__c,
            Loaner_request_no1__c : this.OPDPlan.Rental_Apply2__c,
            Report_OPDPlan__c : this.OPDPlan.Id
         });
         this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: 'Report__c',
                actionName: 'new'
            },
            state: {
                // nooverride: '1',
                defaultFieldValues: defaultValues ,
                recordTypeId : this.selectedRecordTypeId
            }
        });    
    }
 
}