import React,{Component} from 'react'; import {Button,InlineTag,ItemBox,Textarea,Notify} from '@commonComp'; import chooseType from '@containers/eleType.js'; import SearchDrop from '@components/SearchDrop'; import {filterDataArr,getPageCoordinate,windowEventHandler} from '@utils/tools' import $ from 'jquery'; import style from './index.less'; class OtherHistory extends Component{ constructor(props){ super(props); this.state = { boxMark:'3', editable:true, 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); } toggleEditable(){ this.setState({ boxEditable:!this.state.boxEditable }) } handleSearchSelect(obj){ const {questionId,name} = obj; const {fetchModules,focusTextIndex,span,searchInEnd} = this.props; fetchModules&&fetchModules({id:questionId,index:focusTextIndex,name,span,searchInEnd}); } getLabels(){ const {data,showArr,selecteds,saveText} = this.props; const {boxMark} = this.state; let list = data.map((item,i)=>{ return chooseType({item,boxMark,i,hideTag:false,showArr,selecteds,saveText}); }); return list; } handleInput(e){ //主诉未填无法输入 const {type,hasMain} = this.props; if(+type===0&&!hasMain){ e.target.innerText=''; } } getData(){ //第一次聚焦其他史时,主诉有数据则获取最近一次其他史记录(没有的话显示初始模板),主诉无数据则显示提示;其他时间其他史模板数据不调接口 const {hasMain,type,setInitData,data,saveText,changeEditClear} = this.props; const hasData = saveText.join("")||data.length>0; if(hasData){ //其他史已有数据不获取 return; } if(+type===0&&!hasMain){ document.activeElement.blur(); //修改第一次提示后不再提示bug Notify.error("无法操作,请先输入主诉"); return; } //智能模式有主诉或者文本模式获取最近历史 setInitData(); //回读后容器框要不可编辑,否则自由文本标签onInput,onFocus事件失效(原因未知) /*if(data.length>0){ this.setState({ editable:false }); changeEditClear(false) }*/ } handleClick(e){//让搜索框跟随鼠标点击移动 //e.stopPropagation(); const {fetchPushInfos} = this.props; //fetchPushInfos&&fetchPushInfos(); //若使用e.target,因为是onClick事件中,值可能是itembox的而不是span因此会有bug const ele = document.activeElement; if(ele.toString().indexOf('HTMLSpanElement') == -1){ //点击的不是span无法聚焦就不再设置位置 return; } const leftL = ele.offsetLeft; //用焦点元素的左边距替换鼠标点击的左边距,高度还是鼠标点击的位置 this.setState({ // boxLeft:getPageCoordinate(e).boxLeft, boxLeft:leftL+90, 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]) } /*componentWillReceiveProps(next){ const isRead = this.props; this.setState({ isRead:next.isRead !== isRead }); } componentDidMount(){ const {setInitData} = this.props; setInitData&&setInitData(); }*/ render(){ const {data,hasMain,searchData,totalHide,showArr,focusTextIndex,isRead,type,fetchPushInfos,handleInput,saveText,editClear} = this.props; const {boxTop,boxLeft,boxMark} = this.state; const hasData = saveText.join("")||data.length>0; const show = showArr&&showArr[boxMark+focusTextIndex+'0']; if(+type===1){ //文本模式 return