DimensionActivities.vue 12 KB

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