import React,{Component} from 'react';
import {handleEnter,windowEventHandler,filterDataArr,getLabelIndex,setFontColorSize,handleMouseUp} from '@utils/tools.js';
import {DropList,Notify} from '@commonComp';
import config from '@config/index';
import style from "./index.less";
import classNames from 'classnames';
import $ from "jquery";
/****
* 单选下拉,选项带输入
* author:zn@2019-3.18
* 接收参数:
* placeholder:灰显文字
* data:下拉内容数据
* handleSelect:选中事件
*
* ***/
class RadioInpDrop extends Component{
constructor(props){
super(props);
this.state={
texts:props.vals||{0:props.value||props.placeholder},
};
this.$cont = React.createRef();
this.isIE = navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g,"")=="MSIE8.0";
this.handleSelect = this.handleSelect.bind(this);
this.handleShow = this.handleShow.bind(this);
this.parseInputDom = this.parseInputDom.bind(this);
this.handleInnerBlur = this.handleInnerBlur.bind(this);
}
getClass(){
const {value,hideTag,show,isImports,isExtBlue,mouseSelect} = this.props;
const orgBorder = isImports&&!value?style['orange-border']:''; //查体,是否橙色框高亮
const ext = isExtBlue?style['ext']:''; //查体,是否是体征
const selectedArea = mouseSelect?style['selected-area']:'';
if(show){
$(this.$cont.current).addClass(style['borderd']);
}else{
$(this.$cont.current).removeClass(style['borderd']);
}
if(value){
if(hideTag){
return classNames(style['no-tag'],ext,setFontColorSize(),selectedArea);
}
return classNames(style['selected-tag'],setFontColorSize(),selectedArea);
}else{
if(hideTag){
return classNames(style['no-tag'],ext,setFontColorSize(2),selectedArea);
}
return classNames(style['tag'],orgBorder,ext,setFontColorSize(2,6),selectedArea);
}
}
handleSelect(item){
const {handleSelect,ikey,value,placeholder,mainSaveText} = this.props;
let vals = {}, inx = 0;
if(!item){
handleSelect&&handleSelect({ikey}); //清空
this.setState({
texts:{0:placeholder}
});
return ;
}
const arr = item.name.split(config.radioOptionPer);
arr.map((it,i)=>{
inx = (i+1)*2-2;
vals[inx] = it;
if(i!=arr.length-1){
vals[+inx+1]={value:'',index:+inx+1}
};
});
this.setState({
texts:vals
});
handleSelect&&handleSelect({ikey,id:item.id,values:vals,mainSaveText,value});
}
handleShow(e){
e.stopPropagation();
const {handleShow,ikey,id,patId} = this.props;
document.activeElement.blur()//chrome41有效,但是失去焦点的span仍能编辑
handleShow && handleShow({ikey,id:patId||id});
windowEventHandler('scroll',()=>{ //弹窗跟随滚动条滚动或者关闭弹窗
let scrollYs = $("#addScrollEvent")[0].scrollTop;
this.setState({
boxTop:this.state.tmpTop - scrollYs + this.state.tmpScroll
})
},$("#addScrollEvent")[0])
}
handleInnerBlur(i,val){
const {ikey,boxMark,handleSaveInp,mainSaveText} = this.props;
let vals = this.state.texts;
vals[i].value=val;
this.setState({
texts:vals,
});
handleSaveInp({values:vals,ikey,boxMark,mainSaveText});
}
handleMouseDown(){
const {i,setSelectArea,boxMark}= this.props;
setSelectArea({i,boxMark,dir:'start'});
}
parseInputDom(){
const {mainSaveText,ikey,boxMark} = this.props;
const {texts} = this.state;
const inx = ikey.split("-")[1];
let temp='',list=[];
for(let i in texts){
temp = texts[i];
if(typeof temp=='object'){
list.push(