|
@@ -0,0 +1,147 @@
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
|
2
|
+import { Form, Button, message, Table, Pagination, Modal } from 'antd';
|
|
3
|
+import router from 'umi/router';
|
|
4
|
+import AuthButton from '@/components/AuthButton';
|
|
5
|
+import withActions from '@/components/ActionList';
|
|
6
|
+import EditIcon from '@/components/EditIcon';
|
|
7
|
+import { ConfirmButton } from '@/components/ModalButton';
|
|
8
|
+import apis from '@/services/apis';
|
|
9
|
+import request from '@/utils/request'
|
|
10
|
+import BuildSelect from '@/components/SelectButton/BuildSelect';
|
|
11
|
+import Navigate from '@/components/Navigate';
|
|
12
|
+
|
|
13
|
+function NewsType(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({ ...apis.propNews.newsType.list, params: { ...params } }).then((data) => {
|
|
24
|
+ console.log(data)
|
|
25
|
+ setData(data)
|
|
26
|
+ })
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+ // 提交事件
|
|
31
|
+ const handleSubmit = (e, props) => {
|
|
32
|
+ e.preventDefault();
|
|
33
|
+ props.form.validateFields((err, values) => {
|
|
34
|
+ if (!err) {
|
|
35
|
+ getList({ pageNum: 1, pageSize: 10, ...values })
|
|
36
|
+ }
|
|
37
|
+ });
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ const changePageNum = (pageNumber) => {
|
|
41
|
+ props.form.validateFields((err, values) => {
|
|
42
|
+ if (!err) {
|
|
43
|
+ getList({ pageNum: pageNumber, pageSize: 10, ...values })
|
|
44
|
+ }
|
|
45
|
+ });
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+ // 跳转到编辑资讯
|
|
50
|
+ const toEditNews = (id) => () => {
|
|
51
|
+ router.push({
|
|
52
|
+ pathname: '/property/news-type/edit',
|
|
53
|
+ query: {
|
|
54
|
+ id
|
|
55
|
+ },
|
|
56
|
+ });
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+ const changeNewsStatus = (row, newsId) => () => {
|
|
61
|
+ request({ ...propNews.newsType.put, urlData: { id: newsId }, data: { ...row, status: -1 } }).then((data) => {
|
|
62
|
+ message.info('操作成功!')
|
|
63
|
+ getList({ pageNum: 1, pageSize: 10 });
|
|
64
|
+ }).catch((err) => {
|
|
65
|
+ console.log(err)
|
|
66
|
+ message.info(err.msg || err.message)
|
|
67
|
+ })
|
|
68
|
+ }
|
|
69
|
+ /**
|
|
70
|
+ *
|
|
71
|
+ *
|
|
72
|
+ * @param {*} props
|
|
73
|
+ * @returns
|
|
74
|
+ */
|
|
75
|
+ const columns = [
|
|
76
|
+ {
|
|
77
|
+ title: '类型图',
|
|
78
|
+ dataIndex: 'newsTypeImg',
|
|
79
|
+ key: 'newsTypeImg',
|
|
80
|
+ align: 'center',
|
|
81
|
+ render: (text, record) => <img src={record.newsTypeImg} style={{width: '72px', height: '72px'}} />,
|
|
82
|
+ },
|
|
83
|
+ {
|
|
84
|
+ title: '名称',
|
|
85
|
+ dataIndex: 'newsTypeName',
|
|
86
|
+ key: 'newsTypeName',
|
|
87
|
+ align: 'center',
|
|
88
|
+ render: (text, record) => <Navigate to={`/news/type/editNews?id=${record.newsTypeId}`}>{text}</Navigate>
|
|
89
|
+ },
|
|
90
|
+ {
|
|
91
|
+ title: '操作',
|
|
92
|
+ dataIndex: 'handle',
|
|
93
|
+ key: 'handle',
|
|
94
|
+ align: 'center',
|
|
95
|
+ render: withActions((x, row) => [
|
|
96
|
+ <AuthButton name="admin.taNewsType.id.delete" noRight={null}>
|
|
97
|
+ <ConfirmButton type="link" title="确认删除?" onClick={changeNewsStatus(row, row.newsTypeId)}>
|
|
98
|
+ <EditIcon text="删除" type="delete" />
|
|
99
|
+ </ConfirmButton>
|
|
100
|
+ </AuthButton>,
|
|
101
|
+ <AuthButton name="admin.taNewsType.id.put" noRight={null}>
|
|
102
|
+ <EditIcon text="编辑" type="edit" onClick={toEditNews(row.newsTypeId)} />
|
|
103
|
+ </AuthButton>,
|
|
104
|
+ ]),
|
|
105
|
+ },
|
|
106
|
+ ];
|
|
107
|
+
|
|
108
|
+ function handleReset() {
|
|
109
|
+ props.form.resetFields();
|
|
110
|
+ getList({ pageNum: 1, pageSize: 10 })
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ const { getFieldDecorator } = props.form
|
|
114
|
+ return (
|
|
115
|
+
|
|
116
|
+ <>
|
|
117
|
+ {/* <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
|
|
118
|
+ <Form.Item>
|
|
119
|
+ {getFieldDecorator('buildingId')(
|
|
120
|
+ <BuildSelect />,
|
|
121
|
+ )}
|
|
122
|
+ </Form.Item>
|
|
123
|
+ <Form.Item>
|
|
124
|
+ <AuthButton name="admin.taNewsType.search" noRight={null}>
|
|
125
|
+ <Button type="primary" htmlType="submit" >
|
|
126
|
+ 搜索
|
|
127
|
+ </Button>
|
|
128
|
+ </AuthButton>
|
|
129
|
+ <Button style={{ marginLeft: 8 }} onClick={handleReset}>
|
|
130
|
+ 重置
|
|
131
|
+ </Button>
|
|
132
|
+ </Form.Item>
|
|
133
|
+ </Form> */}
|
|
134
|
+ <AuthButton name="admin.taNewsType.post" noRight={null}>
|
|
135
|
+ <Button type="primary" onClick={toEditNews()}>新增</Button>
|
|
136
|
+ </AuthButton>
|
|
137
|
+ <Table rowKey="newsType" dataSource={data.records} columns={columns} pagination={false} />
|
|
138
|
+ <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
|
|
139
|
+ <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
|
|
140
|
+ </div>
|
|
141
|
+ </>
|
|
142
|
+ )
|
|
143
|
+}
|
|
144
|
+
|
|
145
|
+const WrappedHeader = Form.create({ name: 'header' })(NewsType);
|
|
146
|
+
|
|
147
|
+export default WrappedHeader
|