index.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import React, { Component } from "react";
  2. import axios from '@utils/ajax';
  3. import styles from "./index.less";
  4. import { Notify, DelToast } from '@commonComp';
  5. import $ from 'jquery';
  6. import down from '../img/down.png';
  7. import del from '../img/close.png';
  8. class SearchSelect extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. show: false,
  13. data: [],
  14. inpVal: ''
  15. };
  16. this.handleBlur = this.handleBlur.bind(this);
  17. this.getDrugWayList = this.getDrugWayList.bind(this);
  18. this.confirm = this.confirm.bind(this);
  19. }
  20. componentDidMount() {
  21. //关闭下拉弹窗
  22. $(document).click((event) => {
  23. const domClass = $(event.target).attr("class") || '';
  24. if (domClass.indexOf(styles.selectLis) === -1 && domClass.indexOf(styles.inpSearch) === -1) {
  25. this.setState({
  26. show: false
  27. })
  28. }
  29. });
  30. }
  31. handleBlur() {
  32. const { handlePush } = this.props;
  33. handlePush && handlePush({ mode: 8 }); //右侧推送
  34. }
  35. handleFocus() {
  36. const { handlePush } = this.props;
  37. handlePush && handlePush({ mode: 8 });
  38. }
  39. handleSelect(part, idx) {
  40. const { selectJiType, handlePush, type, hosId } = this.props;
  41. const item = Object.assign(part, { uniqueName: hosId === -1 ? part.name : undefined }); //朗通的需要传uniqueName
  42. selectJiType(item, idx, type)
  43. handlePush && handlePush({ mode: 8 });
  44. this.setState({
  45. inpVal: part.name,
  46. });
  47. }
  48. handleFocu(e){
  49. const val = e.target.value;
  50. this.getDrugWayList(val)
  51. }
  52. handleChange(e, isClear) {
  53. const val = e.target.value;
  54. if (isClear || !val) {
  55. this.setState({
  56. data: [],
  57. inpVal: ''
  58. });
  59. this.handleSelect({ name: '', uniqueName: '' }, this.props.idx);
  60. }
  61. this.setState({
  62. show: true,
  63. inpVal: val,
  64. });
  65. //搜索
  66. this.getDrugWayList(val)
  67. }
  68. confirm(){
  69. let val = this.state.inpVal
  70. console.log(this.state);
  71. this.getDrugWayList(val)
  72. }
  73. //获取药品剂型15,、给药途径16
  74. getDrugWayList(val) {
  75. const { hosId, type } = this.props;
  76. axios.json('/demo/retrieval/index', {
  77. "inputStr": val,
  78. "type": type,
  79. "hospitalId": hosId,
  80. "defaultList":1
  81. }).then((res) => {
  82. if (res.data.code == 0) {
  83. const data = res.data.data;
  84. this.setState({
  85. data: data.nameList || [],
  86. show: true,
  87. })
  88. } else {
  89. Notify.success(res.data.msg)
  90. }
  91. })
  92. };
  93. render() {
  94. const { idx, title, selected } = this.props;
  95. const { show, data, inpVal } = this.state;
  96. return (
  97. <div className={styles.medType}>
  98. <input placeholder={title} value={selected} title={selected} className={styles.inpSearch} onFocus={(e) => this.handleFocu(e)} onInput={(e) => this.handleChange(e)} />
  99. <img className={show?styles.up:styles.down} src={down} alt="" onClick={this.confirm}/>
  100. {inpVal? <img className={styles.clear} src={del} alt="清空" onClick={(e) => this.handleChange(e, true)} /> : ''}
  101. {
  102. show ? <ul className={styles.selectLis}>
  103. {
  104. data && data.map((part) => {
  105. return <li title={part.name} onClick={() => this.handleSelect(part, idx)}>{part.name}</li>
  106. })
  107. }
  108. </ul> : ''
  109. }
  110. </div>
  111. );
  112. }
  113. }
  114. export default SearchSelect;