UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

100 lines (93 loc) 3.27 kB
import React from 'react'; import {List} from 'antd-mobile'; import YYIcon from '../icon/YYIcon' import classnames from 'classnames'; import {isFunction} from '../../utils/FunctionUtil'; import './YYScan.less' class YYScan extends React.Component { state = { value: this.props.value } onChange = (value) => { //设值到fieldStore let fields = {}; fields[this.props.field] = { dirty: true, errors: undefined, name: this.props.field, touched: true, validating: true, value: value } this.props.form.setFields(fields); //this.setState({value}) if (isFunction(this.props.onChange)) this.props.onChange(value); } onBlur = (value) => { if (isFunction(this.props.onBlur)) this.props.onBlur(value); } onExtraClick = () => { if (isFunction(this.props.onExtraClick)) this.props.onExtraClick(); } /* onClick = (value) => { if (isFunction(this.props.onClick)&&this.props.disabled) this.props.onClick(value); }*/ onFocus = (value) => { if (isFunction(this.props.onFocus)) this.props.onFocus(value); } onErrorClick = () => { if (isFunction(this.props.onErrorClick)) this.props.onErrorClick(); } validateCallBack = (rule, value, callback) => { if (isFunction(this.props.validateCallBack)) { this.props.validateCallBack(rule, value, callback); callback(); } else { callback(); } } render() { let {getFieldProps} = this.props.form; let wrapClz = classnames('yy-scan', this.props.className); const {scanIconColor,scanIcon,scanValue,field, value, required, trigger, type, placeholder, editable, disabled, clear, maxLength, hasError, extra, updatePlaceholder, label, showIcon, icon, iconColor, ...restProps} = this.props; let requiredMsg = '必填项' + label + '未填写'; return ( <List.Item {...restProps} className={wrapClz} extra={<div>{scanValue}<YYIcon {...isFunction(getFieldProps) ? getFieldProps(field,{ initialValue:scanValue, valuePropName:'scanValue', }):null} disabled={disabled} type={scanIcon} color={scanIconColor} onClick={this.onClick}/></div>} > {showIcon && <YYIcon type={icon} color={iconColor} style={{float:'left',paddingRight:'8px'}} size="xs"/>}{label}</List.Item>); } } YYScan.defaultProps = { field: "default", value: null, required: false, trigger: "onChange", type: "text", placeholder: "", editable: true, disabled: false, clear: true, maxLength: null, hasError: false, extra: "", labelNumber: 7, updatePlaceholder:false, label: '输入框', showIcon: false, icon: "wage", iconColor: "red", } module.exports = YYScan;