|
@@ -0,0 +1,131 @@
|
|
1
|
+import React, { useState, useEffect } from 'react'
|
|
2
|
+import { Select, Spin, Table, Button, Form, Input, Divider, Typography, Popconfirm, notification } from 'antd'
|
|
3
|
+import NavLink from 'umi/navlink'
|
|
4
|
+import { fetchList, apis, fetch } from '@/utils/request'
|
|
5
|
+import Search from '../components/Search'
|
|
6
|
+import List from '../components/List'
|
|
7
|
+import Editor from './components/Editor'
|
|
8
|
+
|
|
9
|
+const listTel = fetch(apis.announcement.getTelList)
|
|
10
|
+const deleteTel = fetch(apis.announcement.deleteTel)
|
|
11
|
+const saveTel = fetch(apis.announcement.saveTel)
|
|
12
|
+const updateTel = fetch(apis.announcement.updateTel)
|
|
13
|
+
|
|
14
|
+const Condition = props => {
|
|
15
|
+ return (
|
|
16
|
+ <Search
|
|
17
|
+ onSearch={props.onSearch}
|
|
18
|
+ onReset={props.onReset}
|
|
19
|
+ render={form => {
|
|
20
|
+ const { getFieldDecorator, setFieldsValue } = form
|
|
21
|
+
|
|
22
|
+ return (
|
|
23
|
+ <>
|
|
24
|
+ <Form.Item label="名称">
|
|
25
|
+ {
|
|
26
|
+ getFieldDecorator('name')(<Input placeholder="名称" />)
|
|
27
|
+ }
|
|
28
|
+ </Form.Item>
|
|
29
|
+ <Form.Item label="电话">
|
|
30
|
+ {
|
|
31
|
+ getFieldDecorator('tel')(<Input placeholder="电话" />)
|
|
32
|
+ }
|
|
33
|
+ </Form.Item>
|
|
34
|
+ </>
|
|
35
|
+ )
|
|
36
|
+ }}
|
|
37
|
+ />
|
|
38
|
+ )
|
|
39
|
+}
|
|
40
|
+
|
|
41
|
+export default props => {
|
|
42
|
+ const [loading, setLoading] = useState(false)
|
|
43
|
+ const [listData, setListData] = useState([])
|
|
44
|
+ const [pagination, setPagination] = useState({})
|
|
45
|
+ const [queryParams, setQueryParams] = useState({ pageNum: 1, pageSize: 10 })
|
|
46
|
+ const [showEditor, setShowEditor] = useState(false)
|
|
47
|
+ const [currentRow, setCurrentRow] = useState()
|
|
48
|
+
|
|
49
|
+ const handleSearch = vals => {
|
|
50
|
+ setQueryParams({
|
|
51
|
+ ...queryParams,
|
|
52
|
+ ...vals,
|
|
53
|
+ pageNum: 1,
|
|
54
|
+ })
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ const handlePageChange = (pageNum, pageSize) => {
|
|
58
|
+ setQueryParams({
|
|
59
|
+ ...queryParams,
|
|
60
|
+ pageNum,
|
|
61
|
+ pageSize,
|
|
62
|
+ })
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ const triggerShowEditor = row => {
|
|
66
|
+ setShowEditor(!showEditor)
|
|
67
|
+ setCurrentRow({...(row || {})})
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ const handleEditor = vals => {
|
|
71
|
+ if (vals.id) {
|
|
72
|
+ updateTel({data: vals}).then(res => {
|
|
73
|
+ notification.success({message: '信息更新成功'})
|
|
74
|
+ triggerShowEditor()
|
|
75
|
+ setQueryParams({...queryParams})
|
|
76
|
+ })
|
|
77
|
+ } else {
|
|
78
|
+ saveTel({data: vals}).then(res => {
|
|
79
|
+ notification.success({message: '信息保存成功'})
|
|
80
|
+ triggerShowEditor()
|
|
81
|
+ setQueryParams({...queryParams})
|
|
82
|
+ })
|
|
83
|
+ }
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ const handleDeleteRow = row => {
|
|
87
|
+ deleteTel({data: [row.id]}).then(res => {
|
|
88
|
+ notification.success({ message: '删除成功' })
|
|
89
|
+ setQueryParams({...queryParams})
|
|
90
|
+ })
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ useEffect(() => {
|
|
94
|
+ setLoading(true)
|
|
95
|
+ listTel({params: queryParams}).then(res => {
|
|
96
|
+ const {list, ...pagi} = res
|
|
97
|
+ setListData(list)
|
|
98
|
+ setPagination(pagi)
|
|
99
|
+ setLoading(false)
|
|
100
|
+ }).catch(e => setLoading(false))
|
|
101
|
+ }, [queryParams])
|
|
102
|
+
|
|
103
|
+ return (
|
|
104
|
+ <div>
|
|
105
|
+ <Condition onSearch={handleSearch} onReset={handleSearch} />
|
|
106
|
+ <div style={{ margin: '24px 0' }}>
|
|
107
|
+ <Button type="primary" onClick={() => triggerShowEditor()}>添加</Button>
|
|
108
|
+ </div>
|
|
109
|
+ <List dataSource={listData} loading={loading} pagination={pagination} onPageChange={handlePageChange} rowKey="id">
|
|
110
|
+ <Table.Column title="名称" dataIndex="name" key="name" />
|
|
111
|
+ <Table.Column title="电话" dataIndex="tel" key="tel" />
|
|
112
|
+ <Table.Column title="备注" dataIndex="remark" key="remark" />
|
|
113
|
+ <Table.Column title="操作" dataIndex="id" key="id" width="200px" render={(_, row) => (
|
|
114
|
+ <>
|
|
115
|
+ <Popconfirm
|
|
116
|
+ title="确认进行删除操作?"
|
|
117
|
+ onConfirm={() => handleDeleteRow(row)}
|
|
118
|
+ okText="删除"
|
|
119
|
+ cancelText="取消"
|
|
120
|
+ >
|
|
121
|
+ <Button type="link">删除</Button>
|
|
122
|
+ </Popconfirm>
|
|
123
|
+ <Divider type="vertical" />
|
|
124
|
+ <Button type="link" onClick={() => triggerShowEditor(row)}>编辑</Button>
|
|
125
|
+ </>
|
|
126
|
+ )} />
|
|
127
|
+ </List>
|
|
128
|
+ <Editor visible={showEditor} dataSource={currentRow} onSubmit={handleEditor} onCancel={triggerShowEditor} />
|
|
129
|
+ </div>
|
|
130
|
+ )
|
|
131
|
+}
|