index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="main-content">
  3. <view class="home-banner" :style="`height: ${globalData.navBarHeight}px `">
  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. <up-icon name="map" color="#fff" size="25"></up-icon>
  8. <text>{{ data.address }}</text>
  9. </view>
  10. <view class="home-banner-cente">金邻助家</view>
  11. <view class="home-banner-rigth">
  12. <!-- <up-icon name="bell" :size="25" color="rgba(46, 46, 46, 1)"></up-icon> -->
  13. </view>
  14. </view>
  15. <view class="home-box" :style="`margin-top: ${globalData.navBarHeight}px `">
  16. <view class="home-main">
  17. <view class="custom-swiper">
  18. <up-swiper :list="list3" indicator indicatorMode="line" circular></up-swiper>
  19. </view>
  20. </view>
  21. <view class="home-grid">
  22. <Client />
  23. </view>
  24. <view class="home-grid hot-box" v-if="userType === 1">
  25. <view v-for="(item, index) in hotList" :key="index + 'hot'" class="hot-item">
  26. <img :src="item" alt="" style="width: 100%;height: 160rpx;">
  27. </view>
  28. </view>
  29. <view class="home-g-bgc">
  30. <view class="home-grid2">
  31. <view class="serve-title hot-box-title" v-if="userType === 1">超值专区</view>
  32. <view class="hot-swiper">
  33. <up-swiper :list="ValueZone" :indicator="false" indicatorMode="line" circular></up-swiper>
  34. </view>
  35. </view>
  36. <view class="home-ranking home-grid2">
  37. <ServIces :leftList="leftList" :rightList="rightList" v-if="userType == 1"></ServIces>
  38. <RankingList v-if="userType === 2" />
  39. </view>
  40. </view>
  41. <up-loadmore style="margin-top: 40rpx;" :status="loadmoreInfo.status"
  42. :loadmoreText="loadmoreInfo.loadingText" :loadingText="loadmoreInfo.loadmoreText"
  43. :nomoreText="loadmoreInfo.nomoreText" @loadmore="handleLoadmore" v-if="userType == 1" />
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import {
  49. ref,
  50. reactive,
  51. onMounted
  52. } from 'vue';
  53. import {
  54. onLoad,
  55. onShow,
  56. onReachBottom
  57. } from "@dcloudio/uni-app";
  58. import RankingList from '@/pages/common/rankingList/index.vue';
  59. import ServIces from "@/components/Services/services.vue"
  60. import {
  61. Client
  62. } from "@/components/Client/new_file.vue"
  63. import {
  64. volunteerinfolist,
  65. } from "@/api/volunteerDetailsApi/details.js"
  66. import {
  67. slideshow
  68. } from '@/api/home.js'
  69. const total = ref(0)
  70. const listData = ref([])
  71. const rightList = ref([])
  72. const leftList = ref([])
  73. const userType = uni.getStorageSync('userType') //读取本地存储
  74. const globalData = ref({
  75. statusBarHeight: 47,
  76. navBarHeight: 91
  77. });
  78. const data = reactive({
  79. address: '重庆市',
  80. queryValue: ''
  81. })
  82. const list3 = ref([]);
  83. const ValueZone = ref([]);
  84. const hotList = ref([])
  85. // 分页
  86. const pages = ref({
  87. current: 1,
  88. pageSize: 10,
  89. total: 0
  90. })
  91. const loadmoreInfo = ref({
  92. status: 'loadmore',
  93. loadingText: '努力加载中...',
  94. loadmoreText: '点击加载更多~',
  95. nomoreText: '已经到底啦~'
  96. })
  97. // 加载更多
  98. async function handleLoadmore(e) {
  99. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  100. pages.value.current += 1;
  101. loadmoreInfo.value.status = 'loading';
  102. await getList();
  103. } else {
  104. loadmoreInfo.value.status = 'nomore';
  105. }
  106. }
  107. const getList = async () => {
  108. try {
  109. loadmoreInfo.value.status = 'loading';
  110. // 请求时传递分页参数
  111. const res = await volunteerinfolist({
  112. pageNumber: pages.value.current, // 当前页码
  113. pageSize: pages.value.pageSize // 每页大小
  114. });
  115. console.log(res, '>>>>>>>res');
  116. if (!res || !res.rows) {
  117. return;
  118. }
  119. // 判断是否已经到了最后一页
  120. if (pages.value.current >= Math.ceil(res.total / pages.value.pageSize)) {
  121. loadmoreInfo.value.status = 'nomore';
  122. } else {
  123. loadmoreInfo.value.status = 'loadmore';
  124. }
  125. // 将数据分成左右两列
  126. res.rows.forEach((item, index) => {
  127. index % 2 !== 0 ? leftList.value.push(item) : rightList.value.push(item);
  128. });
  129. pages.value.total = res.total;
  130. } catch (error) {
  131. leftList.value = [];
  132. rightList.value = [];
  133. loadmoreInfo.value.status = 'loadmore';
  134. pages.value.total = 0;
  135. console.error('Error fetching data:', error);
  136. }
  137. };
  138. onReachBottom(() => {
  139. if (pages.value.current < Math.ceil(pages.value.total / pages.value.pageSize)) {
  140. pages.value.current = pages.value.current + 1
  141. loadmoreInfo.value.status = 'nomore'
  142. getList()
  143. }
  144. })
  145. const getBanners = async () => {
  146. try {
  147. const res = await slideshow(7);
  148. if (res.code === 200 && res.data.picture) {
  149. list3.value = res.data.picture.split(',');
  150. }
  151. const value_res = await slideshow(8);
  152. if (value_res.code === 200 && value_res.data.picture) {
  153. ValueZone.value = value_res.data.picture.split(',');
  154. }
  155. const hot_res = await slideshow(11);
  156. if (hot_res.code === 200 && hot_res.data.picture) {
  157. hotList.value = hot_res.data.picture.split(',');
  158. }
  159. } catch (error) {
  160. console.log('error', error);
  161. }
  162. }
  163. onShow(() => {
  164. getList()
  165. getBanners();
  166. // 在 App.vue 中初始化
  167. uni.getSystemInfo({
  168. success: (res) => {
  169. const statusBarHeight = res.statusBarHeight;
  170. const navBarHeight = res.platform === 'android' ? 48 : 44 + res.statusBarHeight;
  171. globalData.value = { statusBarHeight, navBarHeight };
  172. console.log('statusBarHeight', statusBarHeight, navBarHeight);
  173. }
  174. });
  175. })
  176. </script>
  177. <style scoped lang="scss">
  178. .main-content {
  179. background: rgba(255, 255, 255, 1);
  180. .home-banner {
  181. display: flex;
  182. align-items: flex-end;
  183. justify-content: space-between;
  184. // background: rgba(255, 255, 255, 1);
  185. // background-color: #ED806A;
  186. background-color: rgba(221, 60, 62, 1);
  187. 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);
  188. padding: 20rpx 16rpx;
  189. color: #fff;
  190. position: fixed;
  191. top: 0px;
  192. left: 0px;
  193. right: 0;
  194. z-index: 99;
  195. }
  196. .home-banner-left {
  197. display: flex;
  198. align-items: center;
  199. width: 30%;
  200. }
  201. .home-banner-center {
  202. flex: 1;
  203. font-size: 38rpx;
  204. }
  205. .home-banner-rigth {
  206. width: 30%;
  207. }
  208. .home-main {
  209. padding: 12px 16px 0;
  210. }
  211. .home-ranking {
  212. padding: 24rpx 16px;
  213. }
  214. }
  215. .hot-box-title {
  216. padding: 0 32rpx;
  217. }
  218. .hot-swiper {
  219. padding: 24rpx 32rpx 0;
  220. }
  221. .hot-box {
  222. padding: 24rpx 32rpx;
  223. display: grid;
  224. grid-template-columns: repeat(2, 1fr);
  225. gap: 8rpx;
  226. .hot-item {
  227. // padding: 32rpx 16rpx;
  228. // border-radius: 10rpx;
  229. }
  230. }
  231. .home-grid2 {
  232. margin-bottom: 32rpx;
  233. background: #fff;
  234. padding: 12px 0;
  235. border-radius: 8px;
  236. }
  237. .home-g-bgc {
  238. background: #f7f7f7;
  239. padding: 24rpx;
  240. }
  241. </style>