index.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 && type == 15){
  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":type==15?0:1
  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. })
  87. } else {
  88. Notify.success(res.data.msg)
  89. }
  90. })
  91. };
  92. render() {
  93. const { idx, title, selected } = this.props;
  94. const { show, data, inpVal } = this.state;
  95. return (
  96. <div className={styles.medType}>
  97. <input placeholder={title} value={selected} title={selected} className={styles.inpSearch} onFocus={(e) => this.handleFocu(e)} onInput={(e) => this.handleChange(e)} />
  98. <img className={styles.down} src={dowm} alt="" />
  99. {inpVal? <img className={styles.clear} src={del} alt="清空" onClick={(e) => this.handleChange(e, true)} /> : ''}
  100. {
  101. show ? <ul className={styles.selectLis}>
  102. {
  103. data && data.map((part) => {
  104. return <li title={part.name} onClick={() => this.handleSelect(part, idx)}>{part.name}</li>
  105. })
  106. }
  107. </ul> : ''
  108. }
  109. </div>
  110. );
  111. }
  112. }
  113. export default SearchSelect;