index.jsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React,{Component} from "react";
  2. import {AutoComplete, Input, message, Select} from "antd";
  3. import $ from "jquery/src/ajax";
  4. class StaffSearch extends Component{
  5. constructor(props) {
  6. super(props);
  7. this.state={
  8. superior:'',
  9. customerArr:[],
  10. loading:false,
  11. }
  12. this.httpChange = this.httpChange.bind(this);
  13. this.supervisor = this.supervisor.bind(this);
  14. this.selectAuto = this.selectAuto.bind(this);
  15. }
  16. httpChange(e){
  17. if(e.length>=1){
  18. this.supervisor(e);
  19. }
  20. this.setState({
  21. superior:e
  22. })
  23. }
  24. supervisor(e){
  25. this.setState({
  26. loading: true
  27. });
  28. $.ajax({
  29. method: "post",
  30. dataType: "json",
  31. crossDomain: false,
  32. url: globalConfig.context + "/api/admin/organization/selectName",
  33. data:{
  34. name:e
  35. },
  36. success: function (data) {
  37. if(data.error.length === 0){
  38. this.setState({
  39. customerArr:data.data,
  40. });
  41. }else{
  42. message.error(data.error[0].message)
  43. }
  44. }.bind(this),
  45. }).always(function () {
  46. this.setState({
  47. loading: false
  48. });
  49. }.bind(this));
  50. }
  51. selectAuto(value){
  52. let theType='';
  53. let contactLists=this.state.customerArr||[];
  54. if (value) {
  55. contactLists.map(function (item) {
  56. if (item.name == value.toString()) {
  57. theType = item.id;
  58. }
  59. });
  60. }
  61. this.setState({
  62. superior:value
  63. })
  64. this.props.onBlurChange({title:value,value:theType});
  65. }
  66. render() {
  67. const options = this.state.customerArr.map((group,index) =>
  68. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  69. )
  70. return (
  71. <AutoComplete
  72. className="certain-category-search"
  73. dropdownClassName="certain-category-search-dropdown"
  74. dropdownMatchSelectWidth={false}
  75. size="large"
  76. style={{ width: '200px' }}
  77. dataSource={options}
  78. placeholder={this.props.placeholder}
  79. value={this.state.superior ? this.state.superior : this.props.valueName}
  80. onChange={this.httpChange}
  81. filterOption={true}
  82. onSelect={this.selectAuto}
  83. >
  84. <Input/>
  85. </AutoComplete>
  86. )
  87. }
  88. }
  89. export default StaffSearch;