import React, { Component } from 'react';
import style from './index.less';
import {ConfirmModal} from '@commonComp';

class DiagnosticItem extends Component{
    constructor(props){
        super(props);

        this.state = {
            visible: false
        }

        this.addDiagodal = this.addDiagodal.bind(this);
        this.chooseDiagodal = this.chooseDiagodal.bind(this);
        this.confirm = this.confirm.bind(this);
        this.cancel = this.cancel.bind(this)
        this.close = this.close.bind(this)
    }
    confirm() {
        this.close();
        const diagType = 1;
        this.addDiagodal(diagType)
    }
    cancel() {
        this.close();
        const diagType = 2;
        this.addDiagodal(diagType)
    }
    close(){
            this.setState({
                visible: false
            })
        }
    chooseDiagodal(item) {
        this.setState({
            visible: true
        })
        const { getTips } = this.props;
        getTips && getTips(item);
    }
    addDiagodal(diagType){
        const {item} = this.props;
        item.type = diagType;
        // setTimeout(()=>{
        //     this.setState({
        //         visible: false,
        //     },()=>{
                const { addDiagnostic, clearInput, hideSearch } = this.props;
                addDiagnostic&&addDiagnostic(item);
                clearInput&&clearInput();
                hideSearch&&hideSearch()
        //     })
        // }, 0)
    }

    render(){
        const { visible } = this.state
        const { item } = this.props
        return (<span className={style['diag-item']} >
                    <span className={style['diag-name']} onClick={() =>{this.chooseDiagodal(item)}}>{item.name} </span>
                    <ConfirmModal visible={visible} okText='初诊' cancelText='复诊' confirm={this.confirm}  cancel={this.cancel} close={this.close}>
                        <div className={style['confirm-info']}>确定选择“{item.name}”为</div> 
                    </ConfirmModal>
                </span>)
    }
}

export default DiagnosticItem;