UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

223 lines (188 loc) 9.59 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _picker = require('antd-mobile/lib/picker'); var _picker2 = _interopRequireDefault(_picker); var _list = require('antd-mobile/lib/list'); var _list2 = _interopRequireDefault(_list); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/picker/style/css'); require('antd-mobile/lib/list/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _YYIcon = require('../icon/YYIcon'); var _YYIcon2 = _interopRequireDefault(_YYIcon); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _FunctionUtil = require('../../utils/FunctionUtil'); require('./YYPicker.less'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Item = _list2.default.Item; var YYPicker = function (_Component) { _inherits(YYPicker, _Component); function YYPicker() { var _ref; var _temp, _this, _ret; _classCallCheck(this, YYPicker); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYPicker.__proto__ || Object.getPrototypeOf(YYPicker)).call.apply(_ref, [this].concat(args))), _this), _this.state = { visible: false }, _this.clearDate = function () { var fields = {}; fields[_this.props.field] = { dirty: true, errors: undefined, name: _this.props.field, touched: true, validating: true, value: null }; _this.props.form.setFields(fields); _this.setState({ visible: false }); }, _this.onChange = function (value) { var fields = {}; fields[_this.props.field] = { dirty: true, errors: undefined, name: _this.props.field, touched: true, validating: true, value: value }; _this.props.form.setFields(fields); if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) _this.props.onChange(value); }, _this.onOk = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onOk)) { _this.setState({ visible: false }); _this.props.onOk(value); } else { _this.setState({ visible: false }); } }, _this.onDismiss = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onDismiss)) { _this.props.onDismiss(value); } else { _this.setState({ visible: false }); } }, _this.validateCallBack = function (rule, value, callback) { if ((0, _FunctionUtil.isFunction)(_this.props.validateCallBack)) { _this.props.validateCallBack(rule, value, callback); callback(); } else { callback(); } }, _this.pickerChange = function (value) { if ((0, _FunctionUtil.isFunction)(_this.props.onPickerChange)) { _this.props.onPickerChange(value); } }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(YYPicker, [{ key: 'render', value: function render() { var _this2 = this; var _props = this.props, label = _props.label, field = _props.field, data = _props.data, required = _props.required, errorMsg = _props.errorMsg, disabled = _props.disabled, extra = _props.extra, visible = _props.visible, trigger = _props.trigger, form = _props.form, value = _props.value, cols = _props.cols, cascade = _props.cascade, arrow = _props.arrow, style = _props.style, showIcon = _props.showIcon, icon = _props.icon, iconColor = _props.iconColor, wrap = _props.wrap, restProps = _objectWithoutProperties(_props, ['label', 'field', 'data', 'required', 'errorMsg', 'disabled', 'extra', 'visible', 'trigger', 'form', 'value', 'cols', 'cascade', 'arrow', 'style', 'showIcon', 'icon', 'iconColor', 'wrap']); var getFieldProps = form ? form.getFieldProps : null; var labelClassName = required ? (0, _classnames2.default)('yy-label-required') : (0, _classnames2.default)(''); var wrapClz = (0, _classnames2.default)('yy-picker', !visible && 'hidden', this.props.className); return _react2.default.createElement( 'div', { onClick: function onClick() { return disabled ? null : _this2.setState({ visible: true }); }, className: wrapClz }, _react2.default.createElement( _picker2.default, _extends({}, restProps, { style: Object.assign({}, style, { display: visible ? '' : 'none' }), data: data, extra: extra, title: _react2.default.createElement( 'a', { style: { color: '#108ee9' }, onClick: this.clearDate }, '\u6E05\u9664' ), cols: cols, visible: this.state.visible, disabled: disabled, cascade: cascade, onPickerChange: this.pickerChange, onOk: this.onOk, onDismiss: this.onDismiss }, (0, _FunctionUtil.isFunction)(getFieldProps) ? getFieldProps(field, { initialValue: value, rules: [{ required: required, message: errorMsg }, { validator: this.validateCallBack }], trigger: trigger, valuePropName: 'value' }) : null), _react2.default.createElement( Item, { arrow: disabled ? null : arrow, wrap: wrap }, showIcon && _react2.default.createElement(_YYIcon2.default, { type: icon, color: iconColor, style: { float: 'left', paddingRight: '8px' }, size: 'xs' }), _react2.default.createElement( 'span', { className: labelClassName, style: disabled ? { marginLeft: '0rem' } : { marginLeft: '0rem' } }, label ) ) ) ); } }]); return YYPicker; }(_react.Component); YYPicker.defaultProps = { form: {}, label: "选择", field: "default", cols: 1, errorMsg: "请输入必填项!", required: false, disabled: false, value: null, extra: "", visible: true, trigger: "onChange", cascade: true, arrow: "horizontal", showIcon: false, icon: "Home", iconColor: "red", data: [], wrap: false }; exports.default = YYPicker;