index.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. this.props.onBlurText({ title: e });
  24. if (!e) {
  25. this.props.onBlurChange({ title: e, value: null });
  26. }
  27. }
  28. supervisor(e) {
  29. this.setState({
  30. loading: true
  31. });
  32. $.ajax({
  33. method: "post",
  34. dataType: "json",
  35. crossDomain: false,
  36. url: globalConfig.context + "/api/admin/organization/selectName",
  37. data: {
  38. name: e
  39. },
  40. success: function (data) {
  41. if (data.error.length === 0) {
  42. this.setState({
  43. customerArr: data.data,
  44. });
  45. } else {
  46. message.error(data.error[0].message)
  47. }
  48. }.bind(this),
  49. }).always(function () {
  50. this.setState({
  51. loading: false
  52. });
  53. }.bind(this));
  54. }
  55. selectAuto(value) {
  56. let theType = '';
  57. let contactLists = this.state.customerArr || [];
  58. if (value) {
  59. contactLists.map(function (item) {
  60. if (item.name == value.toString()) {
  61. theType = item.id;
  62. }
  63. });
  64. }
  65. this.setState({
  66. superior: value
  67. })
  68. this.props.onBlurChange({ title: value, value: theType });
  69. }
  70. render() {
  71. const options = this.state.customerArr.map((group, index) =>
  72. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  73. )
  74. return (
  75. <AutoComplete
  76. className="certain-category-search"
  77. dropdownClassName="certain-category-search-dropdown"
  78. dropdownMatchSelectWidth={false}
  79. size="large"
  80. style={{ width: this.props.width || '200px' }}
  81. dataSource={options}
  82. placeholder={this.props.placeholder}
  83. value={this.state.superior ? this.state.superior : this.props.valueName}
  84. onChange={this.httpChange}
  85. filterOption={true}
  86. onSelect={this.selectAuto}
  87. >
  88. <Input />
  89. </AutoComplete>
  90. )
  91. }
  92. }
  93. export default StaffSearch;