|
@@ -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>
|