import { Avatar, Button, Card, Col, DatePicker, Dropdown, Form, Icon, Input, List, Menu, Modal, Progress, Radio, Row, Select, } from 'antd'; import React, { Component } from 'react'; import { Dispatch } from 'redux'; import { FormComponentProps } from 'antd/es/form'; import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { connect } from 'dva'; import { findDOMNode } from 'react-dom'; import moment from 'moment'; import Result from './Result'; import { StateType } from './model'; import { BasicListItemDataType } from './data.d'; import styles from './style.less'; const FormItem = Form.Item; const RadioButton = Radio.Button; const RadioGroup = Radio.Group; const SelectOption = Select.Option; const { Search, TextArea } = Input; interface BasicListProps extends FormComponentProps { listBasicList: StateType; dispatch: Dispatch; loading: boolean; } interface BasicListState { visible: boolean; done: boolean; current?: Partial; } @connect( ({ listBasicList, loading, }: { listBasicList: StateType; loading: { models: { [key: string]: boolean }; }; }) => ({ listBasicList, loading: loading.models.listBasicList, }), ) class BasicList extends Component< BasicListProps, BasicListState > { state: BasicListState = { visible: false, done: false, current: undefined }; formLayout = { labelCol: { span: 7 }, wrapperCol: { span: 13 }, }; addBtn: HTMLButtonElement | undefined | null = undefined; componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'listBasicList/fetch', payload: { count: 5, }, }); } showModal = () => { this.setState({ visible: true, current: undefined, }); }; showEditModal = (item: BasicListItemDataType) => { this.setState({ visible: true, current: item, }); }; handleDone = () => { setTimeout(() => this.addBtn && this.addBtn.blur(), 0); this.setState({ done: false, visible: false, }); }; handleCancel = () => { setTimeout(() => this.addBtn && this.addBtn.blur(), 0); this.setState({ visible: false, }); }; handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const { dispatch, form } = this.props; const { current } = this.state; const id = current ? current.id : ''; setTimeout(() => this.addBtn && this.addBtn.blur(), 0); form.validateFields((err: string | undefined, fieldsValue: BasicListItemDataType) => { if (err) return; this.setState({ done: true, }); dispatch({ type: 'listBasicList/submit', payload: { id, ...fieldsValue }, }); }); }; deleteItem = (id: string) => { const { dispatch } = this.props; dispatch({ type: 'listBasicList/submit', payload: { id }, }); }; render() { const { listBasicList: { list }, loading, } = this.props; const { form: { getFieldDecorator }, } = this.props; const { visible, done, current = {} } = this.state; const editAndDelete = (key: string, currentItem: BasicListItemDataType) => { if (key === 'edit') this.showEditModal(currentItem); else if (key === 'delete') { Modal.confirm({ title: '删除任务', content: '确定删除该任务吗?', okText: '确认', cancelText: '取消', onOk: () => this.deleteItem(currentItem.id), }); } }; const modalFooter = done ? { footer: null, onCancel: this.handleDone } : { okText: '保存', onOk: this.handleSubmit, onCancel: this.handleCancel }; const Info: React.SFC<{ title: React.ReactNode; value: React.ReactNode; bordered?: boolean; }> = ({ title, value, bordered }) => (
{title}

{value}

{bordered && }
); const extraContent = (
全部 进行中 等待中 ({})} />
); const paginationProps = { showSizeChanger: true, showQuickJumper: true, pageSize: 5, total: 50, }; const ListContent = ({ data: { owner, createdAt, percent, status }, }: { data: BasicListItemDataType; }) => (
Owner

{owner}

开始时间

{moment(createdAt).format('YYYY-MM-DD HH:mm')}

); const MoreBtn: React.SFC<{ item: BasicListItemDataType; }> = ({ item }) => ( editAndDelete(key, item)}> 编辑 删除 } > 更多 ); const getModalContent = () => { if (done) { return ( 知道了 } className={styles.formResult} /> ); } return (
{getFieldDecorator('title', { rules: [{ required: true, message: '请输入任务名称' }], initialValue: current.title, })()} {getFieldDecorator('createdAt', { rules: [{ required: true, message: '请选择开始时间' }], initialValue: current.createdAt ? moment(current.createdAt) : null, })( , )} {getFieldDecorator('owner', { rules: [{ required: true, message: '请选择任务负责人' }], initialValue: current.owner, })( , )} {getFieldDecorator('subDescription', { rules: [{ message: '请输入至少五个字符的产品描述!', min: 5 }], initialValue: current.subDescription, })(