index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view class="main-content ">
  3. <view class="home-banner">
  4. <view class="home-banner-left">
  5. <img src="/static/serverImg/home/address.png" alt=""
  6. style="width: 41.67rpx;height: 41.67rpx;margin-right: 8rpx;">
  7. <text>{{ data.address }}</text>
  8. </view>
  9. <view>
  10. <up-icon name="bell" :size="25" color="rgba(46, 46, 46, 1)"></up-icon>
  11. <!-- <img src="/static/serverImg/home/message.png" alt="" style="width: 50rpx;height: 50rpx;"> -->
  12. </view>
  13. </view>
  14. <view class="home-main">
  15. <view class="custom-swiper">
  16. <up-swiper :list="list3" indicator indicatorMode="line" circular></up-swiper>
  17. </view>
  18. </view>
  19. <view class="home-grid">
  20. <Client />
  21. </view>
  22. <!-- <view class="home-grid hot-box">
  23. <view v-for="item in hotList" :key="item.key" class="hot-item">
  24. <view>
  25. <view>{{item.name}}</view>
  26. <view>{{item.text}}</view>
  27. </view>
  28. <up-icon :name="listItem.iconName" :size="22"></up-icon>
  29. </view>
  30. </view> -->
  31. <view class="home-ranking">
  32. <ServIces :leftList="leftList" :rightList="rightList" v-if="userType == 1"></ServIces>
  33. <RankingList v-if="userType === 2" />
  34. </view>
  35. <up-loadmore style="margin-top: 40rpx;margin-bottom: 40rpx;" :status="loadmoreInfo.status"
  36. :loadmoreText="loadmoreInfo.loadmoreTex" :loadingText="loadmoreInfo.loadingText"
  37. :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" />
  38. </view>
  39. </template>
  40. <script setup>
  41. import {
  42. ref,
  43. reactive,
  44. onMounted
  45. } from 'vue';
  46. import {
  47. onLoad,
  48. onShow,
  49. onReachBottom
  50. } from "@dcloudio/uni-app";
  51. import RankingList from '@/pages/common/rankingList/index.vue';
  52. import ServIces from "@/components/Services/services.vue"
  53. import {
  54. Client
  55. } from "@/components/Client/new_file.vue"
  56. import {
  57. volunteerinfolist,
  58. } from "@/api/volunteerDetailsApi/details.js"
  59. import {
  60. slideshow
  61. } from '@/api/home.js'
  62. const listData = ref([])
  63. const leftList = ref([])
  64. const rightList = ref([])
  65. const userType = uni.getStorageSync('userType') //读取本地存储
  66. const data = reactive({
  67. address: '重庆市永川区',
  68. queryValue: ''
  69. })
  70. const list3 = ref([]);
  71. const hotList = [{
  72. key: 1,
  73. icon: '/static/img/构建.png',
  74. name: '专业辅导',
  75. text: '与家长协同制定成长计划',
  76. },
  77. {
  78. key: 2,
  79. icon: '/static/img/构建.png',
  80. name: '暖心陪护',
  81. text: '倾听烦恼、缓解孤独感',
  82. },
  83. ]
  84. const hotList2 = [{
  85. key: 1,
  86. icon: '/static/img/构建.png',
  87. name: '专业辅导',
  88. text: '与家长协同制定成长计划',
  89. },
  90. {
  91. key: 2,
  92. icon: '/static/img/构建.png',
  93. name: '暖心陪护',
  94. text: '倾听烦恼、缓解孤独感',
  95. },
  96. {
  97. key: 3,
  98. icon: '/static/img/构建.png',
  99. name: '专业辅导',
  100. text: '与家长协同制定成长计划',
  101. },
  102. {
  103. key: 4,
  104. icon: '/static/img/构建.png',
  105. name: '暖心陪护',
  106. text: '倾听烦恼、缓解孤独感',
  107. },
  108. ]
  109. // 分页
  110. const pages = ref({
  111. current: 1,
  112. pageSize: 10,
  113. total: 0
  114. })
  115. const loadmoreInfo = ref({
  116. status: 'loadmore',
  117. loadingText: '努力加载中...',
  118. loadmoreText: '点击加载更多~',
  119. nomoreText: '已经到底啦~'
  120. })
  121. // 加载更多
  122. async function handleLoadmore(e) {
  123. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  124. pages.value.current += 1;
  125. loadmoreInfo.value.status = 'loading';
  126. await getList();
  127. } else {
  128. loadmoreInfo.value.status = 'nomore';
  129. }
  130. }
  131. const getList = async () => {
  132. try {
  133. loadmoreInfo.value.status = 'loading';
  134. // 请求时传递分页参数
  135. const res = await volunteerinfolist({
  136. pageNumber: pages.value.current, // 当前页码
  137. pageSize: pages.value.pageSize // 每页大小
  138. });
  139. console.log(res, '>>>>>>>res');
  140. if (!res || !res.rows) {
  141. return;
  142. }
  143. // 判断是否已经到了最后一页
  144. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  145. loadmoreInfo.value.status = 'nomore';
  146. } else {
  147. loadmoreInfo.value.status = 'loadmore';
  148. }
  149. // 将数据分成左右两列
  150. res.rows.forEach((item, index) => {
  151. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  152. });
  153. pages.value.total = res.total;
  154. } catch (error) {
  155. leftList.value = [];
  156. rightList.value = [];
  157. loadmoreInfo.value.status = 'loadmore';
  158. pages.value.total = 0;
  159. console.error('Error fetching data:', error);
  160. }
  161. };
  162. const getBanners = async () => {
  163. try {
  164. const res = await slideshow(7);
  165. if (res.code === 200 && res.data.picture) {
  166. list3.value = res.data.picture.split(',');
  167. }
  168. } catch (error) {
  169. console.log('error', error);
  170. }
  171. }
  172. onReachBottom(() => {
  173. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  174. pages.value.current = pages.value.current + 1
  175. loadmoreInfo.value.status = 'nomore'
  176. getList()
  177. }
  178. })
  179. onShow(() => {
  180. getList()
  181. getBanners();
  182. })
  183. </script>
  184. <style scoped lang="scss">
  185. .main-content {
  186. .home-banner {
  187. display: flex;
  188. align-items: center;
  189. justify-content: space-between;
  190. background: rgba(255, 255, 255, 1);
  191. box-shadow: 0rpx 0rpx 0rpx rgba(0, 0, 0, 0), 0rpx 0rpx 0rpx rgba(0, 0, 0, 0), 0rpx 2.08rpx 4.17rpx rgba(0, 0, 0, 0.05);
  192. padding: 20rpx 16rpx;
  193. }
  194. .home-banner-left {
  195. display: flex;
  196. align-items: center;
  197. }
  198. .home-main {
  199. padding: 12px 16px;
  200. .custom-swiper {}
  201. .home-grid {
  202. margin-bottom: 32px;
  203. }
  204. }
  205. .home-ranking {
  206. padding: 12px 16px;
  207. }
  208. }
  209. .hot-box {
  210. padding: 12px 16px;
  211. display: grid;
  212. grid-template-columns: repeat(2, 1fr);
  213. /* 3 列,每列等宽 */
  214. gap: 32rpx;
  215. .hot-item {
  216. .hot-item {
  217. padding: 12px 16px;
  218. }
  219. }
  220. }
  221. </style>