规格搜索,翻页

This commit is contained in:
zhenxianyimeng 2019-09-01 14:22:18 +08:00
parent 14f6d76088
commit e3a3e005e5
2 changed files with 132 additions and 10 deletions

View File

@ -1,5 +1,18 @@
import React, { PureComponent, Fragment, Component } from 'react'; import React, { PureComponent, Fragment, Component } from 'react';
import { Form, Card, Table, Button, Divider, Modal, Input, message, Switch, Select } from 'antd'; import {
Row,
Col,
Form,
Card,
Table,
Button,
Divider,
Modal,
Input,
message,
Switch,
Select,
} from 'antd';
import moment from 'moment'; import moment from 'moment';
import { connect } from 'dva'; import { connect } from 'dva';
import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import PageHeaderWrapper from '@/components/PageHeaderWrapper';
@ -148,6 +161,9 @@ export default class ProductAttrList extends PureComponent {
valueModalVisible: false, valueModalVisible: false,
modalType: 'add', //add or update modalType: 'add', //add or update
initValues: {}, initValues: {},
current: 1,
pageSize: 10,
name: null,
}; };
componentDidMount() { componentDidMount() {
@ -156,10 +172,13 @@ export default class ProductAttrList extends PureComponent {
initFetch = () => { initFetch = () => {
const { dispatch } = this.props; const { dispatch } = this.props;
const { current, pageSize, name } = this.state;
dispatch({ dispatch({
type: 'productAttrList/page', type: 'productAttrList/page',
payload: { payload: {
...PaginationHelper.defaultPayload, pageNo: current,
pageSize,
name,
}, },
}); });
// const { dispatch } = this.props; // const { dispatch } = this.props;
@ -306,6 +325,19 @@ export default class ProductAttrList extends PureComponent {
}); });
}; };
handleTableChange = pagination => {
const { pageSize, current, index } = pagination;
this.setState(
{
current,
pageSize,
},
function() {
this.initFetch();
}
);
};
switchValueChange = (checked, record) => { switchValueChange = (checked, record) => {
const { dispatch } = this.props; const { dispatch } = this.props;
dispatch({ dispatch({
@ -340,8 +372,82 @@ export default class ProductAttrList extends PureComponent {
}); });
}; };
handleFormReset = () => {
const { form, dispatch } = this.props;
form.resetFields();
this.setState(
{
name: null,
},
function() {
this.initFetch();
}
);
};
handleCondition = e => {
e.preventDefault();
const { dispatch, form } = this.props;
form.validateFields((err, fieldsValue) => {
if (err) return;
const values = {
...fieldsValue,
};
if (values.name) {
this.setState(
{
searched: true,
name: values.name,
},
function() {
this.initFetch();
}
);
} else {
this.initFetch();
}
// dispatch({
// type: 'fenfa/getCategoryList',
// payload: {
// key: values.name
// },
// });
});
};
renderSimpleForm() {
const { form } = this.props;
const { getFieldDecorator } = form;
return (
<Form onSubmit={this.handleCondition} layout="inline">
<Row gutter={{ md: 8, lg: 24, xl: 48 }}>
<Col md={8} sm={24}>
<FormItem label="规格名称">
{getFieldDecorator('name')(<Input placeholder="请输入" />)}
</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>
</span>
</Col>
</Row>
</Form>
);
}
render() { render() {
const { attrData, productAttrList, loading, pagination, tree } = this.props; const { attrData, productAttrList, loading, tree } = this.props;
const columns = [ const columns = [
{ {
title: '规格名称', title: '规格名称',
@ -395,18 +501,31 @@ export default class ProductAttrList extends PureComponent {
tree: tree, tree: tree,
}; };
const pagination = {
total: attrData.count,
index: this.state.current,
pageSize: this.state.pageSize,
};
return ( return (
<PageHeaderWrapper> <PageHeaderWrapper>
<Card> <Card>
<div className={styles.tableList}> <div className={styles.tableList}>
<div className={styles.tableListOperator}> <div className={styles.tableListOperator}>
<Button <Row>
icon="plus" <Col span={8}>
type="primary" <Button
onClick={() => this.handleModalVisible(true, 'add', {})} icon="plus"
> type="primary"
新建规格 onClick={() => this.handleModalVisible(true, 'add', {})}
</Button> >
新建规格
</Button>
</Col>
<Col span={16}>
<div>{this.renderSimpleForm()}</div>
</Col>
</Row>
</div> </div>
</div> </div>
<Table <Table
@ -417,6 +536,8 @@ export default class ProductAttrList extends PureComponent {
loading={loading} loading={loading}
pagination={pagination} pagination={pagination}
expandedRowRender={this.expandedRowRender} expandedRowRender={this.expandedRowRender}
defaultExpandAllRows={false}
onChange={pagination => this.handleTableChange(pagination)}
/> />
</Card> </Card>
{modalVisible ? <CreateForm {...parentMethods} modalVisible={modalVisible} /> : null} {modalVisible ? <CreateForm {...parentMethods} modalVisible={modalVisible} /> : null}

View File

@ -315,6 +315,7 @@ INSERT INTO `resource` VALUES (51, 1, -1, '短信ss', 0, '', 'user', '', '2019-0
INSERT INTO `resource` VALUES (52, 1, 1, '短信签名', 51, '/sms/sign-list', 'user', '', '2019-05-26 12:01:56', '2019-05-26 12:01:56', b'0'); INSERT INTO `resource` VALUES (52, 1, 1, '短信签名', 51, '/sms/sign-list', 'user', '', '2019-05-26 12:01:56', '2019-05-26 12:01:56', b'0');
INSERT INTO `resource` VALUES (53, 1, 2, '短信模板', 51, '/sms/template-list', 'user', '', '2019-05-26 12:02:19', '2019-05-26 12:02:18', b'0'); INSERT INTO `resource` VALUES (53, 1, 2, '短信模板', 51, '/sms/template-list', 'user', '', '2019-05-26 12:02:19', '2019-05-26 12:02:18', b'0');
INSERT INTO `resource` VALUES (54, 1, 3, '部门管理', 13, '/admin/dept-list', 'user', '', '2019-06-27 23:41:19', '2019-06-27 23:41:51', b'0'); INSERT INTO `resource` VALUES (54, 1, 3, '部门管理', 13, '/admin/dept-list', 'user', '', '2019-06-27 23:41:19', '2019-06-27 23:41:51', b'0');
INSERT INTO `resource` VALUES (55, 1, 4, '规格管理', 20, '/product/product-attr-list', null, null, '2019-08-14 23:59:38', '2019-08-14 23:59:38', b'0');
COMMIT; COMMIT;
-- ---------------------------- -- ----------------------------