傅行帆 il y a 5 ans
Parent
révision
4f5e50fffa
1 fichiers modifiés avec 103 ajouts et 16 suppressions
  1. 103
    16
      src/pages/activity/editActivity.jsx

+ 103
- 16
src/pages/activity/editActivity.jsx Voir le fichier

@@ -148,6 +148,7 @@ const Edit = (props) => {
148 148
           method: 'PUT',
149 149
           data: submitValue,
150 150
         }).then((data) => {
151
+          message.info("保存成功")
151 152
           cancelPage()
152 153
         }).catch((err) => {
153 154
           message.info(err.msg || err.message)
@@ -158,6 +159,7 @@ const Edit = (props) => {
158 159
           method: 'POST',
159 160
           data: submitValue,
160 161
         }).then((data) => {
162
+          message.info("保存成功")
161 163
           cancelPage()
162 164
         }).catch((err) => {
163 165
           message.info(err.msg || err.message)
@@ -172,12 +174,55 @@ const Edit = (props) => {
172 174
     const [inputValue, changeInput] = useState('')
173 175
     const [textAreaValue, changeTextArea] = useState('')
174 176
     const [imgValue, changeImg] = useState('')
177
+    const [posterId, setPosterId] = useState('')
178
+
179
+    if(dynamicId){
180
+      useEffect(() => {
181
+        request({
182
+          url: '/api/admin/poster',
183
+          method: 'GET',
184
+          params: {targetId: dynamicId,targetType: 'activity'},
185
+        }).then((data) => {
186
+          console.log(data,"2222")
187
+          if(data.length > 0){
188
+            setPosterId(data[0].posterId)
189
+            changeImg(data[0].posterImg)
190
+            changeTextArea(data[0].posterDescription)
191
+            changeInput(data[0].posterTitle)
192
+          }
193
+        }).catch((err) => {
194
+          message.info(err.msg || err.message)
195
+        })
196
+      }, [])
197
+    }
175 198
 
176 199
     const submitPoster  = () => {
177
-      console.log(inputValue)
178
-      console.log(textAreaValue)
179
-      console.log(imgValue)
180
-      console.log(dynamicId)
200
+       if(dynamicId){
201
+        if(posterId){
202
+          request({
203
+            url: '/api/admin/poster/'+posterId,
204
+            method: 'PUT',
205
+            data: {targetId: dynamicId,targetType: 'activity',posterImg: imgValue,posterTitle: inputValue,posterDescription: textAreaValue},
206
+          }).then((data) => {
207
+            message.info("保存成功")
208
+          }).catch((err) => {
209
+            message.info(err.msg || err.message)
210
+          })
211
+         }else{
212
+          request({
213
+            url: '/api/admin/poster',
214
+            method: 'POST',
215
+            data: {targetId: dynamicId,targetType: 'activity',posterImg: imgValue,posterTitle: inputValue,posterDescription: textAreaValue},
216
+          }).then((data) => {
217
+            setPosterId(data.posterId)
218
+            message.info("保存成功")
219
+          }).catch((err) => {
220
+            message.info(err.msg || err.message)
221
+          })
222
+         }
223
+       }else{
224
+        message.warn("请先保存基本信息数据")
225
+       }
181 226
     }
182 227
 
183 228
     return <div>
@@ -217,15 +262,15 @@ const Edit = (props) => {
217 262
         <div >
218 263
           <div style={{ display: 'flex', width: '100%', margin: '60px 0' }}>
219 264
             <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报图片</p>
220
-            <ImageUploader onChange={e => changeImg(e)} />
265
+            <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
221 266
           </div>
222 267
           <div style={{ display: 'flex', alignItems: 'center', width: '100%', marginBottom: '60px' }}>
223 268
             <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
224
-            <Input style={{ width: '20vw' }} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
269
+            <Input style={{ width: '20vw' }} value={inputValue} placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
225 270
           </div>
226 271
           <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
227 272
             <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报描述</p>
228
-            <TextArea rows={5} onChange={e => changeTextArea(e.target.value)} />
273
+            <TextArea rows={5} value={textAreaValue} onChange={e => changeTextArea(e.target.value)} />
229 274
           </div>
230 275
 
231 276
         </div>
@@ -241,13 +286,55 @@ const Edit = (props) => {
241 286
   const Share = (props) => {
242 287
     const [inputValue, changeInput] = useState('')
243 288
     const [imgValue, changeImg] = useState('')
244
-    // const changeInputValue = e => {
245
-    //   changeInput(e.target.value)
246
-    // }
247
-
248
-    // const handleSubmit = (values) => {
289
+    const [shareContentId, setShareContentId] = useState('')
290
+    
291
+    if(dynamicId){
292
+      useEffect(() => {
293
+        request({
294
+          url: '/api/admin/shareContent',
295
+          method: 'GET',
296
+          params: {targetId: dynamicId,targetType: 'activity'},
297
+        }).then((data) => {
298
+          console.log(data,"2222")
299
+          if(data.length > 0){
300
+            setShareContentId(data[0].shareContentId)
301
+            changeImg(data[0].shareContentImg)
302
+            changeInput(data[0].shareContentTitle)
303
+          }
304
+        }).catch((err) => {
305
+          message.info(err.msg || err.message)
306
+        })
307
+      }, [])
308
+    }
249 309
 
250
-    // }
310
+    const submitShare = () => {
311
+      if(dynamicId){
312
+        if(shareContentId){
313
+          request({
314
+            url: '/api/admin/shareContent/'+shareContentId,
315
+            method: 'PUT',
316
+            data: {targetId: dynamicId,shareContentType: 'activity',shareContentImg: imgValue,shareContentTitle: inputValue},
317
+          }).then((data) => {
318
+            message.info("保存成功")
319
+          }).catch((err) => {
320
+            message.info(err.msg || err.message)
321
+          })
322
+         }else{
323
+          request({
324
+            url: '/api/admin/shareContent',
325
+            method: 'POST',
326
+            data: {targetId: dynamicId,shareContentType: 'activity',shareContentImg: imgValue,shareContentTitle: inputValue},
327
+          }).then((data) => {
328
+            setShareContentId(data.shareContentId)
329
+            message.info("保存成功")
330
+          }).catch((err) => {
331
+            message.info(err.msg || err.message)
332
+          })
333
+         }
334
+       }else{
335
+        message.warn("请先保存基本信息数据")
336
+       }
337
+    }
251 338
 
252 339
     return <div style={{ padding: '20px' }}>
253 340
       <div style={{ display: 'flex', margin: '10px 0 40px 0', width: '100%' }}>
@@ -260,13 +347,13 @@ const Edit = (props) => {
260 347
       </div>
261 348
       <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
262 349
         <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>海报标题</p>
263
-        <Input placeholder="请输入海报标题" onChange={e => changeInput(e.target.value)} />
350
+        <Input placeholder="请输入海报标题" value={inputValue} onChange={e => changeInput(e.target.value)} />
264 351
       </div>
265 352
       <div style={{ display: 'flex', width: '100%', marginTop: '40px' }}>
266 353
         <p style={{ minWidth: '200px', color: '#222', textAlign: 'right', margin: '0 30px 0 0' }}>分享图片</p>
267
-        <ImageUploader onChange={e => changeImg(e)} />
354
+        <ImageUploader value={imgValue} onChange={e => changeImg(e)} />
268 355
       </div>
269
-      <Button type="primary" htmlType="submit" style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
356
+      <Button type="primary" htmlType="submit" onClick={submitShare} style={{ margin: '40px 40px 40px 220px' }}> 确定</Button>
270 357
       <Button onClick={() => router.go(-1)}>取消</Button>
271 358
     </div>
272 359
   }