|
@@ -1,35 +1,90 @@
|
1
|
|
-import React from 'react'
|
2
|
|
-import { Button, Form, Input, Select } from 'antd'
|
|
1
|
+import React, { useEffect, useState } from 'react'
|
|
2
|
+import { connect } from 'dva';
|
|
3
|
+import { Button, Form, Input, message, Select } from 'antd'
|
|
4
|
+import { fetch, apis } from '@/utils/request'
|
3
|
5
|
import InputNumber from './components/InputNumber'
|
4
|
6
|
import { formItemLayout, validMinNum } from './utils'
|
5
|
7
|
|
6
|
|
-const ChannelForm = (props) => {
|
7
|
|
- const { form } = props
|
8
|
|
- const { getFieldDecorator } = form
|
|
8
|
+const getChannel = fetch(apis.building.channel.get)
|
|
9
|
+// const saveChannel = fetch(apis.building.channel.save)
|
|
10
|
+const updateChannel = fetch(apis.building.channel.update)
|
|
11
|
+const getChannelDict = fetch(apis.channelList.getList)
|
|
12
|
+
|
|
13
|
+const ChannelForm = React.forwardRef((props, ref) => {
|
|
14
|
+ const { form, history, user } = props
|
|
15
|
+ const { getFieldDecorator, setFieldsValue, validateFields } = form
|
|
16
|
+ const { query } = history.location;
|
|
17
|
+ const { id } = query;
|
|
18
|
+
|
|
19
|
+ const [loading, setLoading] = useState(false)
|
|
20
|
+ const [dict, setDict] = useState([])
|
|
21
|
+
|
|
22
|
+ const handleSubmit = (e) => {
|
|
23
|
+ e.preventDefault();
|
|
24
|
+ validateFields((err, values) => {
|
|
25
|
+ if (!err) {
|
|
26
|
+ const data = {
|
|
27
|
+ ...values,
|
|
28
|
+ buildingId: id,
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ setLoading(true)
|
|
32
|
+ updateChannel({ data }).then(() => {
|
|
33
|
+ setLoading(false)
|
|
34
|
+ message.success('数据保存成功')
|
|
35
|
+ }).catch(() => {
|
|
36
|
+ setLoading(false)
|
|
37
|
+ })
|
|
38
|
+ }
|
|
39
|
+ });
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ useEffect(() => {
|
|
43
|
+ getChannelDict({ params: { pageSize: 500, institutionId: user.institutionId }}).then((res) => {
|
|
44
|
+ const { records } = res || {}
|
|
45
|
+ if (records?.length) {
|
|
46
|
+ setDict(records)
|
|
47
|
+ }
|
|
48
|
+ })
|
|
49
|
+ }, [])
|
|
50
|
+
|
|
51
|
+ useEffect(() => {
|
|
52
|
+ if (id) {
|
|
53
|
+ getChannel({ urlData: { id } }).then((res) => {
|
|
54
|
+ if (res) {
|
|
55
|
+ setFieldsValue(res)
|
|
56
|
+ }
|
|
57
|
+ })
|
|
58
|
+ }
|
|
59
|
+ }, [id])
|
9
|
60
|
|
10
|
61
|
return (
|
11
|
|
- <Form {...formItemLayout}>
|
|
62
|
+ <Form {...formItemLayout} onSubmit={handleSubmit}>
|
12
|
63
|
<Form.Item label="渠道">
|
13
|
|
- {getFieldDecorator('shareContentTitle', {
|
14
|
|
- rules: [{required: true, message: '请填写分享标题'}]
|
15
|
|
- })(<Select />)}
|
|
64
|
+ {getFieldDecorator('channelIdList', {
|
|
65
|
+ rules: [{required: true, message: '请选择渠道'}]
|
|
66
|
+ })(
|
|
67
|
+ <Select mode="multiple" style={{ width: '100%' }}>
|
|
68
|
+ {
|
|
69
|
+ dict.map((item) => (<Select.Option key={item.channelId} value={`${item.channelId}`}>{item.channelName}</Select.Option>))
|
|
70
|
+ }
|
|
71
|
+ </Select>
|
|
72
|
+ )}
|
16
|
73
|
</Form.Item>
|
17
|
74
|
<Form.Item label="报备有效期">
|
18
|
|
- {getFieldDecorator('posterImg', {
|
|
75
|
+ {getFieldDecorator('expirationDate', {
|
19
|
76
|
rules: [{ validator: validMinNum }],
|
20
|
77
|
})(<InputNumber min={0} step={1} addonAfter="天" />)}
|
21
|
78
|
</Form.Item>
|
22
|
|
- <Form.Item label="报备有效期">
|
23
|
|
- {getFieldDecorator('posterImg', {
|
24
|
|
- rules: [{ validator: validMinNum }],
|
25
|
|
- })(<Input.TextArea row={4} />)}
|
|
79
|
+ <Form.Item label="报备规则">
|
|
80
|
+ {getFieldDecorator('remark', {})(<Input.TextArea row={4} />)}
|
26
|
81
|
</Form.Item>
|
27
|
82
|
<Form.Item label=" " colon={false} style={{marginTop: '2em'}}>
|
28
|
|
- <Button style={{marginLeft: '4em'}} type="primary" htmlType="submit">保存</Button>
|
29
|
|
- <Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button>
|
|
83
|
+ <Button style={{marginLeft: '4em'}} loading={loading} type="primary" htmlType="submit">保存</Button>
|
|
84
|
+ {/* <Button style={{marginLeft: '2em'}} onClick={props.onCancel}>取消</Button> */}
|
30
|
85
|
</Form.Item>
|
31
|
86
|
</Form>
|
32
|
87
|
)
|
33
|
|
-}
|
|
88
|
+})
|
34
|
89
|
|
35
|
|
-export default Form.create({})(ChannelForm)
|
|
90
|
+export default connect((s) => ({ user: s.user.currentUser }))(Form.create({})(ChannelForm))
|