import { EMPTY, of } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { LookupGridResult, PickingResult } from '../lookup-grid-options'; /** 检查帮助输入框值变化后返回的查询结果 */ function checkSearchResult(data = null) { if (this.searchOnServer) { // this._searchResult = data; // this.showDialog(); this.isShow = true; } else { this.setModelValue(this.displayText); this.runDictPickedEvent(null); } } export function onTextChanged() { const self = this; const isPending = () => { return this.lookupUtils.rts.getFormState('lookup.pending'); }; const searchData = (e) => { if (this.isTextChange && this.displayText && (!this.nosearch || e.originalEvent) && !isPending()) { this.lookupUtils.pendingStart(); this.dictPickingSubscription = this.dictPicking({ instance: this }).pipe( switchMap((pr: PickingResult) => { let o = true; if (pr === undefined || pr === null) { o = true; } if (typeof pr === 'boolean') { o = pr; } if (typeof pr === 'object') { if (pr.showDialog === undefined) { o = true; } else { o = pr.showDialog; } if (pr.data) { /** 保存帮助前传递的数据 */ this.customData = pr.data; } } if (o) { return this.httpMgr.getData( { search: { field: '*', value: this.displayText } }, 'search' ); } else { return of({ SHOWDIALOG: o, MESSAGE: pr.message || '' }); } }) ).subscribe( (data: any) => { this.closeLoading(); this.lookupUtils.pendingEnd(); if (data.hasOwnProperty('SHOWDIALOG')) { if (data.SHOWDIALOG && data.MESSAGE) { this.notifyService.warning(data.MESSAGE); } return; } if (data.items && data.items.length === 1) { let rowdata = data.items[0]; if (this.isTree()) { const leafNode = this.treeNodeHelper.getLeafNode(rowdata); if (Array.isArray(leafNode)) { checkSearchResult.bind(self, data)(); return; } else { rowdata = leafNode.data; } } if (!this.singleSelect) { rowdata = [ rowdata ]; } this.selectItem(rowdata); } else { checkSearchResult.bind(self, data)(); } }, (err: any) => { this.closeLoading(); this.lookupUtils.pendingEnd(); this.messagerService.error(err ? err.Message : err); } ); } }; let inputBlurHandler = null; if (this.inputGroup && this.inputGroup.textbox && !this.nosearch) { this.lookupUtils.setActiveLookupInstance(this); inputBlurHandler = this.render2.listen(this.inputGroup.textbox.nativeElement, 'blur', searchData ); } if (this.inputGroup) { this.inputGroup.enterHandle.subscribe( searchData); this.inputGroup.keydownHandle.subscribe((e: any) => { let canOpen = false; if (e.code === 'ArrowRight') { if (this.editable) { canOpen = !e.target.value || e.target.selectionStart === e.target.value.length; } else { canOpen = true; } } else { canOpen = e.code === this.shortcutKey.open; } if (canOpen) { e.stopPropagation(); e.preventDefault(); this.showDialog(); } }); } return inputBlurHandler; }