1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import React,{Component} from 'react';
- import style from './index.less';
- import {Button,InlineTag,ItemBox,EditableSpan,Notify} from '@commonComp';
- import chooseType from '@containers/eleType.js';
- import SearchDrop from '@components/SearchDrop';
- import {getPageCoordinate,windowEventHandler,isIE} from '@utils/tools';
- import $ from "jquery";
- class CheckBody extends Component{
- constructor(props){
- super(props);
- this.state={
- boxMark:'4',
- boxLeft:0,
- boxTop:0,
- tmpScroll:0,
- tmpTop:0,
- };
- this.handleClick = this.handleClick.bind(this);
- this.handleSearchSelect = this.handleSearchSelect.bind(this);
- this.getData = this.getData.bind(this);
- //this.handleInput = this.handleInput.bind(this);
- }
- getLabels(){
- const {data,showArr,saveText,selecteds} = this.props;
- let arr = [],list=[];
- const {boxMark} = this.state;
- if(data){
- list = data;
- arr = list.map((it,i)=>{
- return chooseType({item:it,boxMark,i,showArr,saveText,selecteds});
- });
- }
- return arr;
- }
- handleClick(e){//让搜索框跟随鼠标点击移动
- // e.stopPropagation();
- const {fetchPushInfos,totalHide} = this.props;
- //fetchPushInfos&&fetchPushInfos();
- this.getData();
- if(totalHide){
- return ;
- }
- //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug
-
- let leftL=0; //用焦点元素的左边距替换鼠标点击的左边距,高度还是鼠标点击的位置
- if(isIE()){
- leftL = getPageCoordinate(e).boxLeft
- }else{
- const ele = document.activeElement;
- if(ele.toString().indexOf('HTMLSpanElement') == -1){ //点击的不是span无法聚焦就不再设置位置
- return;
- }
- leftL = ele.offsetLeft+90
- }
- // console.log(leftL,getPageCoordinate(e).boxLeft)
- this.setState({
- // boxLeft:getPageCoordinate(e).boxLeft,
- boxLeft:leftL,
- 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])
- }
- handleSearchSelect(obj){
- const {questionId,name} = obj;
- const {fetchModules,focusTextIndex,span,searchInEnd} = this.props;
- fetchModules&&fetchModules({id:questionId,index:focusTextIndex,name,span,searchInEnd});
- }
- getData(){
- //第一次聚焦查体时,主诉有数据则调接口,主诉无数据则显示提示;其他时间查体模板数据不调接口
- const {hasMain,isEmpty} = this.props;
- //无主诉提示在EditableSpan里
- //有主诉时且本身无数据,第一次点击获取数据,(不论获取成功与否)再点击不获取(直到刷新成空白页或清空)
- if(hasMain&&isEmpty!=false){
- this.props.getInit();
- }
- }
- render(){
- const {searchData,totalHide,data} = this.props;
- const {boxLeft,boxTop,boxMark} = this.state;
- return <div className={style['container']}>
- <ItemBox title='查体' handleClick={this.handleClick}>
- {this.getLabels()}
- {searchData && searchData.length>0?<SearchDrop data={searchData} show={!totalHide} left={boxLeft} top={boxTop} onSelect={this.handleSearchSelect}></SearchDrop>:''}
- </ItemBox>
- </div>
- }
- }
- export default CheckBody;
|