import React, { Component } from 'react';
import './index.less';
import Icon from '../Icon';
export default class Input extends Component {
render() {
const { className = '', onChange, placeholder, value, error, left, right, empty } = this.props;
return (
{left &&
{left}
}
onChange && onChange(data)} />
{right &&
{right}
}
{error}
);
}
}
export class SelectInput extends Component {
constructor(props) {
super(props);
this.state = { showSelect: false };
}
render() {
const { showSelect } = this.state;
const { className = '', onChange, placeholder, value, error, selectValue, select, onSelect, empty } = this.props;
return (
this.setState({ showSelect: !showSelect })}>
{selectValue}
{showSelect && {select.map((row) => {
return - {
this.setState({ showSelect: false });
if (onSelect) onSelect(row.value);
}}>{row.label}
;
})}
}
}
value={value}
placeholder={placeholder}
onChange={data => onChange && onChange(data)}
error={error}
empty={empty}
/>
);
}
}
export class VerificationInput extends Component {
constructor(props) {
super(props);
this.timeKey = null;
this.state = { loading: 0 };
}
componentWillUnmount() {
if (this.timeKey) clearTimeout(this.timeKey);
}
onSend() {
const { onSend, time = 60 } = this.props;
if (onSend) {
onSend()
.then(() => {
if (this.timeKey) clearTimeout(this.timeKey);
this.setTime(time);
});
}
}
setTime(time) {
this.setState({ loading: time });
this.timeKey = setTimeout(() => {
this.setTime(time - 1);
}, 1000);
}
render() {
const { loading } = this.state;
const { className = '', onChange, placeholder, value, error, empty } = this.props;
return (
this.onSend()}>
获取验证码
) : (等待{loading}秒)
}
value={value}
error={error}
empty={empty}
placeholder={placeholder}
onChange={data => onChange && onChange(data)}
/>
);
}
}