|
@@ -17,6 +17,7 @@ class NumberDrop extends Component{
|
|
|
super(props);
|
|
|
this.state={
|
|
|
/*editable:false, //标签是否可输入*/
|
|
|
+ value:props.value||'',
|
|
|
timer:null,
|
|
|
sltTimer:null,
|
|
|
blurTimer:null,
|
|
@@ -30,13 +31,14 @@ class NumberDrop extends Component{
|
|
|
this.handleNumFocus = this.handleNumFocus.bind(this);
|
|
|
this.handleKeyDowm = this.handleKeyDowm.bind(this);
|
|
|
this.beyondArea = this.beyondArea.bind(this);
|
|
|
+ this.emitBMIData = this.emitBMIData.bind(this);
|
|
|
}
|
|
|
select(text){ //选中键盘上数字事件
|
|
|
//placeholder修改后,第一次点击键盘触发blur后onClick不触发,原因未知,改为onMouseup可触发
|
|
|
let timer = null;
|
|
|
clearTimeout(this.state.sltTimer);
|
|
|
clearTimeout(this.state.blurTimer);
|
|
|
- const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max} = this.props;
|
|
|
+ const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max,formulaCode} = this.props;
|
|
|
const needCompare=min!=undefined&&max!=undefined;
|
|
|
if(!text){
|
|
|
this.setState({
|
|
@@ -62,26 +64,45 @@ class NumberDrop extends Component{
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText});
|
|
|
+ handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText,formulaCode});
|
|
|
+ //BMI相关数据上传
|
|
|
+ this.emitBMIData(text);
|
|
|
+ }
|
|
|
+ emitBMIData(text){
|
|
|
+ //手动修改BMI相关值时数据上传
|
|
|
+ const {setBMIParam,formulaCode,setBMI} = this.props;
|
|
|
+ if(formulaCode==="BMI_RES"){
|
|
|
+ setBMI&&setBMI(text);
|
|
|
+ }
|
|
|
+ if(text!==0&&(formulaCode==="BMI_SG"||formulaCode==="BMI_TZ")){
|
|
|
+ const map={
|
|
|
+ BMI_SG:'tall',
|
|
|
+ BMI_TZ:'weight'
|
|
|
+ };
|
|
|
+ setTimeout(function(){
|
|
|
+ setBMIParam&&setBMIParam(map[formulaCode],text);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
beyondArea(){
|
|
|
- const {handleSelect,ikey,suffix,prefix,mainSaveText} = this.props;
|
|
|
+ const {handleSelect,ikey,suffix,prefix,mainSaveText,formulaCode} = this.props;
|
|
|
Notify.info("输入数值不符合规范,请重新输入!");
|
|
|
- handleSelect&&handleSelect({ikey,text:'',suffix,prefix,mainSaveText});
|
|
|
+ handleSelect&&handleSelect({ikey,text:'',suffix,prefix,mainSaveText,formulaCode});
|
|
|
+ this.emitBMIData('');
|
|
|
this.setState({
|
|
|
placeholder:this.props.placeholder,
|
|
|
hasSelect:false
|
|
|
});
|
|
|
}
|
|
|
- handleNumFocus(e){ //数字框可编辑状态下聚集事件,处理是否显示下拉等
|
|
|
- const {placeholder} = this.state;
|
|
|
+ handleNumFocus(e){
|
|
|
+ /*const {placeholder} = this.state;
|
|
|
const val = e.target.innerText.trim();
|
|
|
//console.log(33,e.target.innerText,placeholder,e.target.innerText.trim() == placeholder)
|
|
|
if(val!=''&&val == placeholder){
|
|
|
this.setState({
|
|
|
placeholder:''
|
|
|
});
|
|
|
- }
|
|
|
+ }*/
|
|
|
e.stopPropagation();
|
|
|
}
|
|
|
handleKeyDowm(e){
|
|
@@ -93,14 +114,15 @@ class NumberDrop extends Component{
|
|
|
}
|
|
|
handleNumClick(e){ //数字框不可编辑的状态时点击事件,点击将数字框变为可输入且下拉不再显示直到失焦后再次聚集
|
|
|
e.stopPropagation();
|
|
|
- const {show,handleShow,ikey,id,patId,handleHide,value} = this.props;
|
|
|
+ const {show,handleShow,ikey,id,patId,handleHide} = this.props;
|
|
|
if(show) {
|
|
|
handleHide && handleHide();
|
|
|
return;
|
|
|
}else{
|
|
|
this.$span.current.focus();
|
|
|
this.setState({
|
|
|
- hasSelect:false
|
|
|
+ hasSelect:false,
|
|
|
+ placeholder:'' //火狐26placeholder点击不隐藏bug修改
|
|
|
});
|
|
|
handleShow&&handleShow({ikey,id:patId||id});
|
|
|
}
|
|
@@ -131,13 +153,13 @@ class NumberDrop extends Component{
|
|
|
}
|
|
|
numInpBlur(e){ //数字框失焦,保存值到store中
|
|
|
e.stopPropagation();
|
|
|
- const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max,show} = this.props;
|
|
|
+ const {handleSelect,ikey,suffix,prefix,mainSaveText,min,max,show,formulaCode} = this.props;
|
|
|
/*if(show){ //修改清空后第一次点击键盘不触发click事件bug--失焦placehoder消失,弃用
|
|
|
return;
|
|
|
}*/
|
|
|
//输入超出合理范围或输入不是数字提示且清空
|
|
|
const needCompare=min!=undefined&&max!=undefined;
|
|
|
- const txt = e.target.innerText.trim();
|
|
|
+ const txt = e.target.innerHTML.replace(/ $|^ /,'');//e.target.innerText.trim();
|
|
|
const isFine = this.validSymbols(txt,min,max); //有~或/时是否合理
|
|
|
const hasSymbol = /[\/|\~]/g.test(txt); //是否有~或/
|
|
|
const singleFine = (!isNaN(+txt)&&!needCompare)||(!isNaN(+txt)&&needCompare&&parseFloat(min)<=parseFloat(txt)&&parseFloat(txt)<=parseFloat(max)); //无~或/时是否合理
|
|
@@ -148,7 +170,7 @@ class NumberDrop extends Component{
|
|
|
|
|
|
//输入为空时显示placeholder
|
|
|
const timer = setTimeout(()=>{
|
|
|
- if(!e.target.innerText.trim()){
|
|
|
+ if(!e.target.innerHTML.replace(/ $|^ /,'')){
|
|
|
this.setState({
|
|
|
placeholder:this.props.placeholder
|
|
|
});
|
|
@@ -158,27 +180,33 @@ class NumberDrop extends Component{
|
|
|
blurTimer:timer
|
|
|
});
|
|
|
|
|
|
- const val = e.target.innerText.trim();
|
|
|
+ const val = e.target.innerHTML.replace(/ $|^ /,'');//e.target.innerText.trim();
|
|
|
const {placeholder} = this.state;
|
|
|
let text = val===placeholder?'':val;
|
|
|
//e.target.innerText = ''; //避免出现重复输入值
|
|
|
- handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText});
|
|
|
+ handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText,formulaCode});
|
|
|
+ this.emitBMIData(text);
|
|
|
}
|
|
|
handleSpanInp(e){ //数字框输入事件
|
|
|
e.stopPropagation();
|
|
|
+ const txt = e.target.innerHTML.replace(/ $|^ /,'');
|
|
|
+ this.setState({
|
|
|
+ value:txt
|
|
|
+ });
|
|
|
const {handleHide} = this.props;
|
|
|
handleHide&&handleHide();
|
|
|
}
|
|
|
getClasses(){ //整个标签是否有值的状态
|
|
|
- const {hideTag,placeholder,value,isImports} = this.props;
|
|
|
- const val = value;
|
|
|
+ const {hideTag,placeholder,isImports,isExtBlue} = this.props;
|
|
|
+ const val = this.state.value;
|
|
|
const isSelected = val&&val!=placeholder?style['selected']:style['container'];
|
|
|
const orgBorder = isImports&&!(val&&val!=placeholder)?style['orange-border']:'';
|
|
|
+ const ext = isExtBlue?style['ext']:'';
|
|
|
const noTag = hideTag?style['no-tag']:'';
|
|
|
- return className(isSelected,noTag,orgBorder);
|
|
|
+ return className(isSelected,noTag,orgBorder,ext);
|
|
|
}
|
|
|
getSpanClass(){ //将被替换的文字选中状态显示
|
|
|
- const cls = this.props.show?style['blued']:'';
|
|
|
+ const cls = this.props.show?style['blued']:style['nol'];
|
|
|
return cls;
|
|
|
}
|
|
|
stopBubble(e){
|
|
@@ -196,15 +224,27 @@ class NumberDrop extends Component{
|
|
|
})
|
|
|
}
|
|
|
componentWillReceiveProps(nextProps){
|
|
|
+ //BMI存值
|
|
|
+ const {formulaCode,bmi,suffix,prefix,ikey,handleSelect,mainSaveText,wrBmi} = this.props;
|
|
|
+ if(formulaCode==="BMI_RES"&&nextProps.bmi!==bmi){
|
|
|
+ handleSelect&&handleSelect({ikey,text:nextProps.bmi,suffix,prefix,mainSaveText,formulaCode});
|
|
|
+ }
|
|
|
+ //手动修改BMI时身高体重清空
|
|
|
+ if(wrBmi!==nextProps.wrBmi&&(formulaCode==="BMI_SG"||formulaCode==="BMI_TZ")){
|
|
|
+ handleSelect&&handleSelect({ikey,text:'',suffix,prefix,mainSaveText,formulaCode});
|
|
|
+ }
|
|
|
+
|
|
|
if((nextProps.placeholder == this.props.placeholder)&&(nextProps.value == this.props.value)){
|
|
|
return
|
|
|
}
|
|
|
this.setState({
|
|
|
- placeholder:nextProps.placeholder
|
|
|
- })
|
|
|
+ placeholder:nextProps.placeholder,
|
|
|
+ value:nextProps.value
|
|
|
+ });
|
|
|
}
|
|
|
render(){
|
|
|
- const {prefix,suffix,show,value,handleHide,allClick} = this.props;
|
|
|
+ const {prefix,suffix,show,value,handleHide,allClick,bmi,formulaCode} = this.props;
|
|
|
+ const val = formulaCode==="BMI_RES"?(+bmi===Infinity||isNaN(bmi)?'':bmi):value;
|
|
|
const {placeholder,hasSelect} = this.state;
|
|
|
return <div className={this.getClasses()}
|
|
|
style={{position:'relative'}}
|
|
@@ -215,13 +255,14 @@ class NumberDrop extends Component{
|
|
|
contentEditable={true}
|
|
|
style={{minWidth:'10px',display:'inline-block',textAlign:'center'}}
|
|
|
ref = {this.$span}
|
|
|
- onKeyUp={this.handleKeyDowm}
|
|
|
+ onkeyup={this.handleKeyDowm}
|
|
|
onBlur={this.numInpBlur}
|
|
|
onInput={this.handleSpanInp}
|
|
|
className={this.getSpanClass()}
|
|
|
- > {value||placeholder}</span>
|
|
|
+ > {val||placeholder}</span>
|
|
|
<span>{suffix}</span>
|
|
|
<NumberPan handleSelect={this.select.bind(this)}
|
|
|
+ noString={formulaCode?true:false}
|
|
|
onClose={handleHide}
|
|
|
show={show}
|
|
|
toClear={!hasSelect}/>
|