Browse Source

信息修改

1002884655 3 years ago
parent
commit
252b12cc8e
1 changed files with 146 additions and 118 deletions
  1. 146
    118
      src/pages/index/activityDetail/index.jsx

+ 146
- 118
src/pages/index/activityDetail/index.jsx View File

1
-import { useState, useEffect } from 'react';
2
-import Taro from '@tarojs/taro';
3
-import withLayout from '@/layout';
4
-import { savePoint } from '@/services/common'
1
+import { useState, useEffect } from "react";
2
+import Taro from "@tarojs/taro";
3
+import withLayout from "@/layout";
4
+import { savePoint } from "@/services/common";
5
 import {
5
 import {
6
   ScrollView,
6
   ScrollView,
7
   Image,
7
   Image,
10
   Text,
10
   Text,
11
   Input,
11
   Input,
12
   Picker,
12
   Picker,
13
-  Button
14
-} from '@tarojs/components';
15
-import Disclaimer from '@/components/Disclaimer';
16
-import { useSelector } from 'react-redux';
17
-import {
18
-  signupActivity,
19
-  queryActivityDetail,
20
-} from "@/services/activity";
13
+  Button,
14
+} from "@tarojs/components";
15
+import Disclaimer from "@/components/Disclaimer";
16
+import { useSelector } from "react-redux";
17
+import { signupActivity, queryActivityDetail } from "@/services/activity";
21
 import { getImgURL } from "@/utils/image";
18
 import { getImgURL } from "@/utils/image";
22
 import { formatDate } from "@/utils/chatDate";
19
 import { formatDate } from "@/utils/chatDate";
23
 import useParams from "@/utils/hooks/useParams";
20
 import useParams from "@/utils/hooks/useParams";
24
 import useShare from "@/utils/hooks/useShare";
21
 import useShare from "@/utils/hooks/useShare";
25
 import useFavor from "@/utils/hooks/useFavor";
22
 import useFavor from "@/utils/hooks/useFavor";
26
 import { times } from "@/utils/tools";
23
 import { times } from "@/utils/tools";
27
-import useStatus from './useStatus'
28
-import CountDown from './CountDown'
24
+import useStatus from "./useStatus";
25
+import CountDown from "./CountDown";
29
 
26
 
30
 import "./index.scss";
27
 import "./index.scss";
31
 
28
 
