salary-management-front/pc4mobx/hrmSalary/components/CustomSelect/index.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-09-13 15:22:16 +08:00
/*
* 自定义多选下拉框
* 支持搜索
* @Author: 黎永顺
* @Date: 2024/9/13
* @Wechat:
* @Email: 971387674@qq.com
* @description:
*/
import React, { Component } from "react";
import { WeaLocaleProvider } from "ecCom";
2024-09-13 17:35:14 +08:00
import classNames from "classnames";
2024-09-14 09:55:54 +08:00
import { Select } from "antd";
2024-09-13 15:22:16 +08:00
import "./index.less";
const getLabel = WeaLocaleProvider.getLabel;
2024-09-13 17:35:14 +08:00
const Option = Select.Option;
2024-09-13 15:22:16 +08:00
class Index extends Component {
2024-09-13 17:35:14 +08:00
constructor(props) {
super(props);
this.state = {
2024-09-14 09:55:54 +08:00
visible: false, dropdownWidth: 200, value: props.value || ""
2024-09-13 17:35:14 +08:00
};
this.selectedData = {};
}
componentDidMount() {
const { dropdownWidth } = this.state;
const w = $(this.refs.customSelectMui).outerWidth();
if (dropdownWidth < w) {
this.setState({ dropdownWidth: w });
}
}
2024-09-14 09:55:54 +08:00
handleChange = (value) => {
this.setState({ value });
typeof this.props.onChange == "function" &&
this.props.onChange(`${value}`);
};
2024-09-13 15:22:16 +08:00
render() {
2024-09-14 09:55:54 +08:00
const { dropdownWidth, visible } = this.state;
const { options, defaultValue, value } = this.props;
2024-09-13 17:35:14 +08:00
const clsname = classNames({
"wea-associative-search-mult": true
});
2024-09-14 09:55:54 +08:00
console.log(value);
2024-09-13 15:22:16 +08:00
return (
2024-09-14 09:55:54 +08:00
<div className={`customMuiSelect wea-associative-search ${clsname}`} ref="customSelectMui">
2024-09-13 17:35:14 +08:00
<Select
{...this.props}
hasScroll={false}
hideSelected={true}
transitionName=""
animation=""
multiple={true}
notFoundContent=""
defaultActiveFirstOption={true}
2024-09-14 09:55:54 +08:00
showArrow={true}
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
defaultValue={defaultValue}
value={value}
2024-09-13 17:35:14 +08:00
dropdownStyle={{ minWidth: dropdownWidth }}
onChange={this.handleChange}
2024-09-14 09:55:54 +08:00
onBlur={() => this.setState({ visible: !visible })}
onFocus={() => this.setState({ visible: !visible })}
2024-09-13 17:35:14 +08:00
>
2024-09-14 09:55:54 +08:00
{options.map(d => <Option key={d.id} title={d.name}>{d.name}</Option>)}
2024-09-13 17:35:14 +08:00
</Select>
<div className="ant-input-group-wrap">
2024-09-14 09:55:54 +08:00
{!visible ? <i className="icon-coms-down2 arrow"/> : <i className="icon-coms-up2 arrow"/>}
2024-09-13 17:35:14 +08:00
</div>
2024-09-13 15:22:16 +08:00
</div>
);
}
}
export default Index;