index.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 dowm 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. }
  19. componentDidMount() {
  20. //关闭下拉弹窗
  21. $(document).click((event) => {
  22. const domClass = $(event.target).attr("class") || '';
  23. if (domClass.indexOf(styles.selectLis) === -1 && domClass.indexOf(styles.inpSearch) === -1) {
  24. this.setState({
  25. show: false
  26. })
  27. }
  28. });
  29. }
  30. handleBlur() {
  31. const { handlePush } = this.props;
  32. handlePush && handlePush({ mode: 8 }); //右侧推送
  33. }
  34. handleFocus() {
  35. const { handlePush } = this.props;
  36. handlePush && handlePush({ mode: 8 });
  37. }
  38. handleSelect(part, idx) {
  39. const { selectJiType, handlePush, type, hosId } = this.props;
  40. const item = Object.assign(part, { uniqueName: hosId === -1 ? part.name : undefined }); //朗通的需要传uniqueName
  41. selectJiType(item, idx, type)
  42. handlePush && handlePush({ mode: 8 });
  43. }
  44. handleFocu(e){
  45. const val = e.target.value;
  46. this.getDrugWayList(val)
  47. }
  48. handleChange(e, isClear) {
  49. const val = e.target.value;
  50. if (isClear || !val) {
  51. this.setState({
  52. data: [],
  53. inpVal: ''
  54. });
  55. this.handleSelect({ name: '', uniqueName: '' }, this.props.idx);
  56. }
  57. this.setState({
  58. show: true,
  59. inpVal: val,
  60. });
  61. //搜索
  62. this.getDrugWayList(val)
  63. }
  64. //获取药品剂型15,、给药途径16
  65. getDrugWayList(val) {
  66. const { hosId, type } = this.props;
  67. if(!val){
  68. this.setState({
  69. data: [],
  70. inpVal: ''
  71. });
  72. this.handleSelect({ name: '', uniqueName: '' }, this.props.idx);
  73. return
  74. }
  75. axios.json('/demo/retrieval/index', {
  76. "inputStr": val.trim(),
  77. "type": type,
  78. "hospitalId": hosId,
  79. "defaultList":0
  80. }).then((res) => {
  81. if (res.data.code == 0) {
  82. const data = res.data.data;
  83. this.setState({
  84. data: data.nameList || [],
  85. show: true,
  86. inpVal: val
  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. console.log(inpVal);
  97. return (
  98. <div className={styles.medType}>
  99. <input placeholder={title} value={selected} title={selected} className={styles.inpSearch} onFocus={(e) => this.handleFocu(e)} onInput={(e) => this.handleChange(e)} />
  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;