DimensionActivities.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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">🎯</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">🎯</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, getActivityList } 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. activities: { type: Array, default: function() { return [] } },
  99. isLoggedIn: { type: Boolean, default: false }
  100. },
  101. data: function() {
  102. return {
  103. swiperIndex: 0,
  104. isMember: false,
  105. selfActivities: [],
  106. loading: false
  107. }
  108. },
  109. mounted: function() {
  110. if (!this.activities || this.activities.length === 0) {
  111. this.loadActivities()
  112. }
  113. },
  114. created: function() {
  115. var that = this
  116. getMyMembership().then(function(res) {
  117. if (res.data && res.data.memberLevel) {
  118. that.isMember = res.data.memberLevel !== 'FREE'
  119. }
  120. }).catch(function() {})
  121. },
  122. computed: {
  123. displayActivities: function() {
  124. var self = this
  125. var list = (this.activities && this.activities.length > 0 ? this.activities : self.selfActivities)
  126. return (list || []).slice(0, 3).map(function(item) {
  127. return {
  128. id: item.id,
  129. title: item.title,
  130. coverImage: item.coverImage,
  131. startTime: item.startTime,
  132. status: item.status,
  133. price: item.price,
  134. priceLabel: item.priceLabel,
  135. memberPrice: item.memberPrice,
  136. dimensionWeights: item.dimensionWeights,
  137. _badges: self.parseWeights(item.dimensionWeights),
  138. _timeText: self.formatTime(item.startTime),
  139. _statusText: self.statusText(item.status),
  140. _priceDisplay: self.formatPriceWithSymbol(item.price),
  141. _memberPriceDisplay: self.formatPriceWithSymbol(item.memberPrice)
  142. }
  143. })
  144. }
  145. },
  146. methods: {
  147. loadActivities: function() {
  148. var self = this
  149. self.loading = true
  150. getActivityList({ page: 1, size: 3 }).then(function(res) {
  151. self.loading = false
  152. if (res && res.code === 200 && res.data) {
  153. var list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  154. self.selfActivities = list.slice(0, 3)
  155. }
  156. }).catch(function() {
  157. self.loading = false
  158. self.selfActivities = []
  159. })
  160. },
  161. onSwiperChange: function(e) {
  162. this.swiperIndex = e.detail.current
  163. },
  164. onMemberPriceTap: function() {
  165. if (this.isMember) {
  166. uni.showToast({ title: '会员价将在报名时自动生效', icon: 'none' })
  167. return
  168. }
  169. uni.showToast({ title: '开通会员享专属会员价', icon: 'none' })
  170. uni.navigateTo({ url: '/pages/membership/upgrade' })
  171. },
  172. parseWeights: function(str) {
  173. if (!str) return []
  174. try {
  175. var obj = JSON.parse(str)
  176. var result = []
  177. for (var key in obj) {
  178. if (obj[key] > 0 && DIMENSION_MAP[key]) {
  179. result.push({ name: DIMENSION_MAP[key].name, color: DIMENSION_MAP[key].color, icon: DIMENSION_MAP[key].icon, weight: obj[key] })
  180. }
  181. }
  182. return result
  183. } catch (e) {
  184. return []
  185. }
  186. },
  187. statusText: function(status) {
  188. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  189. return map[status] || '即将开始'
  190. },
  191. formatTime: function(timeStr) {
  192. if (!timeStr) return '待定'
  193. var d = parseDate(timeStr)
  194. if (!d) return timeStr
  195. var month = d.getMonth() + 1
  196. var day = d.getDate()
  197. var hour = d.getHours()
  198. var minute = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()
  199. return month + '月' + day + '日 ' + hour + ':' + minute
  200. },
  201. formatPriceWithSymbol: function(price) {
  202. if (price == null) return '免费'
  203. return '¥' + (Number(price) / 100).toFixed(2)
  204. },
  205. getImageUrl: function(path) {
  206. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  207. var s = String(path).trim()
  208. if (!s || s === 'null' || s === '/null') return ''
  209. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  210. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  211. }
  212. }
  213. }
  214. </script>
  215. <style scoped>
  216. .section {
  217. margin: 16rpx 20rpx;
  218. }
  219. /* ===== 头部 ===== */
  220. .section-header {
  221. display: flex;
  222. flex-direction: row;
  223. justify-content: space-between;
  224. align-items: center;
  225. margin-bottom: 16rpx;
  226. }
  227. .section-header-left {
  228. display: flex;
  229. flex-direction: row;
  230. align-items: center;
  231. }
  232. .section-icon-wrap {
  233. width: 44rpx;
  234. height: 44rpx;
  235. border-radius: 12rpx;
  236. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. margin-right: 12rpx;
  241. }
  242. .section-icon {
  243. font-size: 24rpx;
  244. }
  245. .section-title {
  246. font-size: 32rpx;
  247. font-weight: 700;
  248. color: #1E293B;
  249. letter-spacing: 1rpx;
  250. }
  251. .section-more {
  252. display: flex;
  253. flex-direction: row;
  254. align-items: center;
  255. padding: 8rpx 20rpx;
  256. background: #F1F5F9;
  257. border-radius: 24rpx;
  258. }
  259. .section-more-text {
  260. font-size: 24rpx;
  261. color: #64748B;
  262. margin-right: 4rpx;
  263. }
  264. .section-more-arrow {
  265. font-size: 20rpx;
  266. color: #94A3B8;
  267. }
  268. /* ===== 空状态 ===== */
  269. .empty-state {
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. padding: 30rpx 0;
  274. }
  275. .empty-icon {
  276. font-size: 64rpx;
  277. margin-bottom: 16rpx;
  278. }
  279. .empty-tip {
  280. font-size: 26rpx;
  281. color: #94A3B8;
  282. }
  283. /* ===== 活动轮播 ===== */
  284. .activity-carousel {
  285. width: 100%;
  286. margin: 0 -20rpx;
  287. }
  288. .activity-swiper {
  289. width: 100%;
  290. height: 210rpx;
  291. }
  292. .activity-swiper .swiper-slide {
  293. width: 100%;
  294. height: 100%;
  295. }
  296. /* 轮播指示点 */
  297. .swiper-dots {
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. gap: 8rpx;
  302. margin-top: 12rpx;
  303. }
  304. .dot {
  305. width: 8rpx;
  306. height: 8rpx;
  307. border-radius: 50%;
  308. background: #D1D5DB;
  309. transition: all 0.3s ease;
  310. }
  311. .dot.active {
  312. width: 32rpx;
  313. border-radius: 4rpx;
  314. background: #F97316;
  315. }
  316. /* ===== 活动卡片(行布局) ===== */
  317. .activity-card {
  318. background: #FFFFFF;
  319. border-radius: 16rpx;
  320. overflow: hidden;
  321. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  322. display: flex;
  323. flex-direction: row;
  324. height: 100%;
  325. }
  326. .activity-card:active {
  327. opacity: 0.8;
  328. }
  329. /* 封面图 — 占总宽度1/3,占满卡片高度 */
  330. .card-cover-img {
  331. width: 33.33%;
  332. height: 100%;
  333. flex-shrink: 0;
  334. background: #F1F5F9;
  335. }
  336. /* 右侧信息区 — 文字右对齐 */
  337. .card-info {
  338. flex: 1;
  339. padding: 16rpx;
  340. display: flex;
  341. flex-direction: column;
  342. justify-content: space-between;
  343. align-items: stretch;
  344. text-align: right;
  345. min-width: 0;
  346. }
  347. /* 标题 */
  348. .card-title {
  349. font-size: 28rpx;
  350. font-weight: bold;
  351. color: #333;
  352. margin-bottom: 8rpx;
  353. }
  354. .line-clamp-1 {
  355. overflow: hidden;
  356. text-overflow: ellipsis;
  357. white-space: nowrap;
  358. }
  359. /* 时间和维度标签 */
  360. .card-meta-row {
  361. display: flex;
  362. flex-direction: row;
  363. align-items: center;
  364. justify-content: flex-end;
  365. margin-bottom: 8rpx;
  366. }
  367. .card-time {
  368. display: flex;
  369. flex-direction: row;
  370. align-items: center;
  371. margin-right: 16rpx;
  372. }
  373. .meta-icon {
  374. font-size: 22rpx;
  375. margin-right: 6rpx;
  376. }
  377. .meta-text {
  378. font-size: 24rpx;
  379. color: #64748B;
  380. }
  381. .card-badges {
  382. display: flex;
  383. flex-direction: row;
  384. flex-wrap: wrap;
  385. gap: 8rpx;
  386. }
  387. .card-badge {
  388. width: 36rpx;
  389. height: 36rpx;
  390. border-radius: 50%;
  391. border: 2rpx solid;
  392. display: flex;
  393. align-items: center;
  394. justify-content: center;
  395. background: transparent;
  396. }
  397. .badge-icon {
  398. font-size: 20rpx;
  399. line-height: 1;
  400. }
  401. /* 底部:状态 + 价格 */
  402. .card-bottom {
  403. display: flex;
  404. flex-direction: row;
  405. align-items: center;
  406. justify-content: flex-end;
  407. gap: 12rpx;
  408. }
  409. .card-status {
  410. font-size: 20rpx;
  411. padding: 2rpx 10rpx;
  412. border-radius: 8rpx;
  413. background: #E8F5E9;
  414. color: #2E7D32;
  415. }
  416. .card-status.status-upcoming {
  417. background: #E3F2FD;
  418. color: #1565C0;
  419. }
  420. .card-status.status-ended {
  421. background: #F5F5F5;
  422. color: #999;
  423. }
  424. .card-price {
  425. font-size: 24rpx;
  426. font-weight: bold;
  427. color: #F97316;
  428. }
  429. .card-price.member-teaser {
  430. color: #F97316;
  431. text-decoration: underline;
  432. }
  433. .card-price-free {
  434. font-size: 24rpx;
  435. font-weight: 600;
  436. color: #22C55E;
  437. }
  438. </style>