school_represent.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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="handlebtn">
  10. <uni-icons type="person" size="20" color="#fff"></uni-icons>
  11. <view class="btn_text">母校代言</view>
  12. </view>
  13. </view>
  14. <!-- 列表区域 -->
  15. <view class="list">
  16. <!-- 每一个校友区域 -->
  17. <view class="list_box" v-for="item in dataList" :key="item.id" @click="clickItem(item.id)">
  18. <image class="img" mode="aspectFill" :src="item.image" />
  19. <view class="name">{{ item.name }}</view>
  20. <view class="desc">{{ item.periodName }}届毕业生</view>
  21. </view>
  22. </view>
  23. <!-- 没有数据时展示的页面 -->
  24. <noData v-if="!dataList.length"></noData>
  25. </view>
  26. </template>
  27. <script setup>
  28. import { onLoad, onReachBottom } from '@dcloudio/uni-app'
  29. import { ref } from 'vue'
  30. import { getEndorsePage } from '@/api/index.js'
  31. // 输入框绑定数据
  32. const inputValue = ref('')
  33. // 当前页
  34. const currentPage = ref(1)
  35. // 每页多少条
  36. const pageCount = ref(8)
  37. // 总条数
  38. const total = ref(0)
  39. // 列表数据
  40. const dataList = ref([])
  41. onLoad(() => {
  42. // 获取母校代言分页数据
  43. getData()
  44. })
  45. // 页面触底触发的回调
  46. onReachBottom(() => {
  47. if (total.value > dataList.value.length) {
  48. currentPage.value++
  49. getData()
  50. } else {
  51. uni.showToast({
  52. title: '没有更多数据了~~',
  53. icon: 'none'
  54. })
  55. }
  56. })
  57. // 获取母校代言分页数据
  58. const getData = async () => {
  59. let data = {
  60. currentPage: currentPage.value,
  61. pageCount: pageCount.value,
  62. keyword: inputValue.value
  63. }
  64. const res = await getEndorsePage(data)
  65. // console.log(res)
  66. dataList.value = [...dataList.value, ...res.data.list]
  67. total.value = res.data.totalCount
  68. }
  69. // 点击母校代言按钮的回调
  70. const handlebtn = () => {
  71. uni.navigateTo({
  72. url: '/pages/school_form/school_form'
  73. })
  74. }
  75. // 输入框失去焦点回调
  76. const handleBlur = () => {
  77. currentPage.value = 1
  78. dataList.value = []
  79. getData()
  80. }
  81. // 点击每一项的回调
  82. const clickItem = (id) => {
  83. uni.navigateTo({
  84. url: `/pages/school_represent_detail/school_represent_detail?id=${id}`
  85. })
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .container {
  90. padding: 20rpx 18rpx;
  91. min-height: 100vh;
  92. font-size: 28rpx;
  93. .top {
  94. display: flex;
  95. justify-content: space-between;
  96. .top_search {
  97. display: flex;
  98. align-items: center;
  99. padding: 0 25rpx;
  100. width: 491rpx;
  101. height: 80rpx;
  102. border-radius: 145rpx;
  103. border: 2rpx solid #e5e5e5;
  104. background-color: #f5f5f5;
  105. .input {
  106. margin-left: 20rpx;
  107. font-size: 28rpx;
  108. }
  109. }
  110. .top_btn {
  111. display: flex;
  112. align-items: center;
  113. justify-content: center;
  114. padding: 18rpx;
  115. width: 196rpx;
  116. height: 70rpx;
  117. color: #fff;
  118. font-size: 20rpx;
  119. border-radius: 68rpx;
  120. background-color: #007aff;
  121. .btn_text {
  122. margin-left: 10rpx;
  123. }
  124. }
  125. }
  126. .list {
  127. display: grid;
  128. grid-template-columns: repeat(2, 1fr);
  129. gap: 20rpx 10rpx;
  130. margin-top: 30rpx;
  131. .list_box {
  132. width: 347rpx;
  133. height: 515rpx;
  134. border-radius: 12rpx;
  135. box-shadow: 0 4rpx 8rpx rgba(212, 212, 212, 0.32);
  136. overflow: hidden;
  137. .img {
  138. width: 347rpx;
  139. height: 385rpx;
  140. border-radius: 12rpx;
  141. }
  142. .name {
  143. margin-left: 20rpx;
  144. margin-top: 10rpx;
  145. font-size: 32rpx;
  146. font-weight: bold;
  147. }
  148. .desc {
  149. margin-left: 20rpx;
  150. margin-top: 10rpx;
  151. font-size: 24rpx;
  152. }
  153. }
  154. }
  155. }
  156. </style>