import React, { PureComponent } from 'react'; import { connect } from 'dva'; import { Row, Col, Card, Form, Input, Select, Icon, Button, Dropdown, Menu, InputNumber, DatePicker, Modal, message } from 'antd'; import StandardTable from '../../components/StandardTable'; import PageHeaderLayout from '../../layouts/PageHeaderLayout'; import styles from './TableList.less'; const FormItem = Form.Item; const { Option } = Select; const getValue = obj => Object.keys(obj).map(key => obj[key]).join(','); @connect(({ rule, loading }) => ({ rule, loading: loading.models.rule, })) @Form.create() export default class TableList extends PureComponent { state = { addInputValue: '', modalVisible: false, expandForm: false, selectedRows: [], formValues: {}, }; componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'rule/fetch', }); } handleStandardTableChange = (pagination, filtersArg, sorter) => { const { dispatch } = this.props; const { formValues } = this.state; const filters = Object.keys(filtersArg).reduce((obj, key) => { const newObj = { ...obj }; newObj[key] = getValue(filtersArg[key]); return newObj; }, {}); const params = { currentPage: pagination.current, pageSize: pagination.pageSize, ...formValues, ...filters, }; if (sorter.field) { params.sorter = `${sorter.field}_${sorter.order}`; } dispatch({ type: 'rule/fetch', payload: params, }); } handleFormReset = () => { const { form, dispatch } = this.props; form.resetFields(); this.setState({ formValues: {}, }); dispatch({ type: 'rule/fetch', payload: {}, }); } toggleForm = () => { this.setState({ expandForm: !this.state.expandForm, }); } handleMenuClick = (e) => { const { dispatch } = this.props; const { selectedRows } = this.state; if (!selectedRows) return; switch (e.key) { case 'remove': dispatch({ type: 'rule/remove', payload: { no: selectedRows.map(row => row.no).join(','), }, callback: () => { this.setState({ selectedRows: [], }); }, }); break; default: break; } } handleSelectRows = (rows) => { this.setState({ selectedRows: rows, }); } handleSearch = (e) => { e.preventDefault(); const { dispatch, form } = this.props; form.validateFields((err, fieldsValue) => { if (err) return; const values = { ...fieldsValue, updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(), }; this.setState({ formValues: values, }); dispatch({ type: 'rule/fetch', payload: values, }); }); } handleModalVisible = (flag) => { this.setState({ modalVisible: !!flag, }); } handleAddInput = (e) => { this.setState({ addInputValue: e.target.value, }); } handleAdd = () => { this.props.dispatch({ type: 'rule/add', payload: { description: this.state.addInputValue, }, }); message.success('添加成功'); this.setState({ modalVisible: false, }); } renderSimpleForm() { const { getFieldDecorator } = this.props.form; return (
{getFieldDecorator('no')( )} {getFieldDecorator('status')( )} 展开
); } renderAdvancedForm() { const { getFieldDecorator } = this.props.form; return (
{getFieldDecorator('no')( )} {getFieldDecorator('status')( )} {getFieldDecorator('number')( )} {getFieldDecorator('date')( )} {getFieldDecorator('status3')( )} {getFieldDecorator('status4')( )}
收起
); } renderForm() { return this.state.expandForm ? this.renderAdvancedForm() : this.renderSimpleForm(); } render() { const { rule: { data }, loading } = this.props; const { selectedRows, modalVisible, addInputValue } = this.state; const menu = ( 删除 批量审批 ); return (
{this.renderForm()}
{ selectedRows.length > 0 && ( ) }
this.handleModalVisible()} >
); } }