index.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. if(!val && type == 15){
  77. this.setState({
  78. data: [],
  79. inpVal: ''
  80. });
  81. this.handleSelect({ name: '', uniqueName: '' }, this.props.idx);
  82. return
  83. }
  84. axios.json('/demo/retrieval/index', {
  85. "inputStr": val,
  86. "type": type,
  87. "hospitalId": hosId,
  88. "defaultList":type==15?0:1
  89. }).then((res) => {
  90. if (res.data.code == 0) {
  91. const data = res.data.data;
  92. this.setState({
  93. data: data.nameList || [],
  94. show: true,
  95. })
  96. } else {
  97. Notify.success(res.data.msg)
  98. }
  99. })
  100. };
  101. render() {
  102. const { idx, title, selected } = this.props;
  103. const { show, data, inpVal } = this.state;
  104. return (
  105. <div className={styles.medType}>
  106. <input placeholder={title} value={selected} title={selected} className={styles.inpSearch} onFocus={(e) => this.handleFocu(e)} onInput={(e) => this.handleChange(e)} />
  107. <img className={show?styles.up:styles.down} src={down} alt="" onClick={this.confirm}/>
  108. {inpVal? <img className={styles.clear} src={del} alt="清空" onClick={(e) => this.handleChange(e, true)} /> : ''}
  109. {
  110. show ? <ul className={styles.selectLis}>
  111. {
  112. data && data.map((part) => {
  113. return <li title={part.name} onClick={() => this.handleSelect(part, idx)}>{part.name}</li>
  114. })
  115. }
  116. </ul> : ''
  117. }
  118. </div>
  119. );
  120. }
  121. }
  122. export default SearchSelect;