DimensionActivities.vue 13 KB

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