liuyn
2024-03-22 e8be4d964c6b336ed39dba5900b1b9a8f3181b96
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
import lookUp from '@salesforce/apex/otherLookUpEvent.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 OtherLookUpEvent 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 }) {
        if(this.visitPlaceId) {
            console.log('lookUp,visitPlaceId,'+this.visitPlaceId);
        }
        
        if (data) {
            this.record = data;
            this.error = undefined;
            this.options = this.record;
        } else if (error) {
            this.error = error;
            this.record = undefined;
            console.log("wire.error",this.error);
        }
    }
 
    @wire(getRecordForLwc, { recordId: '$valueId', fields: '$fields' })
     wiredOptions({ error, data }) {
        if(!this.valueId) {
            return;
        }
        if(this.visitPlaceId) {
            console.log('getRecord,visitPlaceId,'+this.visitPlaceId);
        }
        console.log('this.disabled---------' + this.disabled);
        if (data) {
            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;
          
        } else if (error) {
            this.error = error;
            this.record = undefined;
            console.log("this.error", this.error);
        }
    }
    renderedCallback(){
        if(this.disabled) {
            const allInputsAndButtons = this.template.querySelectorAll('button');
           
            allInputsAndButtons.forEach(element => {
                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;
        this.searchTerm = 'refresh';
        this.searchTerm = '';
        refreshApex(this.wiredRecords);
    }
 
    onSelect(event) {
        
        let ele = event.currentTarget;
        let selectedId = ele.dataset.id;
        let selectedName = this.valueObj;
        let key = this.uniqueKey;
      
        const valueSelectedEvent = new CustomEvent('valueselect', {
            detail: { selectedId, key },
        });
        this.dispatchEvent(valueSelectedEvent);
        this.isOpen = false;
    }
 
    searchChange(event) {
        this.searchTerm = event.target.value;
    }
 
    onBlur() {
        if (!this.isCanCanle) {
            return;
        }
        this.isOpen = false;
    }
    onHover() {
    }
    @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);
    }
}