| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- 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(state => ({
- rule: state.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();
- 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 (
- <Form onSubmit={this.handleSearch} layout="inline">
- <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
- <Col md={8} sm={24}>
- <FormItem label="规则编号">
- {getFieldDecorator('no')(
- <Input placeholder="请输入" />
- )}
- </FormItem>
- </Col>
- <Col md={8} sm={24}>
- <FormItem label="使用状态">
- {getFieldDecorator('status')(
- <Select placeholder="请选择" style={{ width: '100%' }}>
- <Option value="0">关闭</Option>
- <Option value="1">运行中</Option>
- </Select>
- )}
- </FormItem>
- </Col>
- <Col md={8} sm={24}>
- <span className={styles.submitButtons}>
- <Button type="primary" htmlType="submit">查询</Button>
- <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}>重置</Button>
- <a style={{ marginLeft: 8 }} onClick={this.toggleForm}>
- 展开 <Icon type="down" />
- </a>
- </span>
- </Col>
- </Row>
- </Form>
- );
- }
- renderAdvancedForm() {
- const { getFieldDecorator } = this.props.form;
- return (
- <Form onSubmit={this.handleSearch} layout="inline">
- <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
- <Col md={8} sm={24}>
- <FormItem label="规则编号">
- {getFieldDecorator('no')(
- <Input placeholder="请输入" />
- )}
- </FormItem>
- </Col>
- <Col md={8} sm={24}>
- <FormItem label="使用状态">
- {getFieldDecorator('status')(
- <Select placeholder="请选择" style={{ width: '100%' }}>
- <Option value="0">关闭</Option>
- <Option value="1">运行中</Option>
- </Select>
- )}
- </FormItem>
- </Col>
- <Col md={8} sm={24}>
- <FormItem label="调用次数">
- {getFieldDecorator('number')(
- <InputNumber style={{ width: '100%' }} />
- )}
- </FormItem>
- </Col>
- </Row>
- <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
- <Col md={8} sm={24}>
- <FormItem label="更新日期">
- {getFieldDecorator('date')(
- <DatePicker style={{ width: '100%' }} placeholder="请输入更新日期" />
- )}
- </FormItem>
- </Col>
- <Col md={8} sm={24}>
- <FormItem label="使用状态">
- {getFieldDecorator('status3')(
- <Select placeholder="请选择" style={{ width: '100%' }}>
- <Option value="0">关闭</Option>
- <Option value="1">运行中</Option>
- </Select>
- )}
- </FormItem>
- </Col>
- <Col md={8} sm={24}>
- <FormItem label="使用状态">
- {getFieldDecorator('status4')(
- <Select placeholder="请选择" style={{ width: '100%' }}>
- <Option value="0">关闭</Option>
- <Option value="1">运行中</Option>
- </Select>
- )}
- </FormItem>
- </Col>
- </Row>
- <div style={{ overflow: 'hidden' }}>
- <span style={{ float: 'right', marginBottom: 24 }}>
- <Button type="primary" htmlType="submit">查询</Button>
- <Button style={{ marginLeft: 8 }} onClick={this.handleFormReset}>重置</Button>
- <a style={{ marginLeft: 8 }} onClick={this.toggleForm}>
- 收起 <Icon type="up" />
- </a>
- </span>
- </div>
- </Form>
- );
- }
- renderForm() {
- return this.state.expandForm ? this.renderAdvancedForm() : this.renderSimpleForm();
- }
- render() {
- const { rule: { loading: ruleLoading, data } } = this.props;
- const { selectedRows, modalVisible, addInputValue } = this.state;
- const menu = (
- <Menu onClick={this.handleMenuClick} selectedKeys={[]}>
- <Menu.Item key="remove">删除</Menu.Item>
- <Menu.Item key="approval">批量审批</Menu.Item>
- </Menu>
- );
- return (
- <PageHeaderLayout title="查询表格">
- <Card bordered={false}>
- <div className={styles.tableList}>
- <div className={styles.tableListForm}>
- {this.renderForm()}
- </div>
- <div className={styles.tableListOperator}>
- <Button icon="plus" type="primary" onClick={() => this.handleModalVisible(true)}>新建</Button>
- {
- selectedRows.length > 0 && (
- <span>
- <Button>批量操作</Button>
- <Dropdown overlay={menu}>
- <Button>
- 更多操作 <Icon type="down" />
- </Button>
- </Dropdown>
- </span>
- )
- }
- </div>
- <StandardTable
- selectedRows={selectedRows}
- loading={ruleLoading}
- data={data}
- onSelectRow={this.handleSelectRows}
- onChange={this.handleStandardTableChange}
- />
- </div>
- </Card>
- <Modal
- title="新建规则"
- visible={modalVisible}
- onOk={this.handleAdd}
- onCancel={() => this.handleModalVisible()}
- >
- <FormItem
- labelCol={{ span: 5 }}
- wrapperCol={{ span: 15 }}
- label="描述"
- >
- <Input placeholder="请输入" onChange={this.handleAddInput} value={addInputValue} />
- </FormItem>
- </Modal>
- </PageHeaderLayout>
- );
- }
- }
|