react引用antd-form组件

const AddMaintainPerson = Form.create()(React.createClass({
    getInitialState() {
        return {
            passwordDirty: false
        };
    },
    /**
     * 表单提交的内容
     * @param e
     */
    handleSubmit(e) {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, values) => {
            if (!err) {
                console.log(values);
                console.log('Received values of form: ', values);
                var managerJson={
                    "phone": values.phone,
                    "email": values.email,
                    "username": values.username,
                    "password": values.password,
                    "role":values.role
                };
                const {dispatch} = this.props;
                dispatch(fetchAddMaintain('token',managerJson));
                //提交成功之后清空数据
                this.props.form.resetFields();
            }
        });
    },
    /**
     *  获取密码框中鼠标的焦点
     * @param e
     */
    handlePasswordBlur(e) {
        const value = e.target.value;
        this.setState({ passwordDirty: this.state.passwordDirty || !!value });
    },
    /**
     *  验证两次输入的密码
     * @param rule
     * @param value
     * @param callback
     */
    checkPassword(rule, value, callback) {
        const form = this.props.form;
        if (value && value !== form.getFieldValue('password')) {
            callback('两次密码输入不一致!');
        } else {
            callback();
        }
    },
    /**
     *  验证密码是否为空
     * @param rule
     * @param value
     * @param callback
     */
    checkConfirm(rule, value, callback) {
        const form = this.props.form;
        if (value && this.state.passwordDirty) {
            form.validateFields(['confirm'], { force: true });
        }
        callback();
    },
    render() {
        const { getFieldDecorator } = this.props.form;
        //设置加载formItemLayout(输入框,单选按钮,多选框,进度条)的样式
        const formItemLayout = {
            labelCol: { span: 6 },
            wrapperCol: { span: 9 }
        };
        //设置加载tailFormItemLayout(提交按钮)的样式
        const tailFormItemLayout = {
            wrapperCol: {
                span: 14,
                offset: 7
            }
        };
        //defaultValue={['唱歌']}  设置多选框的默认值
        return (
            <div className="body_div">
                <div className='module_header'>
                    <div className='title'>
                        添加人员
                    </div>
                </div>
                <div className='module_content' style={{width:'70%'}}>
                    <Form onSubmit={this.handleSubmit}>
                        <FormItem
                            {...formItemLayout}
                            label="手机号"
                        >
                            {getFieldDecorator('phone', {
                                rules: [{
                                    required: true, message: '请输入您的手机号!'
                                }]
                            })(
                                <Input className="content_style" addonBefore={<Icon type="mobile" />} />
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="邮箱"
                            hasFeedback
                        >
                            {getFieldDecorator('email', {
                                rules: [{
                                    type: 'email', message: '输入邮箱的类型错误'
                                }, {
                                    required: true, message: '请输入您的邮箱'
                                }]
                            })(
                                <Input className="content_style" addonBefore={<Icon type="mail" />} />
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="账号"
                        >
                            {getFieldDecorator('username', {
                                rules: [{ required: true, message: '请输入您的账号' }]
                            })(
                                <Input className="content_style" addonBefore={<Icon type="user" />} />
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="密码"
                            hasFeedback
                        >
                            {getFieldDecorator('password', {
                                rules: [{
                                    required: true, message: '请输入您的密码'
                                }, {
                                    validator: this.checkConfirm
                                }]
                            })(
                                <Input className="content_style" addonBefore={<Icon type="lock" />} type="password" onBlur={this.handlePasswordBlur} />
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="确认密码"
                            hasFeedback
                        >
                            {getFieldDecorator('confirm', {
                                rules: [{
                                    required: true, message: '请在次输入您的密码'
                                }, {
                                    validator: this.checkPassword
                                }]
                            })(
                                <Input className="content_style" addonBefore={<Icon type="lock" />} type="password" />
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="权限"
                        >
                            {getFieldDecorator('role',{
                                rules: [{ required: true, message: '请选择您的权限' }]
                            })(
                                <RadioGroup className="content_style">
                                    <Radio value="上传">上传</Radio>
                                    <Radio value="审核">审核</Radio>
                                    <Radio value="审核查询">审核查询</Radio>
                                    <Radio value="统计查询">统计查询</Radio>
                                </RadioGroup>
                            )}
                        </FormItem>
                        <FormItem {...tailFormItemLayout}>
                            <Button type="primary" htmlType="submit" size="large">提交</Button>
                        </FormItem>
                    </Form>
                </div>
            </div>
        );
    }
}));

                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值