|
@@ -0,0 +1,225 @@
|
|
1
|
+import React, { useState, useEffect } from 'react'
|
|
2
|
+import Taro, { Current } from '@tarojs/taro'
|
|
3
|
+import { RichText, Input } from '@tarojs/components'
|
|
4
|
+import request, { apis } from '@/utils/request'
|
|
5
|
+import { useModel } from '@/store'
|
|
6
|
+import Page from '@/layouts'
|
|
7
|
+import toolclass from '@/utils/toolclass.js'
|
|
8
|
+import { getShareObject } from '@/utils/share.js'
|
|
9
|
+import GetUserPhone from '@/components/GetUserPhone/index'
|
|
10
|
+import '@/assets/css/reset.less'
|
|
11
|
+import '@/assets/css/iconfont.less'
|
|
12
|
+import './index.less'
|
|
13
|
+
|
|
14
|
+export default function HuoDongDetail () {
|
|
15
|
+
|
|
16
|
+ const { user } = useModel('user')
|
|
17
|
+ const [DataLock, setDataLock] = useState(false)
|
|
18
|
+ const [HasJoin, setHasJoin] = useState(null)
|
|
19
|
+ const [HasSign, setHasSign] = useState(null)
|
|
20
|
+ const [CanJoin, setCanJoin] = useState(null)
|
|
21
|
+ const [JoinBtnText, setJoinBtnText] = useState(null)
|
|
22
|
+ const [JoinBtnStatus, setJoinBtnStatus] = useState(false)
|
|
23
|
+ const [ShowJoinNumPopup, setShowJoinNumPopup] = useState(false)
|
|
24
|
+ const [JoinNum, setJoinNum] = useState(null)
|
|
25
|
+ const [ShowGetUserPhoneLayer, setShowGetUserPhoneLayer] = useState(false)
|
|
26
|
+ const [CurrnetHuoDongId] = useState(Current.router.params.id) // 当前活动id
|
|
27
|
+ const [ActivityDetail, setActivityDetail] = useState(null) // 活动详情
|
|
28
|
+
|
|
29
|
+ Taro.useShareAppMessage(() => {
|
|
30
|
+ return getShareObject({
|
|
31
|
+ title: ActivityDetail.title,
|
|
32
|
+ id: CurrnetHuoDongId,
|
|
33
|
+ image: ActivityDetail.imgUrl
|
|
34
|
+ }, user)
|
|
35
|
+ })
|
|
36
|
+
|
|
37
|
+ useEffect(() => {
|
|
38
|
+ GetActivityDetail()
|
|
39
|
+ }, [CurrnetHuoDongId])
|
|
40
|
+
|
|
41
|
+ useEffect(() => {
|
|
42
|
+ if (ActivityDetail !== null) {
|
|
43
|
+ ToSetJoinBtnText()
|
|
44
|
+ }
|
|
45
|
+ }, [HasJoin, CanJoin, HasSign, ActivityDetail])
|
|
46
|
+
|
|
47
|
+ const GetActivityDetail = () => { // 获取活动详情
|
|
48
|
+ request({ ...apis.getActivityDetail, args: { id: CurrnetHuoDongId } }).then((res) => {
|
|
49
|
+ setActivityDetail(res)
|
|
50
|
+ CheckActivityJoin()
|
|
51
|
+ })
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ const CheckActivityJoin = () => { // 查询活动参加详情
|
|
55
|
+ request({ ...apis.checkActivityJoin, args: { id: CurrnetHuoDongId } }).then((res) => {
|
|
56
|
+ setHasJoin(!!res.dynamic.isSign)
|
|
57
|
+ setCanJoin(!!res.dynamic.isEnlist)
|
|
58
|
+ setHasSign(!!res.enlist.isCheckin)
|
|
59
|
+ })
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ const ToSetJoinBtnText = () => {
|
|
63
|
+ if (ActivityDetail.activityStatus - 0 === 2) {
|
|
64
|
+ setJoinBtnStatus(false)
|
|
65
|
+ setJoinBtnText(`已结束`)
|
|
66
|
+ return false
|
|
67
|
+ } else {
|
|
68
|
+ if (HasSign) {
|
|
69
|
+ setJoinBtnStatus(false)
|
|
70
|
+ setJoinBtnText(`已签到`)
|
|
71
|
+ return false
|
|
72
|
+ } else {
|
|
73
|
+ if (HasJoin) {
|
|
74
|
+ if (ActivityDetail.activityStatus - 0 === 1) {
|
|
75
|
+ setJoinBtnStatus(false)
|
|
76
|
+ setJoinBtnText(`已报名`)
|
|
77
|
+ } else if (ActivityDetail.activityStatus - 0 === 0) {
|
|
78
|
+ setJoinBtnStatus(true)
|
|
79
|
+ setJoinBtnText(`去签到`)
|
|
80
|
+ }
|
|
81
|
+ return false
|
|
82
|
+ } else {
|
|
83
|
+ if (CanJoin) {
|
|
84
|
+ setJoinBtnStatus(true)
|
|
85
|
+ setJoinBtnText(`去报名`)
|
|
86
|
+ return false
|
|
87
|
+ } else {
|
|
88
|
+ setJoinBtnStatus(false)
|
|
89
|
+ setJoinBtnText(null)
|
|
90
|
+ return false
|
|
91
|
+ }
|
|
92
|
+ }
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ const ConfirmToJoin = () => {
|
|
98
|
+ if (JoinNum === null || JoinNum - 0 < 1) {
|
|
99
|
+ Taro.showToast({ title: '请填入参加活动人数', icon: 'none' })
|
|
100
|
+ setDataLock(false)
|
|
101
|
+ } else {
|
|
102
|
+ const { personId, phone, nickname, orgId } = user
|
|
103
|
+ const { dynamicId } = ActivityDetail
|
|
104
|
+ let Data = {
|
|
105
|
+ phone,
|
|
106
|
+ personId,
|
|
107
|
+ dynamicId,
|
|
108
|
+ name: nickname,
|
|
109
|
+ orgId,
|
|
110
|
+ attendNum: JoinNum - 0 || 1,
|
|
111
|
+ sharePerson: null,
|
|
112
|
+ sharePersonName: null,
|
|
113
|
+ sharePersonType: null
|
|
114
|
+ }
|
|
115
|
+ request({ ...apis.JoinActivity, data: { ...Data } }).then(() => {
|
|
116
|
+ Taro.showToast({ title: '报名成功', icon: 'none' })
|
|
117
|
+ setHasJoin(true)
|
|
118
|
+ setShowJoinNumPopup(false)
|
|
119
|
+ setDataLock(false)
|
|
120
|
+ }).catch((res) => {
|
|
121
|
+ Taro.showToast({ title: res, icon: 'none' })
|
|
122
|
+ setDataLock(false)
|
|
123
|
+ })
|
|
124
|
+ }
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ const ToJoin = () => { // 去报名
|
|
128
|
+ if (DataLock || ActivityDetail === null || !JoinBtnStatus) return
|
|
129
|
+ setDataLock(true)
|
|
130
|
+ if (JoinBtnText === '去签到') {
|
|
131
|
+ setDataLock(false)
|
|
132
|
+ Taro.navigateTo({ url: `/pages/HuoDong/HuoDongSign/index?id=${ActivityDetail.dynamicId}` })
|
|
133
|
+ } else {
|
|
134
|
+ const { phone } = user
|
|
135
|
+ setDataLock(false)
|
|
136
|
+ if (!phone) { // 未授权手机号,唤起授权手机号弹窗
|
|
137
|
+ setShowGetUserPhoneLayer(true)
|
|
138
|
+ return false
|
|
139
|
+ }
|
|
140
|
+ setShowJoinNumPopup(true)
|
|
141
|
+ }
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ const JoinNumChange = (e) => {
|
|
145
|
+ setJoinNum(e.detail.value)
|
|
146
|
+ }
|
|
147
|
+
|
|
148
|
+ const showError = err => {
|
|
149
|
+ Taro.showModal({
|
|
150
|
+ title: '错误',
|
|
151
|
+ content: err,
|
|
152
|
+ showCancel: false
|
|
153
|
+ })
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ return (
|
|
157
|
+ <Page>
|
|
158
|
+ <view className='HuoDongDetail'>
|
|
159
|
+
|
|
160
|
+ <GetUserPhone visible={ShowGetUserPhoneLayer} onError={err => showError(`授权手机失败: ${err}`)} onCancel={() => { }}></GetUserPhone>
|
|
161
|
+
|
|
162
|
+ <view className='BannerLayer'></view>
|
|
163
|
+ {
|
|
164
|
+ ActivityDetail !== null &&
|
|
165
|
+ <view className='Banner'>
|
|
166
|
+ <image mode='aspectFill' src={ActivityDetail.imgUrl} className='centerLabel'></image>
|
|
167
|
+ </view>
|
|
168
|
+ }
|
|
169
|
+ {
|
|
170
|
+ ActivityDetail !== null &&
|
|
171
|
+ <view className='Info'>
|
|
172
|
+ <view className='MainInfo'>
|
|
173
|
+ <text className='Name'>{ActivityDetail.title}</text>
|
|
174
|
+ <text className='Tips'>{ActivityDetail.enlisted}人已报名</text>
|
|
175
|
+ <view className='flex-h'>
|
|
176
|
+ <text>活动时间:</text>
|
|
177
|
+ <view className='flex-item'>{toolclass.FormatDate(ActivityDetail.startDate)}<text>限{ActivityDetail.enlistNum}人</text></view>
|
|
178
|
+ </view>
|
|
179
|
+ <view className='flex-h'>
|
|
180
|
+ <text>活动地址:</text>
|
|
181
|
+ <view className='flex-item'>{ActivityDetail.address}</view>
|
|
182
|
+ </view>
|
|
183
|
+ <view className='flex-h'>
|
|
184
|
+ <text>报名截止:</text>
|
|
185
|
+ <view className='flex-item'>{toolclass.FormatDate(ActivityDetail.enlistEnd)}</view>
|
|
186
|
+ </view>
|
|
187
|
+ </view>
|
|
188
|
+
|
|
189
|
+ <view className='Desc'>
|
|
190
|
+ <text>活动介绍</text>
|
|
191
|
+ <RichText nodes={`${ActivityDetail.desc.replace(/font-size\:\s(\d+)px/ig, 'font-size: $1rpx')}`}></RichText>
|
|
192
|
+ </view>
|
|
193
|
+
|
|
194
|
+ {
|
|
195
|
+ HasJoin !== null &&
|
|
196
|
+ <text className={JoinBtnStatus ? 'active BottomBtn' : 'BottomBtn'} onClick={ToJoin}>{JoinBtnText}</text>
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ </view>
|
|
200
|
+ }
|
|
201
|
+ <view className={ShowJoinNumPopup ? 'JoinNumLayer active' : 'JoinNumLayer'}>
|
|
202
|
+ <view className='centerLabel'>
|
|
203
|
+ <text>温馨提示</text>
|
|
204
|
+ <view className='flex-h Form'>
|
|
205
|
+ <view>
|
|
206
|
+ <text>参数人数:</text>
|
|
207
|
+ </view>
|
|
208
|
+ <view className='flex-item'>
|
|
209
|
+ <Input placeholder='请输入活动参加人数' onInput={JoinNumChange} value={JoinNum}></Input>
|
|
210
|
+ </view>
|
|
211
|
+ </view>
|
|
212
|
+ <view className='flex-h Bottom'>
|
|
213
|
+ <view className='flex-item'>
|
|
214
|
+ <text onClick={() => { setShowJoinNumPopup(false) }}>取消</text>
|
|
215
|
+ </view>
|
|
216
|
+ <view className='flex-item'>
|
|
217
|
+ <text onClick={ConfirmToJoin}>确定</text>
|
|
218
|
+ </view>
|
|
219
|
+ </view>
|
|
220
|
+ </view>
|
|
221
|
+ </view>
|
|
222
|
+ </view>
|
|
223
|
+ </Page>
|
|
224
|
+ )
|
|
225
|
+}
|