index.vue 5.0 KB

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