32
 export default withLayout((props) => {
29
 export default withLayout((props) => {
33
-  const { router, shareContent, trackData, person, page, showShareTimeline, setNavigationBarTitle } = props;
34
-  const { id, eventType = 'dymic' } = router.params;
30
+  const {
31
+    router,
32
+    shareContent,
33
+    trackData,
34
+    person,
35
+    page,
36
+    showShareTimeline,
37
+    setNavigationBarTitle,
38
+  } = props;
39
+  const { id, eventType = "dymic" } = router.params;
35
 
40
 
36
   const user = useSelector((state) => state.user);
41
   const user = useSelector((state) => state.user);
37
 
42
 
38
-  const [detail, setDetail] = useState({})
39
-  const [canChoose, setCanChoose] = useState('none');
40
-  const [inputName, setInputName] = useState('');
41
-  const [selectorChecked, setSelectorChecked] = useState('1');
42
-  const [selector, setSelector] = useState('');
43
+  const [detail, setDetail] = useState({});
44
+  const [canChoose, setCanChoose] = useState("none");
45
+  const [inputName, setInputName] = useState("");
46
+  const [selectorChecked, setSelectorChecked] = useState("1");
47
+  const [selector, setSelector] = useState("");
43
 
48
 
44
   const buildingId = detail?.buildingId;
49
   const buildingId = detail?.buildingId;
45
 
50
 
46
-  const [btnText, btnDisabled] = useStatus(detail)
51
+  const [btnText, btnDisabled] = useStatus(detail);
47
 
52
 
48
   const getDetail = (params) => {
53
   const getDetail = (params) => {
49
     Taro.showLoading();
54
     Taro.showLoading();
50
 
55
 
51
     queryActivityDetail(params).then((res) => {
56
     queryActivityDetail(params).then((res) => {
52
-      const maxperson = 10
57
+      const maxperson = 10;
53
       setSelector(times(maxperson).map((_, i) => `${i + 1}`));
58
       setSelector(times(maxperson).map((_, i) => `${i + 1}`));
54
 
59
 
55
       setDetail(res || {});
60
       setDetail(res || {});
56
-      setNavigationBarTitle(res?.title)
61
+      setNavigationBarTitle(res?.title);
57
       Taro.hideLoading();
62
       Taro.hideLoading();
58
     });
63
     });
59
   };
64
   };
60
 
65
 
61
   useEffect(() => {
66
   useEffect(() => {
62
-    if(trackData.eventType && detail.dynamicId) {
67
+    if (trackData.eventType && detail.dynamicId) {
63
       savePoint({
68
       savePoint({
64
         ...trackData,
69
         ...trackData,
65
-        event: 'detail',
66
-        eventType: detail.type || 'dymic',
67
-        targetType: detail.type || 'dymic'
68
-      })
69
-
70
-      useShare(
71
-        {
72
-          title: shareContent.shareContentTitle || detail?.title,
73
-          path: `${router.path}?${paramsRef.current}&type=${detail.type || 'dymic'}`,
74
-          // image: shareContent.shareContentImg || getImgURL(detail?.imgUrl),
75
-          image: '',
76
-        },
77
-        {...fullTrackData, eventType: detail.type || 'dymic' }
78
-      );
70
+        event: "detail",
71
+        eventType: detail.type || "dymic",
72
+        targetType: detail.type || "dymic",
73
+      });
79
     }
74
     }
80
-  }, [trackData, detail])
75
+  }, [trackData, detail]);
81
 
76
 
82
   // 本页面分享或者海报参数
77
   // 本页面分享或者海报参数
83
   const paramsRef = useParams({
78
   const paramsRef = useParams({
95
     ...trackData,
90
     ...trackData,
96
   });
91
   });
97
 
92
 
93
+  useShare(
94
+    {
95
+      title: shareContent.shareContentTitle || detail?.title,
96
+      path: `${router.path}?${paramsRef.current}&type=${
97
+        detail.type || "dymic"
98
+      }`,
99
+      // image: shareContent.shareContentImg || getImgURL(detail?.imgUrl),
100
+      image: "",
101
+    },
102
+    { ...fullTrackData, eventType: detail.type || "dymic" }
103
+  );
104
+
98
   useEffect(() => {
105
   useEffect(() => {
99
     if (id) {
106
     if (id) {
100
       getDetail(id);
107
       getDetail(id);
101
     }
108
     }
102
-  }, [id])
109
+  }, [id]);
103
 
110
 
104
   const handleSignup = () => {
111
   const handleSignup = () => {
105
     setCanChoose("block");
112
     setCanChoose("block");
106
   };
113
   };
107
 
114
 
108
   const comfire = () => {
115
   const comfire = () => {
109
-    const { dynamicId } = detail
110
-    const { userInfo: { person: { phone, tel } } } = user
111
-    if (inputName === '') {
116
+    const { dynamicId } = detail;
117
+    const {
118
+      userInfo: {
119
+        person: { phone, tel },
120
+      },
121
+    } = user;
122
+    if (inputName === "") {
112
       Taro.showToast({
123
       Taro.showToast({
113
-        title: '请输入姓名',
114
-        icon: 'none'
115
-      })
116
-      return
124
+        title: "请输入姓名",
125
+        icon: "none",
126
+      });
127
+      return;
117
     }
128
     }
118
 
129
 
119
     const payload = {
130
     const payload = {
128
       Taro.showToast({
139
       Taro.showToast({
129
         title: "报名成功",
140
         title: "报名成功",
130
       });
141
       });
131
-      setCanChoose('none')
142
+      setCanChoose("none");
132
       setTimeout(() => {
143
       setTimeout(() => {
133
-        getDetail(id)
134
-      }, 500)
144
+        getDetail(id);
145
+      }, 500);
135
     });
146
     });
136
   };
147
   };
137
 
148
 
138
-  function hideModal () {
139
-    setCanChoose('none');
149
+  function hideModal() {
150
+    setCanChoose("none");
140
   }
151
   }
141
 
152
 
142
   const onInputText = (e) => {
153
   const onInputText = (e) => {
144
   };
155
   };
145
 
156
 
146
   const dymic = () => (
157
   const dymic = () => (
147
-    <view className='Info'>
158
+    <view className="Info">
148
       <view>
159
       <view>
149
-        <view className='Title flex-h'>
150
-          <view className='flex-item'>
160
+        <view className="Title flex-h">
161
+          <view className="flex-item">
151
             <text>{detail.halfTitle}</text>
162
             <text>{detail.halfTitle}</text>
152
           </view>
163
           </view>
153
-          <text className='Tips'>{detail.enlisted || 0}人已报名</text>
164
+          <text className="Tips">{detail.enlisted || 0}人已报名</text>
154
         </view>
165
         </view>
155
-        <text className='Time'>
166
+        <text className="Time">
156
           报名截止时间:
167
           报名截止时间:
157
-          {formatDate(detail.enlistEnd, 'yyyy/MM/dd')}
168
+          {formatDate(detail.enlistEnd, "yyyy/MM/dd")}
158
         </text>
169
         </text>
159
-        <text className='Name'>{detail.title}</text>
160
-        <view className='flex-h Address'>
170
+        <text className="Name">{detail.title}</text>
171
+        <view className="flex-h Address">
161
           <text>活动地址:</text>
172
           <text>活动地址:</text>
162
-          <view className='flex-item'>
173
+          <view className="flex-item">
163
             <text>{detail.address}</text>
174
             <text>{detail.address}</text>
164
           </view>
175
           </view>
165
         </view>
176
         </view>
166
-        <view className='flex-h Date'>
177
+        <view className="flex-h Date">
167
           <text>活动时间:</text>
178
           <text>活动时间:</text>
168
-          <view className='flex-item'>
179
+          <view className="flex-item">
169
             <text>
180
             <text>
170
-              {`${formatDate(detail.startDate, 'yyyy/MM/dd')} - ${formatDate(detail.endDate, 'yyyy/MM/dd')}`}
181
+              {`${formatDate(detail.startDate, "yyyy/MM/dd")} - ${formatDate(
182
+                detail.endDate,
183
+                "yyyy/MM/dd"
184
+              )}`}
171
             </text>
185
             </text>
172
           </view>
186
           </view>
173
         </view>
187
         </view>
174
-        <view className='Btn'>
175
-          <Button open-type='share'>
188
+        <view className="Btn">
189
+          <Button open-type="share">
176
             <text>分享好友</text>
190
             <text>分享好友</text>
177
           </Button>
191
           </Button>
178
         </view>
192
         </view>
181
   );
195
   );
182
 
196
 
183
   const house = () => (
197
   const house = () => (
184
-
185
-    <view className='BuildingInfo'>
186
-
187
-      <view className='flex-h Title'>
188
-        <view className='flex-item'>
189
-          <text className='Name'>{detail.title}</text>
190
-          <view className='Address flex-h'>
191
-            <text className='iconfont icon-dingwei'></text>
192
-            <view className='flex-item'>
198
+    <view className="BuildingInfo">
199
+      <view className="flex-h Title">
200
+        <view className="flex-item">
201
+          <text className="Name">{detail.title}</text>
202
+          <view className="Address flex-h">
203
+            <text className="iconfont icon-dingwei"></text>
204
+            <view className="flex-item">
193
               <text>{detail.address}</text>
205
               <text>{detail.address}</text>
194
             </view>
206
             </view>
195
           </view>
207
           </view>
196
-          <text className='Price'>{detail.groupBuyPrice || '价格待定'}</text>
197
-          <text className='Time'>活动时间:{formatDate(detail.startDate, 'yyyy/MM/dd')} - {formatDate(detail.endDate, 'yyyy/MM/dd')}</text>
208
+          <text className="Price">{detail.groupBuyPrice || "价格待定"}</text>
209
+          <text className="Time">
210
+            活动时间:{formatDate(detail.startDate, "yyyy/MM/dd")} -{" "}
211
+            {formatDate(detail.endDate, "yyyy/MM/dd")}
212
+          </text>
198
         </view>
213
         </view>
199
-        <view className='Option'>
214
+        <view className="Option">
200
           <view>
215
           <view>
201
-            <text className='iconfont icon-fenxiang1'></text>
216
+            <text className="iconfont icon-fenxiang1"></text>
202
             <text>分享</text>
217
             <text>分享</text>
203
-            <Button open-type='share' className='ShareBtn'>分享</Button>
218
+            <Button open-type="share" className="ShareBtn">
219
+              分享
220
+            </Button>
204
           </view>
221
           </view>
205
           <view onClick={() => showShareTimeline(true)}>
222
           <view onClick={() => showShareTimeline(true)}>
206
-            <text className='iconfont icon-pengyouquan1' style='font-size: 32rpx'></text>
223
+            <text
224
+              className="iconfont icon-pengyouquan1"
225
+              style="font-size: 32rpx"
226
+            ></text>
207
             <text>朋友圈</text>
227
             <text>朋友圈</text>
208
           </view>
228
           </view>
209
         </view>
229
         </view>
211
 
231
 
212
       <CountDown endTime={detail?.enlistEnd} />
232
       <CountDown endTime={detail?.enlistEnd} />
213
 
233
 
214
-      <view className='Apply flex-h'>
215
-        <view className='Collect' onClick={handleFavor}>
216
-          <text className='iconfont icon-shoucang' style={isSaved ? { color: 'red' } : undefined}></text>
217
-          <text>{isSaved ? '已收藏' : '收藏'}</text>
234
+      <view className="Apply flex-h">
235
+        <view className="Collect" onClick={handleFavor}>
236
+          <text
237
+            className="iconfont icon-shoucang"
238
+            style={isSaved ? { color: "red" } : undefined}
239
+          ></text>
240
+          <text>{isSaved ? "已收藏" : "收藏"}</text>
218
         </view>
241
         </view>
219
-        <text className='iconfont icon-baoming'></text>
220
-        <view className='flex-item'>
242
+        <text className="iconfont icon-baoming"></text>
243
+        <view className="flex-item">
221
           <text>{detail.enlisted || 0}人已报名</text>
244
           <text>{detail.enlisted || 0}人已报名</text>
222
         </view>
245
         </view>
223
-        <Button className='Btn' disabled={btnDisabled} onClick={handleSignup}>{btnText}</Button>
246
+        <Button className="Btn" disabled={btnDisabled} onClick={handleSignup}>
247
+          {btnText}
248
+        </Button>
224
       </view>
249
       </view>
225
-
226
     </view>
250
     </view>
227
   );
251
   );
228
 
252
 
229
   return (
253
   return (
230
     <>
254
     <>
231
       {detail && (
255
       {detail && (
232
-        <view className='Page activityDetail flex-v'>
233
-          <view className='flex-item'>
256
+        <view className="Page activityDetail flex-v">
257
+          <view className="flex-item">
234
             <view>
258
             <view>
235
               <ScrollView scroll-y>
259
               <ScrollView scroll-y>
236
-                <view className='PageContent'>
237
-                  <view className='Top'>
260
+                <view className="PageContent">
261
+                  <view className="Top">
238
                     <Image
262
                     <Image
239
-                      mode='aspectFill'
263
+                      mode="aspectFill"
240
                       src={getImgURL(detail.imgUrl)}
264
                       src={getImgURL(detail.imgUrl)}
241
-                      className='centerLabel'
265
+                      className="centerLabel"
242
                     ></Image>
266
                     ></Image>
243
                   </view>
267
                   </view>
244
 
268
 
245
                   {detail.type == "dymic" && dymic()}
269
                   {detail.type == "dymic" && dymic()}
246
                   {detail.type !== "dymic" && house()}
270
                   {detail.type !== "dymic" && house()}
247
-                  <view className='ActivityIntro'>
248
-                    <view className='Title'>
271
+                  <view className="ActivityIntro">
272
+                    <view className="Title">
249
                       <text>活动介绍</text>
273
                       <text>活动介绍</text>
250
                     </view>
274
                     </view>
251
                     <RichText nodes={detail.desc} />
275
                     <RichText nodes={detail.desc} />
257
             </view>
281
             </view>
258
           </view>
282
           </view>
259
           {detail.type == "dymic" && (
283
           {detail.type == "dymic" && (
260
-            <view className='PageBottom flex-h'>
261
-              <Button className='Share' open-type='share'>
262
-                <text className='iconfont icon-fenxiang'></text>
284
+            <view className="PageBottom flex-h">
285
+              <Button className="Share" open-type="share">
286
+                <text className="iconfont icon-fenxiang"></text>
263
                 <text>分享</text>
287
                 <text>分享</text>
264
               </Button>
288
               </Button>
265
-              <view className='Collect' onClick={handleFavor}>
289
+              <view className="Collect" onClick={handleFavor}>
266
                 <text
290
                 <text
267
-                  className='iconfont icon-shoucang'
291
+                  className="iconfont icon-shoucang"
268
                   style={isSaved ? { color: "red" } : undefined}
292
                   style={isSaved ? { color: "red" } : undefined}
269
                 ></text>
293
                 ></text>
270
-                <text>{isSaved ? '已收藏' : '收藏'}</text>
294
+                <text>{isSaved ? "已收藏" : "收藏"}</text>
271
               </view>
295
               </view>
272
-              <view className='flex-item'></view>
296
+              <view className="flex-item"></view>
273
 
297
 
274
-              <Button disabled={btnDisabled} className='Post' onClick={handleSignup}>
298
+              <Button
299
+                disabled={btnDisabled}
300
+                className="Post"
301
+                onClick={handleSignup}
302
+              >
275
                 {btnText}
303
                 {btnText}
276
               </Button>
304
               </Button>
277
             </view>
305
             </view>
279
         </view>
307
         </view>
280
       )}
308
       )}
281
 
309
 
282
-      <View className='page-body' style={{ display: canChoose }}>
283
-        <View className='mask' onClick={() => hideModal()}></View>
284
-        <View className='page-section'>
285
-          <Text className='page-section__title'>报名信息</Text>
286
-          <View className='page-content'>
310
+      <View className="page-body" style={{ display: canChoose }}>
311
+        <View className="mask" onClick={() => hideModal()}></View>
312
+        <View className="page-section">
313
+          <Text className="page-section__title">报名信息</Text>
314
+          <View className="page-content">
287
             <Input
315
             <Input
288
-              className='inputName'
316
+              className="inputName"
289
               onInput={onInputText}
317
               onInput={onInputText}
290
-              type='text'
291
-              placeholder='请输入姓名'
318
+              type="text"
319
+              placeholder="请输入姓名"
292
             />
320
             />
293
             <Picker
321
             <Picker
294
-              mode='selector'
322
+              mode="selector"
295
               range={selector}
323
               range={selector}
296
               onChange={(e) => setSelectorChecked(selector[e.detail.value])}
324
               onChange={(e) => setSelectorChecked(selector[e.detail.value])}
297
             >
325
             >
298
-              <View className='picker'>
326
+              <View className="picker">
299
                 <Text>参加人数</Text>
327
                 <Text>参加人数</Text>
300
-                <Text className='content'>{selectorChecked}</Text>
328
+                <Text className="content">{selectorChecked}</Text>
301
                 <Text>人</Text>
329
                 <Text>人</Text>
302
               </View>
330
               </View>
303
             </Picker>
331
             </Picker>
304
-            <View onClick={comfire} className='comfire'>
332
+            <View onClick={comfire} className="comfire">
305
               确认
333
               确认
306
             </View>
334
             </View>
307
           </View>
335
           </View>