DimensionActivities.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <template>
  2. <view class="section">
  3. <!-- 头部 -->
  4. <view class="section-header">
  5. <view class="section-header-left">
  6. <view class="section-icon-wrap">
  7. <text class="section-icon">{{ dimensionIcon }}</text>
  8. </view>
  9. <text class="section-title">推荐活动</text>
  10. </view>
  11. <view class="section-more" @click="$emit('moreActivities')">
  12. <text class="section-more-text">更多</text>
  13. <text class="section-more-arrow">›</text>
  14. </view>
  15. </view>
  16. <!-- 空状态 -->
  17. <view v-if="!displayActivities || displayActivities.length === 0" class="empty-state">
  18. <text class="empty-icon">{{ dimensionIcon }}</text>
  19. <text class="empty-tip">{{ isLoggedIn ? '暂无相关活动' : '登录后查看更多活动' }}</text>
  20. </view>
  21. <!-- 活动卡片轮播(行布局) -->
  22. <view class="activity-carousel" v-if="displayActivities && displayActivities.length > 0">
  23. <swiper
  24. class="activity-swiper"
  25. :indicator-dots="displayActivities.length > 1"
  26. :active-index="swiperIndex"
  27. @change="onSwiperChange"
  28. autoplay
  29. interval="3000"
  30. duration="500"
  31. circular
  32. >
  33. <swiper-item v-for="(act, index) in displayActivities" :key="act.id">
  34. <view class="activity-card" @click.stop="$emit('activityClick', act)">
  35. <!-- 封面图(占满卡片高度) -->
  36. <image
  37. class="card-cover-img"
  38. :src="getImageUrl(act.coverImage) || '/static/default-activity.png'"
  39. mode="aspectFill"
  40. />
  41. <!-- 右侧信息区 -->
  42. <view class="card-info">
  43. <text class="card-title line-clamp-1">{{ act.title }}</text>
  44. <view class="card-meta-row">
  45. <view class="card-time">
  46. <text class="meta-icon">🕐</text>
  47. <text class="meta-text">{{ act._timeText }}</text>
  48. </view>
  49. <view class="card-badges" v-if="act._badges && act._badges.length">
  50. <view
  51. class="card-badge"
  52. v-for="badge in act._badges"
  53. :key="badge.name"
  54. :style="{ borderColor: badge.color }"
  55. >
  56. <text class="badge-icon">{{ badge.icon }}</text>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="card-bottom">
  61. <text class="card-status" :class="'status-' + (act.status || 'upcoming')">
  62. {{ act._statusText }}
  63. </text>
  64. <text class="card-price" v-if="act.priceLabel">{{ act.priceLabel }}</text>
  65. <text class="card-price member-teaser" v-else-if="act.memberPrice && act.memberPrice > 0 && act.memberPrice < (act.price || 0)" @click.stop="onMemberPriceTap">会员价 {{ act._memberPriceDisplay }}</text>
  66. <text class="card-price" v-else-if="act.price && act.price > 0">{{ act._priceDisplay }}</text>
  67. <text class="card-price-free" v-else>免费</text>
  68. </view>
  69. </view>
  70. </view>
  71. </swiper-item>
  72. </swiper>
  73. <!-- 轮播指示点 -->
  74. <view v-if="displayActivities.length > 1" class="swiper-dots">
  75. <view
  76. class="dot"
  77. v-for="(dot, index) in displayActivities"
  78. :key="index"
  79. :class="{ active: swiperIndex === index }"
  80. ></view>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script>
  86. import config from '@/config.js'
  87. import { parseDate } from '@/utils/format.js'
  88. import { getMyMembership } from '@/utils/api.js'
  89. var DIMENSION_MAP = {
  90. body: { name: '身', color: '#FF8C42', icon: '🌏' },
  91. mind: { name: '心', color: '#FF6B9D', icon: '🔥' },
  92. wisdom: { name: '智', color: '#6366F1', icon: '⚡' },
  93. action: { name: '行', color: '#10B981', icon: '🌿' },
  94. wealth: { name: '富', color: '#F59E0B', icon: '💧' }
  95. }
  96. export default {
  97. props: {
  98. dimensionCode: { type: String, default: '' },
  99. activities: { type: Array, default: function() { return [] } },
  100. isLoggedIn: { type: Boolean, default: false }
  101. },
  102. data: function() {
  103. return {
  104. swiperIndex: 0,
  105. isMember: false
  106. }
  107. },
  108. created: function() {
  109. var that = this
  110. getMyMembership().then(function(res) {
  111. if (res.data && res.data.memberLevel) {
  112. that.isMember = res.data.memberLevel !== 'FREE'
  113. }
  114. }).catch(function() {})
  115. },
  116. computed: {
  117. displayActivities: function() {
  118. var self = this
  119. return (this.activities || []).slice(0, 3).map(function(item) {
  120. return {
  121. id: item.id,
  122. title: item.title,
  123. coverImage: item.coverImage,
  124. startTime: item.startTime,
  125. status: item.status,
  126. price: item.price,
  127. priceLabel: item.priceLabel,
  128. memberPrice: item.memberPrice,
  129. dimensionWeights: item.dimensionWeights,
  130. _badges: self.parseWeights(item.dimensionWeights),
  131. _timeText: self.formatTime(item.startTime),
  132. _statusText: self.statusText(item.status),
  133. _priceDisplay: self.formatPriceWithSymbol(item.price),
  134. _memberPriceDisplay: self.formatPriceWithSymbol(item.memberPrice)
  135. }
  136. })
  137. },
  138. dimensionIcon: function() {
  139. var map = { body: '🌏', mind: '🔥', wisdom: '⚡', action: '🌿', wealth: '💧' }
  140. return map[this.dimensionCode] || '🎯'
  141. }
  142. },
  143. methods: {
  144. onSwiperChange: function(e) {
  145. this.swiperIndex = e.detail.current
  146. },
  147. onMemberPriceTap: function() {
  148. if (this.isMember) {
  149. uni.showToast({ title: '会员价将在报名时自动生效', icon: 'none' })
  150. return
  151. }
  152. uni.showToast({ title: '开通会员享专属会员价', icon: 'none' })
  153. uni.navigateTo({ url: '/pages/membership/upgrade' })
  154. },
  155. parseWeights: function(str) {
  156. if (!str) return []
  157. try {
  158. var obj = JSON.parse(str)
  159. var result = []
  160. for (var key in obj) {
  161. if (obj[key] > 0 && DIMENSION_MAP[key]) {
  162. result.push({ name: DIMENSION_MAP[key].name, color: DIMENSION_MAP[key].color, icon: DIMENSION_MAP[key].icon, weight: obj[key] })
  163. }
  164. }
  165. return result
  166. } catch (e) {
  167. return []
  168. }
  169. },
  170. statusText: function(status) {
  171. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  172. return map[status] || '即将开始'
  173. },
  174. formatTime: function(timeStr) {
  175. if (!timeStr) return '待定'
  176. var d = parseDate(timeStr)
  177. if (!d) return timeStr
  178. var month = d.getMonth() + 1
  179. var day = d.getDate()
  180. var hour = d.getHours()
  181. var minute = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()
  182. return month + '月' + day + '日 ' + hour + ':' + minute
  183. },
  184. formatPriceWithSymbol: function(price) {
  185. if (price == null) return '免费'
  186. return '¥' + (Number(price) / 100).toFixed(2)
  187. },
  188. getImageUrl: function(path) {
  189. return config.API_BASE_URL + path
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped>
  195. .section {
  196. margin: 16rpx 20rpx;
  197. }
  198. /* ===== 头部 ===== */
  199. .section-header {
  200. display: flex;
  201. flex-direction: row;
  202. justify-content: space-between;
  203. align-items: center;
  204. margin-bottom: 16rpx;
  205. }
  206. .section-header-left {
  207. display: flex;
  208. flex-direction: row;
  209. align-items: center;
  210. }
  211. .section-icon-wrap {
  212. width: 44rpx;
  213. height: 44rpx;
  214. border-radius: 12rpx;
  215. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  216. display: flex;
  217. align-items: center;
  218. justify-content: center;
  219. margin-right: 12rpx;
  220. }
  221. .section-icon {
  222. font-size: 24rpx;
  223. }
  224. .section-title {
  225. font-size: 32rpx;
  226. font-weight: 700;
  227. color: #1E293B;
  228. letter-spacing: 1rpx;
  229. }
  230. .section-more {
  231. display: flex;
  232. flex-direction: row;
  233. align-items: center;
  234. padding: 8rpx 20rpx;
  235. background: #F1F5F9;
  236. border-radius: 24rpx;
  237. }
  238. .section-more-text {
  239. font-size: 24rpx;
  240. color: #64748B;
  241. margin-right: 4rpx;
  242. }
  243. .section-more-arrow {
  244. font-size: 20rpx;
  245. color: #94A3B8;
  246. }
  247. /* ===== 空状态 ===== */
  248. .empty-state {
  249. display: flex;
  250. flex-direction: column;
  251. align-items: center;
  252. padding: 30rpx 0;
  253. }
  254. .empty-icon {
  255. font-size: 64rpx;
  256. margin-bottom: 16rpx;
  257. }
  258. .empty-tip {
  259. font-size: 26rpx;
  260. color: #94A3B8;
  261. }
  262. /* ===== 活动轮播 ===== */
  263. .activity-carousel {
  264. width: 100%;
  265. margin: 0 -20rpx;
  266. }
  267. .activity-swiper {
  268. width: 100%;
  269. height: 210rpx;
  270. }
  271. .activity-swiper .swiper-slide {
  272. width: 100%;
  273. height: 100%;
  274. }
  275. /* 轮播指示点 */
  276. .swiper-dots {
  277. display: flex;
  278. justify-content: center;
  279. align-items: center;
  280. gap: 8rpx;
  281. margin-top: 12rpx;
  282. }
  283. .dot {
  284. width: 8rpx;
  285. height: 8rpx;
  286. border-radius: 50%;
  287. background: #D1D5DB;
  288. transition: all 0.3s ease;
  289. }
  290. .dot.active {
  291. width: 32rpx;
  292. border-radius: 4rpx;
  293. background: #F97316;
  294. }
  295. /* ===== 活动卡片(行布局) ===== */
  296. .activity-card {
  297. background: #FFFFFF;
  298. border-radius: 16rpx;
  299. overflow: hidden;
  300. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  301. display: flex;
  302. flex-direction: row;
  303. height: 100%;
  304. }
  305. .activity-card:active {
  306. opacity: 0.8;
  307. }
  308. /* 封面图 — 占总宽度1/3,占满卡片高度 */
  309. .card-cover-img {
  310. width: 33.33%;
  311. height: 100%;
  312. flex-shrink: 0;
  313. background: #F1F5F9;
  314. }
  315. /* 右侧信息区 — 文字右对齐 */
  316. .card-info {
  317. flex: 1;
  318. padding: 16rpx;
  319. display: flex;
  320. flex-direction: column;
  321. justify-content: space-between;
  322. align-items: stretch;
  323. text-align: right;
  324. min-width: 0;
  325. }
  326. /* 标题 */
  327. .card-title {
  328. font-size: 28rpx;
  329. font-weight: bold;
  330. color: #333;
  331. margin-bottom: 8rpx;
  332. }
  333. .line-clamp-1 {
  334. overflow: hidden;
  335. text-overflow: ellipsis;
  336. white-space: nowrap;
  337. }
  338. /* 时间和维度标签 */
  339. .card-meta-row {
  340. display: flex;
  341. flex-direction: row;
  342. align-items: center;
  343. justify-content: flex-end;
  344. margin-bottom: 8rpx;
  345. }
  346. .card-time {
  347. display: flex;
  348. flex-direction: row;
  349. align-items: center;
  350. margin-right: 16rpx;
  351. }
  352. .meta-icon {
  353. font-size: 22rpx;
  354. margin-right: 6rpx;
  355. }
  356. .meta-text {
  357. font-size: 24rpx;
  358. color: #64748B;
  359. }
  360. .card-badges {
  361. display: flex;
  362. flex-direction: row;
  363. flex-wrap: wrap;
  364. gap: 8rpx;
  365. }
  366. .card-badge {
  367. width: 36rpx;
  368. height: 36rpx;
  369. border-radius: 50%;
  370. border: 2rpx solid;
  371. display: flex;
  372. align-items: center;
  373. justify-content: center;
  374. background: transparent;
  375. }
  376. .badge-icon {
  377. font-size: 20rpx;
  378. line-height: 1;
  379. }
  380. /* 底部:状态 + 价格 */
  381. .card-bottom {
  382. display: flex;
  383. flex-direction: row;
  384. align-items: center;
  385. justify-content: flex-end;
  386. gap: 12rpx;
  387. }
  388. .card-status {
  389. font-size: 20rpx;
  390. padding: 2rpx 10rpx;
  391. border-radius: 8rpx;
  392. background: #E8F5E9;
  393. color: #2E7D32;
  394. }
  395. .card-status.status-upcoming {
  396. background: #E3F2FD;
  397. color: #1565C0;
  398. }
  399. .card-status.status-ended {
  400. background: #F5F5F5;
  401. color: #999;
  402. }
  403. .card-price {
  404. font-size: 24rpx;
  405. font-weight: bold;
  406. color: #F97316;
  407. }
  408. .card-price.member-teaser {
  409. color: #F97316;
  410. text-decoration: underline;
  411. }
  412. .card-price-free {
  413. font-size: 24rpx;
  414. font-weight: 600;
  415. color: #22C55E;
  416. }
  417. </style>