"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _extends2 = require("babel-runtime/helpers/extends");

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require("babel-runtime/helpers/createClass");

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require("babel-runtime/helpers/inherits");

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _moment = require("moment");

var _moment2 = _interopRequireDefault(_moment);

var _propTypes = require("prop-types");

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require("classnames");

var _classnames2 = _interopRequireDefault(_classnames);

var _row = require("../row");

var _row2 = _interopRequireDefault(_row);

var _col = require("../col");

var _col2 = _interopRequireDefault(_col);

var _form = require("../form");

var _form2 = _interopRequireDefault(_form);

var _input = require("../input");

var _input2 = _interopRequireDefault(_input);

var _select = require("../select");

var _select2 = _interopRequireDefault(_select);

var _datePicker = require("../date-picker");

var _datePicker2 = _interopRequireDefault(_datePicker);

var _inputNumber = require("../input-number");

var _inputNumber2 = _interopRequireDefault(_inputNumber);

var _treeSelect = require("../tree-select");

var _treeSelect2 = _interopRequireDefault(_treeSelect);

var _cascader = require("../cascader");

var _cascader2 = _interopRequireDefault(_cascader);

var _button = require("../button");

var _button2 = _interopRequireDefault(_button);

var _upload = require("../upload");

var _upload2 = _interopRequireDefault(_upload);

var _icon = require("../icon");

var _icon2 = _interopRequireDefault(_icon);

var _radio = require("../radio");

var _radio2 = _interopRequireDefault(_radio);

var _checkbox = require("../checkbox");

var _checkbox2 = _interopRequireDefault(_checkbox);

var _timePicker = require("../time-picker");

var _timePicker2 = _interopRequireDefault(_timePicker);

var _autoComplete = require("../auto-complete");

var _autoComplete2 = _interopRequireDefault(_autoComplete);

var _slider = require("../slider");

var _slider2 = _interopRequireDefault(_slider);

var _divider = require("../divider");

var _divider2 = _interopRequireDefault(_divider);

var _rate = require("../rate");

var _rate2 = _interopRequireDefault(_rate);

var _popEdit = require("../pop-edit");

var _popEdit2 = _interopRequireDefault(_popEdit);

var _LocaleReceiver = require("antd/es/locale-provider/LocaleReceiver");

var _LocaleReceiver2 = _interopRequireDefault(_LocaleReceiver);

var _default = require("../locale/default");

var _default2 = _interopRequireDefault(_default);

require("@whalecloud/fdx-theme-fdx/dynamic-attribute.less");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var __rest = undefined && undefined.__rest || function (s, e) {
    var t = {};
    for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
        if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
};

var judgeShowTime = function judgeShowTime(values, id) {
    var targetItem = values.find(function (v) {
        return v.attrId === id;
    }) || {};
    if (Object.keys(targetItem).length) {
        var attrValue = targetItem.attrValue;

        return attrValue.indexOf(' ') > -1 && attrValue.split(' ').length === 2;
    }
    return false;
};
var transFishformToFdx = function transFishformToFdx(format, values, id) {
    var showTime = judgeShowTime(values, id);
    var fdxFormat = format.toUpperCase();
    fdxFormat = fdxFormat.replace('II', 'mm');
    fdxFormat = fdxFormat.replace(':MM', ':mm'); // #98
    fdxFormat = fdxFormat.replace('SS', 'ss');
    if (fdxFormat.split(' ').length > 1) return fdxFormat;
    return showTime ? fdxFormat + " HH:mm:ss" : fdxFormat;
};
var FormItem = _form2["default"].Item;
var Option = _select2["default"].Option;
var TextArea = _input2["default"].TextArea;

var COMMONRule = {
    required: true,
    msg: 'Required'
};
var COMMONDATE_RULE = {
    type: 'object',
    required: true,
    msg: 'Required'
};
var COMMONARRAY_RULE = {
    type: 'array',
    required: true,
    msg: 'Required'
};
// 默认表单一行一组控件
var ColLayout = {
    xs: 24,
    sm: 24,
    md: 24,
    xl: 24
};
// 默认label和输入控件的样式布局
var FormItemLayout = {
    labelCol: {
        span: 7
    },
    wrapperCol: {
        span: 17
    }
};

