张延森 4 years ago
parent
commit
18b6f04d9a

+ 11
- 0
config/routes.js View File

@@ -602,6 +602,17 @@ export default [
602 602
                 component: './property/notice/Edit',
603 603
                 hideInMenu: true,
604 604
               },
605
+              {
606
+                path: 'news',
607
+                name: '服务内容',
608
+                component: './property/news'
609
+              },
610
+              {
611
+                path: 'news/edit',
612
+                name: '服务内容详情',
613
+                component: './property/news/Edit',
614
+                hideInMenu: true,
615
+              },
605 616
               {
606 617
                 path: 'bill/management',
607 618
                 name: '收费组管理',

+ 128
- 0
src/pages/property/news/Edit.jsx View File

@@ -0,0 +1,128 @@
1
+import React, { useEffect, useState } from 'react'
2
+import { Form, Input, Button, Radio, InputNumber, notification } from 'antd'
3
+import router from 'umi/router'
4
+import { fetch, apis } from '@/utils/request'
5
+import ImageUpload from '@/components/uploadImage/ImageUpload'
6
+import Wangedit from '@/components/Wangedit/Wangedit'
7
+
8
+const formItemLayout = {
9
+  labelCol: {
10
+    xs: { span: 24 },
11
+    sm: { span: 6 },
12
+  },
13
+  wrapperCol: {
14
+    xs: { span: 24 },
15
+    sm: { span: 12 },
16
+  },
17
+}
18
+
19
+const tailFormItemLayout = {
20
+  wrapperCol: {
21
+    xs: {
22
+      span: 24,
23
+      offset: 0,
24
+    },
25
+    sm: {
26
+      span: 16,
27
+      offset: 6,
28
+    },
29
+  },
30
+}
31
+
32
+const getNewsDetail = fetch(apis.propNews.getNewsDetail)
33
+const addNews = fetch(apis.propNews.addNews)
34
+const updateNews = fetch(apis.propNews.updateNews)
35
+
36
+export default Form.create()(props => {
37
+  const [loading, setLoading] = useState(false)
38
+  const [newsData, setNewsData] = useState({})
39
+
40
+  const { id } = props.location.query
41
+  
42
+  const handleSubmit = e => {
43
+    e.preventDefault();
44
+    props.form.validateFields((err, values) => {
45
+      if (!err) {
46
+        setLoading(true)
47
+        if (id) {
48
+          updateNews({data: values, urlData: {id}}).then(res => {
49
+            notification.success({ message: "修改内容成功" })
50
+            setLoading(false)
51
+          }).catch(err => {
52
+            setLoading(false)
53
+          })
54
+        } else {
55
+          addNews({data: values}).then(res => {
56
+            notification.success({ message: "保存内容成功" })
57
+            setLoading(false)
58
+            router.go(-1)
59
+          }).catch(err => {
60
+            setLoading(false)
61
+          })
62
+        }
63
+      }
64
+    });
65
+  }
66
+
67
+  useEffect(() => {
68
+    if (id) {
69
+      getNewsDetail({urlData: {id}}).then(res => {
70
+        setNewsData(res)
71
+        props.form.setFieldsValue(res)
72
+      })
73
+    }
74
+  }, [id])
75
+  
76
+  return (
77
+    <div>
78
+      <Form {...formItemLayout} onSubmit={handleSubmit}>
79
+        <Form.Item label="标题">
80
+          {
81
+            props.form.getFieldDecorator('newsName', {
82
+              rules: [
83
+                { required: true, message: '请填写标题' },
84
+              ],
85
+            })(<Input placeholder="标题" />)
86
+          }
87
+        </Form.Item>
88
+        <Form.Item label="封面">
89
+          {
90
+            props.form.getFieldDecorator('newsImg', {
91
+              rules: [
92
+                { required: true, message: '请上传封面' },
93
+              ],
94
+            })(<ImageUpload />)
95
+          }
96
+        </Form.Item>
97
+        <Form.Item label="内容">
98
+          {
99
+            props.form.getFieldDecorator('newsDetail', {
100
+              rules: [
101
+                { required: true, message: '请填写内容' },
102
+              ],
103
+            })(<Wangedit />)
104
+          }
105
+        </Form.Item>
106
+        <Form.Item label="权重">
107
+          {
108
+            props.form.getFieldDecorator('weight')(<InputNumber min={1} />)
109
+          }
110
+        </Form.Item>
111
+        <Form.Item label="状态">
112
+          {
113
+            props.form.getFieldDecorator('status')(
114
+              <Radio.Group>
115
+                <Radio value={0}>未发布</Radio>
116
+                <Radio value={1}>已发布</Radio>
117
+              </Radio.Group>
118
+            )
119
+          }
120
+        </Form.Item>
121
+        <Form.Item {...tailFormItemLayout} >
122
+          <Button loading={loading} type="primary" htmlType="submit">提交</Button>
123
+          <Button style={{ marginLeft: '24px' }} onClick={() => router.go(-1)}>取消</Button>
124
+        </Form.Item>
125
+      </Form>
126
+    </div>
127
+  )
128
+})

+ 166
- 0
src/pages/property/news/index.jsx View File

@@ -0,0 +1,166 @@
1
+import React, { useState, useEffect } from 'react'
2
+import { Select, Spin, Table, Button, Form, Input, Divider, Modal, Popconfirm, Typography, notification } from 'antd'
3
+import NavLink from 'umi/navlink'
4
+import { fetch, fetchList, apis } from '@/utils/request'
5
+import Search from '../components/Search'
6
+import List from '../components/List'
7
+
8
+const getNewsList = fetchList(apis.propNews.getNewsList)
9
+const updateNews = fetch(apis.propNews.updateNews)
10
+const deleteNews = fetch(apis.propNews.deleteNews)
11
+
12
+const Condition = props => {
13
+  return (
14
+    <Search
15
+      onSearch={props.onSearch}
16
+      onReset={props.onReset}
17
+      render={form => {
18
+        const { getFieldDecorator } = form
19
+        
20
+        return (
21
+          <>
22
+            <Form.Item label="标题">
23
+            {
24
+              getFieldDecorator('newsName')(<Input placeholder="标题" />)
25
+            }
26
+            </Form.Item>
27
+          </>
28
+        )
29
+      }}
30
+    />
31
+  )
32
+}
33
+
34
+const StatusDict = {
35
+  '0': '未发布',
36
+  '1': '已发布',
37
+}
38
+
39
+export default props => {
40
+  const [loading, setLoading] = useState(false)
41
+  const [listData, setListData] = useState([])
42
+  const [pagination, setPagination] = useState({})
43
+  const [queryParams, setQueryParams] = useState({ pageNum: 1, pageSize: 10 })
44
+
45
+  const handleSearch = vals => {
46
+    setQueryParams({
47
+      ...queryParams,
48
+      ...vals,
49
+      pageNum: 1,
50
+    })
51
+  }
52
+
53
+  const handleDeleteRow = row => {
54
+    deleteNews({ urlData: {id: row.newsId} }).then(res => {
55
+      Modal.success({
56
+        content: '删除内容成功',
57
+        onOk: () => {
58
+          // 触发数据刷新
59
+          setQueryParams({...queryParams})
60
+        }
61
+      })
62
+    })
63
+  }
64
+
65
+  const handleStatusTrigger = row => {
66
+    // 发布 -> 取消发布
67
+    // 取消发布 -> 发布
68
+    const status = Math.abs(row.status - 1)
69
+    const data = { ...row, status }
70
+    updateNews({data, urlData: {id: row.newsId}}).then(res => {
71
+      notification.success({message: "操作成功"})
72
+      // 触发数据刷新
73
+      setQueryParams({...queryParams})
74
+    })
75
+  }
76
+
77
+  const handlePageChange = (pageNum, pageSize) => {
78
+    setQueryParams({
79
+      ...queryParams,      
80
+      pageNum,
81
+      pageSize,
82
+    })
83
+  }
84
+
85
+  useEffect(() => {
86
+    setLoading(true)
87
+    getNewsList(queryParams).then(res => {
88
+      const [list, pageInfo] = res || {}
89
+      setListData(list)
90
+      setPagination(pageInfo)
91
+      setLoading(false)
92
+    }).catch(() => setLoading(false))
93
+  }, [queryParams])
94
+
95
+  return (
96
+    <div>
97
+      <Condition onSearch={handleSearch} onReset={handleSearch} />
98
+      <div style={{ margin: '24px 0' }}>
99
+        <NavLink to={`/property/news/edit`}>
100
+          <Button type="primary">添加</Button>
101
+        </NavLink>
102
+      </div>
103
+      <List dataSource={listData} loading={loading} pagination={pagination} onPageChange={handlePageChange} rowKey="newsId">
104
+        <Table.Column title="#ID" dataIndex="newsId" key="newsId" />
105
+        <Table.Column
106
+          title="标题"
107
+          dataIndex="newsName"
108
+          key="newsName"
109
+          render={(_, row) => {
110
+            return (
111
+              <NavLink to={`/property/news/edit?id=${row.newsId}`}>
112
+                <Button type="link">{row.newsName}</Button>
113
+              </NavLink>
114
+            )
115
+          }}
116
+        />
117
+        <Table.Column title="封面" dataIndex="newsImg" key="newsImg" render={t => <img src={t} alt="" style={{ width: '96px', height: '96px' }} />} />
118
+        <Table.Column
119
+          title="内容"
120
+          dataIndex="newsDetail"
121
+          key="newsDetail"
122
+          render={t => <Typography.Text ellipsis>{(t||'').replace(/<[^>]*>|/g,"").substring(0, 20)}</Typography.Text>}
123
+        />
124
+        <Table.Column
125
+          title="状态"
126
+          dataIndex="status"
127
+          key="status"
128
+          render={(_, row) => StatusDict[row.status]}
129
+        />
130
+        <Table.Column title="创建时间" dataIndex="createDate" key="createDate" />
131
+        <Table.Column
132
+          title="操作"
133
+          key="action"
134
+          render={(_, row) => {
135
+            return (
136
+              <>
137
+                <Popconfirm
138
+                  title="确认进行删除操作?"
139
+                  onConfirm={() => handleDeleteRow(row)}
140
+                  okText="删除"
141
+                  cancelText="取消"
142
+                >
143
+                  <Button type="link">删除</Button>
144
+                </Popconfirm>
145
+                <Divider type="vertical" />
146
+                <Popconfirm
147
+                  title={`确认进行${row.status === 1? '取消发布' : '发布'}操作`}
148
+                  onConfirm={() => handleStatusTrigger(row)}
149
+                  okText={row.status === 1? '取消发布' : '发布'}
150
+                  cancelText="取消"
151
+                >
152
+                  <Button type="link">{row.status === 1? '取消发布' : '发布'}</Button>
153
+                </Popconfirm>
154
+                <Divider type="vertical" />
155
+                <NavLink to={`/property/news/edit?id=${row.newsId}`}>
156
+                  <Button type="link">编辑</Button>
157
+                </NavLink>
158
+              </>
159
+            )
160
+          }}
161
+        />
162
+      </List>
163
+
164
+    </div>
165
+  )
166
+}

+ 2
- 0
src/services/apis.js View File

@@ -4,6 +4,7 @@ import buildingOwnerInfo from './buildingOwnerInfo_api'
4 4
 import propUser from './prop_user_api'
5 5
 import announcement from './announcement_api'
6 6
 import ticket from './ticket_api'
7
+import propNews from './prop_news_api'
7 8
 
8 9
 const prefix = `${APIBaseURL}api/admin`
9 10
 
@@ -17,6 +18,7 @@ export default {
17 18
   buildingOwnerInfo: buildingOwnerInfo(prefix),
18 19
   announcement: announcement(prefix),
19 20
   ticket: ticket(prefix),
21
+  propNews: propNews(prefix),
20 22
   image: {
21 23
     uploadForAnt: {
22 24
       url: `${prefix}/antd/image`,

+ 41
- 0
src/services/prop_news_api.js View File

@@ -0,0 +1,41 @@
1
+
2
+const moduleName = 'property-news'
3
+
4
+export default prefix => {
5
+  return {
6
+    // 列表
7
+    getNewsList: {
8
+      url: `${prefix}/${moduleName}`,
9
+      method: 'get',
10
+      action: `admin.${moduleName}.list`
11
+    },
12
+
13
+    // 详情
14
+    getNewsDetail: {
15
+      url: `${prefix}/${moduleName}/:id`,
16
+      method: 'get',
17
+      action: `admin.${moduleName}.detail`
18
+    },
19
+
20
+    // 新增
21
+    addNews: {
22
+      url: `${prefix}/${moduleName}`,
23
+      method: 'post',
24
+      action: `admin.${moduleName}.add`
25
+    },
26
+
27
+    // 更新
28
+    updateNews: {
29
+      url: `${prefix}/${moduleName}/:id`,
30
+      method: 'put',
31
+      action: `admin.${moduleName}.update`
32
+    },
33
+
34
+    // 删除
35
+    deleteNews: {
36
+      url: `${prefix}/${moduleName}/id`,
37
+      method: 'delete',
38
+      action: `admin.${moduleName}.delete`
39
+    }
40
+  }
41
+}