activity.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view class="container">
  3. <!-- 顶部区域 -->
  4. <view class="top">
  5. <view class="top_search">
  6. <uni-icons type="search" size="30" color="#999999"></uni-icons>
  7. <input class="input" type="text" placeholder="请输入活动关键字" v-model="inputValue" @blur="handleBlur" />
  8. </view>
  9. <view class="top_btn" @click="handleSet">
  10. <uni-icons type="plus" size="20" color="#fff"></uni-icons>
  11. <view class="btn_text">发起活动</view>
  12. </view>
  13. </view>
  14. <!-- 分段器区域 -->
  15. <view class="control">
  16. <common-controlTag :tagList="tagList" type="between" @change="handleChange"></common-controlTag>
  17. </view>
  18. <!-- 活动列表区域 -->
  19. <view class="list">
  20. <!-- 每一个活动区域 -->
  21. <view class="list_box" v-for="item in dataList" :key="item.id" @click="clickItem(item.id)">
  22. <view class="box_top">
  23. <img v-if="item.poster" class="img" :src="item.poster" mode="aspectFill" />
  24. <img v-else class="img" src="@/static/images/3.png" mode="aspectFill" />
  25. <view class="top_msg">
  26. <view class="msg_title">{{ item.theme }}</view>
  27. <view class="msg_name">{{ item.orgName }}</view>
  28. <view class="">{{ item.startTime }} 至 {{ item.endTime }}</view>
  29. </view>
  30. </view>
  31. <view v-if="item.activityStatuName == 1" class="box_bottom nostart">活动未开始</view>
  32. <view v-if="item.activityStatuName == 2" class="box_bottom on">活动进行中</view>
  33. <view v-if="item.activityStatuName == 3" class="box_bottom off">活动已结束</view>
  34. </view>
  35. <!-- 没有数据时展示的页面 -->
  36. <noData v-if="!dataList.length"></noData>
  37. </view>
  38. </view>
  39. </template>
  40. <script setup>
  41. import { onLoad, onReachBottom } from '@dcloudio/uni-app'
  42. import { ref } from 'vue'
  43. import { getActivityPages } from '@/api/index.js'
  44. const tagList = ['全部', '未开始', '进行中', '已结束']
  45. // 搜索框绑定数据
  46. const inputValue = ref('')
  47. // 分段器当前索引
  48. const currentIndex = ref(0)
  49. // 当前页
  50. const currentPage = ref(1)
  51. // 每页多少条
  52. const pageCount = ref(6)
  53. // 总条数
  54. const total = ref(0)
  55. // 列表数据
  56. const dataList = ref([])
  57. onLoad(() => {
  58. // 获取活动分页数据
  59. getData()
  60. })
  61. // 页面触底触发回调
  62. onReachBottom(() => {
  63. if (total.value > dataList.value.length) {
  64. currentPage.value++
  65. getData()
  66. } else {
  67. uni.showToast({
  68. title: '没有更多数据了~~',
  69. icon: 'none'
  70. })
  71. }
  72. })
  73. // 获取活动分页数据
  74. const getData = async () => {
  75. let data = {
  76. currentPage: currentPage.value,
  77. pageCount: pageCount.value,
  78. statuId: currentIndex.value,
  79. theme: inputValue.value
  80. }
  81. const res = await getActivityPages(data)
  82. // console.log(res)
  83. dataList.value = [...dataList.value, ...res.data.list]
  84. total.value = res.data.totalCount
  85. }
  86. // 切换分段器回调
  87. const handleChange = (e) => {
  88. // console.log(e)
  89. currentIndex.value = e
  90. currentPage.value = 1
  91. dataList.value = []
  92. getData()
  93. }
  94. // 输入框失去焦点回调 搜索回调
  95. const handleBlur = () => {
  96. currentPage.value = 1
  97. dataList.value = []
  98. getData()
  99. }
  100. // 点击发起活动按钮回调
  101. const handleSet = () => {
  102. uni.navigateTo({
  103. url: '/pages/set_act/set_act'
  104. })
  105. }
  106. // 点击每一个活动的回调
  107. const clickItem = (id) => {
  108. uni.navigateTo({
  109. url: `/pages/act_detail/act_detail?id=${id}`
  110. })
  111. }
  112. </script>
  113. <style lang="scss" scoped>
  114. .container {
  115. padding: 20rpx 18rpx;
  116. min-height: 100vh;
  117. font-size: 28rpx;
  118. .top {
  119. display: flex;
  120. justify-content: space-between;
  121. .top_search {
  122. display: flex;
  123. align-items: center;
  124. padding: 0 25rpx;
  125. width: 491rpx;
  126. height: 80rpx;
  127. border-radius: 145rpx;
  128. border: 2rpx solid #e5e5e5;
  129. background-color: #f5f5f5;
  130. .input {
  131. margin-left: 20rpx;
  132. font-size: 28rpx;
  133. }
  134. }
  135. .top_btn {
  136. display: flex;
  137. align-items: center;
  138. justify-content: center;
  139. padding: 18rpx;
  140. width: 196rpx;
  141. height: 70rpx;
  142. color: #fff;
  143. font-size: 20rpx;
  144. border-radius: 68rpx;
  145. background-color: #007aff;
  146. .btn_text {
  147. margin-left: 10rpx;
  148. }
  149. }
  150. }
  151. .control {
  152. margin-top: 15rpx;
  153. }
  154. .list {
  155. margin-top: 20rpx;
  156. .list_box {
  157. display: flex;
  158. flex-direction: column;
  159. justify-content: space-between;
  160. padding: 30rpx 25rpx;
  161. margin-bottom: 20rpx;
  162. width: 714rpx;
  163. height: 344rpx;
  164. border-radius: 28rpx;
  165. box-shadow: 0 4rpx 35rpx #d3d3d3;
  166. background-color: #fff;
  167. .box_top {
  168. display: flex;
  169. justify-content: space-between;
  170. .img {
  171. margin-right: 24rpx;
  172. width: 249rpx;
  173. height: 168rpx;
  174. border-radius: 8rpx;
  175. }
  176. .top_msg {
  177. display: flex;
  178. flex-direction: column;
  179. justify-content: space-between;
  180. flex: 1;
  181. font-size: 24rpx;
  182. color: #808080;
  183. overflow: hidden;
  184. .msg_title {
  185. font-size: 28rpx;
  186. font-weight: bold;
  187. color: #000;
  188. display: -webkit-box;
  189. -webkit-box-orient: vertical;
  190. -webkit-line-clamp: 2;
  191. overflow: hidden;
  192. }
  193. .msg_name {
  194. white-space: nowrap;
  195. overflow: hidden;
  196. text-overflow: ellipsis;
  197. }
  198. }
  199. }
  200. .box_bottom {
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. width: 661rpx;
  205. height: 80rpx;
  206. border-radius: 8rpx;
  207. }
  208. .on {
  209. color: #fff;
  210. background-color: #007aff;
  211. }
  212. .off {
  213. color: #a6a6a6;
  214. background-color: #e5e5e5;
  215. }
  216. .nostart {
  217. color: #fff;
  218. background-color: #007aff;
  219. opacity: 0.3;
  220. }
  221. }
  222. }
  223. }
  224. </style>