var DynamicAttribute = function (_Component) {
    (0, _inherits3["default"])(DynamicAttribute, _Component);

    function DynamicAttribute(props) {
        (0, _classCallCheck3["default"])(this, DynamicAttribute);

        var _this = (0, _possibleConstructorReturn3["default"])(this, (DynamicAttribute.__proto__ || Object.getPrototypeOf(DynamicAttribute)).call(this, props));

        _this.appendAddition = function () {
            var additionRegistry = _this.props.additionRegistry;

            var registries = {};
            if (!additionRegistry.length) {
                return registries;
            }
            additionRegistry.forEach(function (reg) {
                registries[reg.type] = _this.renderOther;
            });
            return registries;
        };
        // 暴露给外部的方法
        _this.getFieldsValue = function (e) {
            if (e) {
                e.preventDefault();
            }
            var _this$props = _this.props,
                form = _this$props.form,
                layout = _this$props.layout,
                initValues = _this$props.initValues,
                formProps = _this$props.formProps;
            var onSubmit = formProps.onSubmit;

            if (onSubmit) {
                onSubmit(form);
                return;
            }
            var values = {};
            var valid = true;
            form.validateFields(function (err, fieldsValue) {
                if (err) {
                    valid = false;
                    return;
                }
                Object.keys(fieldsValue).forEach(function (key) {
                    var value = fieldsValue[key];
                    if (_moment2["default"].isMoment(value)) {
                        var targetItem = layout.find(function (v) {
                            return v.id === key;
                        });
                        var id = targetItem.id,
                            _targetItem$format = targetItem.format,
                            format = _targetItem$format === undefined ? 'YYYY-MM-DD' : _targetItem$format;

                        var realFormat = transFishformToFdx(format, initValues, id);
                        values[key] = value.format(realFormat);
                    } else values[key] = value;
                });
            });
            return valid ? values : false;
        };
        _this.resetFields = function () {
            var resetFields = _this.props.form.resetFields;

            resetFields();
        };
        _this.judgeIfContain = function (item, currentValue, type) {
            var containFlag = true;
            if (type === 'multiselect' && !Array.isArray(currentValue)) currentValue = currentValue.split("|");
            var getFieldValue = _this.props.form.getFieldValue;
            var bindctrl = item.bindctrl,
                _item$data = item.data,
                data = _item$data === undefined ? [] : _item$data;

            var ctrlVal = getFieldValue(bindctrl);
            var options = data.filter(function (v) {
                return v.bindTo === ctrlVal;
            });
            if (Array.isArray(currentValue)) {
                var optionValues = options.map(function (v) {
                    return v.value;
                });
                if (currentValue.some(function (v) {
                    return !optionValues.includes(v);
                })) {
                    containFlag = false;
                }
            } else if (!options.some(function (v) {
                return v.value === currentValue;
            })) {
                containFlag = false;
            }
            return containFlag;
        };
        _this.handleMultiValues = function (type, value) {
            if (type === 'multiselect') {
                if (!value) return [];
                return value.split("|");
            }
            if (type === 'datetimepicker') {
                return value ? (0, _moment2["default"])(value) : null;
            }
            return value;
        };
        _this.handleInit = function (item) {
            var initValues = _this.props.initValues;
            var id = item.id,
                type = item.type,
                bindctrl = item.bindctrl;

            if (initValues.length > 0) {
                var targetItem = initValues.find(function (v) {
                    return v.attrId === id;
                }) || {};
                if (Object.keys(targetItem).length) {
                    if (bindctrl) {
                        if (targetItem.attrValue) {
                            if (!_this.judgeIfContain(item, targetItem.attrValue, type)) {
                                return type === 'multiselect' ? [] : null;
                            }
                        }
                    }
                    return _this.handleMultiValues(type, targetItem.attrValue);
                }
                return type === 'multiselect' ? [] : null;
            }
            return type === 'multiselect' ? [] : null;
        };
        _this.generateSelectBefore = function (data, restProps, id) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var initValues = _this.props.initValues;

            var targetItem = initValues.find(function (v) {
                return v.attrId === id;
            }) || {};
            return getFieldDecorator('prefixProtocol', {
                initialValue: targetItem.attrValue
            })(_react2["default"].createElement(
                _select2["default"],
                (0, _extends3["default"])({ className: "dynamic-select", style: { width: 90 } }, restProps),
                data.length !== 0 && data.map(function (item, index) {
                    return _react2["default"].createElement(
                        Option,
                        { value: item, key: "protocol-" + index },
                        item
                    );
                })
            ));
        };
        _this.generateSelectAfter = function (data, restProps, id) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var initValues = _this.props.initValues;

            var targetItem = initValues.find(function (v) {
                return v.attrId === id;
            }) || {};
            return getFieldDecorator('suffixSite', {
                initialValue: targetItem.attrValue
            })(_react2["default"].createElement(
                _select2["default"],
                (0, _extends3["default"])({ className: "dynamic-select", style: { width: 80 } }, restProps),
                data.length !== 0 && data.map(function (item, index) {
                    return _react2["default"].createElement(
                        Option,
                        { value: item, key: "site-" + index },
                        item
                    );
                })
            ));
        };
        _this.renderOptions = function (item) {
            var bindctrl = item.bindctrl,
                data = item.data,
                id = item.id,
                type = item.type;
            var _this$props$form = _this.props.form,
                getFieldValue = _this$props$form.getFieldValue,
                resetFields = _this$props$form.resetFields;

            var options = data;
            if (bindctrl) {
                var ctrlVal = getFieldValue(bindctrl);
                if (ctrlVal) {
                    options = data.filter(function (v) {
                        return v.bindTo === ctrlVal;
                    });
                }
                // 若当前选择项不全部属于bindctrl，需要清空选择项
                var currentValue = getFieldValue(id);
                if (currentValue) {
                    if (!_this.judgeIfContain(item, currentValue, type)) {
                        resetFields([id]);
                    }
                }
            }
            return options.map(function (iem) {
                return _react2["default"].createElement(
                    Option,
                    { value: iem.value, key: bindctrl + "_" + iem.value + "_" + iem.name },
                    iem.name
                );
            });
        };
        _this.renderItem = function (item, index) {
            var formProps = _this.props.formProps;
            var registry = _this.state.registry;
            var _formProps$colLayout = formProps.colLayout,
                colLayout = _formProps$colLayout === undefined ? ColLayout : _formProps$colLayout,
                _formProps$formItemLa = formProps.formItemLayout,
                formItemLayout = _formProps$formItemLa === undefined ? FormItemLayout : _formProps$formItemLa;
            var type = item.type,
                label = item.label,
                _item$colLayout = item.colLayout,
                itemColLayout = _item$colLayout === undefined ? colLayout : _item$colLayout,
                _item$formItemLayout = item.formItemLayout,
                itemFormLayout = _item$formItemLayout === undefined ? formItemLayout : _item$formItemLayout,
                _item$ctrlProps = item.ctrlProps,
                ctrlProps = _item$ctrlProps === undefined ? {} : _item$ctrlProps;
            var _ctrlProps$readOnly = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly === undefined ? false : _ctrlProps$readOnly;

            var renderFunc = registry[type];
            var relColLayout = (0, _extends3["default"])({}, itemColLayout);
            if (item.type === 'hidden') relColLayout = { span: 0 }; // #98 隐藏 FormItem 同时 需要隐藏包裹 FormItem 的 Col
            return _react2["default"].createElement(
                _col2["default"],
                (0, _extends3["default"])({ key: "dynamic_" + index }, relColLayout),
                type === 'divider' ? _react2["default"].createElement(_divider2["default"], null) : _react2["default"].createElement(
                    FormItem,
                    (0, _extends3["default"])({ className: (0, _classnames2["default"])('dynamic-form-item', { 'readOnlyItem': readOnly === true, 'hiddenItem': type === 'hidden' }) }, itemFormLayout, { label: label }),
                    renderFunc(item, index)
                )
            );
        };
        _this.renderCommonAttrs = function (item) {
            var onChange = _this.props.onChange;
            var _item$ctrlProps2 = item.ctrlProps,
                ctrlProps = _item$ctrlProps2 === undefined ? {} : _item$ctrlProps2;

            var params = (0, _extends3["default"])({}, ctrlProps);
            if (onChange) {
                params.onChange = function (value) {
                    onChange(item.id, value);
                };
            }
            return params;
        };
        _this.renderSubmit = function (item) {
            var _item$ctrlProps3 = item.ctrlProps,
                ctrlProps = _item$ctrlProps3 === undefined ? {} : _item$ctrlProps3,
                _item$btnProps = item.btnProps,
                btnProps = _item$btnProps === undefined ? {} : _item$btnProps;
            var _ctrlProps$readOnly2 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly2 === undefined ? false : _ctrlProps$readOnly2;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var _btnProps$label = btnProps.label,
                label = _btnProps$label === undefined ? 'submit' : _btnProps$label;

            return _react2["default"].createElement(
                _react.Fragment,
                null,
                _react2["default"].createElement(
                    _button2["default"],
                    (0, _extends3["default"])({ type: "primary", htmlType: "submit" }, restProps),
                    label
                )
            );
        };
        _this.filterRules = function () {
            var rules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

            rules.forEach(function (rule) {
                if (rule.pattern !== undefined) {
                    var flag = rule.flag || 'i';
                    rule.pattern = new RegExp(rule.pattern, flag);
                }
            });
            return rules;
        };
        _this.renderInput = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var _item$datarule = item.datarule,
                datarule = _item$datarule === undefined ? '' : _item$datarule,
                id = item.id,
                required = item.required,
                type = item.type,
                _item$rules = item.rules,
                rules = _item$rules === undefined ? [] : _item$rules;

            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONRule);
            var key = "length";
            if (datarule.length > 0 && datarule.indexOf(key) > -1) {
                var index = datarule.indexOf(key) + key.length;
                var maxmin = datarule.substring(index, datarule.length);
                var min = maxmin.substring(1, maxmin.indexOf("~"));
                var max = maxmin.substring(maxmin.indexOf("~") + 1, maxmin.length - 1);
                if (min !== '') rulesDefault.unshift({
                    min: parseInt(min, 10)
                });
                if (max !== '') rulesDefault.unshift({
                    max: parseInt(max, 10)
                });
            }
            if (type === 'textarea') {
                return getFieldDecorator(id, {
                    initialValue: _this.handleInit(item),
                    rules: rulesDefault
                })(_react2["default"].createElement(TextArea, _this.renderCommonAttrs(item)));
            }
            if (type === 'text') {
                return getFieldDecorator(id, {
                    initialValue: _this.handleInit(item),
                    rules: rulesDefault
                })(_react2["default"].createElement(_input2["default"], _this.renderCommonAttrs(item)));
            }
            if (type === 'password') {
                return getFieldDecorator(id, {
                    initialValue: _this.handleInit(item),
                    rules: rulesDefault
                })(_react2["default"].createElement(_input2["default"].Password, _this.renderCommonAttrs(item)));
            } else {
                return getFieldDecorator(id, {
                    initialValue: _this.handleInit(item)
                })(_react2["default"].createElement(_input2["default"], null));
            }
        };
        _this.renderOther = function (item) {
            var _this$props2 = _this.props,
                getFieldDecorator = _this$props2.form.getFieldDecorator,
                additionRegistry = _this$props2.additionRegistry;
            var required = item.required,
                id = item.id,
                _item$rules2 = item.rules,
                rules = _item$rules2 === undefined ? [] : _item$rules2;

            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var reg = additionRegistry.find(function (data) {
                return data.type === id;
            });
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(reg.getComp());
        };
        _this.renderNumber = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules3 = item.rules,
                rules = _item$rules3 === undefined ? [] : _item$rules3;

            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(_inputNumber2["default"], (0, _extends3["default"])({ className: "dynamic-input-number" }, _this.renderCommonAttrs(item))));
        };
        _this.getUploadBtn = function (item, restProps, locale) {
            var _item$ctrlProps4 = item.ctrlProps,
                ctrlProps = _item$ctrlProps4 === undefined ? {} : _item$ctrlProps4;
            var listType = ctrlProps.listType;

            if (listType === 'picture-card') {
                return _react2["default"].createElement(
                    "div",
                    null,
                    _react2["default"].createElement(_icon2["default"], { type: "plus" }),
                    _react2["default"].createElement(
                        "div",
                        { className: "ant-upload-text" },
                        locale.upload
                    )
                );
            }
            return _react2["default"].createElement(
                _button2["default"],
                restProps,
                _react2["default"].createElement(_icon2["default"], { type: "upload" }),
                " ",
                locale.clickToUpload
            );
        };
        _this.renderFile = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules4 = item.rules,
                rules = _item$rules4 === undefined ? [] : _item$rules4,
                _item$ctrlProps5 = item.ctrlProps,
                ctrlProps = _item$ctrlProps5 === undefined ? {} : _item$ctrlProps5;
            var _ctrlProps$readOnly3 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly3 === undefined ? false : _ctrlProps$readOnly3;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var fileProps = (0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), restProps);
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(
                _upload2["default"],
                fileProps,
                _react2["default"].createElement(
                    _LocaleReceiver2["default"],
                    { componentName: "DynamicAttribute", defaultLocale: _default2["default"].DynamicAttribute },
                    function (locale) {
                        return _this.getUploadBtn(item, restProps, locale);
                    }
                )
            ));
        };
        _this.renderSlider = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules5 = item.rules,
                rules = _item$rules5 === undefined ? [] : _item$rules5,
                _item$ctrlProps6 = item.ctrlProps,
                ctrlProps = _item$ctrlProps6 === undefined ? {} : _item$ctrlProps6,
                _item$data2 = item.data,
                data = _item$data2 === undefined ? {} : _item$data2;
            var _ctrlProps$readOnly4 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly4 === undefined ? false : _ctrlProps$readOnly4;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var sliderProps = (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), restProps), { marks: data });
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item) || 0,
                rules: rulesDefault
            })(_react2["default"].createElement(_slider2["default"], sliderProps));
        };
        _this.renderRate = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules6 = item.rules,
                rules = _item$rules6 === undefined ? [] : _item$rules6,
                _item$ctrlProps7 = item.ctrlProps,
                ctrlProps = _item$ctrlProps7 === undefined ? {} : _item$ctrlProps7,
                _item$data3 = item.data,
                data = _item$data3 === undefined ? {} : _item$data3;
            var _ctrlProps$readOnly5 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly5 === undefined ? false : _ctrlProps$readOnly5;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var sliderProps = (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), restProps), { marks: data });
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(_rate2["default"], (0, _extends3["default"])({ className: "dynamic-rate" }, sliderProps)));
        };
        _this.renderCombination = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                prefixId = item.prefixId,
                suffixId = item.suffixId,
                _item$rules7 = item.rules,
                rules = _item$rules7 === undefined ? [] : _item$rules7,
                _item$ctrlProps8 = item.ctrlProps,
                ctrlProps = _item$ctrlProps8 === undefined ? {} : _item$ctrlProps8,
                _item$addonBefore = item.addonBefore,
                addonBefore = _item$addonBefore === undefined ? ['Http://', 'Https://'] : _item$addonBefore,
                _item$addonAfter = item.addonAfter,
                addonAfter = _item$addonAfter === undefined ? ['.com', '.jp', '.cn', '.org'] : _item$addonAfter;
            var _ctrlProps$readOnly6 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly6 === undefined ? false : _ctrlProps$readOnly6;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var urlProps = (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), restProps), { allowClear: true, addonBefore: _this.generateSelectBefore(addonBefore, restProps, prefixId), addonAfter: _this.generateSelectAfter(addonAfter, restProps, suffixId) });
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(_input2["default"], urlProps));
        };
        _this.filterEmail = function (value) {
            var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

            var emailSearchResult = void 0;
            if (!value || value.indexOf('@') >= 0) {
                emailSearchResult = [];
            } else {
                emailSearchResult = data.map(function (domain) {
                    return value + "@" + domain;
                });
            }
            _this.setState({
                emailSearchResult: emailSearchResult
            });
        };
        _this.renderEmailOption = function (item) {
            var _item$data4 = item.data,
                data = _item$data4 === undefined ? [] : _item$data4,
                id = item.id;
            var getFieldValue = _this.props.form.getFieldValue;

            var target = getFieldValue(id);
            return _this.filterEmail(target, data);
        };
        _this.renderEmail = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules8 = item.rules,
                rules = _item$rules8 === undefined ? [] : _item$rules8,
                _item$ctrlProps9 = item.ctrlProps,
                ctrlProps = _item$ctrlProps9 === undefined ? {} : _item$ctrlProps9;
            var _ctrlProps$readOnly7 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly7 === undefined ? false : _ctrlProps$readOnly7;
            var _this$state$emailSear = _this.state.emailSearchResult,
                emailSearchResult = _this$state$emailSear === undefined ? [] : _this$state$emailSear;

            var children = emailSearchResult.map(function (email) {
                return _react2["default"].createElement(
                    _autoComplete2["default"].Option,
                    { key: email },
                    email
                );
            });
            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var emailProps = (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), restProps), { allowClear: true, style: { width: '100%' }, onSearch: function onSearch() {
                    return _this.renderEmailOption(item);
                } });
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(
                _autoComplete2["default"],
                emailProps,
                children
            ));
        };
        _this.renderRadioGroup = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules9 = item.rules,
                rules = _item$rules9 === undefined ? [] : _item$rules9,
                _item$ctrlProps10 = item.ctrlProps,
                ctrlProps = _item$ctrlProps10 === undefined ? {} : _item$ctrlProps10,
                _item$data5 = item.data,
                data = _item$data5 === undefined ? [] : _item$data5,
                type = item.type;
            var _ctrlProps$readOnly8 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly8 === undefined ? false : _ctrlProps$readOnly8;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var radioProps = (0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), restProps);
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_this.renderGroup(type, data, radioProps));
        };
        _this.renderGroup = function (type) {
            var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
            var props = arguments[2];

            if (type === 'radioGroup') {
                return _react2["default"].createElement(
                    _radio2["default"].Group,
                    (0, _extends3["default"])({ className: "dynamic-radio-group" }, props),
                    data.length !== 0 && data.map(function (radio, index) {
                        return _react2["default"].createElement(
                            _radio2["default"],
                            { value: radio.value, key: "radio-group-" + index },
                            radio.label
                        );
                    })
                );
            } else {
                return _react2["default"].createElement(
                    _radio2["default"].Group,
                    (0, _extends3["default"])({ className: "dynamic-radio-group" }, props),
                    data.length !== 0 && data.map(function (radio, index) {
                        return _react2["default"].createElement(
                            _radio2["default"].Button,
                            { value: radio.value, key: "radio-button-" + index },
                            radio.label
                        );
                    })
                );
            }
        };
        _this.renderCheckbox = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules10 = item.rules,
                rules = _item$rules10 === undefined ? [] : _item$rules10,
                _item$ctrlProps11 = item.ctrlProps,
                ctrlProps = _item$ctrlProps11 === undefined ? {} : _item$ctrlProps11,
                _item$data6 = item.data,
                data = _item$data6 === undefined ? [] : _item$data6;
            var _ctrlProps$readOnly9 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly9 === undefined ? false : _ctrlProps$readOnly9;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var checkboxProps = (0, _extends3["default"])((0, _extends3["default"])({ options: data }, _this.renderCommonAttrs(item)), restProps);
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(_checkbox2["default"].Group, (0, _extends3["default"])({ className: "dynamic-checkbox-group" }, checkboxProps)));
        };
        _this.renderDateItem = function (props, type) {
            switch (type) {
                case 'datetimepicker':
                    return _react2["default"].createElement(_datePicker2["default"], props);
                case 'dateRangePicker':
                    return _react2["default"].createElement(_datePicker2["default"].RangePicker, (0, _extends3["default"])({ className: "dynamic-range-picker" }, props));
                default:
                    break;
            }
        };
        _this.renderDatePicker = function (item) {
            var _this$props3 = _this.props,
                getFieldDecorator = _this$props3.form.getFieldDecorator,
                initValues = _this$props3.initValues;
            var required = item.required,
                id = item.id,
                format = item.format,
                type = item.type,
                _item$ctrlProps12 = item.ctrlProps,
                ctrlProps = _item$ctrlProps12 === undefined ? {} : _item$ctrlProps12,
                _item$rules11 = item.rules,
                rules = _item$rules11 === undefined ? [] : _item$rules11;
            var _ctrlProps$readOnly10 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly10 === undefined ? false : _ctrlProps$readOnly10;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var fdxFormat = format;
            if (format) {
                fdxFormat = transFishformToFdx(format, initValues, id);
            }
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var dateProps = (0, _extends3["default"])((0, _extends3["default"])({ style: { width: '100%' }, format: fdxFormat, allowClear: true, showTime: judgeShowTime(initValues, id) }, _this.renderCommonAttrs(item)), restProps);
            var initTime = type !== 'dateRangePicker' ? _this.handleInit(item) : _this.formatRangeTime(_this.handleInit(item), fdxFormat);
            return getFieldDecorator(id, {
                initialValue: initTime,
                rules: rulesDefault
            })(_this.renderDateItem(dateProps, type));
        };
        _this.formatRangeTime = function (value, format) {
            if (value === null) return null;
            return value.map(function (time) {
                return (0, _moment2["default"])(time, format);
            });
        };
        _this.renderTimePicker = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$format = item.format,
                format = _item$format === undefined ? 'HH:mm:ss' : _item$format,
                _item$ctrlProps13 = item.ctrlProps,
                ctrlProps = _item$ctrlProps13 === undefined ? {} : _item$ctrlProps13,
                _item$rules12 = item.rules,
                rules = _item$rules12 === undefined ? [] : _item$rules12;
            var _ctrlProps$readOnly11 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly11 === undefined ? false : _ctrlProps$readOnly11;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var timeProps = (0, _extends3["default"])((0, _extends3["default"])({ style: { width: '100%' }, format: format, allowClear: true }, _this.renderCommonAttrs(item)), restProps);
            var initTime = _this.handleInit(item) ? (0, _moment2["default"])(_this.handleInit(item), format) : null;
            return getFieldDecorator(id, {
                initialValue: initTime,
                rules: rulesDefault
            })(_react2["default"].createElement(_timePicker2["default"], timeProps));
        };
        _this.renderSelect = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                type = item.type,
                _item$rules13 = item.rules,
                rules = _item$rules13 === undefined ? [] : _item$rules13,
                _item$ctrlProps14 = item.ctrlProps,
                ctrlProps = _item$ctrlProps14 === undefined ? {} : _item$ctrlProps14;
            var _ctrlProps$readOnly12 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly12 === undefined ? false : _ctrlProps$readOnly12;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(type === "multiselect" ? COMMONARRAY_RULE : COMMONRule);
            var selectProps = (0, _extends3["default"])((0, _extends3["default"])({ allowClear: true, width: '100%' }, _this.renderCommonAttrs(item)), restProps);
            if (type === "multiselect") selectProps.mode = "multiple";
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(
                _select2["default"],
                (0, _extends3["default"])({ className: "dynamic-select" }, selectProps),
                _this.renderOptions(item)
            ));
        };
        _this.renderTreeSelect = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules14 = item.rules,
                rules = _item$rules14 === undefined ? [] : _item$rules14,
                _item$ctrlProps15 = item.ctrlProps,
                ctrlProps = _item$ctrlProps15 === undefined ? {} : _item$ctrlProps15;
            var _ctrlProps$readOnly13 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly13 === undefined ? false : _ctrlProps$readOnly13;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var selectTreeProps = (0, _extends3["default"])((0, _extends3["default"])({ width: '100%', allowClear: true, dropdownStyle: { maxHeight: 400, overflow: 'auto' }, treeDefaultExpandAll: true }, _this.renderCommonAttrs(item)), restProps);
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(_treeSelect2["default"], (0, _extends3["default"])({ className: "dynamic-select" }, selectTreeProps)));
        };
        _this.renderCascader = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$rules15 = item.rules,
                rules = _item$rules15 === undefined ? [] : _item$rules15,
                _item$ctrlProps16 = item.ctrlProps,
                ctrlProps = _item$ctrlProps16 === undefined ? {} : _item$ctrlProps16;
            var _ctrlProps$readOnly14 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly14 === undefined ? false : _ctrlProps$readOnly14;

            var restProps = {};
            if (readOnly) restProps.disabled = true;
            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var cascaderProps = (0, _extends3["default"])((0, _extends3["default"])({ width: '100%', allowClear: true }, _this.renderCommonAttrs(item)), restProps);
            return getFieldDecorator(id, {
                initialValue: _this.handleInit(item),
                rules: rulesDefault
            })(_react2["default"].createElement(_cascader2["default"], (0, _extends3["default"])({ className: "dynamic-cascader" }, cascaderProps)));
        };
        _this.renderPopEdit = function (item) {
            var getFieldDecorator = _this.props.form.getFieldDecorator;
            var required = item.required,
                id = item.id,
                _item$popeditProps = item.popeditProps,
                popeditProps = _item$popeditProps === undefined ? {} : _item$popeditProps,
                _item$rules16 = item.rules,
                rules = _item$rules16 === undefined ? [] : _item$rules16,
                _item$ctrlProps17 = item.ctrlProps,
                ctrlProps = _item$ctrlProps17 === undefined ? {} : _item$ctrlProps17;
            var _ctrlProps$readOnly15 = ctrlProps.readOnly,
                readOnly = _ctrlProps$readOnly15 === undefined ? false : _ctrlProps$readOnly15;

            var rulesDefault = _this.filterRules(rules);
            if (required) rulesDefault.unshift(COMMONDATE_RULE);
            var restProps = {};
            if (readOnly) restProps.disabled = true;
            popeditProps.inputProps = (0, _extends3["default"])((0, _extends3["default"])({ width: '100%' }, ctrlProps), popeditProps.inputProps);
            popeditProps.modalProps = (0, _extends3["default"])((0, _extends3["default"])({}, _this.renderCommonAttrs(item)), popeditProps.modalProps);
            var defaultProps = (0, _extends3["default"])((0, _extends3["default"])({}, restProps), popeditProps);
            var defaultValue = _this.handleInit(item);
            if (typeof defaultValue === 'string') {
                try {
                    defaultValue = JSON.parse(defaultValue);
                } catch (error) {
                    // console.log('popEdit 数据格式错误：', error)
                }
            }
            return getFieldDecorator(id, {
                initialValue: defaultValue,
                rules: rulesDefault
            })(_react2["default"].createElement(_popEdit2["default"], defaultProps));
        };
        _this.handleProps = function (formProps) {
            // eslint-disable-next-line no-unused-vars
            var _formProps$colLayout2 = formProps.colLayout,
                colLayout = _formProps$colLayout2 === undefined ? ColLayout : _formProps$colLayout2,
                _formProps$formItemLa2 = formProps.formItemLayout,
                formItemLayout = _formProps$formItemLa2 === undefined ? FormItemLayout : _formProps$formItemLa2,
                resetProps = __rest(formProps, ["colLayout", "formItemLayout"]);

            return (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, colLayout), formItemLayout), resetProps);
        };
        _this.state = {
            emailSearchResult: [],
            popEditModalVisible: false,
            registry: (0, _extends3["default"])({ text: _this.renderInput, textarea: _this.renderInput, password: _this.renderInput, hidden: _this.renderInput, datetimepicker: _this.renderDatePicker, dateRangePicker: _this.renderDatePicker, combobox: _this.renderSelect, multiselect: _this.renderSelect, number: _this.renderNumber, popedit: _this.renderPopEdit, treeSelect: _this.renderTreeSelect, cascader: _this.renderCascader, file: _this.renderFile, radioGroup: _this.renderRadioGroup, radioButton: _this.renderRadioGroup, checkbox: _this.renderCheckbox, timePicker: _this.renderTimePicker, combination: _this.renderCombination, email: _this.renderEmail, slider: _this.renderSlider, rate: _this.renderRate, submit: _this.renderSubmit }, _this.appendAddition())
        };
        return _this;
    }

    (0, _createClass3["default"])(DynamicAttribute, [{
        key: "render",
        value: function render() {
            var _props = this.props,
                layout = _props.layout,
                formProps = _props.formProps,
                children = _props.children;

            return _react2["default"].createElement(
                "div",
                { className: "fdx-form" },
                _react2["default"].createElement(
                    _form2["default"],
                    (0, _extends3["default"])({}, this.handleProps(formProps), { onSubmit: this.getFieldsValue }),
                    _react2["default"].createElement(
                        _row2["default"],
                        null,
                        layout.map(this.renderItem),
                        children
                    )
                )
            );
        }
    }]);
    return DynamicAttribute;
}(_react.Component);

DynamicAttribute.propTypes = {
    formProps: _propTypes2["default"].object,
    layout: _propTypes2["default"].array,
    initValues: _propTypes2["default"].array
};
DynamicAttribute.defaultProps = {
    formProps: {
        colLayout: ColLayout,
        formItemLayout: FormItemLayout
    },
    layout: [],
    initValues: [],
    additionRegistry: []
};
exports["default"] = _form2["default"].create()(DynamicAttribute);
module.exports = exports['default'];