import React,{Component} from 'react'; import style from './index.less'; import Notify from '../Notify/index.js'; import ReactDom from "react-dom"; import backspace from '../../images/backspace.png'; /** * 时间单位组件下拉(tagType=1,controlType=5) * */ class NumberUnitPan extends Component{ constructor(props){ super(props); this.state = { value:'' } this.handleSelect = this.handleSelect.bind(this); this.getUnitTable = this.getUnitTable.bind(this); } handleSelect(e){ e.stopPropagation(); const {handleSelect,toClear} = this.props; const text = e.target.innerText || e.target.innerHTML; const preValue = this.state.value; // if(+text==0 && !preValue){//第一位不能是0 // Notify.info("请输入正确时间"); // return false; // } const value = toClear?'':this.state.value; //键盘输入替换已有的值 this.setState({ value: value+text }); handleSelect&&handleSelect({text:value+text,mark:true});//增加mark参数,清空删除不提示字数限制 } handleClear(e){ e.stopPropagation(); const onSelect = this.props.handleSelect; this.setState({ value: '' }); onSelect&&onSelect({text:'',mark:false}); } handleClose(e){ e.stopPropagation(); //关闭弹窗 const {onClose} = this.props; onClose&&onClose(); } handleBack(e){ e.stopPropagation(); const {handleSelect,value} = this.props; if(value===undefined||value==''){ return; } const len = value.length-1; const text = value.substring(0,len); this.setState({ value:text }); handleSelect&&handleSelect({text,mark:false}); } getStyle(){ const {left,top,show} = this.props; return { /*left:left?left+'px':'0', top:top?top+'px':'0',*/ display:show?'table':'none' } } getUnitTable(){ const {unitType} = this.props; if(unitType == 8){ return
1 2 3 ml qd .
4 5 6 mg bid .
7 8 9 g tid .
. 0 qid
清空 确定
} return
1 2 3 分钟
4 5 6 小时
7 8 9
. 0 /
清空 确定
} componentWillReceiveProps(nextProps){ //重新选择的值替换 不追加 if(!nextProps.show){ this.setState({ value:'' }); } } render(){ const domNode = document.getElementById('root'); return
e.stopPropagation()} style={this.getStyle()}> {this.getUnitTable()}
} } export default NumberUnitPan;