DimensionActivities.vue 10 KB

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