zlisen 3 年前
父节点
当前提交
540eb1e3fc
共有 1 个文件被更改,包括 146 次插入118 次删除
  1. 146
    118
      src/pages/index/activityDetail/index.jsx

+ 146
- 118
src/pages/index/activityDetail/index.jsx 查看文件

@@ -1,7 +1,7 @@
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 5
 import {
6 6
   ScrollView,
7 7
   Image,
@@ -10,74 +10,69 @@ import {
10 10
   Text,
11 11
   Input,
12 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 18
 import { getImgURL } from "@/utils/image";
22 19
 import { formatDate } from "@/utils/chatDate";
23 20
 import useParams from "@/utils/hooks/useParams";
24 21
 import useShare from "@/utils/hooks/useShare";
25 22
 import useFavor from "@/utils/hooks/useFavor";
26 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 27
 import "./index.scss";
31 28
 
32 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 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 49
   const buildingId = detail?.buildingId;
45 50
 
46
-  const [btnText, btnDisabled] = useStatus(detail)
51
+  const [btnText, btnDisabled] = useStatus(detail);
47 52
 
48 53
   const getDetail = (params) => {
49 54
     Taro.showLoading();
50 55
 
51 56
     queryActivityDetail(params).then((res) => {
52
-      const maxperson = 10
57
+      const maxperson = 10;
53 58
       setSelector(times(maxperson).map((_, i) => `${i + 1}`));
54 59
 
55 60
       setDetail(res || {});
56
-      setNavigationBarTitle(res?.title)
61
+      setNavigationBarTitle(res?.title);
57 62
       Taro.hideLoading();
58 63
     });
59 64
   };
60 65
 
61 66
   useEffect(() => {
62
-    if(trackData.eventType && detail.dynamicId) {
67
+    if (trackData.eventType && detail.dynamicId) {
63 68
       savePoint({
64 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
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 78
   const paramsRef = useParams({
@@ -95,25 +90,41 @@ export default withLayout((props) => {
95 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 105
   useEffect(() => {
99 106
     if (id) {
100 107
       getDetail(id);
101 108
     }
102
-  }, [id])
109
+  }, [id]);
103 110
 
104 111
   const handleSignup = () => {
105 112
     setCanChoose("block");
106 113
   };
107 114
 
108 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 123
       Taro.showToast({
113
-        title: '请输入姓名',
114
-        icon: 'none'
115
-      })
116
-      return
124
+        title: "请输入姓名",
125
+        icon: "none",
126
+      });
127
+      return;
117 128
     }
118 129
 
119 130
     const payload = {
@@ -128,15 +139,15 @@ export default withLayout((props) => {
128 139
       Taro.showToast({
129 140
         title: "报名成功",
130 141
       });
131
-      setCanChoose('none')
142
+      setCanChoose("none");
132 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 153
   const onInputText = (e) => {
@@ -144,35 +155,38 @@ export default withLayout((props) => {
144 155
   };
145 156
 
146 157
   const dymic = () => (
147
-    <view className='Info'>
158
+    <view className="Info">
148 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 162
             <text>{detail.halfTitle}</text>
152 163
           </view>
153
-          <text className='Tips'>{detail.enlisted || 0}人已报名</text>
164
+          <text className="Tips">{detail.enlisted || 0}人已报名</text>
154 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 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 172
           <text>活动地址:</text>
162
-          <view className='flex-item'>
173
+          <view className="flex-item">
163 174
             <text>{detail.address}</text>
164 175
           </view>
165 176
         </view>
166
-        <view className='flex-h Date'>
177
+        <view className="flex-h Date">
167 178
           <text>活动时间:</text>
168
-          <view className='flex-item'>
179
+          <view className="flex-item">
169 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 185
             </text>
172 186
           </view>
173 187
         </view>
174
-        <view className='Btn'>
175
-          <Button open-type='share'>
188
+        <view className="Btn">
189
+          <Button open-type="share">
176 190
             <text>分享好友</text>
177 191
           </Button>
178 192
         </view>
@@ -181,29 +195,35 @@ export default withLayout((props) => {
181 195
   );
182 196
 
183 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 205
               <text>{detail.address}</text>
194 206
             </view>
195 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 213
         </view>
199
-        <view className='Option'>
214
+        <view className="Option">
200 215
           <view>
201
-            <text className='iconfont icon-fenxiang1'></text>
216
+            <text className="iconfont icon-fenxiang1"></text>
202 217
             <text>分享</text>
203
-            <Button open-type='share' className='ShareBtn'>分享</Button>
218
+            <Button open-type="share" className="ShareBtn">
219
+              分享
220
+            </Button>
204 221
           </view>
205 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 227
             <text>朋友圈</text>
208 228
           </view>
209 229
         </view>
@@ -211,41 +231,45 @@ export default withLayout((props) => {
211 231
 
212 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 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 244
           <text>{detail.enlisted || 0}人已报名</text>
222 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 249
       </view>
225
-
226 250
     </view>
227 251
   );
228 252
 
229 253
   return (
230 254
     <>
231 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 258
             <view>
235 259
               <ScrollView scroll-y>
236
-                <view className='PageContent'>
237
-                  <view className='Top'>
260
+                <view className="PageContent">
261
+                  <view className="Top">
238 262
                     <Image
239
-                      mode='aspectFill'
263
+                      mode="aspectFill"
240 264
                       src={getImgURL(detail.imgUrl)}
241
-                      className='centerLabel'
265
+                      className="centerLabel"
242 266
                     ></Image>
243 267
                   </view>
244 268
 
245 269
                   {detail.type == "dymic" && dymic()}
246 270
                   {detail.type !== "dymic" && house()}
247
-                  <view className='ActivityIntro'>
248
-                    <view className='Title'>
271
+                  <view className="ActivityIntro">
272
+                    <view className="Title">
249 273
                       <text>活动介绍</text>
250 274
                     </view>
251 275
                     <RichText nodes={detail.desc} />
@@ -257,21 +281,25 @@ export default withLayout((props) => {
257 281
             </view>
258 282
           </view>
259 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 287
                 <text>分享</text>
264 288
               </Button>
265
-              <view className='Collect' onClick={handleFavor}>
289
+              <view className="Collect" onClick={handleFavor}>
266 290
                 <text
267
-                  className='iconfont icon-shoucang'
291
+                  className="iconfont icon-shoucang"
268 292
                   style={isSaved ? { color: "red" } : undefined}
269 293
                 ></text>
270
-                <text>{isSaved ? '已收藏' : '收藏'}</text>
294
+                <text>{isSaved ? "已收藏" : "收藏"}</text>
271 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 303
                 {btnText}
276 304
               </Button>
277 305
             </view>
@@ -279,29 +307,29 @@ export default withLayout((props) => {
279 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 315
             <Input
288
-              className='inputName'
316
+              className="inputName"
289 317
               onInput={onInputText}
290
-              type='text'
291
-              placeholder='请输入姓名'
318
+              type="text"
319
+              placeholder="请输入姓名"
292 320
             />
293 321
             <Picker
294
-              mode='selector'
322
+              mode="selector"
295 323
               range={selector}
296 324
               onChange={(e) => setSelectorChecked(selector[e.detail.value])}
297 325
             >
298
-              <View className='picker'>
326
+              <View className="picker">
299 327
                 <Text>参加人数</Text>
300
-                <Text className='content'>{selectorChecked}</Text>
328
+                <Text className="content">{selectorChecked}</Text>
301 329
                 <Text>人</Text>
302 330
               </View>
303 331
             </Picker>
304
-            <View onClick={comfire} className='comfire'>
332
+            <View onClick={comfire} className="comfire">
305 333
               确认
306 334
             </View>
307 335
           </View>