|
@@ -1,115 +1,128 @@
|
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
|
|
-import styles from './style.less';
|
|
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
|
12
|
|
27
|
|
-// 跳转到编辑资讯
|
28
|
|
-function toEditNews() {
|
29
|
|
- router.push({
|
30
|
|
- pathname: '/news/type/editNews',
|
31
|
|
- query: {
|
32
|
|
- a: 'b',
|
33
|
|
- },
|
34
|
|
- });
|
35
|
|
-}
|
|
13
|
+function header(props) {
|
|
14
|
+ // 获取初始化数据
|
|
15
|
+ const [ data, setData ] = useState({})
|
36
|
16
|
|
37
|
|
-/**
|
38
|
|
- *
|
39
|
|
- *
|
40
|
|
- * @param {*} props
|
41
|
|
- * @returns
|
42
|
|
- */
|
|
17
|
+ useEffect(() => {
|
|
18
|
+ getList({ pageNum: 1, pageSize: 10 });
|
|
19
|
+ },[])
|
43
|
20
|
|
44
|
|
-const dataSource = [
|
45
|
|
- {
|
46
|
|
- key: '1',
|
47
|
|
- img: 'http://img0.imgtn.bdimg.com/it/u=4246326797,2657995307&fm=26&gp=0.jpg',
|
48
|
|
- name: '华为P30 Pro',
|
49
|
|
- },
|
50
|
|
- {
|
51
|
|
- key: '2',
|
52
|
|
- img: '',
|
53
|
|
- name: '大米',
|
54
|
|
- },
|
55
|
|
-];
|
|
21
|
+ // 查询列表
|
|
22
|
+ const getList = (params) => {
|
|
23
|
+ request({
|
|
24
|
+ url: '/api/admin/taNewsType',
|
|
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
|
+ }
|
56
|
42
|
|
57
|
|
-const columns = [
|
58
|
|
- {
|
59
|
|
- title: '类型图片',
|
60
|
|
- dataIndex: 'img',
|
61
|
|
- key: 'img',
|
62
|
|
- align: 'left',
|
63
|
|
- render: (text, record) => <img src={record.img} className={styles.touxiang} />,
|
64
|
|
- },
|
65
|
|
- {
|
66
|
|
- title: '名称',
|
67
|
|
- dataIndex: 'name',
|
68
|
|
- key: 'name',
|
69
|
|
- align: 'center',
|
|
43
|
+ const changePageNum = (pageNumber) => {
|
|
44
|
+ getList({ pageNum: pageNumber, pageSize: 10 })
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+ // 跳转到编辑咨询
|
|
49
|
+ const toEditNews = (id) => () => {
|
|
50
|
+ router.push({
|
|
51
|
+ pathname: '/news/type/editNews',
|
|
52
|
+ query: {
|
|
53
|
+ id
|
|
54
|
+ },
|
|
55
|
+ });
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ const changeNewsStatus = (row) => () => {
|
|
60
|
+ Modal.confirm({
|
|
61
|
+ title: '确认删除该商品?',
|
|
62
|
+ okText: '确认',
|
|
63
|
+ cancelText: '取消',
|
|
64
|
+ onOk() {
|
|
65
|
+ request({
|
|
66
|
+ url: '/api/admin/taNewsType',
|
|
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: 'newsTypeImg',
|
|
86
|
+ key: 'newsTypeImg',
|
|
87
|
+ align: 'center',
|
|
88
|
+ render: (text, record) => <img src={record.newsTypeImg} className={styles.touxiang} />,
|
|
89
|
+ },
|
|
90
|
+ {
|
|
91
|
+ title: '名称',
|
|
92
|
+ dataIndex: 'newsTypeName',
|
|
93
|
+ key: 'newsTypeName',
|
|
94
|
+ align: 'center',
|
70
|
95
|
|
71
|
|
- },
|
72
|
|
- {
|
73
|
|
- title: '操作',
|
74
|
|
- dataIndex: 'handle',
|
75
|
|
- key: 'handle',
|
76
|
|
- align: 'center',
|
77
|
|
- render: () => <>
|
78
|
|
- <span style={{ color: '#1990FF', marginRight: '20px' }} onClick={confirm}>删除<Icon type="shopping-cart" className={styles.shoppingCart} /></span>
|
79
|
|
- <span style={{ color: '#FF925C' }} onClick={toEditNews}>编辑<Icon type="form" className={styles.edit} /></span></>,
|
80
|
|
- },
|
81
|
|
-];
|
82
|
|
-function confirm() {
|
83
|
|
- Modal.confirm({
|
84
|
|
- title: '确认删除该类型?',
|
85
|
|
- okText: '确认',
|
86
|
|
- cancelText: '取消',
|
87
|
|
- onOk() {
|
88
|
|
- console.log('OK');
|
89
|
96
|
},
|
90
|
|
- onCancel() {
|
91
|
|
- console.log('Cancel');
|
|
97
|
+ {
|
|
98
|
+ title: '操作',
|
|
99
|
+ dataIndex: 'handle',
|
|
100
|
+ key: 'handle',
|
|
101
|
+ align: 'center',
|
|
102
|
+ render: (x, row) => <><span style={{ color: '#EF273A', marginRight: '20px' }} onClick={changeNewsStatus(row)}>{row.status == 1 ? '下架' : '上架'}<Icon type="shopping-cart" className={styles.shoppingCart} />
|
|
103
|
+ </span><span style={{ color: '#FF925C' }} onClick={toEditNews(row.newsTypeId)}>编辑<Icon type="form" className={styles.edit} /></span></>,
|
92
|
104
|
},
|
93
|
|
- });
|
|
105
|
+ ];
|
94
|
106
|
|
95
|
|
-}
|
96
|
|
-function header(props) {
|
97
|
107
|
const { getFieldDecorator } = props.form
|
98
|
108
|
return (
|
99
|
109
|
|
100
|
110
|
<>
|
101
|
111
|
<Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
|
102
|
112
|
<Form.Item>
|
103
|
|
- {getFieldDecorator('goodState')(
|
104
|
|
- <Select style={{ width: '180px' }} placeholder="请选择" onChange={handleSelectChange}>
|
105
|
|
- <Option value="1">上架</Option>
|
106
|
|
- <Option value="0">下架</Option>
|
|
113
|
+ {getFieldDecorator('status')(
|
|
114
|
+ <Select style={{ width: '180px' }} placeholder="请选择">
|
|
115
|
+ <Option value="1">已上架</Option>
|
|
116
|
+ <Option value="0">已下架</Option>
|
107
|
117
|
</Select>,
|
108
|
118
|
)}
|
109
|
119
|
</Form.Item>
|
110
|
120
|
</Form>
|
111
|
|
- <Button type="primary" className={styles.addBtn} onClick={toEditNews}>新增</Button>
|
112
|
|
- <Table dataSource={dataSource} columns={columns} />
|
|
121
|
+ <Button type="primary" className={styles.addBtn} onClick={toEditNews()}>新增</Button>
|
|
122
|
+ <Table dataSource={data.records} columns={columns} pagination={false} />
|
|
123
|
+ <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
|
|
124
|
+ <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} />
|
|
125
|
+ </div>
|
113
|
126
|
</>
|
114
|
127
|
)
|
115
|
128
|
}
|