|
@@ -33,6 +33,8 @@ class NumberUnitDrop extends Component{
|
|
|
tmpScroll:0
|
|
|
};
|
|
|
this.$span = React.createRef();
|
|
|
+ this.$pre = React.createRef();
|
|
|
+ this.$suf = React.createRef();
|
|
|
this.$cont = React.createRef();
|
|
|
this.select = this.select.bind(this);
|
|
|
this.numInpBlur = this.numInpBlur.bind(this);
|
|
@@ -41,7 +43,7 @@ class NumberUnitDrop extends Component{
|
|
|
this.changeToEdit = this.changeToEdit.bind(this);
|
|
|
}
|
|
|
select(obj){ //选中键盘上数字事件
|
|
|
- const {handleSelect,ikey,suffix,prefix,mainSaveText} = this.props;
|
|
|
+ const {handleSelect,ikey,suffix,prefix,mainSaveText,formulaCode,mainData} = this.props;
|
|
|
this.setState({
|
|
|
hasSelect:true
|
|
|
});
|
|
@@ -50,7 +52,7 @@ class NumberUnitDrop extends Component{
|
|
|
value:''
|
|
|
});
|
|
|
}
|
|
|
- handleSelect&&handleSelect({ikey,text:obj.text,suffix,prefix,mainSaveText,mark:obj.mark});
|
|
|
+ handleSelect&&handleSelect({ikey,text:obj.text,suffix,prefix,mainSaveText,mark:obj.mark,formulaCode,mainData});
|
|
|
}
|
|
|
|
|
|
handleNumClick(e){
|
|
@@ -85,13 +87,20 @@ class NumberUnitDrop extends Component{
|
|
|
//数字框失焦,保存值到store中
|
|
|
numInpBlur(e){
|
|
|
e.stopPropagation();
|
|
|
- const {handleSelect,ikey,suffix,prefix,mainSaveText,handleLabelChange,boxMark} = this.props;
|
|
|
+ // const {handleSelect,ikey,suffix,prefix,mainSaveText,handleLabelChange,boxMark,formulaCode} = this.props;
|
|
|
+ const {handleSelect,ikey,mainSaveText,handleLabelChange,boxMark,formulaCode} = this.props;
|
|
|
const {editable} = this.state;
|
|
|
if(editable){
|
|
|
- const text = e.target.innerText || e.target.innerHTML;
|
|
|
+ // const text = e.target.innerText || e.target.innerHTML;
|
|
|
// this.$span.current.innerText=''; //修改生成文字变成输入的2倍bug
|
|
|
+ let totalVal = e.target.innerText|| e.target.innerHTML;
|
|
|
+ let changeVal = this.$span.current.innerText.replace(/^\s*/,'');//数字框值-修改后;去掉前空格避免多空格叠加
|
|
|
+ let prefix = this.$pre.current.innerText.replace(/^\s*/,''); //前缀值-修改后
|
|
|
+ let suffix = this.$suf.current.innerText.replace(/^\s*/,''); //后缀值-修改后
|
|
|
+ // console.log('数字框:'+changeVal,";全部:"+totalVal,";前缀:"+prefix+";后缀:"+suffix);
|
|
|
+ handleLabelChange && handleLabelChange({ikey,changeVal,type:boxMark,totalVal,prefix,suffix,formulaCode});
|
|
|
// handleSelect&&handleSelect({ikey,text,suffix,prefix,mainSaveText});
|
|
|
- handleLabelChange&&handleLabelChange({ikey,changeVal:text,suffix,prefix,mainSaveText,type:boxMark});
|
|
|
+ // handleLabelChange&&handleLabelChange({ikey,changeVal:text,suffix,prefix,mainSaveText,type:boxMark,formulaCode});
|
|
|
|
|
|
}
|
|
|
this.setState({
|
|
@@ -143,9 +152,13 @@ class NumberUnitDrop extends Component{
|
|
|
}
|
|
|
changeToEdit(e){ //整个标签双击编辑状态
|
|
|
e.stopPropagation();
|
|
|
- const {value,id,handleDbclick,patId} = this.props;
|
|
|
+ const {value,id,handleDbclick,patId,handleHide,show} = this.props;
|
|
|
const text = e.target.innerText || e.target.innerHTML;
|
|
|
- // clearTimeout(this.state.timer);//取消延时的单击事件
|
|
|
+ clearTimeout(this.state.timer);//取消延时的单击事件
|
|
|
+ e.preventDefault();
|
|
|
+ if(show){
|
|
|
+ handleHide&&handleHide();
|
|
|
+ }
|
|
|
if(value&&value.trim()) {//有选中值的标签才能双击编辑
|
|
|
this.setState({
|
|
|
editable: true,
|
|
@@ -153,7 +166,8 @@ class NumberUnitDrop extends Component{
|
|
|
});
|
|
|
//失焦关闭编辑状态
|
|
|
setTimeout(()=>{
|
|
|
- e.target.focus();
|
|
|
+ // e.target.focus();
|
|
|
+ this.$cont.current.focus();
|
|
|
})
|
|
|
//双击埋点记录
|
|
|
handleDbclick && handleDbclick({id:patId||id});
|
|
@@ -161,7 +175,8 @@ class NumberUnitDrop extends Component{
|
|
|
}
|
|
|
componentDidMount(){
|
|
|
if(isIE()){
|
|
|
- $(this.$span.current).onIe8Input(function(e){
|
|
|
+ // $(this.$span.current).onIe8Input(function(e){
|
|
|
+ $(this.$cont.current).onIe8Input(function(e){
|
|
|
this.handleSpanInp(e)
|
|
|
},this);
|
|
|
}
|
|
@@ -170,17 +185,19 @@ class NumberUnitDrop extends Component{
|
|
|
render(){
|
|
|
const {placeholder,prefix,suffix,show,value,handleHide} = this.props;
|
|
|
const {numEditable,editable,hasSelect,placeholderFlag,boxLeft,boxTop} = this.state;
|
|
|
- return <div className={this.getClasses()} ref={this.$cont}>
|
|
|
- <span>{prefix}</span>
|
|
|
- <span onClick={this.handleNumClick}
|
|
|
- contentEditable={editable}
|
|
|
- ref = {this.$span}
|
|
|
- onBlur={this.numInpBlur}
|
|
|
- onInput={this.handleSpanInp}
|
|
|
- onDoubleClick={this.changeToEdit}
|
|
|
+ return <div className={this.getClasses()}
|
|
|
+ ref={this.$cont}
|
|
|
+ onClick={this.handleNumClick}
|
|
|
+ contentEditable={editable}
|
|
|
+ onBlur={this.numInpBlur}
|
|
|
+ onDoubleClick={this.changeToEdit}
|
|
|
+ onkeydown={handleEnter}
|
|
|
+ onInput={this.handleSpanInp}>
|
|
|
+ <span ref = {this.$pre}>{prefix?prefix+' ':prefix}</span>
|
|
|
+ <span ref = {this.$span}
|
|
|
onkeydown={handleEnter}
|
|
|
style={{cursor:editable?'text':'pointer'}}>{value||placeholder}</span>
|
|
|
- <span>{suffix}</span>
|
|
|
+ <span ref = {this.$suf}>{suffix?' '+suffix:suffix}</span>
|
|
|
<NumberUnitPan handleSelect={(obj)=>this.select(obj)}
|
|
|
onClose={handleHide}
|
|
|
top={boxTop}
|