当前位置:   article > 正文

react+antd的Modal与Form复合使用_react antd 表单复用

react antd 表单复用

效果图

 

点击发放按钮后弹出modal,点击“确认发放”按钮后校验“输入金额”输入框

visible控制modal的显示

 

具体实现代码

Modal+Form代码:

  1. <Modal
  2.     destroyOnClose
  3.     title="工资发放"
  4.     visible={this.state.visible}
  5.     footer={null}
  6. >
  7.     <Form >
  8.  
  9.               <FormItem
  10.             {...formItemLayout}
  11.             label="输入金额"
  12.             hasFeedback
  13.         >
  14.             {getFieldDecorator('account', {
  15.                 rules:[{
  16.                     required:true,
  17.                     pattern: new RegExp(  /^[0-9]+([.]\d{0,2})?$/),
  18.                     message: '请输入正确价格'
  19.                 }],
  20.             })(
  21.                 <Input />
  22.             )}
  23.         </FormItem>
  24.         <FormItem
  25.             {...formItemLayout}
  26.             label="教师编号"
  27.             hasFeedback
  28.             hidden={true}
  29.         >
  30.             {getFieldDecorator('teacherId', {
  31.                 rules:[{
  32.                     required:true,
  33.                 }],
  34.             })(
  35.                 <Input  hidden={true}  />
  36.             )}
  37.         </FormItem>
  38.         <FormItem
  39.             {...formItemLayout}
  40.             label="老师姓名"
  41.             hasFeedback
  42.         >
  43.             {getFieldDecorator('nickName', {
  44.             })(
  45.                 <Input  disabled ={true}/>
  46.             )}
  47.               
  48.         </FormItem>
  49.         <FormItem
  50.             {...formItemLayout}
  51.             label="手机号"
  52.             hasFeedback
  53.         >
  54.             {getFieldDecorator('phone', {
  55.             })(
  56.                 <Input disabled ={true} />
  57.             )}
  58.         </FormItem>
  59.         <FormItem
  60.             {...formItemLayout}
  61.             label="所属银行"
  62.             hasFeedback
  63.         >
  64.             {getFieldDecorator('openAccountBank', {
  65.             })(
  66.                 <Input disabled ={true} />
  67.             )}
  68.         </FormItem>
  69.         <FormItem
  70.             {...formItemLayout}
  71.             label="卡号"
  72.             hasFeedback
  73.         >
  74.             {getFieldDecorator('accountNumber', {
  75.             })(
  76.                 <Input disabled ={true} />
  77.             )}
  78.         </FormItem>
  79.         <FormItem
  80.             {...formItemLayout}
  81.             label="银行卡姓名"
  82.             hasFeedback
  83.         >
  84.             {getFieldDecorator('openAccountName', {
  85.             })(
  86.                 <Input disabled ={true} />
  87.             )}
  88.         </FormItem>
  89.         <FormItem
  90.             {...formItemLayout}
  91.             label="银行预留手机号"
  92.             hasFeedback
  93.         >
  94.             {getFieldDecorator('openAccountPhone', {
  95.             })(
  96.                 <Input disabled ={true} />
  97.             )}
  98.         </FormItem>
  99.         <FormItem
  100.             {...formItemLayout}
  101.             label="身份证号"
  102.             hasFeedback
  103.         >
  104.             {getFieldDecorator('openAccountPaper', {
  105.             })(
  106.                 <Input disabled ={true} />
  107.             )}
  108.         </FormItem>
  109.     </Form>
  110.     <div style={{ width:'100%', margin: ' 20px  30% ' }}>
  111.         <Button  onClick={this.handleCancelOrder}>取消</Button>
  112.         <Button style={{ margin: ' 0  20px ' }}  onClick={this.saveOderInfo} type="primary">确认发放</Button>
  113.     </div>
  114. </Modal>

 

事件:

发放按钮触发事件

  1. handleGive = (item) => {
  2.     let id = item.id;
  3.     this.setState({
  4.         visible: true,
  5.         id:id,
  6.          });
  7.     if(id == 'undefined'){
  8.         return false
  9.     }
  10.     detailTeacherAudit({id:id}).then(res=>{
  11.         if(res.code == 200) {
  12.             console.log(res)
  13.             let i = res.result
  14.             this.setState({
  15.                 id:i.id,
  16.             })
  17.             this.props.form.setFieldsValue({
  18.                 nickName:i.nickName,//老师姓名
  19.                 phone:i.phone, //手机号
  20.                 accountNumber:i.accountNumber,//银行账号
  21.                 teacherId:i.teacherId,//老师姓名
  22.                 openAccountPhone:i.openAccountPhone, //开户手机号
  23.                 openAccountName:i.openAccountName,//开户姓名
  24.                 openAccountBank:i.openAccountBank, //开户银行
  25.                 openAccountPaper:i.openAccountPaper, //开户身份证号
  26.                 account:'',//账户金额
  27.             });
  28.         } else {
  29.         }
  30.     })
  31. };
 
确认发放按钮事件
  1. saveOderInfo = (e) => {
  2.     e.preventDefault();
  3.     this.props.form.validateFields((err, values) => {
  4.         if (!err) {
  5.             console.log('Received values of form: ', values);
  6.             if(values.account == "") {
  7.                 message.error('请输入金额!');
  8.             }
  9.             var param= {}
  10.                 param = {
  11.                     account:values.account, teacherId:values.teacherId,uid:localStorage.getItem('id'),
  12.                 }
  13.             Modal.confirm({
  14.                 title: '确认',
  15.                 content: '您确认要发放?',
  16.                 cancelText:'取消',
  17.                 okText:"确定",
  18.                 onOk: () => {
  19.                                       createOrderByTeacherID(param).then(res=>{
  20.                         if(res.code == 200) {
  21.                             message.success('申请成功');
  22.                             this.setState({
  23.                                 visible: false,
  24.                             });
  25.                             this.props.history.replace('/teacherSalary');
  26.                         }else if (res.code == '-1000'){
  27.                             message.success(res.message);
  28.                             message.success('该用户信息已发起过签约,签约结果:签约中');
  29.                             this.props.history.replace('/teacherSalary');
  30.                         }
  31.                     })
  32.                 }
  33.             })
  34.         }
  35.     });

 

取消按钮触发事件

  1. handleCancelOrder = e => {
  2.     console.log(e);
  3.     this.setState({
  4.         visible: false,
  5.     });
  6. };

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/115647
推荐阅读
相关标签