DimensionActivities.vue 13 KB

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