yylib-quick-mobile
Version:
yylib-quick-mobile
197 lines (161 loc) • 8.84 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
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/list/style/css');
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _YYCheckbox = require('./YYCheckbox');
var _YYCheckbox2 = _interopRequireDefault(_YYCheckbox);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _FunctionUtil = require('../../utils/FunctionUtil');
require('./YYCheckboxGroup.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 YYCheckboxGroup = function (_React$Component) {
_inherits(YYCheckboxGroup, _React$Component);
function YYCheckboxGroup() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, YYCheckboxGroup);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = YYCheckboxGroup.__proto__ || Object.getPrototypeOf(YYCheckboxGroup)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
value: _this.props.value !== undefined ? _this.props.value : _this.props.defaultValue
}, _this.componentWillReceiveProps = function (nextProps) {
var getFieldValue = _this.props.form.getFieldValue;
var valueField = getFieldValue(_this.props.field);
if ('defaultValue' in nextProps) {
if (_this.props.defaultValue != nextProps.defaultValue) {
_this.setState({ value: nextProps.defaultValue });
}
}
if ('value' in nextProps) {
if (_this.props.value != nextProps.value) {
_this.setState({ value: nextProps.value });
}
}
if (valueField) {
_this.setState({
value: valueField
});
}
}, _this.validateCallBack = function (rule, value, callback) {
if ((0, _FunctionUtil.isFunction)(_this.props.validateCallBack)) {
_this.props.validateCallBack(rule, value, callback);
callback();
} else {
callback();
}
}, _this._onChange = function (value, event) {
if (event && event.target) {
event.target.value = event.target.checked;
}
var values = _this.state.value;
var index = values.indexOf(value);
if (index > -1) {
values.splice(index, 1);
} else {
values.push(value);
}
_this.setState({ value: values }, function () {
var fields = {};
fields[_this.props.field] = {
name: _this.props.field,
value: values
};
_this.props.form.setFields(fields);
if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) {
_this.props.onChange(values);
}
});
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(YYCheckboxGroup, [{
key: 'render',
value: function render() {
var _this2 = this;
var getFieldProps = this.props.form.getFieldProps;
var _props = this.props,
field = _props.field,
label = _props.label,
options = _props.options,
visible = _props.visible,
required = _props.required,
trigger = _props.trigger,
disabled = _props.disabled,
findUI = _props.findUI,
offline = _props.offline,
parentType = _props.parentType,
uiorigin = _props.uiorigin,
RunInDesign = _props.RunInDesign,
uititle = _props.uititle,
uitype = _props.uitype,
uikey = _props.uikey,
nid = _props.nid,
control_event = _props.control_event,
restProps = _objectWithoutProperties(_props, ['field', 'label', 'options', 'visible', 'required', 'trigger', 'disabled', 'findUI', 'offline', 'parentType', 'uiorigin', 'RunInDesign', 'uititle', 'uitype', 'uikey', 'nid', 'control_event']);
var wrapClz = (0, _classnames2.default)('yy-checkbox-group', !visible && 'hidden', this.props.className);
var value = this.state.value;
var optionsDesign = [{ label: 'a', value: 'a', checked: true }, { label: 'b', value: 'b', checked: false }, { label: 'c', value: 'c', checked: false }];
var requiredMsg = '必填项' + label + '未选择';
return _react2.default.createElement(
_list2.default,
_extends({}, restProps, {
className: wrapClz
}, (0, _FunctionUtil.isFunction)(getFieldProps) ? getFieldProps(field, {
initialValue: value,
rules: [{ required: required, message: requiredMsg }, { validator: this.validateCallBack }],
trigger: trigger,
valuePropName: 'value'
}) : null, {
renderHeader: label
}),
options && options.length > 0 ? options.map(function (i) {
return _react2.default.createElement(
_YYCheckbox2.default,
{ key: i.value, checked: value && value.length > 0 && value.indexOf(i.value) != '-1', onChange: _this2._onChange.bind(_this2, i.value), disabled: disabled },
i.label
);
}) : null,
RunInDesign ? optionsDesign.map(function (i) {
return _react2.default.createElement(
_YYCheckbox2.default,
{ key: i.value, checked: value && value.length > 0 && value.indexOf(i.value) != '-1', onChange: _this2._onChange.bind(_this2, i.value), disabled: disabled },
i.label
);
}) : null
);
}
}]);
return YYCheckboxGroup;
}(_react2.default.Component);
YYCheckboxGroup.defaultProps = {
field: 'default',
label: '',
options: null,
defaultValue: [],
visible: true,
required: false,
disabled: false,
findUI: '',
offline: false,
parentType: '',
uiorigin: '',
RunInDesign: false,
uititle: '',
uitype: '',
uikey: '',
nid: '',
control_event: {}
};
exports.default = YYCheckboxGroup;
;