|
@@ -1,133 +1,148 @@
|
1
|
|
-import React from 'react';
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
2
|
2
|
import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal,Breadcrumb } from 'antd';
|
3
|
3
|
import { FormattedMessage } from 'umi-plugin-react/locale';
|
4
|
4
|
import styles from '../style/GoodsList.less';
|
5
|
5
|
import router from 'umi/router';
|
|
6
|
+import BuildSelect from '../../components/SelectButton/BuildSelect'
|
|
7
|
+
|
|
8
|
+import request from '../../utils/request'
|
6
|
9
|
|
7
|
10
|
const { Option } = Select;
|
8
|
|
-// 提交事件
|
9
|
|
-function handleSubmit(e, props) {
|
10
|
|
- e.preventDefault();
|
11
|
|
- props.form.validateFields((err, values) => {
|
12
|
|
- if (!err) {
|
13
|
|
- console.log('提交数据: ', values)
|
14
|
|
- }
|
15
|
|
- });
|
16
|
|
-}
|
17
|
|
-// Change 事件
|
18
|
|
-function handleSelectChange(props) {
|
19
|
|
- console.log(props)
|
20
|
|
-}
|
21
|
11
|
|
22
|
|
-// 分页
|
23
|
|
-function onChange(pageNumber) {
|
24
|
|
- console.log('Page: ', pageNumber);
|
25
|
|
-}
|
26
|
|
-// 跳转到编辑商品
|
27
|
|
-function toEditGoods() {
|
28
|
|
- router.push({
|
29
|
|
- pathname: '/integralMall/editGoods',
|
30
|
|
- query: {
|
31
|
|
- a: 'b',
|
32
|
|
- },
|
33
|
|
- });
|
34
|
|
-}
|
35
|
12
|
|
36
|
|
-/**
|
37
|
|
- *
|
38
|
|
- *
|
39
|
|
- * @param {*} props
|
40
|
|
- * @returns
|
41
|
|
- */
|
|
13
|
+function header(props) {
|
|
14
|
+ // 获取初始化数据
|
|
15
|
+ const [ data, setData ] = useState({})
|
|
16
|
+
|
|
17
|
+ useEffect(() => {
|
|
18
|
+ getList({ pageNum: 1, pageSize: 10 });
|
|
19
|
+ },[])
|
|
20
|
+
|
|
21
|
+ // 查询列表
|
|
22
|
+ const getList = (params) => {
|
|
23
|
+ request({
|
|
24
|
+ url: '/api/admin/taGoods',
|
|
25
|
+ method: 'GET',
|
|
26
|
+ params: { ...params },
|
|
27
|
+ }).then((data) => {
|
|
28
|
+ console.log(data)
|
|
29
|
+ setData(data)
|
|
30
|
+ })
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ // 提交事件
|
|
34
|
+ const handleSubmit = (e, props) => {
|
|
35
|
+ e.preventDefault();
|
|
36
|
+ props.form.validateFields((err, values) => {
|
|
37
|
+ if (!err) {
|
|
38
|
+ getList({ pageNum: 1, pageSize: 10, ...values })
|
|
39
|
+ }
|
|
40
|
+ });
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ const changePageNum = (pageNumber) => {
|
|
44
|
+ getList({ pageNum: pageNumber, pageSize: 10 })
|
|
45
|
+ }
|
42
|
46
|
|
43
|
|
-const dataSource = [
|
44
|
|
- {
|
45
|
|
- key: '1',
|
46
|
|
- img: 'http://img0.imgtn.bdimg.com/it/u=4246326797,2657995307&fm=26&gp=0.jpg',
|
47
|
|
- name: '华为P30 Pro',
|
48
|
|
- },
|
49
|
|
- {
|
50
|
|
- key: '2',
|
51
|
|
- img: '',
|
52
|
|
- name: '大米',
|
53
|
|
- },
|
54
|
|
-];
|
55
|
47
|
|
56
|
|
-const columns = [
|
57
|
|
- {
|
58
|
|
- title: '商品图片',
|
59
|
|
- dataIndex: 'img',
|
60
|
|
- key: 'img',
|
61
|
|
- align: 'center',
|
62
|
|
- render: (text, record) => <img src={record.img} className={styles.touxiang} />,
|
63
|
|
- },
|
64
|
|
- {
|
65
|
|
- title: '商品名称',
|
66
|
|
- dataIndex: 'name',
|
67
|
|
- key: 'name',
|
68
|
|
- align: 'center',
|
|
48
|
+ // 跳转到编辑商品
|
|
49
|
+ const toEditGoods = (goodsId) => () => {
|
|
50
|
+ router.push({
|
|
51
|
+ pathname: '/integralMall/editGoods',
|
|
52
|
+ query: {
|
|
53
|
+ goodsId
|
|
54
|
+ },
|
|
55
|
+ });
|
|
56
|
+ }
|
69
|
57
|
|
70
|
|
- },
|
71
|
|
- {
|
72
|
|
- title: '所属积分',
|
73
|
|
- dataIndex: 'integral',
|
74
|
|
- key: 'integral',
|
75
|
|
- align: 'center',
|
76
|
|
- },
|
77
|
|
- {
|
78
|
|
- title: '总数量',
|
79
|
|
- dataIndex: 'total',
|
80
|
|
- key: 'total',
|
81
|
|
- align: 'center',
|
82
|
|
- },
|
83
|
|
- {
|
84
|
|
- title: '已兑换数量',
|
85
|
|
- dataIndex: 'exchanged',
|
86
|
|
- key: 'exchanged',
|
87
|
|
- align: 'center',
|
88
|
|
- },
|
89
|
|
- {
|
90
|
|
- title: '剩余数量',
|
91
|
|
- dataIndex: 'rest',
|
92
|
|
- key: 'rest',
|
93
|
|
- align: 'center',
|
94
|
|
- },
|
95
|
|
- {
|
96
|
|
- title: '状态',
|
97
|
|
- dataIndex: 'state',
|
98
|
|
- key: 'state',
|
99
|
|
- align: 'center',
|
100
|
|
- },
|
101
|
|
- {
|
102
|
|
- title: '操作',
|
103
|
|
- dataIndex: 'handle',
|
104
|
|
- key: 'handle',
|
105
|
|
- align: 'center',
|
106
|
|
- render: () => <><span style={{ color: '#EF273A', marginRight: '20px' }} onClick={confirm}>下架<Icon type="shopping-cart" className={styles.shoppingCart} /></span><span style={{ color: '#FF925C' }} onClick={toEditGoods}>编辑<Icon type="form" className={styles.edit} /></span></>,
|
107
|
|
- },
|
108
|
|
-];
|
109
|
|
-function confirm() {
|
110
|
|
- Modal.confirm({
|
111
|
|
- title: '确认下架该商品?',
|
112
|
|
- okText: '确认',
|
113
|
|
- cancelText: '取消',
|
114
|
|
- onOk() {
|
115
|
|
- console.log('OK');
|
|
58
|
+
|
|
59
|
+ const changeGoodsStatus = (row) => () => {
|
|
60
|
+ Modal.confirm({
|
|
61
|
+ title: '确认下架该商品?',
|
|
62
|
+ okText: '确认',
|
|
63
|
+ cancelText: '取消',
|
|
64
|
+ onOk() {
|
|
65
|
+ request({
|
|
66
|
+ url: '/api/admin/taGoods/change',
|
|
67
|
+ method: 'PUT',
|
|
68
|
+ data: { ...row },
|
|
69
|
+ }).then((data) => {
|
|
70
|
+ message.info('操作成功!')
|
|
71
|
+ getList({ pageNum: 1, pageSize: 10 });
|
|
72
|
+ })
|
|
73
|
+ }
|
|
74
|
+ });
|
|
75
|
+ }
|
|
76
|
+ /**
|
|
77
|
+ *
|
|
78
|
+ *
|
|
79
|
+ * @param {*} props
|
|
80
|
+ * @returns
|
|
81
|
+ */
|
|
82
|
+ const columns = [
|
|
83
|
+ {
|
|
84
|
+ title: '商品图片',
|
|
85
|
+ dataIndex: 'imgUrl',
|
|
86
|
+ key: 'imgUrl',
|
|
87
|
+ align: 'center',
|
|
88
|
+ render: (text, record) => <img src={record.imgUrl} className={styles.touxiang} />,
|
116
|
89
|
},
|
117
|
|
- onCancel() {
|
118
|
|
- console.log('Cancel');
|
|
90
|
+ {
|
|
91
|
+ title: '商品名称',
|
|
92
|
+ dataIndex: 'goodsName',
|
|
93
|
+ key: 'goodsName',
|
|
94
|
+ align: 'center',
|
|
95
|
+
|
|
96
|
+ },
|
|
97
|
+ {
|
|
98
|
+ title: '所属积分',
|
|
99
|
+ dataIndex: 'pointPrice',
|
|
100
|
+ key: 'pointPrice',
|
|
101
|
+ align: 'center',
|
|
102
|
+ },
|
|
103
|
+ {
|
|
104
|
+ title: '总数量',
|
|
105
|
+ dataIndex: 'totalNum',
|
|
106
|
+ key: 'totalNum',
|
|
107
|
+ align: 'center',
|
|
108
|
+ },
|
|
109
|
+ {
|
|
110
|
+ title: '已兑换数量',
|
|
111
|
+ dataIndex: 'exchanged',
|
|
112
|
+ key: 'exchanged',
|
|
113
|
+ align: 'center',
|
|
114
|
+ render: (x,row) => <><span>{row.totalNum - row.inventory}</span></>
|
|
115
|
+ },
|
|
116
|
+ {
|
|
117
|
+ title: '剩余数量',
|
|
118
|
+ dataIndex: 'inventory',
|
|
119
|
+ key: 'inventory',
|
|
120
|
+ align: 'center',
|
119
|
121
|
},
|
120
|
|
- });
|
|
122
|
+ {
|
|
123
|
+ title: '状态',
|
|
124
|
+ dataIndex: 'status',
|
|
125
|
+ key: 'status',
|
|
126
|
+ align: 'center',
|
|
127
|
+ render: (status)=> <><span>{status == 1 ? '已上架' : '未上架'}</span></>
|
|
128
|
+ },
|
|
129
|
+ {
|
|
130
|
+ title: '操作',
|
|
131
|
+ dataIndex: 'handle',
|
|
132
|
+ key: 'handle',
|
|
133
|
+ align: 'center',
|
|
134
|
+ render: (x, row) => <><span style={{ color: '#EF273A', marginRight: '20px' }} onClick={changeGoodsStatus(row)}>{row.status == 1 ? '下架' : '上架'}<Icon type="shopping-cart" className={styles.shoppingCart} />
|
|
135
|
+ </span><span style={{ color: '#FF925C' }} onClick={toEditGoods(row.goodsId)}>编辑<Icon type="form" className={styles.edit} /></span></>,
|
|
136
|
+ },
|
|
137
|
+ ];
|
121
|
138
|
|
122
|
|
-}
|
123
|
|
-function header(props) {
|
124
|
139
|
const { getFieldDecorator } = props.form
|
125
|
140
|
return (
|
126
|
141
|
|
127
|
142
|
<>
|
128
|
143
|
<Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
|
129
|
144
|
<Form.Item>
|
130
|
|
- {getFieldDecorator('name')(
|
|
145
|
+ {getFieldDecorator('goodsName')(
|
131
|
146
|
<Input
|
132
|
147
|
prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
133
|
148
|
placeholder="商品名称"
|
|
@@ -135,49 +150,45 @@ function header(props) {
|
135
|
150
|
)}
|
136
|
151
|
</Form.Item>
|
137
|
152
|
<Form.Item>
|
138
|
|
- {getFieldDecorator('goodState')(
|
139
|
|
- <Select style={{ width: '180px' }} placeholder="状态" onChange={handleSelectChange}>
|
140
|
|
- <Option value="1">上架</Option>
|
141
|
|
- <Option value="0">下架</Option>
|
|
153
|
+ {getFieldDecorator('status')(
|
|
154
|
+ <Select style={{ width: '180px' }} placeholder="状态">
|
|
155
|
+ <Option value="1">已上架</Option>
|
|
156
|
+ <Option value="0">已下架</Option>
|
142
|
157
|
</Select>,
|
143
|
158
|
)}
|
144
|
159
|
</Form.Item>
|
145
|
160
|
<Form.Item>
|
146
|
|
- {getFieldDecorator('isMain')(
|
147
|
|
- <Select style={{ width: '180px' }} placeholder="所属项目" onChange={handleSelectChange}>
|
148
|
|
- <Option value="1">首页推荐</Option>
|
149
|
|
- <Option value="0">首页未推荐</Option>
|
150
|
|
- </Select>,
|
|
161
|
+ {getFieldDecorator('buildingId')(
|
|
162
|
+ <BuildSelect />,
|
151
|
163
|
)}
|
152
|
164
|
</Form.Item>
|
153
|
165
|
<Form.Item>
|
154
|
|
- {getFieldDecorator('min')(
|
|
166
|
+ {getFieldDecorator('priceLesser')(
|
155
|
167
|
<Input
|
156
|
168
|
prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
157
|
|
- placeholder="最小积分"
|
|
169
|
+ placeholder="价格小"
|
158
|
170
|
/>,
|
159
|
171
|
)}
|
160
|
172
|
</Form.Item>
|
161
|
173
|
<Form.Item>
|
162
|
|
- {getFieldDecorator('max')(
|
|
174
|
+ {getFieldDecorator('priceGreater')(
|
163
|
175
|
<Input
|
164
|
176
|
prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
|
165
|
|
- placeholder="最大积分"
|
|
177
|
+ placeholder="价格大"
|
166
|
178
|
/>,
|
167
|
179
|
)}
|
168
|
180
|
</Form.Item>
|
169
|
181
|
<Form.Item>
|
170
|
|
- <Button type="primary" htmlType="submit" >
|
|
182
|
+ <Button type="primary" htmlType="submit" className={styles.searchBtn}>
|
171
|
183
|
搜索
|
172
|
184
|
</Button>
|
173
|
185
|
</Form.Item>
|
174
|
186
|
</Form>
|
175
|
|
- <Button type="danger" className={styles.addBtn} onClick={toEditGoods}>新增</Button>
|
176
|
|
- <Table dataSource={dataSource} columns={columns} />
|
177
|
|
- {/* 分页 */
|
178
|
|
- /* <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
|
179
|
|
- <Pagination showQuickJumper defaultCurrent={1} total={500} onChange={onChange} />
|
180
|
|
- </div> */}
|
|
187
|
+ <Button type="primary" className={styles.addBtn} onClick={toEditGoods()}>新增</Button>
|
|
188
|
+ <Table dataSource={data.records} columns={columns} pagination={false} />
|
|
189
|
+ <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
|
|
190
|
+ <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} />
|
|
191
|
+ </div>
|
181
|
192
|
</>
|
182
|
193
|
)
|
183
|
194
|
}
|