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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import lookUp from '@salesforce/apex/otherLookUp.lookUp';
import getRecordForLwc from '@salesforce/apex/ControllerUtil.getRecordForLwc';
import { getRecord } from 'lightning/uiRecordApi';
import { NavigationMixin } from 'lightning/navigation';
import { api, LightningElement, track, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
 
export default class OtherLookUp extends NavigationMixin(LightningElement) {
    AWSService;
    @track theContact = {};
    @track showModal = false;
    //记录id
    @api valueId;
    @api objName;
    @api visitPlaceId ='';
    @api iconName;
    @api disabled;
    @api filter = '';
    @api uniqueKey;
    @api fields;
    @api searchLabel;
    @track searchTerm;
    @track valueObj;
    @track href;
    @track options;
    //是否展示pill
    @track isValue = false;
    isCanCanle = true;
    @track blurTimeout;
    isOpen = false;
    get boxClass() {
        let classes = "slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus";
        if (this.isOpen) {
            return classes + " slds-is-open";
        }
        return classes;
    }
    _passFilter;
    @api
    get passFilter() {
        return this._passFilter;
    }
 
    set passFilter(newValue) {
        this._passFilter = newValue;
        this.filter = newValue;
    }
    @track inputClass = '';
 
    @wire(lookUp, { searchTerm: '$searchTerm', objName: '$objName', filter: '$filter',visitPlaceId:'$visitPlaceId'})
    wiredRecords({ error, data }) {
        console.log('searchTerm = '+ this.searchTerm);
        console.log('objName = '+ this.objName);
        console.log('filter = '+ this.filter);
        console.log('visitPlaceId,'+this.visitPlaceId);
 
        if(this.visitPlaceId) {
            console.log('lookUp,visitPlaceId,'+this.visitPlaceId);
        }
        
        if (data) {
            this.record = data;
            this.error = undefined;
            this.options = this.record;
            console.log("common this.options", JSON.stringify(this.options));
        } else if (error) {
            this.error = error;
            this.record = undefined;
            console.log("wire.error",this.error);
        }
 
        
    }
 
    //To get preselected or selected record
    // @wire(getRecord, { recordId: '$valueId', fields: '$fields' })
    //  wiredOptions({ error, data }) {
    //     console.log('otherlookup wiredOptions:recordId:'+this.valueId);
    //     if(this.visitPlaceId) {
    //         console.log('getRecord,visitPlaceId,'+this.visitPlaceId);
    //     }
        
    //     console.log('getRecord start:');
    //     if (data) {
    //         console.log('execute1');
    //         this.record = data;
    //         this.error = undefined;
    //         this.valueObj = this.record.fields.Name.value;
    //         this.href = '/'+this.record.id;
    //         this.isValue = true;
    //         let selectedId = this.record.id;
    //         let selectedName = this.valueObj;
    //         let key = this.uniqueKey;
 
    //         console.log("this.href", this.href);
    //         console.log("this.record", JSON.stringify(this.record));
          
    //     } else if (error) {
    //         console.log('execute2');
    //         this.error = error;
    //         this.record = undefined;
    //         console.log("this.error", this.error);
    //     }
    // }
 
    @wire(getRecordForLwc, { recordId: '$valueId', fields: '$fields' })
     wiredOptions({ error, data }) {
        if(!this.valueId) {
            return;
        }
        console.log('otherlookup wiredOptions:recordId:'+this.valueId);
        if(this.visitPlaceId) {
            console.log('getRecord,visitPlaceId,'+this.visitPlaceId);
        }
        
        console.log('getRecord start:');
        console.log('getRecord start:fields' +this.fields);
        if (data) {
            console.log('execute1');
            this.record = data;
            this.error = undefined;
            this.valueObj = this.record.Name;
            this.href = '/'+this.record.Id;
            this.isValue = true;
            let selectedId = this.record.Id;
            let selectedName = this.valueObj;
            let key = this.uniqueKey;
 
            console.log("this.href", this.href);
            console.log("this.record", JSON.stringify(this.record));
          
        } else if (error) {
            console.log('execute2');
            this.error = error;
            this.record = undefined;
            console.log("this.error", this.error);
        }
    }
    renderedCallback(){
        console.log('otherlookup renderedCallback:recordId:'+this.valueId);
        console.log('otherlookup renderedCallback');
        if(this.disabled) {
            const allInputsAndButtons = this.template.querySelectorAll('button');
           
            allInputsAndButtons.forEach(element => {
                console.log('---------zzzz-------')
                console.log(element);
                // if(!element.id.includes('cancleApply')) {
                    element.variant = "plain";
                // } 
            });
        }
    }
    handleClick() {
        console.log("In handleClick");
        if(this.disabled){
            return;
        }
        this.searchTerm = '';
        this.inputClass = 'slds-has-focus';
        this.isOpen = true;
        //deloitte-zhj refresh wiredRecords start 
        this.searchTerm = 'refresh';
        this.searchTerm = '';
        refreshApex(this.wiredRecords);
        //deloitte-zhj refresh wiredRecords end
        // this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus slds-is-open';
    }
 
    onSelect(event) {
        
        console.log("In onSelect");
        let ele = event.currentTarget;
        let selectedId = ele.dataset.id;
        let selectedName = this.valueObj;
        let key = this.uniqueKey;
        console.log("key = " + key);
        console.log("selectedId = " + selectedId);
      
        const valueSelectedEvent = new CustomEvent('valueselect', {
            detail: { selectedId, key },
        });
        this.dispatchEvent(valueSelectedEvent);
        this.isOpen = false;
        // this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus';
    }
 
    searchChange(event) {
        this.searchTerm = event.target.value;
    }
 
    onBlur() {
        if (!this.isCanCanle) {
            return;
        }
        this.isOpen = false;
        // this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus';
    }
    onHover() {
        // alert(this.disabled);
    }
    @api
    handleRemovePill() {
        console.log("In handleRemovePill");
        if(this.disabled){
            return;
        }
        this.isValue = false;
        let selectedId = '';
        let key = this.uniqueKey;
        const valueSelectedEvent = new CustomEvent('valueselect', {
            detail: { selectedId, key },
        });
        this.dispatchEvent(valueSelectedEvent);
    }
    closeModal() {
        console.log('closeModal');
        this.showModal = false;
    }
    handleMouseleave() {
        this.isCanCanle = true;
    }
    handleMouseenter(event) {
        this.isCanCanle = false;
    }
    stringIsEmpty(str) {
        if (str === '' || str === undefined || str === null) {
            return true;
        } else {
            return false;
        }
    }
    showToast(variant, mes) {
        const event = new ShowToastEvent({
            message: mes,
            variant: variant,
        });
        this.dispatchEvent(event);
    }
}