19626
2023-07-12 fbd4bea7bd57b4d4a33cb9ed0ebc15d9bf6551c0
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
/*
 * @Description: 
 * @version: 
 * @Author: chen jing wu
 * @Date: 2023-06-09 16:41:45
 * @LastEditors: chen jing wu
 * @LastEditTime: 2023-07-06 09:34:39
 */
import { LightningElement,api, track, wire } 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/ReportController.initForOPDReportConsumButton';
 
export default class LexOPDReportConsum extends NavigationMixin(LightningElement) {
    @api recordId;
    raStatus;
    productCategory;
    hospital;
    strategicDept;
    account;
    consumApplyId;
    recordTypeId;
    recordTypeId1;
    msg;
    Isloading = true;
 
    @wire(CurrentPageReference)
    getStateParameters(currentPageReference) {
            console.log(111);
            console.log(currentPageReference);
 
        if (currentPageReference) {
          const urlValue = currentPageReference.state.recordId;
          if (urlValue) {
            let str = `${urlValue}`;
            console.log("str");
            console.log(str);
            this.recordId = str;
          }
        }
    }
    showToast(msg,type) {
        const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
        });
        this.dispatchEvent(event);
        this.dispatchEvent(new CloseActionScreenEvent());
    }
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
 
    connectedCallback(){
        init({
            recordId: this.recordId
        }).then(result=>{
            this.raStatus = result.raStatus;
            this.productCategory = result.productCategory;
            this.hospital = result.hospital;
            this.strategicDept = result.strategicDept;
            this.account = result.account;
            this.consumApplyId = result.consumApplyId;   
            this.recordTypeId = result.recordTypeId;
            this.recordTypeId1 = result.recordTypeId1;
            this.OPDReportConsum();
        });
    }
 
    OPDReportConsum(){
        var status = this.raStatus;
        if(status != "已出库" && status != "申请者已收货" && status != "待消耗" && status != "已回寄" && status != "完了"){
            this.msg = "耗材借出状态:" + status + ",不能创建报告书!";
            this.showToast(this.msg,'error');
            return;
        }
        var Product_category = this.productCategory;
        var strs ;
        var url
        if(Product_category =='ET'){
            const defaultValues = encodeDefaultFieldValues({
                Consum_Apply__c: this.recordId, // 关联主记录 ID
                Hospital_Reference__c: this.hospital,
                Department_Class_Ref__c: this.strategicDept,
                Hospital_Department__c: this.account
            });
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'Report__c',
                    actionName: 'new'
                },
                state: {
                    nooverride: '1',
                    defaultFieldValues: defaultValues,
                    recordTypeId: this.recordTypeId
                }
            });
        }else if(Product_category =='DISP'){
            const defaultValues = encodeDefaultFieldValues({
                Consum_Apply__c: this.recordId, // 关联主记录 ID
                Hospital_Reference__c: this.hospital,
                Department_Class_Ref__c: this.strategicDept,
                Hospital_Department__c: this.account
            });
            this[NavigationMixin.Navigate]({
                type: 'standard__objectPage',
                attributes: {
                    objectApiName: 'Report__c',
                    actionName: 'new'
                },
                state: {
                    nooverride: '1',
                    defaultFieldValues: defaultValues,
                    recordTypeId: this.recordTypeId1
                }
            });
        }
    }
}