/** * 搜索面板 * * Created by GUY on 2015/9/28. * @class BI.SearcherView * @extends BI.Pane */ import { shortcut } from "../../core/decorator"; @shortcut() export class SearcherView extends BI.Pane { static xtype = "bi.searcher_view"; static EVENT_CHANGE = "EVENT_CHANGE"; _defaultConfig() { const conf = super._defaultConfig(arguments); return BI.extend(conf, { baseCls: (conf.baseCls || "") + " bi-searcher-view bi-card", tipText: BI.i18nText("BI-No_Select"), chooseType: BI.Selection.Single, matcher: { // 完全匹配的构造器 type: "bi.button_group", behaviors: { redmark: ()=> { return true; }, }, items: [], layouts: [{ type: "bi.vertical", }], }, searcher: { type: "bi.button_group", behaviors: { redmark: function () { return true; }, }, items: [], layouts: [{ type: "bi.vertical", }], }, }); } render() { const { matcher, chooseType, value, searcher } = this.options; this.matcher = BI.createWidget(matcher, { type: "bi.button_group", chooseType, behaviors: { redmark: ()=> { return true; }, }, layouts: [{ type: "bi.vertical", }], value, }); this.matcher.on(BI.Controller.EVENT_CHANGE, (type, val, ob)=> { this.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { this.fireEvent(SearcherView.EVENT_CHANGE, val, ob); } }); this.spliter = BI.createWidget({ type: "bi.vertical", height: 1, hgap: 10, items: [{ type: "bi.layout", height: 1, cls: "searcher-view-spliter bi-background", }], }); this.searcher = BI.createWidget(searcher, { type: "bi.button_group", chooseType, behaviors: { redmark: ()=> { return true; }, }, layouts: [{ type: "bi.vertical", }], value, }); this.searcher.on(BI.Controller.EVENT_CHANGE, (type, val, ob)=> { this.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { this.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob); } }); BI.createWidget({ type: "bi.vertical", element: this, items: [this.matcher, this.spliter, this.searcher], }); } startSearch() { } stopSearch() { } setValue(v) { this.matcher.setValue(v); this.searcher.setValue(v); } getValue() { return this.matcher.getValue().concat(this.searcher.getValue()); } populate(searchResult, matchResult, keyword) { searchResult || (searchResult = []); matchResult || (matchResult = []); this.setTipVisible(searchResult.length + matchResult.length === 0); this.spliter.setVisible(BI.isNotEmptyArray(matchResult) && BI.isNotEmptyArray(searchResult)); this.matcher.populate(matchResult, keyword); this.searcher.populate(searchResult, keyword); } empty() { this.searcher.empty(); this.matcher.empty(); } hasMatched() { return this.matcher.getAllButtons().length > 0; } } BI.extend(BI, { SearcherView });