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 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. console.log(123);
  67. const { hosId, type } = this.props;
  68. if(!val && type == 15){
  69. this.setState({
  70. data: [],
  71. inpVal: ''
  72. });
  73. this.handleSelect({ name: '', uniqueName: '' }, this.props.idx);
  74. return
  75. }
  76. axios.json('/demo/retrieval/index', {
  77. "inputStr": val.trim(),
  78. "type": type,
  79. "hospitalId": hosId,
  80. "defaultList":type==15?0: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. {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;