123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- 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 (
- <div className={styles.medType}>
- <input placeholder={title} value={selected} title={selected} className={styles.inpSearch} onFocus={(e) => this.handleFocu(e)} onInput={(e) => this.handleChange(e)} />
- {inpVal? <img className={styles.clear} src={del} alt="清空" onClick={(e) => this.handleChange(e, true)} /> : ''}
- {
- show ? <ul className={styles.selectLis}>
- {
- data && data.map((part) => {
- return <li title={part.name} onClick={() => this.handleSelect(part, idx)}>{part.name}</li>
- })
- }
- </ul> : ''
- }
- </div>
- );
- }
- }
- export default SearchSelect;
|