buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
import { LightningElement ,api, track, wire } from 'lwc';
 
import { CurrentPageReference } from "lightning/navigation";
import { getRecord } from 'lightning/uiRecordApi';
import USER_ID from '@salesforce/user/Id';
import USERPROFILE_ID from '@salesforce/schema/User.ProfileId';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import init from'@salesforce/apex/LexNoReportApplicationController.initGetOpdData';
import getProfileIdByName from'@salesforce/apex/LexNoReportApplicationController.getProfileIdByName';
import { CloseActionScreenEvent } from 'lightning/actions';
 
 const event = new ShowToastEvent({
            title: '检查状态',
            message:
                '只有状态为待提交报告的OPD计划才能进行无报告申请',
        });
export default class lexNoReportApplication extends LightningElement {
 
 
    @api recordId;
 
 
    OPDPlan__c;
    currentUserProfileId;
    error;
    NotSupportProfileId;
 
 
 
 
    @wire(getRecord, { recordId: USER_ID, fields: [USERPROFILE_ID]}) 
         userDetails({error, data}) {
            console.log('222');
            if (data) {
                this.currentUserProfileId = data.fields.ProfileId.value;
                console.log(this.currentUserProfileId);
               
            } else if (error) {
                this.error = error ;
            }
    }
 
    @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;
 
           }
         }
     }
 
    
 
    async connectedCallback(){
        console.log('333');
       await init({
            recordId: this.recordId
        }).then(result=>{
            this.OPDPlan__c=result;
            this.NoReportApplication();
        }).catch(error=>{
            console.log("error");
            console.log(error);
        });
    }
 
 
 
    async NoReportApplication() {
 
    
    //OPD计划状态
    var status = this.OPDPlan__c.Status__c;
    console.log('status:'+this.OPDPlan__c.Status__c);
    console.log('ProfileId');
    console.log(this.currentUserProfileId);
    this.NotSupportProfileId= await getProfileIdByName({Name : "系统管理员"});
    //当前用户简档id
    var ProfileId = this.currentUserProfileId;
    console.log('不支持的简档Id'+this.NotSupportProfileId);
    //跳过系统管理员
    if(status !='待提交报告'&& ProfileId != this.NotSupportProfileId){
        this.dispatchEvent(new CloseActionScreenEvent());
        this.dispatchEvent(event);    
         
        return;
    }
    else{
        this.dispatchEvent(new CloseActionScreenEvent());
        window.open ('/apex/OPDNoReportApplication?id='+this.OPDPlan__c.Id+'&name='+this.OPDPlan__c.Name, '无报告申请',
        'height=400, width=700, top=200, left=400, toolbar=no, menubar=no, scrollbars=no, location=no, status=no');
    
    }
    }
 
}