木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
11 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <view class="activity-page">
  3. <!-- 搜索栏和一级Tab合并容器 -->
  4. <view class="search-section">
  5. <view class="search-bar">
  6. <uv-search placeholder="请输入搜索内容" v-model="params.title" @search="handleSearch" @clear="handleSearch" @clickIcon="handleSearch" :showAction="false" ></uv-search>
  7. </view>
  8. <!-- 一级Tab当前活动/往期活动 移到搜索容器内 -->
  9. <view class="primary-tabs">
  10. <view
  11. class="primary-tab-item"
  12. :class="{ active: primaryActiveTab === 'current' }"
  13. @click="switchPrimaryTab('current')"
  14. >
  15. 当前活动
  16. </view>
  17. <view
  18. class="primary-tab-item"
  19. :class="{ active: primaryActiveTab === 'past' }"
  20. @click="switchPrimaryTab('past')"
  21. >
  22. 往期活动
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 二级Tab自定义Tab组件 -->
  27. <view class="secondary-tabs">
  28. <scroll-view scroll-x="true" class="tab-scroll">
  29. <view class="tab-list">
  30. <!-- 全部Tab -->
  31. <view
  32. class="tab-item"
  33. :class="{ active: secondaryActiveIndex === 0 }"
  34. @click="switchSecondaryTab(0, '全部')"
  35. >
  36. <text class="tab-text">全部</text>
  37. </view>
  38. <!-- 从store获取的活动分类Tab -->
  39. <view
  40. v-for="(category, index) in categoryActivityList"
  41. :key="category.id"
  42. class="tab-item"
  43. :class="{ active: secondaryActiveIndex === index + 1 }"
  44. @click="switchSecondaryTab(index + 1, category.title, category.id)"
  45. >
  46. <text class="tab-text">{{ category.title }}</text>
  47. </view>
  48. <!-- 动画下划线 -->
  49. <!-- <view class="tab-line" :style="lineStyle"></view> -->
  50. </view>
  51. </scroll-view>
  52. </view>
  53. <!-- 活动列表 -->
  54. <view class="activity-list">
  55. <view
  56. class="activity-item"
  57. v-for="(item, index) in activities"
  58. :key="index"
  59. @click="goToActivityDetail(item)"
  60. >
  61. <!-- 活动图片 -->
  62. <view class="activity-image">
  63. <image :src="item.image" mode="aspectFill" class="image"></image>
  64. </view>
  65. <!-- 活动信息 -->
  66. <view class="activity-info">
  67. <view class="title-row">
  68. <!-- 活动标签 -->
  69. <view class="activity-tag" :style="{ backgroundColor: item.tagColor }">
  70. {{ item.score }}
  71. </view>
  72. <view class="activity-title">{{ item.title }}</view>
  73. </view>
  74. <view class="activity-location">
  75. <uv-icon name="map-fill" size="14" color="#999"></uv-icon>
  76. <text class="location-text">{{ item.address }}</text>
  77. </view>
  78. <view class="activity-time">
  79. <uv-icon name="calendar" size="14" color="#999"></uv-icon>
  80. <text class="time-text">{{ item.createTime }}</text>
  81. </view>
  82. <view class="activity-participants">
  83. <uv-icon name="account-fill" size="14" color="#999"></uv-icon>
  84. <text class="participants-text" >报名人数{{ item.numActivity }}/{{ item.numLimit }}</text>
  85. </view>
  86. </view>
  87. <!-- 报名按钮 -->
  88. <view class="activity-action">
  89. <uv-button v-if="item.status === '1'" type="primary" size="mini" shape="circle" text="已结束" disabled @click.stop="signUpActivity(item)"></uv-button>
  90. <uv-button v-else-if="item.isApply === 1" type="primary" size="mini" shape="circle" text="已报名" disabled @click.stop="signUpActivity(item)"></uv-button>
  91. <uv-button v-else type="primary" size="mini" shape="circle" :text="item.numActivity >= item.numLimit ? '已结束' : '报名中'" :disabled="item.numActivity >= item.numLimit" @click.stop="signUpActivity(item)"></uv-button>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- 空状态 -->
  96. <view class="empty-state" v-if="activities.length === 0">
  97. <uv-empty mode="data" text="暂无活动数据"></uv-empty>
  98. </view>
  99. </view>
  100. </template>
  101. <script>
  102. export default {
  103. data() {
  104. return {
  105. searchKeyword: '',
  106. primaryActiveTab: 'current', // current: 当前活动, past: 往期活动
  107. params: {
  108. pageNo: 1,
  109. pageSize: 10,
  110. title: '', // 搜索关键字
  111. // categoryId: null, // 分类的id
  112. status: 0 // 活动的状态 0是当前 1是往期
  113. },
  114. secondaryActiveIndex: 0,
  115. // 模拟活动数据
  116. activities: []
  117. }
  118. },
  119. computed: {
  120. // 从store获取活动分类列表
  121. categoryActivityList() {
  122. return this.$store.state.categoryActivityList || []
  123. },
  124. },
  125. methods: {
  126. handleSearch(value) {
  127. if (value) {
  128. this.params['title'] = value
  129. }
  130. this.initData()
  131. this.getActivityList()
  132. },
  133. // 切换一级tab
  134. switchPrimaryTab(tab) {
  135. this.primaryActiveTab = tab;
  136. this.initData()
  137. delete this.params['categoryId']
  138. // 标签回到全部
  139. this.secondaryActiveIndex = 0
  140. this.params['status'] = tab === 'current' ? 0 : 1
  141. this.getActivityList()
  142. },
  143. // 切换二级tab
  144. async switchSecondaryTab(index, tabName, categoryId = null) {
  145. this.initData()
  146. this.secondaryActiveIndex = index
  147. delete this.params['categoryId']
  148. if (index === 0) {
  149. // 全部Tab
  150. console.log('点击了全部Tab')
  151. } else {
  152. // 活动分类Tab
  153. this.params['categoryId'] = categoryId
  154. }
  155. await this.getActivityList()
  156. },
  157. // 跳转到活动详情
  158. goToActivityDetail(activity) {
  159. uni.navigateTo({
  160. url: `/subPages/index/activityDetail?id=${activity.id}`
  161. });
  162. },
  163. // 报名活动
  164. signUpActivity(item) {
  165. if (item.isFullOrExpired) {
  166. uni.showToast({
  167. title: '活动已结束',
  168. icon: 'none'
  169. });
  170. return;
  171. }
  172. uni.navigateTo({
  173. url: `/subPages/index/activityDetail?id=${item.id}`
  174. });
  175. },
  176. // 获取活动列表
  177. async getActivityList(){
  178. const res = await this.$api.activity.queryActivityList(this.params)
  179. if(res.result.records.length){
  180. this.activities.push(...res.result.records)
  181. this.params.pageNo++
  182. }else {
  183. uni.showToast({
  184. title: '暂无活动数据',
  185. icon: 'none'
  186. })
  187. }
  188. },
  189. initData() {
  190. this.params['pageNo'] = 1
  191. this.activities = []
  192. }
  193. },
  194. async onShow() {
  195. // 确保store中的活动分类数据已加载
  196. if (this.categoryActivityList.length === 0) {
  197. await this.$store.dispatch('getCategoryActivityList')
  198. }
  199. this.initData()
  200. this.params['title'] = ''
  201. await this.getActivityList()
  202. },
  203. onReachBottom() {
  204. this.getActivityList()
  205. },
  206. async onPullDownRefresh() {
  207. this.initData()
  208. await this.getActivityList()
  209. uni.stopPullDownRefresh()
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .activity-page {
  215. background-color: #f5f5f5;
  216. min-height: 100vh;
  217. }
  218. // 搜索栏样式 - 修改为包含一级Tab
  219. .search-section {
  220. height: 350rpx;
  221. background: linear-gradient(180deg,#1488db, #98b5f1);
  222. padding-top: 180rpx; /* 使用padding-top避免margin塌陷 */
  223. box-sizing: border-box; /* 确保padding包含在高度内 */
  224. }
  225. .search-bar {
  226. // background-color: white;
  227. // border-radius: 50rpx;
  228. padding: 5rpx 40rpx;
  229. // display: flex;
  230. // align-items: center;
  231. // gap: 20rpx;
  232. // width: 85%;
  233. // margin: 0 auto ; /* 移除margin-top,只保留左右居中和下边距 */
  234. }
  235. .search-input {
  236. flex: 1;
  237. font-size: 28rpx;
  238. color: #333;
  239. &::placeholder {
  240. color: #999;
  241. }
  242. }
  243. // 一级Tab样式 - 调整为在蓝色背景内
  244. .primary-tabs {
  245. display: flex;
  246. padding: 0 20rpx;
  247. margin-bottom: 20rpx;
  248. }
  249. .primary-tab-item {
  250. flex: 1;
  251. text-align: center;
  252. padding: 20rpx 0;
  253. font-size: 32rpx;
  254. color: #000000; /* 白色半透明 */
  255. position: relative;
  256. transition: color 0.3s ease;
  257. &.active {
  258. color: white; /* 激活状态为纯白色 */
  259. font-weight: 600;
  260. &::after {
  261. content: '';
  262. position: absolute;
  263. bottom: 0;
  264. left: 50%;
  265. transform: translateX(-50%);
  266. // transition: transform 0.3s ease;
  267. width: 100rpx;
  268. height: 6rpx;
  269. background-color: white; /* 下划线改为白色 */
  270. border-radius: 3rpx;
  271. }
  272. }
  273. }
  274. // 二级Tab样式 - 自定义实现
  275. .secondary-tabs {
  276. background-color: white;
  277. border-bottom: 1px solid #f0f0f0;
  278. position: relative;
  279. .tab-scroll {
  280. white-space: nowrap;
  281. .tab-list {
  282. display: flex;
  283. // position: relative;
  284. justify-content: space-evenly;
  285. .tab-item {
  286. flex-shrink: 0;
  287. padding: 24rpx 32rpx;
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. transition: all 0.3s ease;
  292. .tab-text {
  293. font-size: 28rpx;
  294. color: #666666;
  295. font-weight: 500;
  296. transition: color 0.3s ease;
  297. }
  298. &.active {
  299. .tab-text {
  300. color: #007AFF;
  301. font-weight: 600;
  302. }
  303. }
  304. }
  305. }
  306. .tab-line {
  307. position: absolute;
  308. bottom: 10;
  309. height: 6rpx;
  310. background-color: #007AFF;
  311. border-radius: 3rpx;
  312. transition: transform 0.3s ease;
  313. }
  314. }
  315. }
  316. // 活动列表样式
  317. .activity-list {
  318. padding: 20rpx;
  319. }
  320. .activity-item {
  321. background-color: white;
  322. border-radius: 12rpx;
  323. margin-bottom: 30rpx;
  324. padding: 20rpx;
  325. display: flex;
  326. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  327. }
  328. .activity-image {
  329. width: 180rpx;
  330. height: 180rpx;
  331. border-radius: 8rpx;
  332. overflow: hidden;
  333. flex-shrink: 0;
  334. margin-right: 20rpx;
  335. }
  336. .image {
  337. width: 100%;
  338. height: 100%;
  339. }
  340. .activity-info {
  341. flex: 1;
  342. display: flex;
  343. flex-direction: column;
  344. justify-content: space-between;
  345. }
  346. .title-row {
  347. display: flex;
  348. align-items: center;
  349. margin-bottom: 10rpx;
  350. }
  351. .activity-tag {
  352. width: 31px;
  353. height: 20px;
  354. background: #218cdd;
  355. border-radius: 3.5px;
  356. margin-right: 7rpx;
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. font-size: 18rpx;
  361. color: white;
  362. font-weight: 600;
  363. }
  364. .activity-title {
  365. font-size: 28rpx;
  366. font-weight: bold;
  367. color: #333;
  368. line-height: 1.4;
  369. }
  370. .activity-location,
  371. .activity-time,
  372. .activity-participants {
  373. display: flex;
  374. align-items: center;
  375. margin-bottom: 6rpx;
  376. .location-text,
  377. .time-text,
  378. .participants-text {
  379. font-size: 24rpx;
  380. color: #666;
  381. margin-left: 6rpx;
  382. }
  383. }
  384. .activity-action {
  385. display: flex;
  386. align-items: flex-end;
  387. padding-bottom: 10rpx;
  388. }
  389. // 空状态样式
  390. .empty-state {
  391. padding: 100rpx 40rpx;
  392. }
  393. </style>