UNPKG

7.79 kBJavaScriptView Raw
1import React, {Component} from 'react'
2import debounce from '@beisen/es6-promise-debounce';
3import CommonInput from '@beisen-platform/common-input';
4import EditFilters from './edit_Filters.js';
5import {decode, judgeBrowser} from '@beisen-platform/common-func';
6import CloseIcon from '@beisen-platform/react-icons/lib/icons/Close.js';
7
8export default class AutoForm_Input extends Component {
9 constructor(props) {
10 super(props)
11 this.state = {
12 isMinWidth: false,
13 pointerEvent: "auto",
14 showHiddenTips: 'block',
15 mouseTips: false
16 }
17 }
18
19 resizeInputWidth = () => {
20 let inputNode = this.refs.autoFormInput;
21 if (inputNode!=undefined && inputNode.clientWidth!=0) {
22 inputNode.clientWidth <= 270 ? this.setState({isMinWidth: true}) : this.setState({isMinWidth: false}) ;
23 }
24 }
25
26 componentDidMount() {
27 const {status, showDropDown} = this.props;
28 let self = this;
29 //编辑态双排排列时 根据宽度自适应
30 if(status == 'edit' && showDropDown == true) {
31 this.resizeInputWidth();
32 window.addEventListener('resize',debounce(function() {
33 self.resizeInputWidth();
34 },200),false)
35 }
36 }
37
38 componentWillReceiveProps(nextProps) {
39 const {commmonInput_Data, single, defaultValue, inputValue, disabled} = this.props;
40 if (defaultValue != nextProps.defaultValue && single && !disabled) {
41 this.refs.autoTreeInput.value = decode(nextProps.defaultValue);
42 }
43 if (inputValue != nextProps.inputValue && single && !disabled) {
44 this.refs.autoTreeInput.value = decode(nextProps.inputValue);
45 }
46 if (commmonInput_Data.selectDate && nextProps.selectDate) {
47 let updateSelectData = commmonInput_Data.selectDate.length != nextProps.selectDate.length ? true : false;
48 if (updateSelectData) this.setState({});
49 }
50 if (commmonInput_Data.isActive && nextProps.isActive && commmonInput_Data.isActive != nextProps.isActive) {
51 this.setState({});
52 }
53 }
54
55 onMouseTip = () => {
56 let self =this;
57 //解决点击输入框时光标错位,引起原因是输入框上有层div导致
58 setTimeout(() => {
59 self.setState({mouseTips: true})
60 },100)
61 }
62
63 tipsClick = () => {
64 this.setState({pointerEvent: "none", showHiddenTips: 'none'})
65 this.refs.autoTreeInput.focus()
66 }
67
68 handlerOver = () => {
69 this.props.handlerOver()
70 }
71
72 handlerOut = e => {
73 this.setState({
74 mouseTips: false,
75 hoverFocusing: false
76 })
77 clearToolTipDom();
78 this.props.handlerOut(e)
79 }
80
81 render() {
82 const {disabled, status, isShowMouseOverIcon, showDropDown, DropDownData, placeholder, inputValue,
83 defaultValue, isFocus, errorStatus, errorMsg, single, showText, commmonInput_Data,
84 isSearchAutoTreeEdit, readOnly} = this.props;
85 const {isMinWidth, pointerEvent, showHiddenTips, mouseTips} = this.state;
86 let isMinClass, inutClassStyle, inputClass, isDisabled, inputStyle, autoInput_class, closeBtnClass,
87 dropDownIcon, iconOrText, erroStyle, notDropDown, baseStyle;
88 let _autoTreeLeft_Class = '';
89
90 isMinClass = isMinWidth ? 'leftInput-showDropDown isMinWidth' : 'leftInput-showDropDown notMin';
91 inutClassStyle = status=='edit'
92 ? showDropDown
93 ? isMinWidth
94 ? 'auto-form-input-active-showDropDownisMin '
95 : 'auto-form-input-active-showDropDown '
96 :'auto-form-input-active-notShowDropDown '
97 : 'auto-form-input-active-seach ';
98
99 inputClass = !errorStatus && isFocus && single ? inutClassStyle : '';
100 closeBtnClass = status=='search'
101 ? 'icon-close date-time-close-search closeBtn-search'
102 : showDropDown
103 ? 'icon-close date-time-close closeBtn-edit-showDropDown'
104 : 'icon-close date-time-close closeBtn-edit-notShowDropDown';
105
106 if (status=='search') erroStyle = {'height': '45px'};
107 if (!errorStatus) baseStyle = {'height': '0px'};
108 let showClose = (inputValue.length>0 && (isFocus==true || isShowMouseOverIcon))
109 ? 'block'
110 : 'none' ;
111
112 if (disabled == false || disabled == undefined) {
113 isDisabled = '';
114 inputStyle = {'paddingRight': '33px'};
115 } else {
116 isDisabled = 'disabled';
117 inputStyle = { 'background': 'rgb(245, 248, 250)',
118 'border': '1px solid rgb(228, 235, 240)',
119 'borderRadius': '5px',
120 'fontFamily': 'PingFangSC-Regular',
121 'fontSize': '12px',
122 'color': '#3E4E59',
123 'letterSpacing': '0px',
124 'lineHeight': '20px',
125 'textAlign': 'left',
126 'cursor': 'no-drop'
127 }
128 }
129
130 if (disabled) {
131 dropDownIcon = '';
132 } else {
133 dropDownIcon = <span className={showDropDown ?'autoTreeIcon-showDropDown pc-sys-arrowdown-nomal-svg' :'autoTreeIcon-notShowDropDown pc-sys-arrowdown-nomal-svg'} onClick={this.props.editInput_focus}>
134 </span>;
135 }
136
137 if (status=='edit') {
138 iconOrText = dropDownIcon;
139 autoInput_class = single ? 'auto-input-edit' : 'auto-input-edit_muit' ;
140 _autoTreeLeft_Class = !single ? '' : 'autoTreeLeftInput-single ' ;
141 notDropDown = isSearchAutoTreeEdit ? ' auto-tree__input_not-dropdown' : '' ;
142 } else {
143 autoInput_class = 'auto-input-search'
144 iconOrText = <div className='findAll'><label onClick={this.props.findAll}>全部查找</label></div>;
145 }
146 let decodeValue = decode(defaultValue)
147 console.log(decodeValue)
148 return (
149 <div ref="autoFormInput"
150 className={"field-right auto-rightinput auto-form-input " + inputClass + autoInput_class + notDropDown}
151 style={erroStyle}
152 >
153 <div ref='leftInput' className={status=='edit'?showDropDown && !isSearchAutoTreeEdit?isMinClass:'leftInput-notShowDropDown':''}>
154 {single && status == 'edit' || status == 'search'
155 ?
156 isDisabled
157 ? <CommonInput readonly={true} errorStatus={errorStatus} errorMsg={errorMsg} defaultValue={decodeValue} />
158 : <div onMouseOver={this.handlerOver} onMouseOut={this.handlerOut} >
159 {
160 mouseTips
161 ? null
162 : <ToolTip title={inputValue} >
163 <div className="form-item_is-hidden-tips" onMouseEnter={this.onMouseTip} style={{pointerEvents: pointerEvent, display: showHiddenTips}} onClick={this.tipsClick}>
164 {inputValue}
165 </div>
166 </ToolTip>
167 }
168 <input
169 className={'autoTreeLeftInput '+ _autoTreeLeft_Class +(status=='edit'?'':'autoTree-search-input')}
170 type="text"
171 ref='autoTreeInput'
172 placeholder={disabled ? '' :placeholder}
173 defaultValue={decodeValue}
174 onClick={this.props.addClass}
175 onBlur={this.props.removeClass}
176 onChange={this.props.onChange}
177 onFocus={this.props.addClass}
178 disabled={isDisabled}
179 readOnly={readOnly}
180 style={inputStyle}
181 />
182 <span style={{"display": showClose, "top": judgeBrowser().isIe10 ? '0' : 'none'}} className={closeBtnClass} ref="mouseIconClose" onClick={this.props.clearData}><CloseIcon /></span>
183 {iconOrText}
184 {status=='edit'
185 ? <div className='base-input-show' style={baseStyle}>
186 <span className={'base-input-show-text '+ (isFocus? 'input-pFoucus '+ (errorStatus? 'input-pError ':'input-pRight '): (errorStatus? 'input-pFoucus input-pError ':'input-pBlur input-pRight '))}>
187 {errorStatus ? errorMsg : showText}
188 </span>
189 </div>
190 : ''
191 }
192 </div>
193 : <div ref='autoTree_commonInput' className={'autoTreeLeftInput '+(status=='edit'?'':'autoTree-search-input')}>
194 <CommonInput {...commmonInput_Data} />
195 </div>
196 }
197 </div>
198 {
199 !isSearchAutoTreeEdit
200 ? <EditFilters DropDownData={DropDownData} isMinWidth={isMinWidth} status={status} changeFilter={this.props.changeFilter} showDropDown={showDropDown} />
201 : ''
202 }
203 </div>
204 )
205 }
206}
\No newline at end of file