forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.7 KiB
96 lines
2.7 KiB
import { shortcut, Widget, Func, createWidget, bind, each, makeObject, filter, delay } from "@/core"; |
|
import { Msg } from "@/base"; |
|
|
|
@shortcut() |
|
export class MultiSelectCombo extends Widget { |
|
static xtype = "demo.multi_select_combo"; |
|
|
|
props = { baseCls: "demo-multi-select-combo" }; |
|
|
|
_createMultiSelectCombo() { |
|
const self = this; |
|
const widget = createWidget({ |
|
type: "bi.multi_select_insert_combo", |
|
// allowEdit: false, |
|
itemsCreator: bind(this._itemsCreator, this), |
|
width: 200, |
|
value: { |
|
type: 1, |
|
value: [ |
|
"柳州市城贸金属材料有限责任公司", |
|
"柳州市建福房屋租赁有限公司", |
|
"柳州市迅昌数码办公设备有限责任公司" |
|
], |
|
}, |
|
}); |
|
|
|
widget.on(MultiSelectCombo.EVENT_CONFIRM, function () { |
|
Msg.toast(JSON.stringify(this.getValue())); |
|
}); |
|
|
|
return widget; |
|
} |
|
|
|
_getItemsByTimes(items, times) { |
|
const res = []; |
|
for (let i = (times - 1) * 100; items[i] && i < times * 100; i++) { |
|
res.push(items[i]); |
|
} |
|
|
|
return res; |
|
} |
|
|
|
_hasNextByTimes(items, times) { |
|
return times * 100 < items.length; |
|
} |
|
|
|
_itemsCreator(options, callback) { |
|
const self = this; |
|
let items = Demo.CONSTANTS.ITEMS; |
|
const keywords = (options.keywords || []).slice(); |
|
if (options.keyword) { |
|
keywords.push(options.keyword); |
|
} |
|
each(keywords, (i, kw) => { |
|
const search = Func.getSearchResult(items, kw); |
|
items = search.match.concat(search.find); |
|
}); |
|
if (options.selectedValues) { |
|
// 过滤 |
|
const filter = makeObject(options.selectedValues, true); |
|
items = filter(items, (i, ob) => !filter[ob.value]); |
|
} |
|
if (options.type == MultiSelectCombo.REQ_GET_ALL_DATA) { |
|
callback({ |
|
items, |
|
}); |
|
|
|
return; |
|
} |
|
if (options.type == MultiSelectCombo.REQ_GET_DATA_LENGTH) { |
|
callback({ count: items.length }); |
|
|
|
return; |
|
} |
|
delay(() => { |
|
callback({ |
|
items: self._getItemsByTimes(items, options.times), |
|
hasNext: self._hasNextByTimes(items, options.times), |
|
}); |
|
}, 1000); |
|
} |
|
|
|
render() { |
|
return { |
|
type: "bi.absolute", |
|
scrolly: false, |
|
items: [ |
|
{ |
|
el: this._createMultiSelectCombo(), |
|
right: "50%", |
|
top: 10, |
|
} |
|
], |
|
}; |
|
} |
|
}
|
|
|