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); } }