activity.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. 发起活动
  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: space-between;
  139. padding: 18rpx;
  140. width: 196rpx;
  141. height: 70rpx;
  142. color: #fff;
  143. border-radius: 68rpx;
  144. background-color: #007aff;
  145. }
  146. }
  147. .control {
  148. margin-top: 15rpx;
  149. }
  150. .list {
  151. margin-top: 20rpx;
  152. .list_box {
  153. display: flex;
  154. flex-direction: column;
  155. justify-content: space-between;
  156. padding: 30rpx 25rpx;
  157. margin-bottom: 20rpx;
  158. width: 714rpx;
  159. height: 344rpx;
  160. border-radius: 28rpx;
  161. box-shadow: 0 4rpx 35rpx #d3d3d3;
  162. background-color: #fff;
  163. .box_top {
  164. display: flex;
  165. justify-content: space-between;
  166. .img {
  167. margin-right: 24rpx;
  168. width: 249rpx;
  169. height: 168rpx;
  170. border-radius: 8rpx;
  171. }
  172. .top_msg {
  173. display: flex;
  174. flex-direction: column;
  175. justify-content: space-between;
  176. flex: 1;
  177. font-size: 24rpx;
  178. color: #808080;
  179. overflow: hidden;
  180. .msg_title {
  181. font-size: 28rpx;
  182. font-weight: bold;
  183. color: #000;
  184. display: -webkit-box;
  185. -webkit-box-orient: vertical;
  186. -webkit-line-clamp: 2;
  187. overflow: hidden;
  188. }
  189. .msg_name {
  190. white-space: nowrap;
  191. overflow: hidden;
  192. text-overflow: ellipsis;
  193. }
  194. }
  195. }
  196. .box_bottom {
  197. display: flex;
  198. justify-content: center;
  199. align-items: center;
  200. width: 661rpx;
  201. height: 80rpx;
  202. border-radius: 8rpx;
  203. }
  204. .on {
  205. color: #fff;
  206. background-color: #007aff;
  207. }
  208. .off {
  209. color: #a6a6a6;
  210. background-color: #e5e5e5;
  211. }
  212. .nostart {
  213. color: #fff;
  214. background-color: #007aff;
  215. opacity: 0.3;
  216. }
  217. }
  218. }
  219. }
  220. </style>