|
@@ -15,10 +15,10 @@ const goBack = () => router.goBack(-1);
|
15
|
15
|
|
16
|
16
|
const CurriculumForm = React.forwardRef((props, ref) => {
|
17
|
17
|
const [loading, setLoading] = useState(false);//防止多次点击 定义loadind
|
18
|
|
- const [formData, setFormData] = useState();//提交表单的数据
|
19
|
|
- const [contentType, setContentType] = useState(1);//单选。初始默认显示1 富文本框。点击视频, 渲染2
|
|
18
|
+ // const [formData, setFormData] = useState({});//提交表单的数据
|
|
19
|
+ const [contentType, setContentType] = useState(0);//单选。初始默认显示0 富文本框。点击视频, 渲染1
|
20
|
20
|
const { form, history } = props;
|
21
|
|
- const { getFieldDecorator, setFieldsValue, validateFields } = form;
|
|
21
|
+ const { getFieldDecorator, setFieldsValue, validateFields,getFieldValue } = form;
|
22
|
22
|
const { curriculumId } = history.location.query || {}
|
23
|
23
|
|
24
|
24
|
const formItemLayout = {
|
|
@@ -28,6 +28,18 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
28
|
28
|
|
29
|
29
|
};
|
30
|
30
|
|
|
31
|
+ const fileUploadBeforeUpload = (file, fileList) => {
|
|
32
|
+ return new Promise((resolve, reject) => {
|
|
33
|
+ if (file.type === 'video/mp4' || file.type === '.mp4') {
|
|
34
|
+ // setVideoImage(true)
|
|
35
|
+ resolve(file);
|
|
36
|
+ } else {
|
|
37
|
+ notification.error({ message: '项目视频,仅支持MP4格式' });
|
|
38
|
+ reject();
|
|
39
|
+ }
|
|
40
|
+ });
|
|
41
|
+ };
|
|
42
|
+
|
31
|
43
|
const handleSubmit = (e) => {
|
32
|
44
|
e.preventDefault();
|
33
|
45
|
validateFields((err, values) => {
|
|
@@ -37,7 +49,9 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
37
|
49
|
}
|
38
|
50
|
|
39
|
51
|
setLoading(true);//loading开始
|
40
|
|
-
|
|
52
|
+ if (values.curriculumUrl) {
|
|
53
|
+ values.curriculumUrl = values.curriculumUrl[0];
|
|
54
|
+ }
|
41
|
55
|
if (curriculumId) {
|
42
|
56
|
//如果有这个id拿。没有就,拿返回的curriculumId
|
43
|
57
|
updateCurriculumData({
|
|
@@ -69,7 +83,12 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
69
|
83
|
|
70
|
84
|
const getCourseData = useCallback(({ curriculumId }) => {//函数结果存 初始化运行一次,等待调用。
|
71
|
85
|
getCurriculumData({urlData: { id: curriculumId }}).then((res) => {
|
72
|
|
- setFormData(res)
|
|
86
|
+ if(res.curriculumUrl){
|
|
87
|
+ res.curriculumUrl = [res.curriculumUrl];
|
|
88
|
+ }
|
|
89
|
+ setFieldsValue(res)
|
|
90
|
+ // setFormData(res)
|
|
91
|
+ // setContentType(res.type)
|
73
|
92
|
})
|
74
|
93
|
}, [])
|
75
|
94
|
|
|
@@ -79,11 +98,11 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
79
|
98
|
}
|
80
|
99
|
}, [curriculumId])//第二次id一样不执行
|
81
|
100
|
|
82
|
|
- useEffect(() => {
|
83
|
|
- if (formData) {//1.form表单数据{2} 执行。无变更不执行
|
84
|
|
- setFieldsValue(formData)
|
85
|
|
- }
|
86
|
|
- }, [formData])//2.有变更跟的话
|
|
101
|
+ // useEffect(() => {
|
|
102
|
+ // if (formData) {//1.form表单数据{2} 执行。无变更不执行
|
|
103
|
+ // setFieldsValue(formData)
|
|
104
|
+ // }
|
|
105
|
+ // }, [formData])//2.有变更跟的话
|
87
|
106
|
|
88
|
107
|
|
89
|
108
|
return (
|
|
@@ -99,8 +118,8 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
99
|
118
|
})(
|
100
|
119
|
<Select style={{width:'500px'}}>
|
101
|
120
|
<Option value="1">经纪人</Option>
|
102
|
|
- <Option value="2">职业顾问</Option>
|
103
|
|
- <Option value="0">职业顾问&经纪人</Option>
|
|
121
|
+ <Option value="2">置业顾问</Option>
|
|
122
|
+ <Option value="3">{`置业顾问&经纪人`}</Option>
|
104
|
123
|
</Select>
|
105
|
124
|
)
|
106
|
125
|
}
|
|
@@ -142,13 +161,14 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
142
|
161
|
<FormItem label="详情">
|
143
|
162
|
{
|
144
|
163
|
getFieldDecorator('type', {
|
|
164
|
+ initialValue:0,
|
145
|
165
|
rules: [
|
146
|
166
|
{ required: true, message: '请选择详情类型' }
|
147
|
167
|
]
|
148
|
168
|
})(
|
149
|
|
- <Radio.Group value={contentType} onChange={e=> setContentType(e.target.value)} style={{width:'500px'}} defaultValue={1}>
|
150
|
|
- <Radio value={1}>图文</Radio>
|
151
|
|
- <Radio value={2}>视频</Radio>
|
|
169
|
+ <Radio.Group style={{width:'500px'}} >
|
|
170
|
+ <Radio value={0}>图文</Radio>
|
|
171
|
+ <Radio value={1}>视频</Radio>
|
152
|
172
|
</Radio.Group>
|
153
|
173
|
)
|
154
|
174
|
}
|
|
@@ -169,18 +189,30 @@ const CurriculumForm = React.forwardRef((props, ref) => {
|
169
|
189
|
}
|
170
|
190
|
|
171
|
191
|
</FormItem> */}
|
172
|
|
-
|
173
|
|
- <FormItem label="详情内容">
|
|
192
|
+ { getFieldValue('type')==0?<FormItem label="图文">
|
174
|
193
|
{
|
175
|
194
|
getFieldDecorator('content', {
|
176
|
195
|
rules: [
|
177
|
196
|
{ required: true, message: '请输入详情内容' }
|
178
|
197
|
]
|
179
|
198
|
})(
|
180
|
|
- contentType == 1 ? <Wangedit style={{width:'500px'}} /> : <FileUpload />
|
|
199
|
+ <Wangedit style={{width:'500px'}} />
|
181
|
200
|
)
|
182
|
201
|
}
|
183
|
|
- </FormItem>
|
|
202
|
+ </FormItem>:
|
|
203
|
+ <FormItem label="视频">
|
|
204
|
+ {
|
|
205
|
+ getFieldDecorator('curriculumUrl', {
|
|
206
|
+ rules: [
|
|
207
|
+ { required: true, message: '请上传视频文件' }
|
|
208
|
+ ]
|
|
209
|
+ })(
|
|
210
|
+ <FileUpload accept=".mp4" beforeUpload={fileUploadBeforeUpload} label="上传视频" size={1} />,
|
|
211
|
+ )
|
|
212
|
+ }
|
|
213
|
+ </FormItem>}
|
|
214
|
+
|
|
215
|
+
|
184
|
216
|
<FormItem label="权重" >
|
185
|
217
|
{
|
186
|
218
|
getFieldDecorator('weight', {
|