张延森 2 年之前
父節點
當前提交
da33e67da6

+ 1
- 0
src/components/QueryTable/index.jsx 查看文件

@@ -16,6 +16,7 @@ export default React.forwardRef((props, ref) => {
16 16
       }
17 17
     },
18 18
     getSearchData: searchData,
19
+    refreshList: tableRef.current.refreshList
19 20
   }))
20 21
 
21 22
   return (

+ 2
- 2
src/components/SelectButton/CitySelect.jsx 查看文件

@@ -52,14 +52,14 @@ const CitySelect = (props) => {
52 52
       placeholder="请选择城市"
53 53
       showSearch
54 54
       {...props}
55
-      value={props.value}
55
+      value={`${props.value || ''}`}
56 56
       onChange={props.onChange}
57 57
       filterOption={(input, option) =>
58 58
         option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
59 59
       }
60 60
       >
61 61
           {data.map(city => (
62
-            <Option key={city.id} value={city.id}>{city.name}</Option>
62
+            <Option key={city.id} value={`${city.id}`}>{city.name}</Option>
63 63
           ))}
64 64
       </Select>
65 65
   )

+ 1
- 1
src/components/TableList/index.jsx 查看文件

@@ -35,7 +35,6 @@ export default React.forwardRef((props, ref) => {
35 35
   const fetchData = useCallback(() => {
36 36
     setLoading(true);
37 37
 
38
-
39 38
     const queryParams = {
40 39
       pageNum: pageConfig.current,
41 40
       pageSize: pageConfig.pageSize,
@@ -90,6 +89,7 @@ export default React.forwardRef((props, ref) => {
90 89
   // 透传给父组件部分方法
91 90
   useImperativeHandle(ref, () => ({
92 91
     reload: fetchData,
92
+    refreshList: cb => cb(list, setList)
93 93
   }));
94 94
 
95 95
   return (

+ 52
- 7
src/pages/borker/announcement/Edit/index.jsx 查看文件

@@ -1,9 +1,10 @@
1
-import React, { useState } from 'react'
2
-import { Card, Form, Select, Input, Button } from 'antd'
1
+import React, { useEffect, useState } from 'react'
2
+import { Row, Col, Card, Form, Select, Input, Button, notification } from 'antd'
3 3
 import SelectCity from '@/components/SelectButton/CitySelect'
4 4
 import ImageUpload from '@/components/XForm/ImageUpload'
5 5
 import Wangedit from '@/components/Wangedit/Wangedit';
6
-
6
+import { fetch, apis } from '@/utils/request';
7
+import { router } from 'umi';
7 8
 import { formItemLayout, showTypeList, pages } from '../util'
8 9
 
9 10
 const FormItem = Form.Item
@@ -25,17 +26,58 @@ const editorMenus = [
25 26
 ];
26 27
 const fullWidth = { width: '100%' }
27 28
 
28
-const AnnouncementEdit = React.forwardRef((props) => {
29
+const getFirstScreenDetail = fetch(apis.borker.getFirstScreenDetail)
30
+const saveFirstScreen = fetch(apis.borker.saveFirstScreen)
31
+const updateFirstScreen = fetch(apis.borker.updateFirstScreen)
32
+
33
+const AnnouncementEdit = React.forwardRef((props, ref) => {
29 34
   const { history, form } = props
30 35
   const { query } = history.location
31 36
   const { id } = query
32
-  const { getFieldDecorator, getFieldValue, setFieldsValue } = form
37
+  const { getFieldDecorator, validateFieldsAndScroll, setFieldsValue } = form
33 38
 
34 39
   const [loading, setLoading] = useState(false)
35 40
 
41
+  const handleSubmit = (e) => {
42
+    validateFieldsAndScroll((err, values) => {
43
+      if (err) return;
44
+
45
+      setLoading(true)
46
+      const p = !id ? saveFirstScreen({ data: values }) : updateFirstScreen({ urlData: { id }, data: values })
47
+      p.then(res => {
48
+        // setFieldsValue(res)
49
+        setLoading(false)
50
+        notification.success({ message: "操作成功" })
51
+        router.goBack()
52
+      }).catch(() => {
53
+        setLoading(false)
54
+      })
55
+    })
56
+  }
57
+
58
+  useEffect(() => {
59
+    if (id) {
60
+      setLoading(true)
61
+      getFirstScreenDetail({ urlData: { id } }).then(res => {
62
+        // ant3 的 form 赋值很诡异
63
+        const t = setTimeout(() => {
64
+          clearTimeout(t)
65
+          setLoading(false)
66
+          setFieldsValue(res)
67
+        }, 200)
68
+      }).catch(() => {
69
+        setLoading(false)
70
+      })
71
+    } else {
72
+      setFieldsValue({
73
+        showType: 'first-screen'
74
+      })
75
+    }
76
+  }, [id, setFieldsValue])
77
+
36 78
   return (
37
-    <Card>
38
-      <Form {...formItemLayout}>
79
+    <Card loading={loading}>
80
+      <Form {...formItemLayout} onSubmit={handleSubmit}>
39 81
         <FormItem label="公告类型">
40 82
           {
41 83
             getFieldDecorator('showType', {
@@ -97,6 +139,9 @@ const AnnouncementEdit = React.forwardRef((props) => {
97 139
           <Button type="primary" htmlType="submit" loading={loading}>
98 140
             提交
99 141
           </Button>
142
+          <Button onClick={router.goBack} style={{ marginLeft: '2em' }}>
143
+            返回
144
+          </Button>
100 145
         </FormItem>
101 146
       </Form>
102 147
     </Card>

+ 29
- 4
src/pages/borker/announcement/index.jsx 查看文件

@@ -5,7 +5,7 @@ import moment from 'moment'
5 5
 import QueryTable from '@/components/QueryTable'
6 6
 import SelectCity from '@/components/SelectButton/CitySelect'
7 7
 import OperButton from '@/components/OperButton'
8
-import { apis } from '@/utils/request'
8
+import { fetch, apis } from '@/utils/request';
9 9
 
10 10
 import { pages } from './util'
11 11
 
@@ -18,6 +18,8 @@ const searchFields = [
18 18
   },
19 19
 ]
20 20
 
21
+const updateFirstScreen = fetch(apis.borker.updateFirstScreen)
22
+
21 23
 const actionRender = () => {
22 24
   const gotoAdd = () => router.push('/borker/announcement/edit')
23 25
   return (
@@ -37,13 +39,14 @@ export default (props) => {
37 39
       key: 'imageUrl',
38 40
       align: 'center',
39 41
       render: (t) => {
40
-        return <img src={t} width={72} height={128} style={{borderRadius: '4px'}} alt="" />
42
+        return <img src={t} width={64} height={96} style={{borderRadius: '4px'}} alt="" />
41 43
       }
42 44
     },
43 45
     {
44 46
       title: '标题',
45 47
       dataIndex: 'title',
46 48
       key: 'title',
49
+      render: (t, row) => <Button type="link" onClick={() => router.push(`/borker/announcement/edit?id=${row.screenId}`)}>{t}</Button>
47 50
     },
48 51
     {
49 52
       title: '跳转页面',
@@ -71,13 +74,35 @@ export default (props) => {
71 74
       align: 'center',
72 75
       render: (_, row) => (
73 76
         <>
74
-          <OperButton>查看详情</OperButton>,
75
-          <OperButton onClick={() => onPublish(row)}>{row.status === 1 ? '取消发布' : '发布'}</OperButton>
77
+          <OperButton onClick={() => router.push(`/borker/announcement/edit?id=${row.screenId}`)}>详情</OperButton>
78
+          <OperButton.Confirm title="确认进行操作?" color="#1890ff" onClick={() => onPublish(row)}>{row.status === 1 ? '取消发布' : '发布'}</OperButton.Confirm>
76 79
         </>
77 80
       )
78 81
     },
79 82
   ]
80 83
 
84
+  const onPublish = (row) => {
85
+    setLoading(true)
86
+    updateFirstScreen({ urlData: { id: row.screenId }, data: { status: Math.abs(row.status - 1) } }).then(() => {
87
+      setLoading(false)
88
+
89
+      // 修改记录
90
+      ref.current.refreshList((list, next) => {
91
+        next(list.map(it => {
92
+          if (it.screenId === row.screenId) {
93
+            return {
94
+              ...it,
95
+              status: Math.abs(row.status - 1)
96
+            }
97
+          } else {
98
+            return it
99
+          }
100
+        }))
101
+      })
102
+    }).catch(() => {
103
+      setLoading(false)
104
+    })
105
+  }
81 106
 
82 107
   return (
83 108
     <Spin spinning={loading}>

+ 15
- 0
src/services/apis.js 查看文件

@@ -2429,5 +2429,20 @@ export default {
2429 2429
       method: 'GET',
2430 2430
       url: `${prefix}/bkFirstScreen`,
2431 2431
     },
2432
+    // 新增公告
2433
+    saveFirstScreen: {
2434
+      method: 'POST',
2435
+      url: `${prefix}/bkFirstScreen`,
2436
+    },
2437
+    // 更新公告
2438
+    updateFirstScreen: {
2439
+      method: 'PUT',
2440
+      url: `${prefix}/bkFirstScreen/:id`,
2441
+    },
2442
+    // 消息通知列表
2443
+    getFirstScreenDetail: {
2444
+      method: 'GET',
2445
+      url: `${prefix}/bkFirstScreen/:id`,
2446
+    },
2432 2447
   }
2433 2448
 };