ludc
2023-03-16 86b6157299a50579f454e4fb45a09ff21d252dab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#set($upperEntityPath=$table.entityPath.toUpperCase())
import React, { PureComponent } from 'react';
import { Form, Input, Card, Button } from 'antd';
import { connect } from 'dva';
import Panel from '../../../components/Panel';
import styles from '../../../layouts/Sword.less';
import { $!{upperEntityPath}_DETAIL, $!{upperEntityPath}_SUBMIT } from '../../../actions/$!{table.entityPath}';
 
const FormItem = Form.Item;
 
@connect(({ $!{table.entityPath}, loading }) => ({
  $!{table.entityPath},
  submitting: loading.effects['$!{table.entityPath}/submit'],
}))
@Form.create()
class $!{entity}Edit extends PureComponent {
  componentWillMount() {
    const {
      dispatch,
      match: {
        params: { id },
      },
    } = this.props;
    dispatch($!{upperEntityPath}_DETAIL(id));
  }
 
  handleSubmit = e => {
    e.preventDefault();
    const {
      dispatch,
      match: {
        params: { id },
      },
      form,
    } = this.props;
    form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        const params = {
          id,
          ...values,
        };
        console.log(params);
        dispatch($!{upperEntityPath}_SUBMIT(params));
      }
    });
  };
 
  render() {
    const {
      form: { getFieldDecorator },
      $!{table.entityPath}: { detail },
      submitting,
    } = this.props;
 
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };
 
    const action = (
      <Button type="primary" onClick={this.handleSubmit} loading={submitting}>
        提交
      </Button>
    );
 
    return (
      <Panel title="修改" back="/$!{servicePackage}/$!{table.entityPath}" action={action}>
        <Form hideRequiredMark style={{ marginTop: 8 }}>
          <Card className={styles.card} bordered={false}>
#foreach($field in $!{table.fields})
#if($!{field.name}!=$!{tenantColumn})
            <FormItem {...formItemLayout} label="$!{field.comment}">
              {getFieldDecorator('$!{field.propertyName}', {
                rules: [
                  {
                    required: true,
                    message: '请输入$!{field.comment}',
                  },
                ],
                initialValue: detail.$!{field.propertyName},
              })(<Input placeholder="请输入$!{field.comment}" />)}
            </FormItem>
#end
#end
          </Card>
        </Form>
      </Panel>
    );
  }
}
 
export default $!{entity}Edit;