import debounce from 'lodash/debounce';
constructor(props) {
super(props);
this.fetchSku = debounce(this.fetchSku, 1000);
}
fetchSku = val => {
const { dispatch } = this.props;
if (val.length === 0) {
this.setState({
skuList: [],
});
} else {
dispatch({
type: 'customSkus/searchCustomSku',
payload: {
keyword: val,
},
callback: res => {
this.setState({
skuList: res,
});
},
});
}
};
<Select
showSearch
allowClear
filterOption={false}
showArrow={false}
placeholder={
<span>
<Icon type="search" /> 请输入sku进行搜索
</span>
}
notFoundContent={searching ? <Spin size="small" /> : null}
onSearch={this.fetchSku}
style={{ width: '100%', marginBottom: '15px' }}
size="small"
>
{skuList.map(sku => (
<Option
key={sku.id}
value={sku.sku_code}
onClick={() => this.addToSkuArr(sku)}
style={{ width: '100%', borderBottom: '1px solid #eee' }}
>
<div style={{ display: 'flex', fontSize: '12px', width: '350px' }}>
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{sku.sku_code}
</span>
<span style={{ margin: '0 10px', color: '#ccc' }}>|</span>
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
{sku.title}
</span>
</div>
</Option>
))}
</Select>