BasicForm.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'dva';
  3. import {
  4. Form, Input, DatePicker, Select, Button, Card, InputNumber, Radio, Icon, Tooltip,
  5. } from 'antd';
  6. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  7. import styles from './style.less';
  8. const FormItem = Form.Item;
  9. const { Option } = Select;
  10. const { RangePicker } = DatePicker;
  11. const { TextArea } = Input;
  12. @connect(state => ({
  13. submitting: state.form.regularFormSubmitting,
  14. }))
  15. @Form.create()
  16. export default class BasicForms extends PureComponent {
  17. handleSubmit = (e) => {
  18. e.preventDefault();
  19. this.props.form.validateFieldsAndScroll((err, values) => {
  20. if (!err) {
  21. this.props.dispatch({
  22. type: 'form/submitRegularForm',
  23. payload: values,
  24. });
  25. }
  26. });
  27. }
  28. render() {
  29. const { submitting } = this.props;
  30. const { getFieldDecorator, getFieldValue } = this.props.form;
  31. const formItemLayout = {
  32. labelCol: {
  33. xs: { span: 24 },
  34. sm: { span: 7 },
  35. },
  36. wrapperCol: {
  37. xs: { span: 24 },
  38. sm: { span: 12 },
  39. md: { span: 10 },
  40. },
  41. };
  42. const submitFormLayout = {
  43. wrapperCol: {
  44. xs: { span: 24, offset: 0 },
  45. sm: { span: 10, offset: 7 },
  46. },
  47. };
  48. return (
  49. <PageHeaderLayout title="基础表单" content="表单页用于向用户收集或验证信息,基础表单常见于数据项较少的表单场景。">
  50. <Card bordered={false}>
  51. <Form
  52. onSubmit={this.handleSubmit}
  53. hideRequiredMark
  54. style={{ marginTop: 8 }}
  55. >
  56. <FormItem
  57. {...formItemLayout}
  58. label="标题"
  59. >
  60. {getFieldDecorator('title', {
  61. rules: [{
  62. required: true, message: '请输入标题',
  63. }],
  64. })(
  65. <Input placeholder="给目标起个名字" />
  66. )}
  67. </FormItem>
  68. <FormItem
  69. {...formItemLayout}
  70. label="起止日期"
  71. >
  72. {getFieldDecorator('date', {
  73. rules: [{
  74. required: true, message: '请选择起止日期',
  75. }],
  76. })(
  77. <RangePicker style={{ width: '100%' }} placeholder={['开始日期', '结束日期']} />
  78. )}
  79. </FormItem>
  80. <FormItem
  81. {...formItemLayout}
  82. label="目标描述"
  83. >
  84. {getFieldDecorator('goal', {
  85. rules: [{
  86. required: true, message: '请输入目标描述',
  87. }],
  88. })(
  89. <TextArea style={{ minHeight: 32 }} placeholder="请输入你的阶段性工作目标" rows={4} />
  90. )}
  91. </FormItem>
  92. <FormItem
  93. {...formItemLayout}
  94. label="衡量标准"
  95. >
  96. {getFieldDecorator('standard', {
  97. rules: [{
  98. required: true, message: '请输入衡量标准',
  99. }],
  100. })(
  101. <TextArea style={{ minHeight: 32 }} placeholder="请输入衡量标准" rows={4} />
  102. )}
  103. </FormItem>
  104. <FormItem
  105. {...formItemLayout}
  106. label={
  107. <span>
  108. 客户
  109. <em className={styles.optional}>
  110. (选填)
  111. <Tooltip title="目标的服务对象">
  112. <Icon type="info-circle-o" style={{ marginRight: 4 }} />
  113. </Tooltip>
  114. </em>
  115. </span>
  116. }
  117. >
  118. {getFieldDecorator('client')(
  119. <Input placeholder="请描述你服务的客户,内部客户直接 @姓名/工号" />
  120. )}
  121. </FormItem>
  122. <FormItem
  123. {...formItemLayout}
  124. label={<span>邀评人<em className={styles.optional}>(选填)</em></span>}
  125. >
  126. {getFieldDecorator('invites')(
  127. <Input placeholder="请直接 @姓名/工号,最多可邀请 5 人" />
  128. )}
  129. </FormItem>
  130. <FormItem
  131. {...formItemLayout}
  132. label={<span>权重<em className={styles.optional}>(选填)</em></span>}
  133. >
  134. {getFieldDecorator('weight')(
  135. <InputNumber placeholder="请输入" min={0} max={100} />
  136. )}
  137. <span>%</span>
  138. </FormItem>
  139. <FormItem
  140. {...formItemLayout}
  141. label="目标公开"
  142. help="客户、邀评人默认被分享"
  143. >
  144. <div>
  145. {getFieldDecorator('public', {
  146. initialValue: '1',
  147. })(
  148. <Radio.Group>
  149. <Radio value="1">公开</Radio>
  150. <Radio value="2">部分公开</Radio>
  151. <Radio value="3">不公开</Radio>
  152. </Radio.Group>
  153. )}
  154. <FormItem style={{ marginBottom: 0 }}>
  155. {getFieldDecorator('publicUsers')(
  156. <Select
  157. mode="multiple"
  158. placeholder="公开给"
  159. style={{
  160. margin: '8px 0',
  161. display: getFieldValue('public') === '2' ? 'block' : 'none',
  162. }}
  163. >
  164. <Option value="1">同事甲</Option>
  165. <Option value="2">同事乙</Option>
  166. <Option value="3">同事丙</Option>
  167. </Select>
  168. )}
  169. </FormItem>
  170. </div>
  171. </FormItem>
  172. <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
  173. <Button type="primary" htmlType="submit" loading={submitting}>
  174. 提交
  175. </Button>
  176. <Button style={{ marginLeft: 8 }}>保存</Button>
  177. </FormItem>
  178. </Form>
  179. </Card>
  180. </PageHeaderLayout>
  181. );
  182. }
  183. }