import React, { Component } from "react"; import axios from '@utils/ajax'; import styles from "./index.less"; import { Notify, DelToast } from '@commonComp'; import $ from 'jquery'; import dowm from '../img/down.png'; import del from '../img/close.png'; class SearchSelect extends Component { constructor(props) { super(props); this.state = { show: false, data: [], inpVal: '' }; this.handleBlur = this.handleBlur.bind(this); this.getDrugWayList = this.getDrugWayList.bind(this); } componentDidMount() { //关闭下拉弹窗 $(document).click((event) => { const domClass = $(event.target).attr("class") || ''; if (domClass.indexOf(styles.selectLis) === -1 && domClass.indexOf(styles.inpSearch) === -1) { this.setState({ show: false }) } }); } handleBlur() { const { handlePush } = this.props; handlePush && handlePush({ mode: 8 }); //右侧推送 } handleFocus() { const { handlePush } = this.props; handlePush && handlePush({ mode: 8 }); } handleSelect(part, idx) { const { selectJiType, handlePush, type, hosId } = this.props; const item = Object.assign(part, { uniqueName: hosId === -1 ? part.name : undefined }); //朗通的需要传uniqueName selectJiType(item, idx, type) handlePush && handlePush({ mode: 8 }); } handleFocu(e){ const val = e.target.value; this.getDrugWayList(val) } handleChange(e, isClear) { const val = e.target.value; if (isClear || !val) { this.setState({ data: [], inpVal: '' }); this.handleSelect({ name: '', uniqueName: '' }, this.props.idx); } this.setState({ show: true, inpVal: val, }); //搜索 this.getDrugWayList(val) } //获取药品剂型15,、给药途径16 getDrugWayList(val) { const { hosId, type } = this.props; if(!val){ this.setState({ data: [], inpVal: '' }); this.handleSelect({ name: '', uniqueName: '' }, this.props.idx); return } axios.json('/demo/retrieval/index', { "inputStr": val.trim(), "type": type, "hospitalId": hosId, "defaultList":0 }).then((res) => { if (res.data.code == 0) { const data = res.data.data; this.setState({ data: data.nameList || [], show: true, inpVal: val }) } else { Notify.success(res.data.msg) } }) }; render() { const { idx, title, selected } = this.props; const { show, data, inpVal } = this.state; console.log(inpVal); return (
this.handleFocu(e)} onInput={(e) => this.handleChange(e)} /> {inpVal? 清空 this.handleChange(e, true)} /> : ''} { show ? : '' }
); } } export default SearchSelect;