edit.js.vm 2.5 KB

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