BasicForm.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. 邀评人
  136. <em className={styles.optional}>(选填)</em>
  137. </span>
  138. }
  139. >
  140. {getFieldDecorator('invites')(
  141. <Input placeholder="请直接 @姓名/工号,最多可邀请 5 人" />
  142. )}
  143. </FormItem>
  144. <FormItem
  145. {...formItemLayout}
  146. label={
  147. <span>
  148. 权重
  149. <em className={styles.optional}>(选填)</em>
  150. </span>
  151. }
  152. >
  153. {getFieldDecorator('weight')(<InputNumber placeholder="请输入" min={0} max={100} />)}
  154. <span className="ant-form-text">%</span>
  155. </FormItem>
  156. <FormItem {...formItemLayout} label="目标公开" help="客户、邀评人默认被分享">
  157. <div>
  158. {getFieldDecorator('public', {
  159. initialValue: '1',
  160. })(
  161. <Radio.Group>
  162. <Radio value="1">公开</Radio>
  163. <Radio value="2">部分公开</Radio>
  164. <Radio value="3">不公开</Radio>
  165. </Radio.Group>
  166. )}
  167. <FormItem style={{ marginBottom: 0 }}>
  168. {getFieldDecorator('publicUsers')(
  169. <Select
  170. mode="multiple"
  171. placeholder="公开给"
  172. style={{
  173. margin: '8px 0',
  174. display: getFieldValue('public') === '2' ? 'block' : 'none',
  175. }}
  176. >
  177. <Option value="1">同事甲</Option>
  178. <Option value="2">同事乙</Option>
  179. <Option value="3">同事丙</Option>
  180. </Select>
  181. )}
  182. </FormItem>
  183. </div>
  184. </FormItem>
  185. <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
  186. <Button type="primary" htmlType="submit" loading={submitting}>
  187. 提交
  188. </Button>
  189. <Button style={{ marginLeft: 8 }}>保存</Button>
  190. </FormItem>
  191. </Form>
  192. </Card>
  193. </PageHeaderLayout>
  194. );
  195. }
  196. }