|
@@ -0,0 +1,202 @@
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
|
2
|
+import { Form, Input, Button, Icon, Select, message, Table, Divider, Tag, Pagination, Modal, DatePicker } from 'antd';
|
|
3
|
+import { FormattedMessage } from 'umi-plugin-react/locale';
|
|
4
|
+import styles from '../style/GoodsList.less';
|
|
5
|
+import router from 'umi/router';
|
|
6
|
+import moment from 'moment';
|
|
7
|
+import SelectCity from '../../components/SelectButton/CitySelect'
|
|
8
|
+import BuildSelect from '../../components/SelectButton/BuildSelect'
|
|
9
|
+
|
|
10
|
+import request from '../../utils/request'
|
|
11
|
+
|
|
12
|
+const { Option } = Select;
|
|
13
|
+const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
|
|
14
|
+
|
|
15
|
+const header = (props) => {
|
|
16
|
+ const [ data, setData ] = useState({})
|
|
17
|
+
|
|
18
|
+ useEffect(() => {
|
|
19
|
+ getList({ pageNum: 1, pageSize: 10,cityId: '' });
|
|
20
|
+ },[])
|
|
21
|
+
|
|
22
|
+ // 查询列表
|
|
23
|
+ const getList = (params) => {
|
|
24
|
+ request({
|
|
25
|
+ url: '/api/admin/taPolicy',
|
|
26
|
+ method: 'GET',
|
|
27
|
+ params: { ...params },
|
|
28
|
+ }).then((data) => {
|
|
29
|
+ console.log(data)
|
|
30
|
+ setData(data)
|
|
31
|
+ })
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+// 跳转到编辑商品
|
|
36
|
+const toEditPolicy = (policyId) => () => {
|
|
37
|
+ router.push({
|
|
38
|
+ pathname: '/system/editPolicy',
|
|
39
|
+ query: {
|
|
40
|
+ policyId
|
|
41
|
+ },
|
|
42
|
+ });
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ /**
|
|
46
|
+ *
|
|
47
|
+ *
|
|
48
|
+ * @param {*} props
|
|
49
|
+ * @returns
|
|
50
|
+ */
|
|
51
|
+
|
|
52
|
+ const columns = [
|
|
53
|
+ {
|
|
54
|
+ title: '购房政策主图',
|
|
55
|
+ dataIndex: 'policyImg',
|
|
56
|
+ key: 'policyImg',
|
|
57
|
+ align: 'center',
|
|
58
|
+ render: (policyImg) => <img src={policyImg} className={styles.touxiang} />,
|
|
59
|
+ },
|
|
60
|
+ {
|
|
61
|
+ title: '标题',
|
|
62
|
+ dataIndex: 'title',
|
|
63
|
+ key: 'title',
|
|
64
|
+ align: 'center',
|
|
65
|
+ },
|
|
66
|
+ {
|
|
67
|
+ title: '城市',
|
|
68
|
+ dataIndex: 'cityName',
|
|
69
|
+ key: 'cityName',
|
|
70
|
+ align: 'center',
|
|
71
|
+ },
|
|
72
|
+ {
|
|
73
|
+ title: '创建时间',
|
|
74
|
+ dataIndex: 'createDate',
|
|
75
|
+ key: 'createDate',
|
|
76
|
+ align: 'center',
|
|
77
|
+ render: (createDate) => <><span>{moment(createDate).format('YYYY-MM-DD')}</span></>
|
|
78
|
+ },
|
|
79
|
+ {
|
|
80
|
+ title: '状态',
|
|
81
|
+ dataIndex: 'publishStatus',
|
|
82
|
+ key: 'publishStatus',
|
|
83
|
+ align: 'center',
|
|
84
|
+ render: (publishStatus)=> <><span>{publishStatus === 1 ? '已发布' : '未发布' }</span></>
|
|
85
|
+ },
|
|
86
|
+ {
|
|
87
|
+ title: '操作',
|
|
88
|
+ dataIndex: 'handle',
|
|
89
|
+ key: 'handle',
|
|
90
|
+ align: 'center',
|
|
91
|
+ render: (x,row) => <>
|
|
92
|
+ <span style={{ color: '#1990FF' }} onClick={publicOrNoPublic(row)}>{ row.publishStatus === 0 ? '发布' : '取消发布' }<Icon type="close-circle" className={styles.edit} /></span>
|
|
93
|
+ <span style={{ color: '#1990FF', marginRight: '20px' }} onClick={topPolicy(row)}>{ row.weight === 1 ? '取消置顶' : '置顶' }<Icon type="vertical-align-top" className={styles.edit} /></span>
|
|
94
|
+ <span style={{ color: '#FF925C' }} onClick={toEditPolicy(row.policyId)}>编辑<Icon type="form" className={styles.edit} /></span>
|
|
95
|
+ <span style={{ color: '#FF925C' }} onClick={deletePolicy(row.policyId)}>删除<Icon type="form" className={styles.edit} /></span>
|
|
96
|
+ </>
|
|
97
|
+ },
|
|
98
|
+ ];
|
|
99
|
+
|
|
100
|
+ // 删除
|
|
101
|
+const deletePolicy = (policyId) => () => {
|
|
102
|
+ Modal.confirm({
|
|
103
|
+ title: '是否继续删除此政策?',
|
|
104
|
+ okText: '确定',
|
|
105
|
+ cancelText: '取消',
|
|
106
|
+ onOk() {
|
|
107
|
+ request({
|
|
108
|
+ url: '/api/admin/taPolicy/'+policyId,
|
|
109
|
+ method: 'DELETE',
|
|
110
|
+ }).then((data) => {
|
|
111
|
+ message.info('操作成功!')
|
|
112
|
+ getList({ pageNum: 1, pageSize: 10,cityId: '' });
|
|
113
|
+ }).catch((err) => {
|
|
114
|
+ console.log(err)
|
|
115
|
+ message.info(err.msg || err.message)
|
|
116
|
+ })
|
|
117
|
+ },
|
|
118
|
+ });
|
|
119
|
+}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+// 置顶
|
|
123
|
+ const topPolicy = (row) => () => {
|
|
124
|
+ const weight = Math.abs(row.weight - 1)
|
|
125
|
+ row.weight = weight
|
|
126
|
+ request({
|
|
127
|
+ url: '/api/admin/taPolicy/'+row.policyId,
|
|
128
|
+ method: 'PUT',
|
|
129
|
+ data: row,
|
|
130
|
+ }).then((data) => {
|
|
131
|
+ console.log(data)
|
|
132
|
+ message.info('操作成功!')
|
|
133
|
+ getList({ pageNum: 1, pageSize: 10,cityId: '' });
|
|
134
|
+ }).catch((err) => {
|
|
135
|
+ console.log(err)
|
|
136
|
+ message.info(err.msg || err.message)
|
|
137
|
+ })
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ const publicOrNoPublic = (row) => () => {
|
|
141
|
+ if (row.publishStatus === 1) {
|
|
142
|
+ row.publishStatus = 0
|
|
143
|
+ } else {
|
|
144
|
+ row.publishStatus = 1
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ request({
|
|
148
|
+ url: '/api/admin/taPolicy/'+row.policyId,
|
|
149
|
+ method: 'PUT',
|
|
150
|
+ data: row,
|
|
151
|
+ }).then((data) => {
|
|
152
|
+ console.log(data)
|
|
153
|
+ message.info('操作成功!')
|
|
154
|
+ getList({ pageNum: 1, pageSize: 10,cityId: '' });
|
|
155
|
+ }).catch((err) => {
|
|
156
|
+ console.log(err)
|
|
157
|
+ message.info(err.msg || err.message)
|
|
158
|
+ })
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ const changePageNum = (pageNumber) => {
|
|
162
|
+ getList({ pageNum: pageNumber, pageSize: 10 })
|
|
163
|
+ }
|
|
164
|
+
|
|
165
|
+ // 提交事件
|
|
166
|
+const handleSubmit = (e, props) => {
|
|
167
|
+ e.preventDefault();
|
|
168
|
+ props.form.validateFields((err, values) => {
|
|
169
|
+ if (!err) {
|
|
170
|
+ console.log('提交数据: ', values)
|
|
171
|
+ getList({ pageNum: 1, pageSize: 10, ...values })
|
|
172
|
+ }
|
|
173
|
+ });
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ const { getFieldDecorator } = props.form
|
|
177
|
+ return (
|
|
178
|
+
|
|
179
|
+ <>
|
|
180
|
+ <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
|
|
181
|
+ <Form.Item>
|
|
182
|
+ {getFieldDecorator('cityId')(
|
|
183
|
+ <SelectCity />,
|
|
184
|
+ )}
|
|
185
|
+ </Form.Item>
|
|
186
|
+ <Form.Item>
|
|
187
|
+ <Button type="primary" htmlType="submit" className={styles.searchBtn}>
|
|
188
|
+ 搜索
|
|
189
|
+ </Button>
|
|
190
|
+ </Form.Item>
|
|
191
|
+ </Form>
|
|
192
|
+ <Button type="primary" className={styles.addBtn} onClick={toEditPolicy()}>新增</Button>
|
|
193
|
+ <Table dataSource={data.records} columns={columns} pagination={false}/>
|
|
194
|
+ <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
|
|
195
|
+ <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} />
|
|
196
|
+ </div>
|
|
197
|
+ </>
|
|
198
|
+ )
|
|
199
|
+}
|
|
200
|
+const WrappedHeader = Form.create({ name: 'header' })(header);
|
|
201
|
+
|
|
202
|
+export default WrappedHeader
|