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
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
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/LexMeetingCostsController.init';
import judgeMember  from '@salesforce/apex/LexMeetingCostsController.judgeMumber';
import getProfileIdByName  from '@salesforce/apex/LexMeetingCostsController.getProfileIdByName';
 
  // author: kkbes
 
  const event = new ShowToastEvent({
            title: '权限不足',
            message:
                '无权查看会议费用情况',
        });
export default class lexMeetingCosts extends LightningElement {
 
    @api recordId;
    Campaign;
    IsLoading = true;
    userId = USER_ID;
    currentUserProfileId;
    NotSupportProfileId;
 
    @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;
          }
        }
    }
 
     @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 ;
            }
    }
 
 
 
    connectedCallback(){
        console.log(this.recordId);
        init({
            recordId: this.recordId
        }).then(result => {
            console.log(result);
            if (result != null) {
                this.Campaign = result;
                console.log(this.Campaign);
                console.log(this.userId);
                this.MeetingCosts();
            }
        }).catch(error => {
            console.log("error");
            console.log(error);
        });
 
    }
 
 
 
    async MeetingCosts(){
 
        var logUser = this.userId;
 
        var records = await judgeMember({ UserId : this.userId});
 
        var ProfileId= await getProfileIdByName({Name : "系统管理员"}); 
 
        console.log('scscscsccsc');
        console.log(records);
        console.log(ProfileId);
 
 
        if(records.length>0 && this.Campaign.Sponsor_Ones_Post__c == '1.华北'){
        console.log('if');
        window.open("/apex/CampaignMeetingcost?id=" + this.Campaign.Id ,'CampaignMember','height=500,width=950');
        }
        else if (logUser == this.Campaign.OwnerId 
            || logUser == this.Campaign.JingliApprovalManager__c 
            || logUser == this.Campaign.BuchangApprovalManager__c 
            || logUser == this.Campaign.ZongjianApprovalManager__c  
            || this.currentUserProfileId == ProfileId){
        console.log('else if');
        window.open("/apex/CampaignMeetingcost?id=" + this.Campaign.Id ,'CampaignMember','height=500,width=950');
        }
        else {
        this.dispatchEvent(event);
        return;
        }
 
    }
 
 
 
 
 
}
 
 
 
// old  js
// {!RequireScript("/soap/ajax/51.0/connection.js")}
// {!RequireScript("/soap/ajax/51.0/apex.js")}
// {!RequireScript("/resource/CommonUtilJs")}
// var foo = function(){
// var logUser = "{!$User.Id}";
// var owner = "{!Campaign.OwnerId}";
// var Jingli = "{!Campaign.JingliApprovalManagerId__c}";
// var Buchang = "{!Campaign.BuchangApprovalManagerId__c}";
// var Zongjian = "{!Campaign.ZongjianApprovalManagerId__c}";
// var Sponsor = "{!Campaign.Sponsor_Ones_Post__c}";
 
 
// //判断是否是 00 华北市场费用共享组成员
// var myquery = "SELECT Id FROM groupmember WHERE group.developername = 'X00_Meetingfee_Huabei' and userorgroupid = '{!$User.Id}'";
// sqlResult = sforce.connection.query(myquery);
// records = sqlResult.getArray("records");
// if(records.length>0 && Sponsor == '1.华北'){
// window.open("/apex/CampaignMeetingcost?id=" + '{!Campaign.Id}' ,'CampaignMember','height=500,width=950');
// }else if (logUser == owner || logUser == Jingli || logUser == Buchang || logUser == Zongjian || "{!$User.ProfileId}" == '00e10000000Y3o5'){
// window.open("/apex/CampaignMeetingcost?id=" + '{!Campaign.Id}' ,'CampaignMember','height=500,width=950');
// }else {
// alert("无权查看会议费用情况");
// return;
// }
// };
// foo();