|
@@ -2,8 +2,9 @@ import React,{Component} from 'react';
|
|
|
import classNames from 'classnames';
|
|
|
import config from '@config/index.js';
|
|
|
import style from './index.less';
|
|
|
-import {deepClone,filterArr,handleEnter,isIE} from '@utils/tools.js';
|
|
|
+import {deepClone,filterArr,handleEnter,isIE,getPageCoordinate,windowEventHandler} from '@utils/tools.js';
|
|
|
import {Notify} from '@commonComp';
|
|
|
+import ReactDom from "react-dom";
|
|
|
import {getIds} from '@common/js/func.js';
|
|
|
import $ from 'jquery';
|
|
|
/****
|
|
@@ -35,8 +36,10 @@ class SpreadDrop extends Component{
|
|
|
ban:{}, //放'伴'字段
|
|
|
editable:false, //双击编辑
|
|
|
labelVal:'', //存放标签原有的值--主诉字数限制用
|
|
|
- boxLeft:null,
|
|
|
- boxTop:null
|
|
|
+ boxLeft:0,
|
|
|
+ boxTop:0,
|
|
|
+ tmpScroll:0,
|
|
|
+ tmpTop:0,
|
|
|
};
|
|
|
this.$div = React.createRef();
|
|
|
this.handleSelect = this.handleSelect.bind(this);
|
|
@@ -53,14 +56,26 @@ class SpreadDrop extends Component{
|
|
|
}
|
|
|
handleShow(e){//单击
|
|
|
e&&e.stopPropagation();
|
|
|
- let boxLeft = e.pageX -175 + 'px';
|
|
|
- let offsetTop = e.target.offsetTop;
|
|
|
- const ht = e.target.offsetHeight; //如杂音选中文字有多行时,写死会遮挡
|
|
|
- let boxTop = offsetTop + ht +2 + 'px';
|
|
|
+ // let boxLeft = e.pageX -175 + 'px';
|
|
|
+ // let offsetTop = e.target.offsetTop;
|
|
|
+ // const ht = e.target.offsetHeight; //如杂音选中文字有多行时,写死会遮挡
|
|
|
+ // let boxTop = offsetTop + ht +2 + 'px';
|
|
|
+ // this.setState({
|
|
|
+ // boxLeft:boxLeft,
|
|
|
+ // boxTop:boxTop
|
|
|
+ // })
|
|
|
this.setState({
|
|
|
- boxLeft:boxLeft,
|
|
|
- boxTop:boxTop
|
|
|
- })
|
|
|
+ boxLeft:getPageCoordinate(e).boxLeft,
|
|
|
+ boxTop:getPageCoordinate(e).boxTop,
|
|
|
+ tmpScroll: $("#addScrollEvent")[0].scrollTop,
|
|
|
+ tmpTop:getPageCoordinate(e).boxTop
|
|
|
+ });
|
|
|
+ windowEventHandler('scroll',()=>{ //弹窗跟随滚动条滚动或者关闭弹窗
|
|
|
+ let scrollYs = $("#addScrollEvent")[0].scrollTop;
|
|
|
+ this.setState({
|
|
|
+ boxTop:this.state.tmpTop - scrollYs + this.state.tmpScroll
|
|
|
+ })
|
|
|
+ },$("#addScrollEvent")[0])
|
|
|
// window.event? window.event.cancelBubble = true : e.stopPropagation();
|
|
|
this.setStateInit(); //恢复初始选中状态
|
|
|
const {ikey,handleShow,placeholder,flag,id,value,tagType,type} = this.props;
|
|
@@ -295,8 +310,44 @@ class SpreadDrop extends Component{
|
|
|
}
|
|
|
return style['tag'];
|
|
|
}
|
|
|
+
|
|
|
+ componentDidMount(){
|
|
|
+ if(isIE()){
|
|
|
+ $(this.$div.current).onIe8Input(function(e){
|
|
|
+ this.onChange(e)
|
|
|
+ },this);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ render(){
|
|
|
+ const {placeholder,value,show,data} = this.props;
|
|
|
+ const {editable,boxLeft,boxTop} = this.state;
|
|
|
+ return <div className={style['container']}
|
|
|
+ onFocus={(e)=>e.stopPropagation()}
|
|
|
+ onBlur={(e)=>e.stopPropagation()}
|
|
|
+ onInput={(e)=>e.stopPropagation()}>
|
|
|
+ <div
|
|
|
+ ref={this.$div}
|
|
|
+ onClick={this.handleShow}
|
|
|
+ className={this.getClass()}
|
|
|
+ contentEditable={editable}
|
|
|
+ onDoubleClick={this.changeToEdit}
|
|
|
+ onBlur={this.handleBlur}
|
|
|
+ onInput={this.onChange}
|
|
|
+ onkeydown={handleEnter}
|
|
|
+ >{value||placeholder}</div>
|
|
|
+ <ListItems data={data} left={boxLeft}
|
|
|
+ top={boxTop} show={show} handleSelect={this.handleSelect} handleConfirm={this.handleConfirm} handleClear={this.handleClear} {...this.state}></ListItems>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class ListItems extends Component{
|
|
|
+ constructor(props){
|
|
|
+ super(props);
|
|
|
+ }
|
|
|
getLabels(){
|
|
|
- const {data} = this.props;
|
|
|
+ const {data,handleSelect} = this.props;
|
|
|
let detail = [];
|
|
|
let isSpecialPos = false; //是否特殊位置(单行在上面,如无殊)
|
|
|
let isExclu = false; //是否与其他互斥
|
|
@@ -310,53 +361,39 @@ class SpreadDrop extends Component{
|
|
|
}else{
|
|
|
detail = it.questionDetailList;
|
|
|
}
|
|
|
- return <ListItem data={detail}
|
|
|
+ return <ListItem datas={detail}
|
|
|
isRadio={isRadio}
|
|
|
joint={it.joint}
|
|
|
listIndex={i}
|
|
|
isSpecialPos={isSpecialPos}
|
|
|
isExclu={isExclu}
|
|
|
- handleClick={this.handleSelect}
|
|
|
- {...this.state}></ListItem>;
|
|
|
+ handleClick={handleSelect}
|
|
|
+ {...this.props}></ListItem>;
|
|
|
});
|
|
|
return list;
|
|
|
}
|
|
|
- componentDidMount(){
|
|
|
- if(isIE()){
|
|
|
- $(this.$div.current).onIe8Input(function(e){
|
|
|
- this.onChange(e)
|
|
|
- },this);
|
|
|
+ getStyle(){
|
|
|
+ const {left,top,show} = this.props;
|
|
|
+ return {
|
|
|
+ left:left?left+'px':'',
|
|
|
+ top:top?top+'px':'',
|
|
|
+ display:show?'block':'none'
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- render(){
|
|
|
- const {placeholder,value,show} = this.props;
|
|
|
- const {editable,boxLeft,boxTop} = this.state;
|
|
|
- return <div className={style['container']}
|
|
|
- onFocus={(e)=>e.stopPropagation()}
|
|
|
- onBlur={(e)=>e.stopPropagation()}
|
|
|
- onInput={(e)=>e.stopPropagation()}>
|
|
|
- <div
|
|
|
- ref={this.$div}
|
|
|
- onClick={this.handleShow}
|
|
|
- className={this.getClass()}
|
|
|
- contentEditable={editable}
|
|
|
- onDoubleClick={this.changeToEdit}
|
|
|
- onBlur={this.handleBlur}
|
|
|
- onInput={this.onChange}
|
|
|
- onkeydown={handleEnter}
|
|
|
- >{value||placeholder}</div>
|
|
|
- <div className={style["drop-list"]} style={{display:show?'block':'none',top:boxTop,left:boxLeft}} contentEditable="false" onClick={(e)=>{e.stopPropagation();}}>
|
|
|
+ render (){
|
|
|
+ const {handleClear,handleConfirm} = this.props;
|
|
|
+ const domNode = document.getElementById('root');
|
|
|
+ return ReactDom.createPortal(
|
|
|
+ <div className={style["drop-list"]} style={this.getStyle()} contentEditable="false" onClick={(e)=>{e.stopPropagation();}}>
|
|
|
{this.getLabels()}
|
|
|
<div className="oper">
|
|
|
- <span className={style['clear']} onClick={this.handleClear}>清空选项</span>
|
|
|
- <span className={style['confirm']} onClick={this.handleConfirm}>确定</span>
|
|
|
+ <span className={style['clear']} onClick={handleClear}>清空选项</span>
|
|
|
+ <span className={style['confirm']} onClick={handleConfirm}>确定</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ ,domNode)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
class ListItem extends Component{
|
|
|
constructor(props){
|
|
|
super(props);
|
|
@@ -365,6 +402,7 @@ class ListItem extends Component{
|
|
|
e.stopPropagation();
|
|
|
// window.event? window.event.cancelBubble = true : e.stopPropagation();
|
|
|
const {handleClick,isExclu,isRadio,data,exists,noneIds,withs,joint,listIndex} = this.props;
|
|
|
+
|
|
|
const index=listIndex+''+i;
|
|
|
//列单选处理
|
|
|
if(isRadio){
|
|
@@ -406,15 +444,14 @@ class ListItem extends Component{
|
|
|
}
|
|
|
}
|
|
|
render(){
|
|
|
- const {data,isSpecialPos} = this.props;
|
|
|
+ const {datas,isSpecialPos} = this.props;
|
|
|
const pos = isSpecialPos?style['independent']:'';
|
|
|
return <ul className={classNames(style['row'],pos)} onBlur={(e)=>e.stopPropagation()}>
|
|
|
- {data&&data.map((it,i)=>{
|
|
|
+ {datas&&datas.map((it,i)=>{
|
|
|
return <li onClick={(e)=>this.handleClick(e,it,i)}
|
|
|
className={this.getClass(it.id)}>{it.labelPrefix}{it.name}{it.labelSuffix}</li>
|
|
|
})}
|
|
|
</ul>;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
export default SpreadDrop;
|