import React, { Component } from 'react'; import { Input, Select, Button, DatePicker, Form, Modal, Steps, Radio } from 'antd'; import { TableListItem } from '../data'; import { FormComponentProps } from 'antd/lib/form'; export type IFormValsType = { target?: string; template?: string; type?: string; time?: string; frequency?: string; } & Partial; export interface UpdateFormProps extends FormComponentProps { handleUpdateModalVisible: (flag?: boolean, formVals?: IFormValsType) => void; handleUpdate: (values: IFormValsType) => void; updateModalVisible: boolean; values: Partial; } const FormItem = Form.Item; const { Step } = Steps; const { TextArea } = Input; const { Option } = Select; const RadioGroup = Radio.Group; export interface UpdateFormState { formVals: IFormValsType; currentStep: number; } class UpdateForm extends Component { static defaultProps = { handleUpdate: () => {}, handleUpdateModalVisible: () => {}, values: {}, }; formLayout = { labelCol: { span: 7 }, wrapperCol: { span: 13 }, }; constructor(props: UpdateFormProps) { super(props); this.state = { formVals: { name: props.values.name, desc: props.values.desc, key: props.values.key, target: '0', template: '0', type: '1', time: '', frequency: 'month', }, currentStep: 0, }; } handleNext = (currentStep: number) => { const { form, handleUpdate } = this.props; const { formVals: oldValue } = this.state; form.validateFields((err, fieldsValue) => { if (err) return; const formVals = { ...oldValue, ...fieldsValue }; this.setState( { formVals, }, () => { if (currentStep < 2) { this.forward(); } else { handleUpdate(formVals); } } ); }); }; backward = () => { const { currentStep } = this.state; this.setState({ currentStep: currentStep - 1, }); }; forward = () => { const { currentStep } = this.state; this.setState({ currentStep: currentStep + 1, }); }; renderContent = (currentStep: number, formVals: IFormValsType) => { const { form } = this.props; if (currentStep === 1) { return [ {form.getFieldDecorator('target', { initialValue: formVals.target, })( )} , {form.getFieldDecorator('template', { initialValue: formVals.template, })( )} , {form.getFieldDecorator('type', { initialValue: formVals.type, })( )} , ]; } if (currentStep === 2) { return [ {form.getFieldDecorator('time', { rules: [{ required: true, message: '请选择开始时间!' }], })( )} , {form.getFieldDecorator('frequency', { initialValue: formVals.frequency, })( )} , ]; } return [ {form.getFieldDecorator('name', { rules: [{ required: true, message: '请输入规则名称!' }], initialValue: formVals.name, })()} , {form.getFieldDecorator('desc', { rules: [{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 }], initialValue: formVals.desc, })(