BasicForm.js 6.3 KB

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